gpalta.core
Class Evolution

java.lang.Object
  extended by gpalta.core.Evolution

public class Evolution
extends java.lang.Object

This is the highest level class of GPalta and stores the whole state of the system. Users should create an instance of Evolution and use it to perform all aspects of a GP run.


Field Summary
 Config config
           
 EvolutionStats evoStats
           
 Fitness fitness
           
 int generation
           
 Population population
           
 
Constructor Summary
Evolution(Config config, boolean initPop)
          Creates a new Evolution, loading data from file
Evolution(Config config, double[][] data, double[] desiredOutputs, double[] weights, boolean initPop)
          Creates a new instance of Evolution, using the given data, desiredOutputs and weights
 
Method Summary
 void eval()
          Evaluate the current population.
 void evolve()
          Evolve one generation.
protected  void finalize()
           
 Output getProcessedOutput(Individual ind)
          Evaluate a single Individual and get its output after being further processed by the Fitness
 Output getProcessedOutput(Individual ind, double[][] data)
          Evaluate a single Individual and get its "raw" output for every sample, using the supplied data matrix, instead of the one used in evolution.
 Output getRawOutput(Individual ind)
          Evaluate a single Individual and get its "raw" output for every sample.
 Output getRawOutput(Individual ind, double[][] data)
          Evaluate a single Individual and get its "raw" output for every sample, using the supplied data matrix, instead of the one used in evolution.
 void read(java.lang.String fileName)
          Read Evolution from file.
 void save(java.lang.String fileName)
          Save Evolution to file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

population

public Population population

fitness

public Fitness fitness

generation

public int generation

config

public Config config

evoStats

public EvolutionStats evoStats
Constructor Detail

Evolution

public Evolution(Config config,
                 boolean initPop)
Creates a new Evolution, loading data from file

Parameters:
config - The evolution configuration
initPop - If true, the population is randomly initialized. Else, nothing is done (population will be later read from a file)

Evolution

public Evolution(Config config,
                 double[][] data,
                 double[] desiredOutputs,
                 double[] weights,
                 boolean initPop)
Creates a new instance of Evolution, using the given data, desiredOutputs and weights

Parameters:
config - The evolution configuration
data - The current problem's data, where every row correponds to all the samples for a variable.
desiredOutputs - The desired outputs
weights - The weight (importance) of each sample
initPop - If true, the population is randomly initialized. Else, nothing is done (population will be later read from a file)
Method Detail

eval

public void eval()
Evaluate the current population.


getRawOutput

public Output getRawOutput(Individual ind)
Evaluate a single Individual and get its "raw" output for every sample. Raw means that the result is obtained only from the Individual, and not modified by the Fitness. The individual will be evaluated on the problem data currently stored.

Returns:
The "raw" output of the Individual for every sample

getRawOutput

public Output getRawOutput(Individual ind,
                           double[][] data)
Evaluate a single Individual and get its "raw" output for every sample, using the supplied data matrix, instead of the one used in evolution. Raw means that the result is obtained only from the Individual, and not modified by the Fitness

Parameters:
ind - The individual to evaluate
data - A matrix with all the samples in which to evaluate the individual
Returns:
The "raw" output of the Individual for every sample in the given data matrix

getProcessedOutput

public Output getProcessedOutput(Individual ind)
Evaluate a single Individual and get its output after being further processed by the Fitness

Returns:
The "processed" output of the Individual for every sample

getProcessedOutput

public Output getProcessedOutput(Individual ind,
                                 double[][] data)
Evaluate a single Individual and get its "raw" output for every sample, using the supplied data matrix, instead of the one used in evolution. Raw means that the result is obtained only from the Individual, and not modified by the Fitness

Parameters:
ind - The individual to evaluate
data - A matrix with all the samples in which to evaluate the individual
Returns:
The "raw" output of the Individual for every sample in the given data matrix

evolve

public void evolve()
Evolve one generation. Assumes the current population is already evaluated and doesn't evaluate the evolved one


save

public void save(java.lang.String fileName)
          throws java.io.IOException
Save Evolution to file. TODO: We should do something to check that the saved info is correct. Maybe more things should be saved. For instance, if the file was saved with a grater maxDepth than it is now, there would be nodes with larger depth than current maxDepth, and an attempt to mutate those nodes would result in an error.

Parameters:
fileName - The file to write to
Throws:
java.io.IOException - if a problem is encountered while writing (controlling classes should do something about it)

read

public void read(java.lang.String fileName)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Read Evolution from file. TODO: We should do something to check that the saved info is correct. Maybe more things should be saved. For instance, if the file was saved with a grater maxDepth than it is now, there would be nodes with larger depth than current maxDepth, and an attempt to mutate those nodes would result in an error.

Parameters:
fileName - The file to be read
Throws:
java.io.IOException - if a problem is encountered while reading (controlling classes should do something about it)
java.lang.ClassNotFoundException - if class read doesn't match existing classes (probably old data in file)

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object