This file contains hidden or 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 Op<Double> one = Const.of(1.0); | |
| final Op<Double> pi = Const.of("π", Math.PI); |
This file contains hidden or 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 Op<Double> rand1 = EphemeralConst.of(Math::random); | |
| final Op<Double> rand2 = EphemeralConst.of("R", Math::random); |
This file contains hidden or 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 int depth = 5; | |
| final ISeq<Op<Double>> operations = ISeq.of(...); | |
| final ISeq<Op<Double>> terminals = ISeq.of(...); | |
| final ProgramChromosome<Double> program = ProgramChromosome.of( | |
| depth, | |
| operations, | |
| terminals | |
| ); |
This file contains hidden or 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 Engine<ProgramGene<Double>, Double> engine = Engine | |
| .builder(Main::error, program) | |
| .minimizing() | |
| .alterers( | |
| new SingleNodeCrossover<>(), | |
| new Mutator<>()) | |
| .build(); |
This file contains hidden or 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
| static final ISeq<Op<Double>> OPERATIONS = ISeq.of( | |
| MathOp.ADD, | |
| MathOp.SUB, | |
| MathOp.MUL | |
| ); | |
| static final ISeq<Op<Double>> TERMINALS = ISeq.of( | |
| Var.of("x", 0), | |
| EphemeralConst.of(() -> | |
| (double)RandomRegistry.getRandom().nextInt(10)) |
This file contains hidden or 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) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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; |