New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to find two optimal parameters with jenetics ? #167
Comments
here the code, can anyone help me? thanks
public void testGA(){
` |
In the mthond 'testGA', i got the error with Engine.builder: |
The main problem with your code was, that the fitness function can only take one parameter. If you want to have more, you have to wrap it into an array: static double fitness(final double[] params) {
final double C = params[0];
final double gamma = params[1];
// Your fitness calculation.
return C + gamma;
} The fixed program would look like this: public class GetMonthDataForQPE {
static double fitness(final double[] params) {
final double C = params[0];
final double gamma = params[1];
// Your fitness calculation.
return C + gamma;
}
public static void main(final String[] args) {
codecs.ofVector(DoubleRange.of(-8.0, 8.0), 2);
final Engine<DoubleGene, Double> engine = Engine
.builder(
GetMonthDataForQPE::fitness,
codecs.ofVector(DoubleRange.of(-8.0, 8.0), 2))
.populationSize(500)
.optimize(Optimize.MAXIMUM)
.alterers(
new Mutator<>(0.03),
new MeanAlterer<>(0.6)
)
.build();
// Create evolution statistics consumer.
final EvolutionStatistics<Double, ?>
statistics = EvolutionStatistics.ofNumber();
final Phenotype<DoubleGene, Double> best = engine.stream()
.limit(bySteadyFitness(7))
.limit(100)
.peek(statistics)
.collect(toBestPhenotype());
System.out.println(statistics);
System.out.println(best);
}
} |
No description provided.
The text was updated successfully, but these errors were encountered: