input
stringlengths
10
828
output
stringlengths
5
107
public double derivative function double d return d 1 0 d
some training methods require the derivative
public double derivative function double d throw new neural network error can t use the linear activation function where a derivative is required
some training methods require the derivative
public double derivative function double d return 1 0 math pow activation function d 2 0
some training methods require the derivative
public void update error final double actual final double ideal for int i 0 i actual length i final double delta ideal i actual i this global error delta delta this set size ideal length
called to update for each number that should be checked
public int get cycles return this cycles
called to get the current number of cycles
public double get percent to mate return this percent to mate
get the percent to mate
public void set gene final int gene final gene type value this genes gene value
set the specified genes value
public executor service get pool return this pool
get the optional threadpool
public void set genes final gene type genes throws neural network error this genes genes
set the entire gene array
public boolean get done return this done
called to determine if we are done in an incremental prune
public boolean is prevent repeat return this prevent repeat
should repeating genes be prevented
public void set genetic algorithm final ga type genetic algorithm this genetic algorithm genetic algorithm
set the genetic algorithm
public double get error return this error
called to get the current error
private int size return this genes length
get the size of the gene array
public void set chromosome final int i final chromosome type value this chromosomes i value
set the specified chromosome
protected int get hidden count final collection feedforward layer c this current network get hidden layers final object layers c to array return feedforward layer layers 0 get neuron count
the current number of hidden neurons being evaluated
public void set chromosomes final chromosome type chromosomes this chromosomes chromosomes
set the entire population
public double get hidden neuron count return this hidden neuron count
get the number of hidden neurons
public void set cut length final int cut length this cut length cut length
set the cut length
public void prune incramental if this done return this backprop iteration this error this backprop get error this cycles increment
method that is called to prune the neural network incramentaly
public void set mating population final double mating population this mating population mating population
set the mating population percent
public feedforward network get network return this network
get the best network from the training
public double get error throws neural network error final feedforward network network this get network return network calculate error this input this ideal
returns the root mean square error for a complet training set
public void set mutation percent final double mutation percent this mutation percent mutation percent
set the mutation percent
public int prune selective final int i this get hidden count while find neuron return i this get hidden count
called to complete the selective pruning process
public void set percent to mate final double percent to mate this percent to mate percent to mate
set the percent to mate
public void accumulate threshold delta final int index final double value this acc matrix delta add this bias row index value
accumulate a threshold delta
public void set pool final executor service pool this pool pool
set the optional thread pool
public void calc error final double ideal layer errors and deltas for output layer for int i 0 i this layer get neuron count i set error i ideal i this layer get fire i set error delta i bound numbers bound calculate delta i
calculate the error for the given ideal values
public void start incremental this hidden neuron count 1 this cycles 0 this done false this current network new feedforward network this current network add layer new feedforward layer this train 0 length this current network add layer new feedforward layer this hidden neuron count this current network add layer new feedforward layer this ideal 0 length this current network reset this backprop new backpropagation this current network this train this ideal this rate this momentum
method that is called to start the incremental prune process
public void add layer final feedforward layer layer setup the forward and back pointer if this output layer null layer set previous this output layer this output layer set next layer update the input layer and output layer variables if this layers size 0 this input layer this output layer layer else this output layer layer add the new layer to the list this layers add layer
add a layer to the neural network
public void set population size final int population size this population size population size
set the population size
private double calculate delta final int i return get error i this layer get activation function derivative function this layer get fire i
calculate the delta for actual vs ideal
public void set prevent repeat final boolean prevent repeat this prevent repeat prevent repeat
set the gene
public void iteration for int j 0 j this input length j this network compute outputs this input j calc error this ideal j learn this error this network calculate error this input this ideal
perform one iteration of training
public feedforward network get network final neural chromosome ga type c get chromosome 0 c update network return c get network
get the current best neural network
public int calculate neuron count int result 0 for final feedforward layer layer this layers result layer get neuron count return result
calculate the total number of neurons in the network across all layers
public double get error final int index return this error index
get the error for the specified neuron
public void learn for final feedforward layer layer this network get layers get backpropagation layer layer learn this learn rate this momentum
modify the weight matrix and thresholds based on the last call to
public feedforward layer clone structure return new feedforward layer this activation function this get neuron count
clone the structure of this layer but do not copy any matrix data
public matrix get input matrix return this input matrix
get the resulting input matrix
public int get input neuron count return this input neuron count
get the input neuron count
public double get error delta final int index return this error delta index
get the error delta for the specified neuron
protected void present pattern final double i1 final double i2 double result double delta run the net as is on training data and get the error system out print presented i1 i2 result recognize i1 i2 system out print result result adjust weight 1 delta training function this rate i1 result this w1 delta system out print delta w1 delta adjust weight 2 delta training function this rate i2 result this w2 delta system out println delta w2 delta
present a pattern and learn from it
public double get normfac return this normfac
the normalization factor
public normalization type get normalization type return this normalization type
get the normalization type
public void run for int i 0 i 5 i epoch
this method loops through 10 epochs
protected double get error final double actual final double anticipated return anticipated actual
this method will calculate the error between the anticipated output and
public void learn final double learn rate final double momentum process the matrix if this layer has matrix final matrix m1 matrix math multiply this acc matrix delta learn rate final matrix m2 matrix math multiply this matrix delta momentum this matrix delta matrix math add m1 m2 this layer set matrix matrix math add this layer get matrix this matrix delta this acc matrix delta clear
learn from the last error calculation
public double get synth return this synth
the synthetic input
public int get output neuron count return this output neuron count
get the output neuron count
public double get fire final int index return this fire index
get the output from an individual neuron
protected void calculate factors final double input final matrix input matrix matrix create column matrix input double len matrix math vector length input matrix len math max len self organizing map verysmall final int num inputs input length if this type normalization type multiplicative this normfac 1 0 len this synth 0 0 else this normfac 1 0 math sqrt num inputs final double d num inputs math pow len 2 if d 0 0 this synth math sqrt d this normfac else this synth 0
determine both the normalization factor and the synthetic input for the
public matrix get output weights return this output weights
get the output neuron weights
public void set error final int index final double e this error index bound numbers bound e
set the error for the specified neuron
public matrix get matrix return this matrix
get the weight and threshold matrix
public void run for int i 0 i 100 i epoch
this method loops through 100 epochs
public void set output weights final matrix output weights this output weights output weights
set the output neuron weights
public int get matrix size if this matrix null return 0 else return this matrix size
get the size of the matrix or zero if one is not defined
public void set error delta final int index final double d this error delta index d
set the error delta for the specified neuron
public int get hidden layer count return this layers size 2
get the count for how many hidden layers are present
public int winner final double input final normalize input normalized input new normalize input input this normalization type return winner normalized input
determine the winner for the specified input
public void clear this entry graphics set color color white this entry graphics fill rect 0 0 get width get height this down sample bottom this down sample top this down sample left this down sample right 0 repaint
called to clear the image
public void clear for int x 0 x this grid length x for int y 0 y this grid 0 length y this grid x y false
clear the downsampled image
public int get neuron count return this fire length
get the neuron count for this layer
public int winner final normalize input input int win 0 double biggest double min value for int i 0 i this output neuron count i final matrix optr this output weights get row i this output i matrix math dot product input get input matrix optr input get normfac this output i this output i 1 0 2 0 if this output i biggest biggest this output i win i if this output i 0 this output i 0 if this output i 1 this output i 1 return win
determine the winner for the specified input
public feedforward layer get input layer return this input layer
get the input layer
public void clear int index 0 for int y 0 y this grid y y for int x 0 x this grid x x this grid index false repaint
clear the grid
public boolean get data final int x final int y return this grid x y
get a pixel from the sample
public void action performed final java awt event action event event final object object event get source if object this go run network else if object this clear clear else if object this train train
called when the user clicks one of the buttons
private void clear matrix this hopfield get matrix clear
clear the weight matrix
public double get best error return this best error
get the best error so far
protected boolean down sample region final int x final int y final int w this entry image get width this final int start x int this down sample left x this ratio x final int start y int this down sample top y this ratio y final int end x int start x this ratio x final int end y int start y this ratio y for int yy start y yy end y yy for int xx start x xx end x xx final int loc xx yy w if this pixel map loc 1 return true return false
called to downsample a quadrant of the image
public feedforward layer get output layer return this output layer
get the output layer
public int get height return this grid 0 length
get the height of the down sampled image
public void go this grid this hopfield present this grid repaint
run the neural network
private void collect matrix values for int row 0 row 4 row for int col 0 col 4 col final string str this matrix row col get text int value 0 try value integer parse int str catch final number format exception e let the value default to zero which it already is by this point do not allow neurons to self connect if row col this network get matrix set row col 0 else this network get matrix set row col value
collect the matrix values from the applet and place inside the weight
protected void find bounds final int w final int h top line for int y 0 y h y if h line clear y this down sample top y break bottom line for int y h 1 y 0 y if h line clear y this down sample bottom y break left line for int x 0 x w x if v line clear x this down sample left x break right line for int x w 1 x 0 x if v line clear x this down sample right x break
this method is called to automatically crop the image so that whitespace
public boolean has matrix return this matrix null
determine if this layer has a matrix
public double get total error return this total error
get the error for this iteration
public int get weight matrix size int result 0 for final feedforward layer layer this layers result layer get matrix size return result
get the size of the weight and threshold matrix
public int get width return this grid length
get the width of the downsampled image
public void set data final int x final int y final boolean v this grid x y v
set one pixel of sample data
public sample get sample return this sample
get the down sample component to be used with this component
public boolean is hidden return this next null this previous null
determine if this is a hidden layer
public void reset for final feedforward layer layer this layers layer reset
reset the weight matrix and the thresholds
public void set letter final char letter this letter letter
set the letter that this sample represents
public void initialize this som get output weights ramdomize 1 1 for int i 0 i this output neuron count i normalize weight this som get output weights i
called to initialize the som
public boolean is input return this previous null
determine if this is an input layer
public void iteration evaluate errors this total error this global error if this total error this best error this best error this total error copy weights this som this bestnet int winners 0 for int i 0 i this won length i if this won i 0 winners if winners this output neuron count winners this train length force win return adjust weights if this learn rate 0 01 this learn rate this reduction
this method is called for each training iteration
protected void init image this entry image create image get width get height this entry graphics this entry image get graphics this entry graphics set color color white this entry graphics fill rect 0 0 get width get height
setup the internal image that the user draws onto
public void train this hopfield train this grid
train the neural network
public boolean is output return this next null
determine if this is an output layer
protected void normalize weight final matrix matrix final int row double len matrix math vector length matrix get row row len math max len self organizing map verysmall len 1 0 len for int i 0 i this input neuron count i matrix set row i matrix get row i len matrix set row this input neuron count 0
normalize the specified row in the weight matrix
public void prune final int neuron delete a row on this matrix if this matrix null set matrix matrix math delete row this matrix neuron delete a column on the previous final feedforward layer previous this get previous if previous null if previous get matrix null previous set matrix matrix math delete col previous get matrix neuron
prune one of the neurons from this layer
public void reset if this matrix null this matrix ramdomize 1 1
reset the weight matrix and threshold values to random numbers between 1
public void set fire final int index final double f this fire index f
set the last output value for the specified neuron
public void set matrix final matrix matrix if matrix get rows 2 throw new neural network error weight matrix includes threshold values and must have at least 2 rows if matrix null this fire new double matrix get rows 1 this matrix matrix
assign a new weight and threshold matrix to this layer
public void set next final feedforward layer next this next next add one to the neuron count to provide a threshold value in row 0 this matrix new matrix this get neuron count 1 next get neuron count
set the next layer
public void set sample final sample s this sample s
set the sample control to use