public class ConjGradNN
extends java.lang.Object
Optimized Classificator/Model by Conjugated Gradient. Also this class is a container for a perceptron neural network and implements the training methods: * Conjugated Gradient: conjugatedGradient. * Descendent Gradient: descentGradient. Input-Layer Hidden Layer-i x nLayers Output-Layer - | I H | I H - | I H O | nInputs | I H O | nOutputs | I H O | | I H O | | I H - | I H -
| Constructor and Description |
|---|
ConjGradNN(int[] vNelement,
double[][] vInput,
double[][] vOutput,
Randomize pr)
Constructor for a perceptron neural network from its basic elements.
|
| Modifier and Type | Method and Description |
|---|---|
void |
changeWeights(double x)
Updates the matrix of weights with the addition of random valued in the range [-x,x].
|
double |
conjugatedGradient(FUN f,
double TOL_ERR,
double MIN_DELTAGC,
int MAX_ITER)
Returns the mean square error of the output perceptron calculated with Conjugated Gradient training algorithm.
|
void |
debugOutput()
Prints to standard output the main information about the training algorithm run:
-the matrix of weights
-the original input examples (not scaled)
-the original obtained output (not scaled)
-the original expected output (not scaled)
|
double |
descentGradient(FUN f,
double TOL_ERR,
double MIN_DELTAGC,
int MAX_ITER)
Returns the mean square error of the output perceptron calculated with Descendent Gradient training algorithm.
|
double |
f_denormalized(double[][][] x,
double[] FACTOR)
Returns the denormalized mean square error of a perceptron with weights x for all the examples Input
|
double |
f(double[][][] x)
Returns the mean square error of a perceptron with weights x for all the examples Input
|
void |
getWeights(double[] p)
Returns a copy of weights in vector p.
|
java.lang.String |
getWeightsAsString()
Return the weights as a String to print them
|
double[] |
nn(double[] x,
double[][][] W)
Calculates the output of a perceptron with weights W for input x
|
void |
randomWeights(double x)
Initializes the matrix of weights with random valued in the range [-x,x].
|
void |
sample(double[][][] x)
Prints to standard output N-tier Neural Network x
|
void |
scale()
Scales the input examples values and expected output valued
|
void |
setWeights(double[] p)
Copy the weights contained in p to the weights matrix.
|
public ConjGradNN(int[] vNelement,
double[][] vInput,
double[][] vOutput,
Randomize pr)
Constructor for a perceptron neural network from its basic elements.
vNelement - topology. Number of neurons by hidden layer.vInput - input examples.vOutput - expected outputs.pr - Random generator.public void sample(double[][][] x)
Prints to standard output N-tier Neural Network x
x - the example to printpublic double[] nn(double[] x,
double[][][] W)
Calculates the output of a perceptron with weights W for input x
x - the example to give the perceptronW - the weights of the perceptronpublic double f(double[][][] x)
Returns the mean square error of a perceptron with weights x for all the examples Input
x - the example to give the perceptronpublic double f_denormalized(double[][][] x,
double[] FACTOR)
Returns the denormalized mean square error of a perceptron with weights x for all the examples Input
x - the example to give the perceptron.FACTOR - a vector with difference between the max and min value for each outputpublic void scale()
Scales the input examples values and expected output valued
public double conjugatedGradient(FUN f, double TOL_ERR, double MIN_DELTAGC, int MAX_ITER)
Returns the mean square error of the output perceptron calculated with Conjugated Gradient training algorithm.
f - the error function.TOL_ERR - the stop error.MIN_DELTAGC - is not used.MAX_ITER - number of maximum iteratations.public double descentGradient(FUN f, double TOL_ERR, double MIN_DELTAGC, int MAX_ITER)
Returns the mean square error of the output perceptron calculated with Descendent Gradient training algorithm.
f - the error function.TOL_ERR - the stop error.MIN_DELTAGC - is not used.MAX_ITER - number of maximum iteratations.public void randomWeights(double x)
Initializes the matrix of weights with random valued in the range [-x,x].
x - the lower/upper limit for random values.public void changeWeights(double x)
Updates the matrix of weights with the addition of random valued in the range [-x,x].
x - the lower/upper limit for random values.public void debugOutput()
Prints to standard output the main information about the training algorithm run: -the matrix of weights -the original input examples (not scaled) -the original obtained output (not scaled) -the original expected output (not scaled)
public void getWeights(double[] p)
Returns a copy of weights in vector p.
p - an output parameter to obtaing a copy of weights.public void setWeights(double[] p)
Copy the weights contained in p to the weights matrix.
p - an output parameter to obtaing a copy of weights.public java.lang.String getWeightsAsString()