Borrador del Proyecto de Ley de Coordinación y cooperación entre la justicia indígena y la jurisdicción ordinaria
DISPOSICIONES GENERALES
Training a NEAT neural network is very similar to training any other neural network in Encog: create a training object and begin looping through itera- tions. As these iterations progress, the quality of the neural networks in the population should increase.
A NEAT neural network is trained with the NEATTraining class. Here you can see a NEATTraining object being created.
var t r a i n = new NEATTraining ( score , pop ) ; This object trains the population to a 1% error rate.
EncogUtility . TrainToError ( train , 0 . 0 1 ) ;
Once the population has been trained, extract the best neural network. var network = (NEATNetwork) t r a i n . Method ;
With an established neural network, its performance must be tested. Now, display the results from the neural network.
Console . WriteLine (@” Neural Network Results : ” ) ; EncogUtility . Evaluate ( network , t r a i n i n g S e t ) ; This will produce the following output.
Beginning t r a i n i n g . . .
I t e r a t i o n #1 Error :25.000000% Target Error : 1.000000% I t e r a t i o n #2 Error :0.000000% Target Error : 1.000000% Neural Network Results :
Input =0.0000 ,0.0000 , Actual =0.0000 , I d e a l =0.0000 Input =1.0000 ,0.0000 , Actual =1.0000 , I d e a l =1.0000 Input =0.0000 ,1.0000 , Actual =1.0000 , I d e a l =1.0000 Input =1.0000 ,1.0000 , Actual =0.0000 , I d e a l =0.0000
The neural network only took two iterations to produce a neural network that knew how to function as an XOR operator. The network has learned the XOR operator from the above results. XOR will produce an output of 1.0 only when the two inputs are not both of the same value.
7.5
Summary
While previous chapters focused mainly on feedforward neural networks, this chapter explores some of the other Encog-supported network types including the Elman, Jordan, ART1 and NEAT neural networks.
In this chapter you learned about recurrent neural networks, which contain connections backwards to previous layers. Elman and Jordan neural networks make use of a context layer. This context layer allows them to learn patterns that span several items of training data. This makes them very useful for temporal neural networks.
The ART1 neural network can be used to learn binary patterns. Unlike other neural networks, there is no distinct learning and usage state. The ART1 neural network learns as it is used and requires no training stage. This mimics the human brain in that humans learn a task as they perform that task.
This chapter concluded with the NEAT neural network. The NEAT net- work does not have hidden layers like a typical feedforward neural network. A NEAT network starts out with only an input and output layer. The structure
of the hidden neurons evolves as the NEAT network is trained using a genetic algorithm.
In the next chapter we will look at temporal neural networks. A temporal neural network is used to attempt to predict the future. This type of neural network can be very useful in a variety of fields such as finance, signal process- ing and general business. The next chapter will show how to structure input data for neural network queries to make a future prediction.
Chapter 8
Using Temporal Data
• How a Predictive Neural Network Works • Using the Encog Temporal Dataset • Attempting to Predict Sunspots • Using the Encog Market Dataset• Attempting to Predict the Stock Market
Prediction is another common use for neural networks. A predictive neural network will attempt to predict future values based on present and past values. Such neural networks are called temporal neural networks because they operate over time. This chapter will introduce temporal neural networks and the support classes that Encog provides for them.
In this chapter, you will see two applications of Encog temporal neural net- works. First, we will look at how to use Encog to predict sunspots. Sunspots are reasonably predictable and the neural network should be able to learn fu- ture patterns by analyzing past data. Next, we will examine a simple case of applying a neural network to making stock market predictions.
Before we look at either example we must see how a temporal neural net- work actually works. A temporal neural network is usually either a feedfor- ward or simple recurrent network. Structured properly, the feedforward neural
networks shown so far could be structured as a temporal neural network by assigning certain input and output neurons.
8.1
How a Predictive Neural Network Works
A predictive neural network uses its inputs to accept information about current data and uses its outputs to predict future data. It uses two “windows,” a future window and a past window. Both windows must have a window size, which is the amount of data that is either predicted or is needed to predict. To see the two windows in action, consider the following data.
Day 1 : 100 Day 2 : 102 Day 3 : 104 Day 4 : 110 Day 5 : 99 Day 6 : 100 Day 7 : 105 Day 8 : 106 Day 9 : 110 Day 10 : 120
Consider a temporal neural network with a past window size of five and a future window size of two. This neural network would have five input neurons and two output neurons. We would break the above data among these windows to produce training data. The following data shows one such element of training data.
Input 1 : Day 1 : 100 ( input neuron ) Input 2 : Day 2 : 102 ( input neuron ) Input 3 : Day 3 : 104 ( input neuron ) Input 4 : Day 4 : 110 ( input neuron ) Input 5 : Day 5 : 99 ( input neuron ) I d e a l 1 : Day 6 : 100 ( output neuron ) I d e a l 2 : Day 7 : 105 ( output neuron )
Of course the data above needs to be normalized in some way before it can be fed to the neural network. The above illustration simply shows how the input and output neurons are mapped to the actual data. To get additional
data, both windows are simply slid forward. The next element of training data would be as follows.
Input 1 : Day 2 : 102 ( input neuron ) Input 2 : Day 3 : 104 ( input neuron ) Input 3 : Day 4 : 110 ( input neuron ) Input 4 : Day 5 : 99 ( input neuron ) Input 5 : Day 6 : 100 ( input neuron ) I d e a l 1 : Day 7 : 105 ( output neuron ) I d e a l 2 : Day 8 : 106 ( output neuron )
You would continue sliding the past and future windows forward as you gen- erate more training data. Encog contains specialized classes to prepare data in this format. Simply specify the size of the past, or input, window and the future, or output, window. These specialized classes will be discussed in the next section.