This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2023 Franz Wilhelmstötter | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.EOFException; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.OutputStream; | |
import java.io.UncheckedIOException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.jenetics.DoubleGene; | |
import io.jenetics.EnumGene; | |
import io.jenetics.Genotype; | |
import io.jenetics.engine.Codec; | |
import io.jenetics.engine.Codecs; | |
import io.jenetics.engine.Engine; | |
import io.jenetics.engine.EvolutionResult; | |
import io.jenetics.util.DoubleRange; | |
import io.jenetics.util.ProxySorter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This codec creates a split range, where only values between [0, 2) and | |
* [8, 10) are valid. The valid range is marked with '-' and the invalid | |
* range with 'x'. | |
* | |
* +--+--+--+--+--+--+--+--+--+--+ | |
* | | | | | | | | | | | | |
* 0 1 2 3 4 5 6 7 8 9 10 | |
* |-----|xxxxxxxxxxxxxxxxx|-----| | |
* ^ |llllllll|rrrrrrrr| ^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.util.Collections.emptyList; | |
import static io.jenetics.engine.EvolutionResult.toBestPhenotype; | |
import java.util.List; | |
import java.util.function.Function; | |
import java.util.stream.DoubleStream; | |
import java.util.stream.Stream; | |
import io.jenetics.DoubleChromosome; | |
import io.jenetics.DoubleGene; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.lang.String.format; | |
import java.util.Comparator; | |
/** | |
* Sample implementation of a 3D double point. | |
*/ | |
public final class Point3 implements Vec<Point3> { | |
private final double _x; | |
private final double _y; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sortStringArray() { | |
final String[] strings = new String[]{"g", "f", "r", "u", "a"}; | |
final int[] proxy = ProxySorter.sort( | |
strings, strings.length, | |
(a, i, j) -> a[i].compareTo(a[j]) | |
); | |
// Printing strings in ascending order. | |
for (int index : proxy) { | |
System.out.println(strings[index]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Polynomial { | |
private final double[] a; | |
Polynomial(final double... a) { | |
this.a = a.clone(); | |
} | |
// Uses Horner's Method to evaluate the polynomial. | |
double apply(final double x) { | |
double result = a[a.length - 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Error error = Error.of( | |
LossFunction::mse, | |
Complexity.ofMaxNodeCount(50) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
NewerOlder