Class Regression<T>

java.lang.Object
io.jenetics.prog.regression.Regression<T>
Type Parameters:
T - the operation type
All Implemented Interfaces:
Problem<Tree<Op<T>,?>,ProgramGene<T>,Double>

public final class Regression<T> extends Object implements Problem<Tree<Op<T>,?>,ProgramGene<T>,Double>
This class implements a symbolic regression problem. The example below shows a typical usage of the Regression class.
public class SymbolicRegression {
    private static final ISeq<Op<Double>> OPERATIONS =
        ISeq.of(MathOp.ADD, MathOp.SUB, MathOp.MUL);

    private static final ISeq<Op<Double>> TERMINALS = ISeq.of(
        Var.of("x", 0),
        EphemeralConst.of(() -> (double)RandomRegistry.random().nextInt(10))
    );

    private static final Regression<Double> REGRESSION = Regression.of(
        Regression.codecOf(OPERATIONS, TERMINALS, 5),
        Error.of(LossFunction::mse),
        Sample.ofDouble(-1.0, -8.0000),
        // ...
        Sample.ofDouble(0.9, 1.3860),
        Sample.ofDouble(1.0, 2.0000)
    );

    public static void main(final String[] args) {
        final Engine<ProgramGene<Double>, Double> engine = Engine
            .builder(REGRESSION)
            .minimizing()
            .alterers(
                new SingleNodeCrossover<>(0.1),
                new Mutator<>())
            .build();

        final EvolutionResult<ProgramGene<Double>, Double> result = engine.stream()
            .limit(Limits.byFitnessThreshold(0.01))
            .collect(EvolutionResult.toBestEvolutionResult());

        final ProgramGene<Double> program = result.bestPhenotype()
            .genotype()
            .gene();

        final TreeNode<Op<Double>> tree = program.toTreeNode();
        MathExpr.rewrite(tree); // Simplify result program.
        System.out.println("Generations: " + result.totalGenerations());
        System.out.println("Function:    " + new MathExpr(tree));
        System.out.println("Error:       " + REGRESSION.error(tree));
    }
}
Since:
5.0
Version:
6.0
See Also: