-
Hello, I am currently facing a problem, where I would like to find a symbolic regression for a function with discontinuities, e.g. I tried the example in HeuristicLab and it gave me a solution with basically a conditional "if x smaller than or of x greater then": Is this possible with jenetics? At a first look I found this nice example for a setup with doubles and have seen that A small hint or example would be very nice. Regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can try an extension to the MultiRootGP example. static final Codec<ISeq<Function<Double[], Double>>, ProgramGene<Double>> CODEC =
Codec.of(
Genotype.of(
// Discriminator
ProgramChromosome.of(
0,
ISeq.of(Op.of("identity", UnaryOperator.identity())),
ISeq.of(EphemeralConst.of(() -> (double)RandomRegistry.random().nextInt(100)))
),
// First 'program'
ProgramChromosome.of(
5,
ch -> ch.root().size() <= 50,
OPERATIONS,
TERMINALS
),
// Second 'program'
ProgramChromosome.of(
5,
ch -> ch.root().size() <= 50,
OPERATIONS,
TERMINALS
)
),
gt -> gt.stream()
.map(Chromosome::gene)
.collect(ISeq.toISeq())
);
static double fitness(final ISeq<Function<Double[], Double>> programs) {
final var discriminator = programs.get(0).apply(new Double[] {0.0});
if (discriminator <= 50) {
// Evaluate programs.get(1)
return 1;
} else {
// Evaluate program.get(2)
return 2;
}
} |
Beta Was this translation helpful? Give feedback.
You can try an extension to the MultiRootGP example.