aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java')
-rw-r--r--src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
index 04e9fe8..24c61d6 100644
--- a/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
+++ b/src/jcgp/backend/modules/problem/SymbolicRegressionProblem.java
@@ -4,7 +4,6 @@ import jcgp.backend.function.SymbolicRegressionFunctions;
import jcgp.backend.parameters.BooleanParameter;
import jcgp.backend.parameters.DoubleParameter;
import jcgp.backend.parameters.ParameterStatus;
-import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Population;
import jcgp.backend.resources.Resources;
@@ -20,12 +19,12 @@ import jcgp.backend.resources.Resources;
* <li>Error threshold: the maximum difference allowed between an
* evolved output and the equivalent output from the problem data.
* Outputs within the error threshold will be considered correct.
- * This is only used if HITS is enabled.</li>
+ * This is only used if hits is enabled.</li>
* <li>Perfection threshold: if the fitness is calculated without
- * using the HITS method, it is a decimal value. A solution is
+ * using the hits method, it is a decimal value. A solution is
* considered perfect when the difference between its fitness and
* the maximum possible fitness is within the perfection threshold.</li>
- * <li>HITS-based fitness: increment the fitness by 1 whenever the
+ * <li>Hits-based fitness: increment the fitness by 1 whenever the
* chromosome output is within the error threshold.</li></ul>
*
*
@@ -79,7 +78,7 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
}
};
- hitsBasedFitness = new BooleanParameter(true, "HITS-based fitness");
+ hitsBasedFitness = new BooleanParameter(false, "Hits-based fitness");
registerParameters(errorThreshold, perfectionThreshold, hitsBasedFitness);
}
@@ -87,15 +86,15 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
@Override
public void evaluate(Population population, Resources resources) {
// for every chromosome in the population
- for (int i = 0; i < resources.populationSize(); i++) {
+ for (int i = 0; i < getResources().populationSize(); i++) {
// assume an initial fitness of 0
double fitness = 0;
// for each test case
for (int t = 0; t < testCases.size(); t++) {
- population.getChromosome(i).setInputs((Object[]) testCases.get(t).getInputs());
+ population.get(i).setInputs((Object[]) testCases.get(t).getInputs());
// check each output
- for (int o = 0; o < resources.outputs(); o++) {
- Double cgpValue = (Double) population.getChromosome(i).getOutput(o).calculate();
+ for (int o = 0; o < getResources().outputs(); o++) {
+ Double cgpValue = (Double) population.get(i).getOutput(o).calculate();
Double dataValue = testCases.get(t).getOutput(o);
if (hitsBasedFitness.get()) {
if (Math.abs(cgpValue - dataValue) <= errorThreshold.get()) {
@@ -107,11 +106,8 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
}
}
// assign the resulting fitness to the respective individual
- population.getChromosome(i).setFitness(fitness);
+ population.get(i).setFitness(fitness);
}
-
- // sort population
- population.sortAscending();
}
@Override
@@ -130,19 +126,27 @@ public class SymbolicRegressionProblem extends TestCaseProblem<Double> {
}
@Override
- public boolean isPerfectSolution(Chromosome fittest) {
+ public int perfectSolutionFound(Population population) {
// higher fitness is better
- return fittest.getFitness() >= maxFitness.get() - perfectionThreshold.get();
+ for (int i = 0; i < getResources().populationSize(); i++) {
+ if (population.get(i).getFitness() >= maxFitness.get() - perfectionThreshold.get()) {
+ return i;
+ }
+ }
+ return -1;
}
@Override
- public boolean isImprovement(Chromosome fittest) {
+ public int hasImprovement(Population population) {
// higher fitness is better
- if (fittest.getFitness() > bestFitness.get()) {
- bestFitness.set(fittest.getFitness());
- return true;
- } else {
- return false;
+ for (int i = 0; i < getResources().populationSize(); i++) {
+ System.out.println("checking for improvement");
+ if (population.get(i).getFitness() > bestFitness.get()) {
+ System.out.println("found a better chr, " + i);
+ bestFitness.set(population.get(i).getFitness());
+ return i;
+ }
}
+ return -1;
}
}