Source

GrayIbis / src / main / scala / pl / put / ri / problem / IntRegressionProblem.scala

package pl.put.ri.problem

import ec.Problem
import ec.simple.SimpleProblemForm
import ec.util.Parameter
import ec.EvolutionState
import ec.Individual
import org.ecj.psh.PshProblem
import org.ecj.psh.PshEvaluator
import pl.put.ri.mapper.ICodeMapper
import ec.vector.ShortVectorIndividual
import ec.gp.koza.KozaFitness
import pl.put.ri.mapper.FlatCodeMapper
import org.spiderland.Psh.Interpreter
import org.spiderland.Psh.Program
import pl.put.regression.RegressionCase
import org.slf4j.LoggerFactory

/**
 * Simple Integer Symbolic Regression Problem.
 *
 * Based on ECJ-PSH IntRegressionProblem.
 *
 * @author Piotr Jessa
 *
 */
class IntRegressionProblem extends PshRegressionProblem {

    private val logger = LoggerFactory.getLogger(classOf[IntRegressionProblem])

    override protected def evaluateTestCase(testCase: RegressionCase, state: EvolutionState, thread: Int): Double = {

        // NOTE: this code should match higher dimensionality
        interpreter.ClearStacks()

        // NOTE: this int case here is very very bad beacause of this some things are 
        // not typesafe, for the ease of the programming
        val input = testCase.variables(0).toInt

        // pushing input value to int stack
        for (i <- 0 until repeatInStack) {
            for (value <- testCase.variables) {
                interpreter.intStack().push(value.toInt)
            }
        }

        // setting input value to input stack
        interpreter.inputStack().push(input);

        // executing the program
        interpreter.Execute(program, interpreter.getExecutionLimit());

        // Penalize individual if there is no result on the stack.
        if (interpreter.intStack().size() == 0) {
            return Float.NaN
        }

        return interpreter.intStack().top()
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.