Backpropagation Neural Networks

Backpropagation Neural Networks

with the User Interface. Design, Teach and Use Neural Networks. Tutorial with examples (stock market trading).


Visibility is very important for this site. If you like it please link to this URL.

Cortex ver.5.0 Tutorial.

A Backpropagation Neural Networks Application.

Limited time offer for students: Cortex ($14.95), Cortex Scripting Language ($14.95) and Cortex API ($7.95) at just $7.95!

Contents

What is Cortex

Neural Networks: Features

Installation

Uninstallation

Registration

Cortex Neural Networks

Databases

What is "Cortex"?

Neural Networks

Feedforward Backpropagation Neural Networks, with an easy to use interface and large number of additional features, like charting, for example.

Genetic computations

Genetic computations, when applied to neural networks, result in a powerfull data analysis tool. Add here the scripting language, that gives you an ability to write your own genetic algorythms...

Kohonen Self Organizing Maps

SOM are available from scripting language. With SOM you can perform network teaching and to use a resulting net for data classification.

Scripting

A built-in scripting language, that allows you to perform routine tasks automatically. Loading and converting data, optimizations, creating charts, as well as web pages containing these charts, and much more can be created by scripts, with no interference from the user.

Extras

Additional features, that include databases, image processing, HTML/XML based forms and data import-export.

This tutorial illustrates the use of UI (non-scripting) features of Cortex. For the scripting language, see scripting tutorial and scripting reference guide.

Neural Networks: Features

Let's outline the steps that we need to take, to use the Neural Network as the data analysing tool (I assume that you are already familiar with the Neural Networks theory). The Cortex will help you to do these steps faster and with less frustration, something you may want to keep in mind while reading.

1. First of all, we need data, anything from stock quotes to the sound patterns for a speech recognition software. The only criteria is - the data must be sequential (a table with numbers in it's cells is a good example).

2.These data need to be fed to the neural network one row in a time. Let's say, we want to do stock trading. One row of data is simply not enough! You need a HISTORY, not just a current OHLC information. Can you predict the tomorrow's stock price based on today's price? Not unless you have the "historical price" information for at least couple of prior days.
Therefore, to use a "one row in a time" approach, we need to make sure that this row contains all the historical data we need, for example, it can contain the today's data in the column one, the yesterday's data in a column two, and so on. This kind of file is called (at least in this tutorial) a lag-file, it can be automatically generated by the "Cortex" program. As a mater of fact, it can be either generated by the Cortex, OR by its scripting language, if you need to have more flexibility (for example, having Close, you may want to calculate moving average of Close, as well as couple of indicators that are used in stock trading, and only then create lags of this - advanced - input.

3. We need to choose a Neural Network configuration - number of neurons, activation type and so on. The "Cortex" presents a simple visual interface, that allows to do just that. (Again, you can use scripting language to do it in automated way. When you only need one neural network, it does not make a lot of sense, but sometimes, you need to try many different combinations of input data, with different networks - automating this task is a real time saver).

4. We need to teach the Neural Network. To do it, we run it against part of the data in the "backpropagation" mode, using another part of the data to test the performance of the net. The first part of the data will be (again - in this tutorial) called a learning data set, the second part is called a "testing" data set.
As the "Cortex" is fine-tuning the Neural Network, it is displaying both values and charts for learning and testing errors.

5. After the Neural Network training is completed, we can use it on the "real" data. For example, we may teach it on the stock qoutes for the last year, and then we expect it to predict the tomorrow's price, based on the price for today, and couple of days of history.

To do it we need (again) to generate a lag file, and to run the data rows we want to analyze through the Neural Network. The resulting file will have the following columns:

Columns for the input. What we present to the Neural Network.
Columns for the output - what we were trying to predict.
And the prediction: the column(s), generated by the Neural Net.

Here is an example:

Inputs Output Predicted
No Close-1 Close-2 Close-3 Close-4 Close NN: Close
0 5.150000 5.180000 5.120000 5.100000 5.200000 5.070705
1 5.180000 5.120000 5.100000 4.950000 5.150000 5.094328
...

As was already mentioned, the Cortex Neural Network Application does just that - and much more.

6. Finally, after the Neural Network is created, we need to somehow call it from the trading software of our choice: TradeStation, MetaStocks, MetaTrader... In this article you will find a working system that is created, step by step, and then moved from Cortex to the trading platform, capable to place real trades with the real brocker.

Installation.

Download the Cortex archive.

Some programs that you can download from this site can work together. If you want (strongly recommended) this kind of functionality to be available, you should create a common folder, called (recommended) S_PROJECTS, and to unzip all software in this folder. The sub-folders will be created for you automatically.

When specifying options in your Winzip software, make sure that all subdirectories (subfolders) are restored. Usually it is the default setting for the WinZip. Installation is complete.

On 20-May-2003, the S.Projects changed the passwords for all the software. If you have purchased the software before this date, we strongly advice you to make a backup copy of the entire folder, prior to re-downloading.

Uninstallation.

Delete the folder containing the Cortex files.

Registration

Cortex is distributed as feature-limited shareware.

If you choose to register the Cortex software, you will need to enter the password (provided in the e.mail that you will receive after the registration) into the registration prompt.

Cortex Neural Networks

The following chapters will walk you through a simple example of using the "Cortex" Neural Networks software - we are going to build the stock price predicting net.

Note: This example is to teach you how to work with Cortex, not how to trade!

We also have a tutorial on the Scripting language, that can make your life (for example, finding the best NN structure) much easier.

Run the Cortex.exe. From the main menu select File - New NN File.

The program comes with three sample data file groups - genz.*, msft.* and eurusd.*. First two contain data for Genzyme and Microsoft stocks, the third one contains FOREX (Foreign exchange) quotes for conversion between US dollar and EURO.

From the NN point of view, there is no difference between stock market and FOREX (except, stocks sometimes split), whatever you learn for one area, usually applies to the other.

Click the "..." button to open the data/stocks/genz.txt file.

Note that you can specify what are the start and end line patterns, and how many lines should we skip before and after the start line pattern. Use it if the data are in the middle of the text file (for example, the file has a header and a footer).
For this example, leave the first field blank.

If you look inside the GENZ.TXT file, that you have received with the Cortex archive, you will notice that the last line has nothing to do with the stocks - it is some kind of a commercial. This is exactly the way it looked when I got this file from the Yahoo quote server. To deal with the problem (we do not want to feed THESE data to the program!), copy this last line, or at least its beginning, and paste it to the "End line" field of the Input dialog. Now the program will stop extracting the data, when it finds the string you provided.

Important note: the stock quote file that I have downloaded from the Internet contains newest data FIRST. The NN (as many other data analyzing packages) expects the newest data LAST. So we need to click the "Reverse" checkbox to make sure data arrays are reversed before we do the processing.

Also note that no mater if the "Reverse" is checked or not, the resulting file that the program will produce, will have records in the same order as the original file had. This way if you have some other program that can work with stock price file having new data at the beginning, it will also be able to work with whatever output we produce with Cortex. Also it is much less confusing, especially when you work with the sequence of files.

What that means? Lets say you have a GENZ.TXT file. You checked the "Reverse" box, and then (see below for details) you clicked "Generate LAG file". The resulting lag file will still be reversed. But if you select Date and Close, and click Chart, the program will load the data, and then reverse them.

To put it differently, "reverse" checkbox only works for the current tab in a dialog box. To have it at the next tab, check it there.

Still, if you want, you can use the scripting language instead, it will give you the full control over the data.

Click the "Select fields...". The first (after we found the start pattern and skipped extra lines) line will be broken into the column names and presented in the list box for inputs and outputs.

Select "Adj. Close*" both for the input and output. We are going to use past values of the stock closing price, to predict future values.

By the way, "adj" means "adjusted, the file I have is adjusted for stock splits. Some data sources do not have this nice feature - what shall we do then?

One of the possible solutions is to use the Built-in scripting language to pre-process the file.

As we are trying to create a network to PREDICT the future values for the line (represented by data in genz.txt), we need to provide the input in the form of HISTORICAL PATTERNS - not only today's data, but yesterdays, and so on.

The reason we need it is simple. Can we predict the future value of the stock price by the current value ONLY? No. We need to know what the price was yesterday, and the day before yesterday - we need to know what is going on with this price.

The "Adj. Close*" is now selected in the list boxes. We are about to generate what is called a lag file. The idea of the lag file is to represent today's data in the same table, side by side with the data for yesterday and so on. Press the "lag file" button. You will have the file with .lgg extention containing something like:

No Close Close-1 Close-2 ...
10 5.200000 5.150000 5.180000 ...
11 5.150000 5.180000 5.120000 ...
12 5.180000 5.120000 5.100000 ...

As you can see, the first value in Close-1 column was removed, and the entire column moved up. For the Close-2, TWO first values were removed and so on. Therefore, each line of this new file contains data for the current day AND data for nine previous days.

Let's select the new inputs. Click on the "Select fields" again, and select "Adj. Close*-1", "Adj. Close*-2"... "Adj. Close*-9" as inputs and "Adj. Close*" as output. This way we will be using nine PREVIOUS days to predict the coming price.

Click on the "Network" tab.

As you can see, you can specify the number of layers, number of neurons in hidden layers (see Introduction to Neural Networks for details on what the elements of a Neural Net are), one of two activation functions (standard for almost any NN package), and stop criteria, if you want the learning process to stop automatically.

For this particular task let's select 7 neurons in the hidden layer.

Click on the "Processing" tab.

Here you can specify one of two ways of breaking the data to the "learning" and "testing" parts (see Introduction to Neural Networks for details). You can use first N records (patterns) as a "learning" material and the rest - as a "testing" data. Or you can randomly select N % of the data.

The random selection does not work with the prediction - it is called cheating ;) But it works well when you are trying to do a line fitting. So for this example we will choose the "First N records" option.

How do we know how many records we have in our .lgg file? We can open the file in a text editor and find out. Or we can click the button on the right from the data entry field. I got 1228 records, and I have decided to use 1000 of them for "learning", and the rest - for the "testing".

The "adjust range" combo box is important if there is a chance for our "test" data to get out from the range where the "learning" data are. To compensate, we can extend the range. Let's leave it at 1.0 as in our case the last 228 records are not out of range of the first 1000.

Click the "Learning" tab, select all check boxes and press Run. The Neural Network will begin the learning process. The number of epochs (how many times the entire data set was presented to the network), and the best (smallest) learning and testing errors will be displayed.

As the learning continues, the error (representing the difference between the actual output of the network and the desired output) is decreasing. When we decide that it is small enough (and we can always go back and continue the training) we click "Stop" and go to the "Apply" tab.

The "Apply" tab is an exact copy of a "Input" tab except for the "Chart" and "Apply" buttons. The functionality is different, however.

Click the "..." and open the .LGG file. Select same fields you used as the inputs and outputs.

When you press the "Apply" button, the file with the .apl extention is generated. It contains all data that the input contained, plus extra fields for the output, generated by the Neural Network.

Finally, switch to the "Output" tab, click the "..." and open the .APL file.

Select the No (record number) as the input and Close and NN:Close as outputs - we are going to plot the Close and Predicted Close together on the same chart, to be able to compare them visually.

Use the "Chart" button, to plot the desired output (Close) vs. the output, produced by the Neural Net.

The following image is produced by the undertrained Neural Net. The approximation is not very poor (for a one-day prediction). If you continue training, you will get better results.


Databases

Cortex uses SQLite database engine - fast, reliable and file based, which means, you don't have to mess with drivers. You can use them through the UI, to keep data organized. Or you can access databases from Cortex scripting language.

Note: for a complete list of available SQL commands, see the documentation at SQLite home page.

The tutorial below requires some basic knowleges of SQL and relational databases, but it has nothing one cannot learn in an hour or two by searching Google.

Create / modify database

From the main menu, select File - Create / modify database.

Click the "..." button, make sure you are in "databases" folder (whereever you prefer to keep your databases), type in the database file name (in our example, it is "photo.db") and click OK. The file photo.db is created.

Cortex uses a free-style database system, it does not imply any limitations on tables and fields you use. So the first thing we need to do is to decide what information the database will contain, and what the structure of a database should be.

For this example, we are going to create a simple photo album. It will have information about location of image files on disk, names of images, and more or less detailed (multiline, perhaps) descriptions for each image. It will also contain the location information: Country, State and City, where a photo was taken.

There are few ways of organizing the data, we will use a relational approach. The location information (Country, State, City) will be kept in the Places table, while the image information will be kept in Images table.

First, let's create the Images table. In the bottom window of the dialog, type the SQL statement (note the semicolon at the end):

CREATE TABLE Images(ImageName TEXT, ImageDescription TEXT, ImageLocation TEXT, PlaceId INTEGER);

Click "Run", and the table will be created. The table info will appear in the upper (non-editable) window:

type = table
name = Images
tbl_name = Images
rootpage = 2
sql = CREATE TABLE Images(ImageName TEXT, 
	ImageDescription TEXT, ImageLocation TEXT, 
	PlaceId INTEGER);

Note that the PlaceId field is used to refer to the location information in the Places table. This is the way relational databases work; using this approach we can reduce the size of our database (by not typing "USA, Utah, Salt Lake City" over and over again), and to reduce errors (by not typing "USA, Utah, Salt Lake City" in one place and "USA, UT, Salt-Lake-City" in the other, which are two totally different places from the point of view of a database engine).

Creating Places table is a bit trickier, as it contains a field with unique value: PlaceId. To enforce its uniqueness, we make it INTEGER PRIMARY KEY (AUTOINCREMENT is optional, but if we want to make sure deleted values are not reused, we add this parameter, too).

CREATE TABLE Places( PlaceId INTEGER PRIMARY KEY AUTOINCREMENT, Country TEXT, State TEXT, City TEXT);

Now we want to enforce uniqueness of each Country-State-City combination. To do so, we create an index, called PlaceIndex:

CREATE UNIQUE INDEX PlacesIndex ON Places(Country,State,City);

The resulting database looks like:

type = table
name = Images
tbl_name = Images
rootpage = 2
sql = CREATE TABLE Images(ImageName TEXT, 
	ImageDescription TEXT, ImageLocation TEXT, 
	PlaceId INTEGER)
-------------
type = table
name = Places
tbl_name = Places
rootpage = 3
sql = CREATE TABLE Places(PlaceId INTEGER PRIMARY 
	KEY AUTOINCREMENT, Country TEXT, State TEXT, 
	City TEXT)
-------------
type = index
name = PlacesIndex
tbl_name = Places
rootpage = 5
sql = CREATE UNIQUE INDEX PlacesIndex ON 
	Places(Country,State,City)
-------------

Note, this is only one of few possible ways "to skin the cat". For example, you can keep Country-State-City information in three different cross-linked tables, or in the same table with Images. You can (and probably should) add a field with keywords, like "winter, sunsets, outdoors" so that you can perform complex queries later, and so on.

Edit table records

From the main menu, select File - Edit table records... Select the database and a table you want to edit.

As expected, the table comes up empty:

From the toolbar, click the "Insert" button. A new empty record will be inserted to the table. Double-click the field you want to edit (the leftmost field contains the row number and cannot be edited: it is not part of the table. Also you cannot edit INTEGER UNIQUE fields, they are taken care of by the system). The in-place editor will pop up:

To close the in-place editor, click outside its window, or click "Save" button on the toolbar, or click "Cancel" button.

The use of "Delete", "Edit", "Save" and "Save all" buttons is the same you usually expect from Windows applications, except they work without asking for a confirmation.

Importing image metadata

As we are going to create a photo database, regardless the fact, that it is just an example, lets do it right. Images (photos) may contain so called meta data, like title, keywords or (C) information. We are going to extract it from image files we have and to store them in our database. Once again, this is just an example, skip it, it you do not care about image meta information.

Before we import meta data, we need to have something to import from. By metadata, we mean keywords, author information, image size, camera settings and so on. This information is, or at least, it can be, part of the image, and modern image processing programs, like Photoshop, allow you to edit it. Also, some of these fields are filled by the digital cameras (camera settings, image size, sometimes even GPS position...)

Let's say, we have a directory (with or without subdirectories), containing our collection of images. We have entered there (to the images, using Photoshop or similar software) keywords, and some other important information, and we do not want to retype it "by hand" while filling our database. Here are the steps to automate this task.

First of all, let's use a freeware, and, probably, the most sophisticated metadata extracting program, exiftool.
If, by some reason, that link to a (third-party, we do not control it) software becomes invalid, you can always find it in Google, using "exiftool" keyword.

The exiftool comes with detailed manual, also, some details you can find in DigitalSell tutorial. For now, let's use its command line version for Windows, that produces a file, containing a) file name b) title and c) keywords (the first is the name of an image, and the second and third are values of the corresponding fields, that are extracted from that image):

C:\exiftool\exiftool.exe -p "$directory\$filename --- $Title --- $Keywords" -m -r -s -ext .jpg -ext .tif C:\photo > C:\exiftool\exiftool.txt

Just keep in mind, that the command line above is wrapped by your browser, when you type it in a Windows command prompt (Start-Run-"cmd"), it should be a single line.

All information, extracted from all files in C:\photo directory will be written into the "exiftool.txt" file:

C:\photo\Canada\BC\BC_001.tif --- BC trip --- ocean, sky
C:\photo\Canada\BC\BC_002.tif --- BC trip --- ocean, sky
...

Note, that I used " --- " as a field separator, you can, to some extent, change it, of course.

Now, that we have the information to import, we need to select a Cortex database table to import into.

From the main menu, select File - Edit table records... That will bring up the table you want to edit.

After the table is opened, from the main menu, select Edit - Import data...

The "import from" field allows you to select a file to import from, then, just below it, you will see a small fragment of this file, allowing you to see its structure.

Then, below this read-only "preview" field, you can see the SQL editor. SiteBuilder allows you to specify placeholders, containing field numbers. In the image above, the ###1### is the placeholder for the first field of the "import from" file, which is the image file name. The ###3### is a placeholder for the 3rd field, which is "keywords".

Note the "WHERE" part of the SQL. The SiteBuilder program will read records from "import from" file sequentially, then it will replace placeholders in the SQL with field values, and then it will run SQL against the database. The "WHERE" part is used to decide, which record to update.

Also note the "separator" field. It is used to parse the "import from" records into separate fields.

Compacting redundant keywords

In the previous chapter, you learned how to import data from a text file to the table's field. However, sometimes these fields already have some data. Obviously, sometimes you don't want to overwrite them, but would prefer adding new data to existing ones. For example, if the field contains keywords "ocean, sea", and you are importing keywords "nature", the statement above will give you just "nature" as the field's value, while "ocean, sea" will be lost.

SQL allows to join strings by using something like this:

UPDATE Images 
	SET keywords = keywords || ',' || '###3###' 
	WHERE ImageLocation LIKE '###1###';

However, here is a problem: sometimes both the field and a new data we want to import, contain the same keyword (we are using keywords as an example here, as this is one of the most frequent uses of this feature).

Let's say we have a field, containing "ocean, sea", and we want to import "ocean, nature" in it. As the result, we will get a duplication: "ocean, sea, ocean, nature".

To remove duplicates (assuming the field contains comma separated keywords):

From the Main menu, select Edit - Compact fields...

Select fields you want to "compact" (remove duplicated keywords within the field) and click OK.

Exporting image metadata

By exporting meta data, we mean taking the information from Cortex's database (perhaps, after we edited it), and writing it back to the corresponding images.

Cortex does not have a menu option for this operation, and it can only be performed using scripting language.

The idea is to generate a command (.BAT) file, that is calling exiftool for every image we want. Then we run this command file (by double-clicking it in the Explorer, or from Windows command prompt), and it does the rest of the job.

Import from directory

To be done

Subtract directories

To be done

Using Viewer.

Viewer can be used to preview image files, stored in the database. It can be accessed from View - Show Viewer (Hide Viever to exit the mode), and when activated, will show the preview of a specified field of a table every time you change the current selection.

The field selected should, of course, contain a valid path to the image. As the path can be partial (USA\Colorado\image_01.jpg instead of c:\Photo\USA\Colorado\image_01.jpg), we can optionally provide a path prefix (for the example above, c:\Photo).

As the field may point to files of different types, including ones you cannot preview, or ones that are too slow to preview (Word documents as an example), you can provide a semicolon-separated list of file extentions, to filter out files you don't want to preview.

Also, in case of large images, you will only see upper-left corner of it, as the rest wouldn't fit on screen. To solve this problem, you can specify the viewer.htm file, one that handles scaling (included in the archive).

As the result, you will be able to see images as you scroll through them:


To get fully enabled version of the Cortex, you need to register.

Limited time offer for students: Cortex ($14.95), Cortex Scripting Language ($14.95) and Cortex API ($7.95) at just $7.95!

State of Power Tutorial

Hypnosis Tutorial

NLP Tutorial

Working with the Future Tutorial

Hypnotic Inductions

Working with Money

Working with Habits

Manipulation Tutorial


Karate online tutorial

Chi Gun online tutorial

Tai Chi 24 forms online tutorial

Tai Chi 40 forms online tutorial

Tai Chi 108 forms online tutorial

Tai Chi Chi Gun 18 forms online tutorial

Chi Gun (Dao In) Heart and Blood Vessels 8 forms online tutorial

Chi Gun (Dao In) Kidneys 8 forms online tutorial

Joints Gymnastics, Chi Gun warm-up online tutorial

Chi Gun tao of Dr. Shi online tutorial


Sore back treatment

Headache Relief Pressure Points Tutorial


Making a small profitable web site


Neural Networks for stock and FOREX trading

Thumbnails Generator

Calendar Creator

Learn Touch Typing


Flow Charts and decision trees for web sites and presentations

Another Flow Charts Designer

Stock trading - technical analysis

Leaving already? Please let us know why!
It is a mater of life and death for us, but will only take 20 seconds for you.
No personal info collected.
Proceed...
NLP, Hypnosis, Power, Manipulation Tai Chi, Chi Gun Neural Networks
Stock and FOREX trading: full cycle, steps-by-step.
Habits Management Karate tutorial

Sore back treatment Calendar Creator
Building a small profitable site Joints Gymnastics Another Flow Charts Designer
Profitable web site in 9 days
Flow charts for Presentations and Web

Shareware Directory
Touch Typing: how fast can you learn it? Web programming : Perl, XML Stock and FOREX Trading

Home


neural networks stock prediction
The Cortex neural networks software that you can download from this site comes with the network trained to predict the price of a stock.

neural networks download
Download the Cortex neural networks software from this site.

free neural networks software
The Cortex neural networks software is feature limited, however you can use even a free version to solve many practical tasks.

tutorial on neural networks
On this site you will find both the tutorial on the neural nets and the user guide for the Cortex program, the easy to use and powerfull neural networks software.

neural network free software
Download and try the Cortex program, the easy to use and powerfull neural networks software.

stock market neural network
The Cortex neural networks software works with stock data as with any other data. The Trader stock trading simulator can use these neural networks to generate trading signals.

neural network tool box
The Cortex neural networks software provides you with the easy to use interface, allowing to create, teach and use the Neural Networks with your data.

application data mining
The Cortex neural networks software can be used to create the neural networks, that can become part of the custom data mining tools.

network neural programming
The software that you find on this site allows seamless neural network programming, it includes both creating neural networks and teaching them using the feedforward backpropagation algorythm.

data mining job
Neural networks can be used as a part of a data mining software. Their job in this tast may differ from identifiying binary or stored in tables data patterns, to suggesting the most promicing approach to a search.

application data mining
"Cortex", the neural networks package, may, to some extent, be considered as a data mining tool.

genetic computations software
Cortex allows you to perform genetic computetions using neural networks. You can create "mutations" in neiral networks, find winners, and perform "breeding" in the winning part of a population. Evolutionary computations illustrated in the articles on this site.

Kohonen software
Cortex has built-in Kohonen Self Organizing maps. You can teach the map, visually control the result, use resulting map and create a chart using claster-related colors. As SOM software, Cortex implements simplest rectangular Kohonen map. However, not every self organizing map software will allow you to build external circles to perform optimizations.

Stock market neural network software
This is the most interesting topic. Can neural networks be used to perform trading on the stock market? We have few examples on this site. We use Feedforward Backpropagation neural network software together with genetic algorithms and even wth SOM.