repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
jenetics/jenetics
jenetics.tool/src/main/java/io/jenetics/tool/trial/Gnuplot.java
Gnuplot.create
public void create(final Path data, final Path output) throws IOException { _parameters.put(DATA_NAME, data.toString()); _parameters.put(OUTPUT_NAME, output.toString()); final String params = _parameters.entrySet().stream() .map(Gnuplot::toParamString) .collect(Collectors.joining("; ")); String script = new String(Files.readAllBytes(_template)); for (Map.Entry<String, String> entry : _environment.entrySet()) { final String key = format("${%s}", entry.getKey()); script = script.replace(key, entry.getValue()); } final Path scriptPath = tempPath(); try { IO.write(script, scriptPath); final List<String> command = Arrays. asList("gnuplot", "-e", params, scriptPath.toString()); final Process process = new ProcessBuilder() .command(command) .start(); System.out.println(IO.toText(process.getErrorStream())); try { process.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } finally { deleteIfExists(scriptPath); } }
java
public void create(final Path data, final Path output) throws IOException { _parameters.put(DATA_NAME, data.toString()); _parameters.put(OUTPUT_NAME, output.toString()); final String params = _parameters.entrySet().stream() .map(Gnuplot::toParamString) .collect(Collectors.joining("; ")); String script = new String(Files.readAllBytes(_template)); for (Map.Entry<String, String> entry : _environment.entrySet()) { final String key = format("${%s}", entry.getKey()); script = script.replace(key, entry.getValue()); } final Path scriptPath = tempPath(); try { IO.write(script, scriptPath); final List<String> command = Arrays. asList("gnuplot", "-e", params, scriptPath.toString()); final Process process = new ProcessBuilder() .command(command) .start(); System.out.println(IO.toText(process.getErrorStream())); try { process.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } finally { deleteIfExists(scriptPath); } }
[ "public", "void", "create", "(", "final", "Path", "data", ",", "final", "Path", "output", ")", "throws", "IOException", "{", "_parameters", ".", "put", "(", "DATA_NAME", ",", "data", ".", "toString", "(", ")", ")", ";", "_parameters", ".", "put", "(", ...
Generate the Gnuplot graph. @param data the input data file @param output the output path of the graph @throws IOException if the Gnuplot generation fails
[ "Generate", "the", "Gnuplot", "graph", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.tool/src/main/java/io/jenetics/tool/trial/Gnuplot.java#L86-L121
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Timer.java
Timer.of
public static Timer of(final Clock clock) { requireNonNull(clock); return clock instanceof NanoClock ? new Timer(System::nanoTime) : new Timer(() -> nanos(clock)); }
java
public static Timer of(final Clock clock) { requireNonNull(clock); return clock instanceof NanoClock ? new Timer(System::nanoTime) : new Timer(() -> nanos(clock)); }
[ "public", "static", "Timer", "of", "(", "final", "Clock", "clock", ")", "{", "requireNonNull", "(", "clock", ")", ";", "return", "clock", "instanceof", "NanoClock", "?", "new", "Timer", "(", "System", "::", "nanoTime", ")", ":", "new", "Timer", "(", "(",...
Return an new timer object which uses the given clock for measuring the execution time. @param clock the clock used for measuring the execution time @return a new timer
[ "Return", "an", "new", "timer", "object", "which", "uses", "the", "given", "clock", "for", "measuring", "the", "execution", "time", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Timer.java#L86-L91
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/stat/Quantile.java
Quantile.adjustMarkerHeights
private void adjustMarkerHeights() { double mm = _n[1] - 1.0; double mp = _n[1] + 1.0; if (_nn[0] >= mp && _n[2] > mp) { _q[1] = qPlus(mp, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]); _n[1] = mp; } else if (_nn[0] <= mm && _n[0] < mm) { _q[1] = qMinus(mm, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]); _n[1] = mm; } mm = _n[2] - 1.0; mp = _n[2] + 1.0; if (_nn[1] >= mp && _n[3] > mp) { _q[2] = qPlus(mp, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]); _n[2] = mp; } else if (_nn[1] <= mm && _n[1] < mm) { _q[2] = qMinus(mm, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]); _n[2] = mm; } mm = _n[3] - 1.0; mp = _n[3] + 1.0; if (_nn[2] >= mp && _n[4] > mp) { _q[3] = qPlus(mp, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]); _n[3] = mp; } else if (_nn[2] <= mm && _n[2] < mm) { _q[3] = qMinus(mm, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]); _n[3] = mm; } }
java
private void adjustMarkerHeights() { double mm = _n[1] - 1.0; double mp = _n[1] + 1.0; if (_nn[0] >= mp && _n[2] > mp) { _q[1] = qPlus(mp, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]); _n[1] = mp; } else if (_nn[0] <= mm && _n[0] < mm) { _q[1] = qMinus(mm, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]); _n[1] = mm; } mm = _n[2] - 1.0; mp = _n[2] + 1.0; if (_nn[1] >= mp && _n[3] > mp) { _q[2] = qPlus(mp, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]); _n[2] = mp; } else if (_nn[1] <= mm && _n[1] < mm) { _q[2] = qMinus(mm, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]); _n[2] = mm; } mm = _n[3] - 1.0; mp = _n[3] + 1.0; if (_nn[2] >= mp && _n[4] > mp) { _q[3] = qPlus(mp, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]); _n[3] = mp; } else if (_nn[2] <= mm && _n[2] < mm) { _q[3] = qMinus(mm, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]); _n[3] = mm; } }
[ "private", "void", "adjustMarkerHeights", "(", ")", "{", "double", "mm", "=", "_n", "[", "1", "]", "-", "1.0", ";", "double", "mp", "=", "_n", "[", "1", "]", "+", "1.0", ";", "if", "(", "_nn", "[", "0", "]", ">=", "mp", "&&", "_n", "[", "2", ...
Adjust heights of markers 0 to 2 if necessary
[ "Adjust", "heights", "of", "markers", "0", "to", "2", "if", "necessary" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/stat/Quantile.java#L302-L332
train
jenetics/jenetics
jenetics.example/src/main/java/io/jenetics/example/BatchEvalKnapsack.java
BatchEvalKnapsack.batchEval
private static <G extends Gene<?, G>, C extends Comparable<? super C>> ISeq<C> batchEval( final Seq<Genotype<G>> genotypes, final Function<? super Genotype<G>, ? extends C> function ) { return genotypes.<C>map(function).asISeq(); }
java
private static <G extends Gene<?, G>, C extends Comparable<? super C>> ISeq<C> batchEval( final Seq<Genotype<G>> genotypes, final Function<? super Genotype<G>, ? extends C> function ) { return genotypes.<C>map(function).asISeq(); }
[ "private", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "ISeq", "<", "C", ">", "batchEval", "(", "final", "Seq", "<", "Genotype", "<", "G", ">", ">", "genotyp...
Not really batch eval. Just for testing.
[ "Not", "really", "batch", "eval", ".", "Just", "for", "testing", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.example/src/main/java/io/jenetics/example/BatchEvalKnapsack.java#L68-L74
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/engine/ConcatEngine.java
ConcatEngine.of
@SafeVarargs public static <G extends Gene<?, G>, C extends Comparable<? super C>> ConcatEngine<G, C> of(final EvolutionStreamable<G, C>... engines) { return new ConcatEngine<>(Arrays.asList(engines)); }
java
@SafeVarargs public static <G extends Gene<?, G>, C extends Comparable<? super C>> ConcatEngine<G, C> of(final EvolutionStreamable<G, C>... engines) { return new ConcatEngine<>(Arrays.asList(engines)); }
[ "@", "SafeVarargs", "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "ConcatEngine", "<", "G", ",", "C", ">", "of", "(", "final", "EvolutionStreamable", "<"...
Create a new concatenating evolution engine with the given array of engines. @param engines the engines which are concatenated to <em>one</em> engine @param <G> the gene type @param <C> the fitness type @return a new concatenating evolution engine @throws NullPointerException if the {@code engines} or one of it's elements is {@code null}
[ "Create", "a", "new", "concatenating", "evolution", "engine", "with", "the", "given", "array", "of", "engines", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/engine/ConcatEngine.java#L225-L229
train
jenetics/jenetics
jenetics.doc/src/main/java/TravelingSalesman.java
TravelingSalesman.of
public static TravelingSalesman of(int stops, double radius) { final MSeq<double[]> points = MSeq.ofLength(stops); final double delta = 2.0*PI/stops; for (int i = 0; i < stops; ++i) { final double alpha = delta*i; final double x = cos(alpha)*radius + radius; final double y = sin(alpha)*radius + radius; points.set(i, new double[]{x, y}); } // Shuffling of the created points. final Random random = RandomRegistry.getRandom(); for (int j = points.length() - 1; j > 0; --j) { final int i = random.nextInt(j + 1); final double[] tmp = points.get(i); points.set(i, points.get(j)); points.set(j, tmp); } return new TravelingSalesman(points.toISeq()); }
java
public static TravelingSalesman of(int stops, double radius) { final MSeq<double[]> points = MSeq.ofLength(stops); final double delta = 2.0*PI/stops; for (int i = 0; i < stops; ++i) { final double alpha = delta*i; final double x = cos(alpha)*radius + radius; final double y = sin(alpha)*radius + radius; points.set(i, new double[]{x, y}); } // Shuffling of the created points. final Random random = RandomRegistry.getRandom(); for (int j = points.length() - 1; j > 0; --j) { final int i = random.nextInt(j + 1); final double[] tmp = points.get(i); points.set(i, points.get(j)); points.set(j, tmp); } return new TravelingSalesman(points.toISeq()); }
[ "public", "static", "TravelingSalesman", "of", "(", "int", "stops", ",", "double", "radius", ")", "{", "final", "MSeq", "<", "double", "[", "]", ">", "points", "=", "MSeq", ".", "ofLength", "(", "stops", ")", ";", "final", "double", "delta", "=", "2.0"...
of stops. All stops lie on a circle with the given radius.
[ "of", "stops", ".", "All", "stops", "lie", "on", "a", "circle", "with", "the", "given", "radius", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.doc/src/main/java/TravelingSalesman.java#L56-L77
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/Args.java
Args.arg
public Optional<String> arg(final String name) { int index = _args.indexOf("--" + name); if (index == -1) index = _args.indexOf("-" + name); return index >= 0 && index < _args.length() - 1 ? Optional.of(_args.get(index + 1)) : Optional.empty(); }
java
public Optional<String> arg(final String name) { int index = _args.indexOf("--" + name); if (index == -1) index = _args.indexOf("-" + name); return index >= 0 && index < _args.length() - 1 ? Optional.of(_args.get(index + 1)) : Optional.empty(); }
[ "public", "Optional", "<", "String", ">", "arg", "(", "final", "String", "name", ")", "{", "int", "index", "=", "_args", ".", "indexOf", "(", "\"--\"", "+", "name", ")", ";", "if", "(", "index", "==", "-", "1", ")", "index", "=", "_args", ".", "i...
Return the parameter with the given name. @param name the parameter name @return the parameter with the given name, if any
[ "Return", "the", "parameter", "with", "the", "given", "name", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/Args.java#L51-L58
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/Args.java
Args.intArg
public Optional<Integer> intArg(final String name) { return arg(name) .flatMap(s -> parse(s, Integer::valueOf)); }
java
public Optional<Integer> intArg(final String name) { return arg(name) .flatMap(s -> parse(s, Integer::valueOf)); }
[ "public", "Optional", "<", "Integer", ">", "intArg", "(", "final", "String", "name", ")", "{", "return", "arg", "(", "name", ")", ".", "flatMap", "(", "s", "->", "parse", "(", "s", ",", "Integer", "::", "valueOf", ")", ")", ";", "}" ]
Return the int-argument with the given name. @param name the argument name @return the int argument value, if any
[ "Return", "the", "int", "-", "argument", "with", "the", "given", "name", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/Args.java#L66-L69
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/Args.java
Args.longArg
public Optional<Long> longArg(final String name) { return arg(name) .flatMap(s -> parse(s, Long::valueOf)); }
java
public Optional<Long> longArg(final String name) { return arg(name) .flatMap(s -> parse(s, Long::valueOf)); }
[ "public", "Optional", "<", "Long", ">", "longArg", "(", "final", "String", "name", ")", "{", "return", "arg", "(", "name", ")", ".", "flatMap", "(", "s", "->", "parse", "(", "s", ",", "Long", "::", "valueOf", ")", ")", ";", "}" ]
Return the long-argument with the given name. @param name the argument name @return the long argument value, if any
[ "Return", "the", "long", "-", "argument", "with", "the", "given", "name", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/Args.java#L88-L91
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/Args.java
Args.doubleArg
public Optional<Double> doubleArg(final String name) { return arg(name) .flatMap(s -> parse(s, Double::valueOf)); }
java
public Optional<Double> doubleArg(final String name) { return arg(name) .flatMap(s -> parse(s, Double::valueOf)); }
[ "public", "Optional", "<", "Double", ">", "doubleArg", "(", "final", "String", "name", ")", "{", "return", "arg", "(", "name", ")", ".", "flatMap", "(", "s", "->", "parse", "(", "s", ",", "Double", "::", "valueOf", ")", ")", ";", "}" ]
Return the double-argument with the given name. @param name the argument name @return the double argument value, if any
[ "Return", "the", "double", "-", "argument", "with", "the", "given", "name", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/Args.java#L99-L102
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/stat/DoubleSummary.java
DoubleSummary.min
public static double min(final double[] values) { double min = NaN; if (values.length > 0) { min = values[0]; for (int i = 0; i < values.length; ++i) { if (values[i] < min) { min = values[i]; } } } return min; }
java
public static double min(final double[] values) { double min = NaN; if (values.length > 0) { min = values[0]; for (int i = 0; i < values.length; ++i) { if (values[i] < min) { min = values[i]; } } } return min; }
[ "public", "static", "double", "min", "(", "final", "double", "[", "]", "values", ")", "{", "double", "min", "=", "NaN", ";", "if", "(", "values", ".", "length", ">", "0", ")", "{", "min", "=", "values", "[", "0", "]", ";", "for", "(", "int", "i...
Return the minimum value of the given double array. @since 4.0 @param values the double array. @return the minimum value or {@link Double#NaN} if the given array is empty. @throws NullPointerException if the given array is {@code null}.
[ "Return", "the", "minimum", "value", "of", "the", "given", "double", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/stat/DoubleSummary.java#L243-L256
train
jenetics/jenetics
jenetics.xml/src/main/java/io/jenetics/xml/Readers.java
Readers.read
public static < A, G extends Gene<A, G>, C extends Chromosome<G> > List<io.jenetics.Genotype<G>> read(final InputStream in, final Reader<? extends C> chromosomeReader) throws XMLStreamException { return Genotypes.read(in, chromosomeReader); }
java
public static < A, G extends Gene<A, G>, C extends Chromosome<G> > List<io.jenetics.Genotype<G>> read(final InputStream in, final Reader<? extends C> chromosomeReader) throws XMLStreamException { return Genotypes.read(in, chromosomeReader); }
[ "public", "static", "<", "A", ",", "G", "extends", "Gene", "<", "A", ",", "G", ">", ",", "C", "extends", "Chromosome", "<", "G", ">", ">", "List", "<", "io", ".", "jenetics", ".", "Genotype", "<", "G", ">", ">", "read", "(", "final", "InputStream...
Reads the genotypes by using the given chromosome reader. @see Genotypes#read(InputStream, Reader) @param <A> the allele type @param <G> the gene type @param <C> the chromosome type @param in the input stream to read the genotype from @param chromosomeReader the used chromosome reader @return a genotype by using the given chromosome reader @throws XMLStreamException if reading the genotype fails @throws NullPointerException if one of the arguments is {@code null}
[ "Reads", "the", "genotypes", "by", "using", "the", "given", "chromosome", "reader", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.xml/src/main/java/io/jenetics/xml/Readers.java#L746-L756
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/CharacterChromosome.java
CharacterChromosome.toArray
public char[] toArray(final char[] array) { final char[] a = array.length >= length() ? array : new char[length()]; for (int i = length(); --i >= 0;) { a[i] = charAt(i); } return a; }
java
public char[] toArray(final char[] array) { final char[] a = array.length >= length() ? array : new char[length()]; for (int i = length(); --i >= 0;) { a[i] = charAt(i); } return a; }
[ "public", "char", "[", "]", "toArray", "(", "final", "char", "[", "]", "array", ")", "{", "final", "char", "[", "]", "a", "=", "array", ".", "length", ">=", "length", "(", ")", "?", "array", ":", "new", "char", "[", "length", "(", ")", "]", ";"...
Returns an char array containing all of the elements in this chromosome in proper sequence. If the chromosome fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the length of this chromosome. @since 3.0 @param array the array into which the elements of this chromosomes are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose. @return an array containing the elements of this chromosome @throws NullPointerException if the given {@code array} is {@code null}
[ "Returns", "an", "char", "array", "containing", "all", "of", "the", "elements", "in", "this", "chromosome", "in", "proper", "sequence", ".", "If", "the", "chromosome", "fits", "in", "the", "specified", "array", "it", "is", "returned", "therein", ".", "Otherw...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/CharacterChromosome.java#L192-L201
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/engine/AdaptiveEngine.java
AdaptiveEngine.of
public static <G extends Gene<?, G>, C extends Comparable<? super C>> AdaptiveEngine<G, C> of( final Function< ? super EvolutionResult<G, C>, ? extends EvolutionStreamable<G, C>> engine ) { return new AdaptiveEngine<>(engine); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> AdaptiveEngine<G, C> of( final Function< ? super EvolutionResult<G, C>, ? extends EvolutionStreamable<G, C>> engine ) { return new AdaptiveEngine<>(engine); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "AdaptiveEngine", "<", "G", ",", "C", ">", "of", "(", "final", "Function", "<", "?", "super", "EvolutionR...
Return a new adaptive evolution engine, with the given engine generation function. @param engine the engine generating function used for adapting the engines. <b>Be aware, that the {@code EvolutionResult} for the first created {@code Engine} is {@code null}.</b> @param <G> the gene type @param <C> the fitness type @return a new adaptive evolution engine @throws NullPointerException if the given {@code engine} is {@code null}
[ "Return", "a", "new", "adaptive", "evolution", "engine", "with", "the", "given", "engine", "generation", "function", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/engine/AdaptiveEngine.java#L200-L207
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/PermutationChromosome.java
PermutationChromosome.ofInteger
public static PermutationChromosome<Integer> ofInteger(final int start, final int end) { if (end <= start) { throw new IllegalArgumentException(format( "end <= start: %d <= %d", end, start )); } return ofInteger(IntRange.of(start, end), end - start); }
java
public static PermutationChromosome<Integer> ofInteger(final int start, final int end) { if (end <= start) { throw new IllegalArgumentException(format( "end <= start: %d <= %d", end, start )); } return ofInteger(IntRange.of(start, end), end - start); }
[ "public", "static", "PermutationChromosome", "<", "Integer", ">", "ofInteger", "(", "final", "int", "start", ",", "final", "int", "end", ")", "{", "if", "(", "end", "<=", "start", ")", "{", "throw", "new", "IllegalArgumentException", "(", "format", "(", "\...
Create an integer permutation chromosome with the given range. @since 2.0 @param start the start of the integer range (inclusively) of the returned chromosome. @param end the end of the integer range (exclusively) of the returned chromosome. @return a integer permutation chromosome with the given integer range values. @throws IllegalArgumentException if {@code start >= end} or {@code start <= 0}
[ "Create", "an", "integer", "permutation", "chromosome", "with", "the", "given", "range", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/PermutationChromosome.java#L283-L292
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/PermutationChromosome.java
PermutationChromosome.ofInteger
public static PermutationChromosome<Integer> ofInteger(final IntRange range, final int length) { return of( range.stream() .boxed() .collect(ISeq.toISeq()), length ); }
java
public static PermutationChromosome<Integer> ofInteger(final IntRange range, final int length) { return of( range.stream() .boxed() .collect(ISeq.toISeq()), length ); }
[ "public", "static", "PermutationChromosome", "<", "Integer", ">", "ofInteger", "(", "final", "IntRange", "range", ",", "final", "int", "length", ")", "{", "return", "of", "(", "range", ".", "stream", "(", ")", ".", "boxed", "(", ")", ".", "collect", "(",...
Create an integer permutation chromosome with the given range and length @since 3.4 @param range the value range @param length the chromosome length @return a new integer permutation chromosome @throws NullPointerException if the given {@code range} is {@code null} @throws IllegalArgumentException if {@code range.getMax() - range.getMin() < length}, {@code length <= 0} or {@code (range.getMax() - range.getMin())*length} will cause an integer overflow.
[ "Create", "an", "integer", "permutation", "chromosome", "with", "the", "given", "range", "and", "length" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/PermutationChromosome.java#L309-L317
train
jenetics/jenetics
jenetics.example/src/main/java/io/jenetics/example/TravelingSalesman.java
TravelingSalesman.districtCapitals
private static ISeq<WayPoint> districtCapitals() throws IOException { final String capitals = "/io/jenetics/example/DistrictCapitals.gpx"; try (InputStream in = TravelingSalesman .class.getResourceAsStream(capitals)) { return ISeq.of(GPX.read(in).getWayPoints()); } }
java
private static ISeq<WayPoint> districtCapitals() throws IOException { final String capitals = "/io/jenetics/example/DistrictCapitals.gpx"; try (InputStream in = TravelingSalesman .class.getResourceAsStream(capitals)) { return ISeq.of(GPX.read(in).getWayPoints()); } }
[ "private", "static", "ISeq", "<", "WayPoint", ">", "districtCapitals", "(", ")", "throws", "IOException", "{", "final", "String", "capitals", "=", "\"/io/jenetics/example/DistrictCapitals.gpx\"", ";", "try", "(", "InputStream", "in", "=", "TravelingSalesman", ".", "...
Return the district capitals, we want to visit.
[ "Return", "the", "district", "capitals", "we", "want", "to", "visit", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.example/src/main/java/io/jenetics/example/TravelingSalesman.java#L125-L132
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/EnumGene.java
EnumGene.of
public static <A> EnumGene<A> of(final ISeq<? extends A> validAlleles) { return new EnumGene<>( RandomRegistry.getRandom().nextInt(validAlleles.length()), validAlleles ); }
java
public static <A> EnumGene<A> of(final ISeq<? extends A> validAlleles) { return new EnumGene<>( RandomRegistry.getRandom().nextInt(validAlleles.length()), validAlleles ); }
[ "public", "static", "<", "A", ">", "EnumGene", "<", "A", ">", "of", "(", "final", "ISeq", "<", "?", "extends", "A", ">", "validAlleles", ")", "{", "return", "new", "EnumGene", "<>", "(", "RandomRegistry", ".", "getRandom", "(", ")", ".", "nextInt", "...
Return a new enum gene with an allele randomly chosen from the given valid alleles. @param <A> the allele type @param validAlleles the sequence of valid alleles. @return a new {@code EnumGene} with an randomly chosen allele from the sequence of valid alleles @throws java.lang.IllegalArgumentException if the give valid alleles sequence is empty @throws NullPointerException if the valid alleles seq is {@code null}.
[ "Return", "a", "new", "enum", "gene", "with", "an", "allele", "randomly", "chosen", "from", "the", "given", "valid", "alleles", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/EnumGene.java#L224-L229
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/EnumGene.java
EnumGene.of
@SafeVarargs public static <A> EnumGene<A> of( final int alleleIndex, final A... validAlleles ) { return new EnumGene<>(alleleIndex, ISeq.of(validAlleles)); }
java
@SafeVarargs public static <A> EnumGene<A> of( final int alleleIndex, final A... validAlleles ) { return new EnumGene<>(alleleIndex, ISeq.of(validAlleles)); }
[ "@", "SafeVarargs", "public", "static", "<", "A", ">", "EnumGene", "<", "A", ">", "of", "(", "final", "int", "alleleIndex", ",", "final", "A", "...", "validAlleles", ")", "{", "return", "new", "EnumGene", "<>", "(", "alleleIndex", ",", "ISeq", ".", "of...
Create a new enum gene from the given valid genes and the chosen allele index. @param <A> the allele type @param alleleIndex the index of the allele for this gene. @param validAlleles the array of valid alleles. @return a new {@code EnumGene} with the given with the allele {@code validAlleles[alleleIndex]} @throws java.lang.IllegalArgumentException if the give valid alleles array is empty of the allele index is out of range.
[ "Create", "a", "new", "enum", "gene", "from", "the", "given", "valid", "genes", "and", "the", "chosen", "allele", "index", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/EnumGene.java#L243-L249
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/DoubleChromosome.java
DoubleChromosome.toArray
public double[] toArray(final double[] array) { final double[] a = array.length >= length() ? array : new double[length()]; for (int i = length(); --i >= 0;) { a[i] = doubleValue(i); } return a; }
java
public double[] toArray(final double[] array) { final double[] a = array.length >= length() ? array : new double[length()]; for (int i = length(); --i >= 0;) { a[i] = doubleValue(i); } return a; }
[ "public", "double", "[", "]", "toArray", "(", "final", "double", "[", "]", "array", ")", "{", "final", "double", "[", "]", "a", "=", "array", ".", "length", ">=", "length", "(", ")", "?", "array", ":", "new", "double", "[", "length", "(", ")", "]...
Returns an double array containing all of the elements in this chromosome in proper sequence. If the chromosome fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the length of this chromosome. @since 3.0 @param array the array into which the elements of this chromosomes are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose. @return an array containing the elements of this chromosome @throws NullPointerException if the given {@code array} is {@code null}
[ "Returns", "an", "double", "array", "containing", "all", "of", "the", "elements", "in", "this", "chromosome", "in", "proper", "sequence", ".", "If", "the", "chromosome", "fits", "in", "the", "specified", "array", "it", "is", "returned", "therein", ".", "Othe...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/DoubleChromosome.java#L167-L174
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/moea/ParetoFront.java
ParetoFront.toParetoFront
public static <C extends Comparable<? super C>> Collector<C, ?, ParetoFront<C>> toParetoFront() { return toParetoFront(Comparator.naturalOrder()); }
java
public static <C extends Comparable<? super C>> Collector<C, ?, ParetoFront<C>> toParetoFront() { return toParetoFront(Comparator.naturalOrder()); }
[ "public", "static", "<", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Collector", "<", "C", ",", "?", ",", "ParetoFront", "<", "C", ">", ">", "toParetoFront", "(", ")", "{", "return", "toParetoFront", "(", "Comparator", ".", "natura...
Return a pareto-front collector. The natural order of the elements is used as pareto-dominance order. @param <C> the element type @return a new pareto-front collector
[ "Return", "a", "pareto", "-", "front", "collector", ".", "The", "natural", "order", "of", "the", "elements", "is", "used", "as", "pareto", "-", "dominance", "order", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/moea/ParetoFront.java#L228-L231
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Limits.java
Limits.byFitnessThreshold
public static <C extends Comparable<? super C>> Predicate<EvolutionResult<?, C>> byFitnessThreshold(final C threshold) { return new FitnessThresholdLimit<>(threshold); }
java
public static <C extends Comparable<? super C>> Predicate<EvolutionResult<?, C>> byFitnessThreshold(final C threshold) { return new FitnessThresholdLimit<>(threshold); }
[ "public", "static", "<", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Predicate", "<", "EvolutionResult", "<", "?", ",", "C", ">", ">", "byFitnessThreshold", "(", "final", "C", "threshold", ")", "{", "return", "new", "FitnessThresholdLi...
Return a predicate, which will truncated the evolution stream if the best fitness of the current population becomes less than the specified threshold and the objective is set to minimize the fitness. This predicate also stops the evolution if the best fitness in the current population becomes greater than the user-specified fitness threshold when the objective is to maximize the fitness. <pre>{@code final Phenotype<DoubleGene, Double> result = engine.stream() // Truncate the evolution stream if the best fitness is higher than // the given threshold of '2.3'. .limit(byFitnessThreshold(2.3)) // The evolution will stop after maximal 250 generations; guarantees // the termination (truncation) of the evolution stream. .limit(250) .collect(toBestPhenotype()); }</pre> @since 3.1 @param threshold the desired threshold @param <C> the fitness type @return the predicate which truncates the evolution stream based on the given {@code threshold}. @throws NullPointerException if the given {@code threshold} is {@code null}.
[ "Return", "a", "predicate", "which", "will", "truncated", "the", "evolution", "stream", "if", "the", "best", "fitness", "of", "the", "current", "population", "becomes", "less", "than", "the", "specified", "threshold", "and", "the", "objective", "is", "set", "t...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Limits.java#L203-L206
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Limits.java
Limits.byFitnessConvergence
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byFitnessConvergence( final int shortFilterSize, final int longFilterSize, final BiPredicate<DoubleMoments, DoubleMoments> proceed ) { return new FitnessConvergenceLimit<>( shortFilterSize, longFilterSize, proceed ); }
java
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byFitnessConvergence( final int shortFilterSize, final int longFilterSize, final BiPredicate<DoubleMoments, DoubleMoments> proceed ) { return new FitnessConvergenceLimit<>( shortFilterSize, longFilterSize, proceed ); }
[ "public", "static", "<", "N", "extends", "Number", "&", "Comparable", "<", "?", "super", "N", ">", ">", "Predicate", "<", "EvolutionResult", "<", "?", ",", "N", ">", ">", "byFitnessConvergence", "(", "final", "int", "shortFilterSize", ",", "final", "int", ...
Return a predicate, which will truncate the evolution stream if the fitness is converging. Two filters of different lengths are used to smooth the best fitness across the generations. <pre>{@code final Phenotype<DoubleGene, Double> result = engine.stream() .limit(byFitnessConvergence(5, 15, (s, l) -> { final double div = max(abs(s.getMean()), abs(l.getMean())); final eps = abs(s.getMean() - l.getMean())/(div <= 10E-20 ? 1.0 : div); return eps >= 10E-5 })) .collect(toBestPhenotype()); }</pre> In the example above, the moving average of the short- and long filter is used for determining the fitness convergence. @apiNote The returned predicate maintains mutable state. Using it in a parallel evolution streams needs external synchronization of the {@code test} method. @since 3.7 @param shortFilterSize the size of the short filter @param longFilterSize the size of the long filter. The long filter size also determines the minimum number of generations of the evolution stream. @param proceed the predicate which determines when the evolution stream is truncated. The first parameter of the predicate contains the double statistics of the short filter and the second parameter contains the statistics of the long filter @param <N> the fitness type @return a new fitness convergence strategy @throws NullPointerException if the {@code proceed} predicate is {@code null}
[ "Return", "a", "predicate", "which", "will", "truncate", "the", "evolution", "stream", "if", "the", "fitness", "is", "converging", ".", "Two", "filters", "of", "different", "lengths", "are", "used", "to", "smooth", "the", "best", "fitness", "across", "the", ...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Limits.java#L245-L256
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Limits.java
Limits.byFitnessConvergence
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byFitnessConvergence( final int shortFilterSize, final int longFilterSize, final double epsilon ) { if (epsilon < 0.0 || epsilon > 1.0) { throw new IllegalArgumentException(format( "The given epsilon is not in the range [0, 1]: %f", epsilon )); } return new FitnessConvergenceLimit<>( shortFilterSize, longFilterSize, (s, l) -> eps(s.getMean(), l.getMean()) >= epsilon ); }
java
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byFitnessConvergence( final int shortFilterSize, final int longFilterSize, final double epsilon ) { if (epsilon < 0.0 || epsilon > 1.0) { throw new IllegalArgumentException(format( "The given epsilon is not in the range [0, 1]: %f", epsilon )); } return new FitnessConvergenceLimit<>( shortFilterSize, longFilterSize, (s, l) -> eps(s.getMean(), l.getMean()) >= epsilon ); }
[ "public", "static", "<", "N", "extends", "Number", "&", "Comparable", "<", "?", "super", "N", ">", ">", "Predicate", "<", "EvolutionResult", "<", "?", ",", "N", ">", ">", "byFitnessConvergence", "(", "final", "int", "shortFilterSize", ",", "final", "int", ...
Return a predicate, which will truncate the evolution stream if the fitness is converging. Two filters of different lengths are used to smooth the best fitness across the generations. When the smoothed best fitness from the long filter is less than a user-specified percentage away from the smoothed best fitness from the short filter, the fitness is deemed as converged and the evolution terminates. <pre>{@code final Phenotype<DoubleGene, Double> result = engine.stream() .limit(byFitnessConvergence(5, 15, 10E-4)) .collect(toBestPhenotype()); }</pre> In the given example, the evolution stream stops, if the difference of the mean values of the long and short filter is less than 1%. The short filter calculates the mean of the best fitness values of the last 5 generations. The long filter uses the best fitness values of the last 15 generations. @apiNote The returned predicate maintains mutable state. Using it in a parallel evolution streams needs external synchronization of the {@code test} method. @since 3.7 @param shortFilterSize the size of the short filter @param longFilterSize the size of the long filter. The long filter size also determines the minimum number of generations of the evolution stream. @param epsilon the maximal relative distance of the mean value between the short and the long filter. The {@code epsilon} must within the range of {@code [0..1]}. @param <N> the fitness type @return a new fitness convergence strategy @throws IllegalArgumentException if {@code shortFilterSize < 1} || {@code longFilterSize < 2} || {@code shortFilterSize >= longFilterSize} @throws IllegalArgumentException if {@code epsilon} is not in the range of {@code [0..1]}
[ "Return", "a", "predicate", "which", "will", "truncate", "the", "evolution", "stream", "if", "the", "fitness", "is", "converging", ".", "Two", "filters", "of", "different", "lengths", "are", "used", "to", "smooth", "the", "best", "fitness", "across", "the", ...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Limits.java#L299-L316
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Limits.java
Limits.eps
private static double eps(final double s, final double l) { final double div = max(abs(s), abs(l)); return abs(s - l)/(div <= 10E-20 ? 1.0 : div); }
java
private static double eps(final double s, final double l) { final double div = max(abs(s), abs(l)); return abs(s - l)/(div <= 10E-20 ? 1.0 : div); }
[ "private", "static", "double", "eps", "(", "final", "double", "s", ",", "final", "double", "l", ")", "{", "final", "double", "div", "=", "max", "(", "abs", "(", "s", ")", ",", "abs", "(", "l", ")", ")", ";", "return", "abs", "(", "s", "-", "l",...
Calculate the relative mean difference between short and long filter.
[ "Calculate", "the", "relative", "mean", "difference", "between", "short", "and", "long", "filter", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Limits.java#L319-L322
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Limits.java
Limits.byPopulationConvergence
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byPopulationConvergence(final double epsilon) { if (epsilon < 0.0 || epsilon > 1.0) { throw new IllegalArgumentException(format( "The given epsilon is not in the range [0, 1]: %f", epsilon )); } return new PopulationConvergenceLimit<>((best, moments) -> eps(best, moments.getMean()) >= epsilon ); }
java
public static <N extends Number & Comparable<? super N>> Predicate<EvolutionResult<?, N>> byPopulationConvergence(final double epsilon) { if (epsilon < 0.0 || epsilon > 1.0) { throw new IllegalArgumentException(format( "The given epsilon is not in the range [0, 1]: %f", epsilon )); } return new PopulationConvergenceLimit<>((best, moments) -> eps(best, moments.getMean()) >= epsilon ); }
[ "public", "static", "<", "N", "extends", "Number", "&", "Comparable", "<", "?", "super", "N", ">", ">", "Predicate", "<", "EvolutionResult", "<", "?", ",", "N", ">", ">", "byPopulationConvergence", "(", "final", "double", "epsilon", ")", "{", "if", "(", ...
A termination method that stops the evolution when the population is deemed as converged. The population is deemed as converged when the average fitness across the current population is less than a user-specified percentage away from the best fitness of the current population. @since 3.9 @param epsilon the maximal relative distance of the best fitness value of the population and the mean value of the population fitness values. @param <N> the fitness type @return a new fitness convergence strategy @throws IllegalArgumentException if {@code epsilon} is not in the range of {@code [0..1]}
[ "A", "termination", "method", "that", "stops", "the", "evolution", "when", "the", "population", "is", "deemed", "as", "converged", ".", "The", "population", "is", "deemed", "as", "converged", "when", "the", "average", "fitness", "across", "the", "current", "po...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Limits.java#L367-L379
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/CompositeAlterer.java
CompositeAlterer.of
@SafeVarargs static <G extends Gene<?, G>, C extends Comparable<? super C>> CompositeAlterer<G, C> of(final Alterer<G, C>... alterers) { return new CompositeAlterer<>(ISeq.of(alterers)); }
java
@SafeVarargs static <G extends Gene<?, G>, C extends Comparable<? super C>> CompositeAlterer<G, C> of(final Alterer<G, C>... alterers) { return new CompositeAlterer<>(ISeq.of(alterers)); }
[ "@", "SafeVarargs", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "CompositeAlterer", "<", "G", ",", "C", ">", "of", "(", "final", "Alterer", "<", "G", ",", "C...
Combine the given alterers. @param <G> the gene type @param <C> the fitness function result type @param alterers the alterers to combine. @return a new alterer which consists of the given one @throws NullPointerException if one of the alterers is {@code null}.
[ "Combine", "the", "given", "alterers", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/CompositeAlterer.java#L135-L139
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/CompositeAlterer.java
CompositeAlterer.join
static <T extends Gene<?, T>, C extends Comparable<? super C>> CompositeAlterer<T, C> join( final Alterer<T, C> a1, final Alterer<T, C> a2 ) { return CompositeAlterer.of(a1, a2); }
java
static <T extends Gene<?, T>, C extends Comparable<? super C>> CompositeAlterer<T, C> join( final Alterer<T, C> a1, final Alterer<T, C> a2 ) { return CompositeAlterer.of(a1, a2); }
[ "static", "<", "T", "extends", "Gene", "<", "?", ",", "T", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "CompositeAlterer", "<", "T", ",", "C", ">", "join", "(", "final", "Alterer", "<", "T", ",", "C", ">", "a1", ",...
Joins the given alterer and returns a new CompositeAlterer object. If one of the given alterers is a CompositeAlterer the sub alterers of it are unpacked and appended to the newly created CompositeAlterer. @param <T> the gene type of the alterers. @param <C> the fitness function result type @param a1 the first alterer. @param a2 the second alterer. @return a new CompositeAlterer object. @throws NullPointerException if one of the given alterer is {@code null}.
[ "Joins", "the", "given", "alterer", "and", "returns", "a", "new", "CompositeAlterer", "object", ".", "If", "one", "of", "the", "given", "alterers", "is", "a", "CompositeAlterer", "the", "sub", "alterers", "of", "it", "are", "unpacked", "and", "appended", "to...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/CompositeAlterer.java#L154-L160
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/Phenotype.java
Phenotype.newInstance
@Deprecated public Phenotype<G, C> newInstance( final long generation, final Function<? super Genotype<G>, ? extends C> function, final Function<? super C, ? extends C> scaler ) { return of(_genotype, generation, function, scaler); }
java
@Deprecated public Phenotype<G, C> newInstance( final long generation, final Function<? super Genotype<G>, ? extends C> function, final Function<? super C, ? extends C> scaler ) { return of(_genotype, generation, function, scaler); }
[ "@", "Deprecated", "public", "Phenotype", "<", "G", ",", "C", ">", "newInstance", "(", "final", "long", "generation", ",", "final", "Function", "<", "?", "super", "Genotype", "<", "G", ">", ",", "?", "extends", "C", ">", "function", ",", "final", "Func...
Return a new phenotype with the the genotype of this and with new fitness function, fitness scaler and generation. @param generation the generation of the new phenotype. @param function the (new) fitness scaler of the created phenotype. @param scaler the (new) fitness scaler of the created phenotype @return a new phenotype with the given values. @throws NullPointerException if one of the values is {@code null}. @throws IllegalArgumentException if the given {@code generation} is {@code < 0}. @deprecated Will be removed in a later version
[ "Return", "a", "new", "phenotype", "with", "the", "the", "genotype", "of", "this", "and", "with", "new", "fitness", "function", "fitness", "scaler", "and", "generation", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/Phenotype.java#L349-L356
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/Phenotype.java
Phenotype.newInstance
@Deprecated public Phenotype<G, C> newInstance( final long generation, final Function<? super Genotype<G>, ? extends C> function ) { return of(_genotype, generation, function, a -> a); }
java
@Deprecated public Phenotype<G, C> newInstance( final long generation, final Function<? super Genotype<G>, ? extends C> function ) { return of(_genotype, generation, function, a -> a); }
[ "@", "Deprecated", "public", "Phenotype", "<", "G", ",", "C", ">", "newInstance", "(", "final", "long", "generation", ",", "final", "Function", "<", "?", "super", "Genotype", "<", "G", ">", ",", "?", "extends", "C", ">", "function", ")", "{", "return",...
Return a new phenotype with the the genotype of this and with new fitness function and generation. @param generation the generation of the new phenotype. @param function the (new) fitness scaler of the created phenotype. @return a new phenotype with the given values. @throws NullPointerException if one of the values is {@code null}. @throws IllegalArgumentException if the given {@code generation} is {@code < 0}. @deprecated Will be removed in a later version
[ "Return", "a", "new", "phenotype", "with", "the", "the", "genotype", "of", "this", "and", "with", "new", "fitness", "function", "and", "generation", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/Phenotype.java#L371-L377
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/Phenotype.java
Phenotype.of
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Phenotype<G, C> of( final Genotype<G> genotype, final long generation, final Function<? super Genotype<G>, ? extends C> function, final Function<? super C, ? extends C> scaler ) { return new Phenotype<>( genotype, generation, function, scaler, null ); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Phenotype<G, C> of( final Genotype<G> genotype, final long generation, final Function<? super Genotype<G>, ? extends C> function, final Function<? super C, ? extends C> scaler ) { return new Phenotype<>( genotype, generation, function, scaler, null ); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Phenotype", "<", "G", ",", "C", ">", "of", "(", "final", "Genotype", "<", "G", ">", "genotype", ",", ...
Create a new phenotype from the given arguments. @param <G> the gene type of the chromosome @param <C> the fitness value type @param genotype the genotype of this phenotype. @param generation the current generation of the generated phenotype. @param function the fitness function of this phenotype. @param scaler the fitness scaler. @return a new phenotype object @throws NullPointerException if one of the arguments is {@code null}. @throws IllegalArgumentException if the given {@code generation} is {@code < 0}.
[ "Create", "a", "new", "phenotype", "from", "the", "given", "arguments", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/Phenotype.java#L423-L437
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/internal/util/TreePattern.java
TreePattern.compile
public static TreePattern compile(final String pattern) { return new TreePattern(TreeNode.parse(pattern, Decl::of)); }
java
public static TreePattern compile(final String pattern) { return new TreePattern(TreeNode.parse(pattern, Decl::of)); }
[ "public", "static", "TreePattern", "compile", "(", "final", "String", "pattern", ")", "{", "return", "new", "TreePattern", "(", "TreeNode", ".", "parse", "(", "pattern", ",", "Decl", "::", "of", ")", ")", ";", "}" ]
Compiles the given tree pattern string. @param pattern the tree pattern string @return the compiled pattern @throws NullPointerException if the given pattern is {@code null} @throws IllegalArgumentException if the given parentheses tree string doesn't represent a valid pattern tree
[ "Compiles", "the", "given", "tree", "pattern", "string", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/internal/util/TreePattern.java#L328-L330
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/collection/Array.java
Array.sort
public void sort( final int from, final int until, final Comparator<? super T> comparator ) { _store.sort(from + _start, until + _start, comparator); }
java
public void sort( final int from, final int until, final Comparator<? super T> comparator ) { _store.sort(from + _start, until + _start, comparator); }
[ "public", "void", "sort", "(", "final", "int", "from", ",", "final", "int", "until", ",", "final", "Comparator", "<", "?", "super", "T", ">", "comparator", ")", "{", "_store", ".", "sort", "(", "from", "+", "_start", ",", "until", "+", "_start", ",",...
Sort the store. @param from the start index where to start sorting (inclusively) @param until the end index where to stop sorting (exclusively) @param comparator the {@code Comparator} used to compare sequence elements. A {@code null} value indicates that the elements' Comparable natural ordering should be used
[ "Sort", "the", "store", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/collection/Array.java#L126-L132
train
jenetics/jenetics
jenetics.tool/src/main/java/io/jenetics/tool/trial/TrialMeter.java
TrialMeter.of
public static <T> TrialMeter<T> of( final String name, final String description, final Params<T> params, final String... dataSetNames ) { return new TrialMeter<T>( name, description, Env.of(), params, DataSet.of(params.size(), dataSetNames) ); }
java
public static <T> TrialMeter<T> of( final String name, final String description, final Params<T> params, final String... dataSetNames ) { return new TrialMeter<T>( name, description, Env.of(), params, DataSet.of(params.size(), dataSetNames) ); }
[ "public", "static", "<", "T", ">", "TrialMeter", "<", "T", ">", "of", "(", "final", "String", "name", ",", "final", "String", "description", ",", "final", "Params", "<", "T", ">", "params", ",", "final", "String", "...", "dataSetNames", ")", "{", "retu...
Return a new trial measure environment. @param name the trial meter name @param description the trial meter description, maybe {@code null} @param params the parameters which are tested by this trial meter @param dataSetNames the names of the calculated data sets @param <T> the parameter type @return a new trial measure environment
[ "Return", "a", "new", "trial", "measure", "environment", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.tool/src/main/java/io/jenetics/tool/trial/TrialMeter.java#L211-L224
train
jenetics/jenetics
jenetics.doc/src/main/java/OnesCounting.java
OnesCounting.count
private static Integer count(final Genotype<BitGene> gt) { return gt.getChromosome() .as(BitChromosome.class) .bitCount(); }
java
private static Integer count(final Genotype<BitGene> gt) { return gt.getChromosome() .as(BitChromosome.class) .bitCount(); }
[ "private", "static", "Integer", "count", "(", "final", "Genotype", "<", "BitGene", ">", "gt", ")", "{", "return", "gt", ".", "getChromosome", "(", ")", ".", "as", "(", "BitChromosome", ".", "class", ")", ".", "bitCount", "(", ")", ";", "}" ]
This method calculates the fitness for a given genotype.
[ "This", "method", "calculates", "the", "fitness", "for", "a", "given", "genotype", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.doc/src/main/java/OnesCounting.java#L17-L21
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionStatistics.java
EvolutionStatistics.accept
private void accept(final EvolutionDurations durations) { final double selection = toSeconds(durations.getOffspringSelectionDuration()) + toSeconds(durations.getSurvivorsSelectionDuration()); final double alter = toSeconds(durations.getOffspringAlterDuration()) + toSeconds(durations.getOffspringFilterDuration()); _selectionDuration.accept(selection); _alterDuration.accept(alter); _evaluationDuration .accept(toSeconds(durations.getEvaluationDuration())); _evolveDuration .accept(toSeconds(durations.getEvolveDuration())); }
java
private void accept(final EvolutionDurations durations) { final double selection = toSeconds(durations.getOffspringSelectionDuration()) + toSeconds(durations.getSurvivorsSelectionDuration()); final double alter = toSeconds(durations.getOffspringAlterDuration()) + toSeconds(durations.getOffspringFilterDuration()); _selectionDuration.accept(selection); _alterDuration.accept(alter); _evaluationDuration .accept(toSeconds(durations.getEvaluationDuration())); _evolveDuration .accept(toSeconds(durations.getEvolveDuration())); }
[ "private", "void", "accept", "(", "final", "EvolutionDurations", "durations", ")", "{", "final", "double", "selection", "=", "toSeconds", "(", "durations", ".", "getOffspringSelectionDuration", "(", ")", ")", "+", "toSeconds", "(", "durations", ".", "getSurvivorsS...
Calculate duration statistics
[ "Calculate", "duration", "statistics" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionStatistics.java#L136-L150
train
jenetics/jenetics
jenetics.example/src/main/java/io/jenetics/example/EvolutionResume.java
EvolutionResume.run
private EvolutionResult<BitGene, Double> run( final EvolutionResult<BitGene, Double> last, final AtomicBoolean proceed ) { System.out.println("Starting evolution with existing result."); return (last != null ? ENGINE.stream(last) : ENGINE.stream()) .limit(r -> proceed.get()) .collect(EvolutionResult.toBestEvolutionResult()); }
java
private EvolutionResult<BitGene, Double> run( final EvolutionResult<BitGene, Double> last, final AtomicBoolean proceed ) { System.out.println("Starting evolution with existing result."); return (last != null ? ENGINE.stream(last) : ENGINE.stream()) .limit(r -> proceed.get()) .collect(EvolutionResult.toBestEvolutionResult()); }
[ "private", "EvolutionResult", "<", "BitGene", ",", "Double", ">", "run", "(", "final", "EvolutionResult", "<", "BitGene", ",", "Double", ">", "last", ",", "final", "AtomicBoolean", "proceed", ")", "{", "System", ".", "out", ".", "println", "(", "\"Starting e...
Run the evolution.
[ "Run", "the", "evolution", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.example/src/main/java/io/jenetics/example/EvolutionResume.java#L61-L70
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/stat/DoubleMomentStatistics.java
DoubleMomentStatistics.accept
@Override public void accept(final double value) { super.accept(value); _min = Math.min(_min, value); _max = Math.max(_max, value); _sum.add(value); }
java
@Override public void accept(final double value) { super.accept(value); _min = Math.min(_min, value); _max = Math.max(_max, value); _sum.add(value); }
[ "@", "Override", "public", "void", "accept", "(", "final", "double", "value", ")", "{", "super", ".", "accept", "(", "value", ")", ";", "_min", "=", "Math", ".", "min", "(", "_min", ",", "value", ")", ";", "_max", "=", "Math", ".", "max", "(", "_...
Records a new value into the moments information @param value the input {@code value}
[ "Records", "a", "new", "value", "into", "the", "moments", "information" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/stat/DoubleMomentStatistics.java#L91-L97
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/BitChromosome.java
BitChromosome.toBitSet
public BitSet toBitSet() { final BitSet set = new BitSet(length()); for (int i = 0, n = length(); i < n; ++i) { set.set(i, getGene(i).getBit()); } return set; }
java
public BitSet toBitSet() { final BitSet set = new BitSet(length()); for (int i = 0, n = length(); i < n; ++i) { set.set(i, getGene(i).getBit()); } return set; }
[ "public", "BitSet", "toBitSet", "(", ")", "{", "final", "BitSet", "set", "=", "new", "BitSet", "(", "length", "(", ")", ")", ";", "for", "(", "int", "i", "=", "0", ",", "n", "=", "length", "(", ")", ";", "i", "<", "n", ";", "++", "i", ")", ...
Return the corresponding BitSet of this BitChromosome. @return The corresponding BitSet of this BitChromosome.
[ "Return", "the", "corresponding", "BitSet", "of", "this", "BitChromosome", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/BitChromosome.java#L358-L364
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/BitChromosome.java
BitChromosome.invert
public BitChromosome invert() { final byte[] data = _genes.clone(); bit.invert(data); return new BitChromosome(data, _length, 1.0 - _p); }
java
public BitChromosome invert() { final byte[] data = _genes.clone(); bit.invert(data); return new BitChromosome(data, _length, 1.0 - _p); }
[ "public", "BitChromosome", "invert", "(", ")", "{", "final", "byte", "[", "]", "data", "=", "_genes", ".", "clone", "(", ")", ";", "bit", ".", "invert", "(", "data", ")", ";", "return", "new", "BitChromosome", "(", "data", ",", "_length", ",", "1.0",...
Invert the ones and zeros of this bit chromosome. @return a new BitChromosome with inverted ones and zeros.
[ "Invert", "the", "ones", "and", "zeros", "of", "this", "bit", "chromosome", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/BitChromosome.java#L450-L454
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/BitChromosome.java
BitChromosome.of
public static BitChromosome of(final int length, final double p) { return new BitChromosome(bit.newArray(length, p), length, p); }
java
public static BitChromosome of(final int length, final double p) { return new BitChromosome(bit.newArray(length, p), length, p); }
[ "public", "static", "BitChromosome", "of", "(", "final", "int", "length", ",", "final", "double", "p", ")", "{", "return", "new", "BitChromosome", "(", "bit", ".", "newArray", "(", "length", ",", "p", ")", ",", "length", ",", "p", ")", ";", "}" ]
Construct a new BitChromosome with the given _length. @param length Length of the BitChromosome, number of bits. @param p Probability of the TRUEs in the BitChromosome. @return a new {@code BitChromosome} with the given parameter @throws NegativeArraySizeException if the {@code length} is smaller than one. @throws IllegalArgumentException if {@code p} is not a valid probability.
[ "Construct", "a", "new", "BitChromosome", "with", "the", "given", "_length", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/BitChromosome.java#L466-L468
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java
IntList.forEach
public void forEach(final IntConsumer action) { requireNonNull(action); final int size = _size; for (int i = 0; i < size; ++i) { action.accept(_data[i]); } }
java
public void forEach(final IntConsumer action) { requireNonNull(action); final int size = _size; for (int i = 0; i < size; ++i) { action.accept(_data[i]); } }
[ "public", "void", "forEach", "(", "final", "IntConsumer", "action", ")", "{", "requireNonNull", "(", "action", ")", ";", "final", "int", "size", "=", "_size", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "size", ";", "++", "i", ")", "{", ...
Performs the given action for each element of the list. @param action the action to be performed for each element @throws NullPointerException if the specified action is {@code null}
[ "Performs", "the", "given", "action", "for", "each", "element", "of", "the", "list", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java#L93-L100
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java
IntList.addAll
public boolean addAll(final int[] elements) { final int count = elements.length; ensureSize(_size + count); arraycopy(elements, 0, _data, _size, count); _size += count; return count != 0; }
java
public boolean addAll(final int[] elements) { final int count = elements.length; ensureSize(_size + count); arraycopy(elements, 0, _data, _size, count); _size += count; return count != 0; }
[ "public", "boolean", "addAll", "(", "final", "int", "[", "]", "elements", ")", "{", "final", "int", "count", "=", "elements", ".", "length", ";", "ensureSize", "(", "_size", "+", "count", ")", ";", "arraycopy", "(", "elements", ",", "0", ",", "_data", ...
Appends all of the elements in the specified array to the end of this list. @param elements array containing elements to be added to this list @return <tt>true</tt> if this list changed as a result of the call @throws NullPointerException if the specified array is null
[ "Appends", "all", "of", "the", "elements", "in", "the", "specified", "array", "to", "the", "end", "of", "this", "list", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java#L153-L160
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java
IntList.addAll
public boolean addAll(final int index, final int[] elements) { addRangeCheck(index); final int count = elements.length; ensureSize(_size + count); final int moved = _size - index; if (moved > 0) { arraycopy(_data, index, _data, index + count, moved); } arraycopy(elements, 0, _data, index, count); _size += count; return count != 0; }
java
public boolean addAll(final int index, final int[] elements) { addRangeCheck(index); final int count = elements.length; ensureSize(_size + count); final int moved = _size - index; if (moved > 0) { arraycopy(_data, index, _data, index + count, moved); } arraycopy(elements, 0, _data, index, count); _size += count; return count != 0; }
[ "public", "boolean", "addAll", "(", "final", "int", "index", ",", "final", "int", "[", "]", "elements", ")", "{", "addRangeCheck", "(", "index", ")", ";", "final", "int", "count", "=", "elements", ".", "length", ";", "ensureSize", "(", "_size", "+", "c...
Inserts all of the elements in the specified array into this list, starting at the specified position. @param index index at which to insert the first element from the specified collection @param elements collection containing elements to be added to this list @return <tt>true</tt> if this list changed as a result of the call @throws IndexOutOfBoundsException if the index is out of range {@code (index < 0 || index > size())} @throws NullPointerException if the specified array is null
[ "Inserts", "all", "of", "the", "elements", "in", "the", "specified", "array", "into", "this", "list", "starting", "at", "the", "specified", "position", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/internal/IntList.java#L174-L188
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/AbstractTreeGene.java
AbstractTreeGene.getChild
@Override public G getChild(final int index) { checkTreeState(); if (index < 0 || index >= childCount()) { throw new IndexOutOfBoundsException(format( "Child index out of bounds: %s", index )); } assert _genes != null; return _genes.get(_childOffset + index); }
java
@Override public G getChild(final int index) { checkTreeState(); if (index < 0 || index >= childCount()) { throw new IndexOutOfBoundsException(format( "Child index out of bounds: %s", index )); } assert _genes != null; return _genes.get(_childOffset + index); }
[ "@", "Override", "public", "G", "getChild", "(", "final", "int", "index", ")", "{", "checkTreeState", "(", ")", ";", "if", "(", "index", "<", "0", "||", "index", ">=", "childCount", "(", ")", ")", "{", "throw", "new", "IndexOutOfBoundsException", "(", ...
Return the child gene with the given index. @param index the child index @return the child node with the given index @throws IndexOutOfBoundsException if the {@code index} is out of bounds ({@code [0, childCount())}) @throws IllegalStateException if this gene is not part of a chromosome
[ "Return", "the", "child", "gene", "with", "the", "given", "index", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/AbstractTreeGene.java#L162-L173
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/Mutator.java
Mutator.mutate
@SuppressWarnings("deprecation") protected MutatorResult<Phenotype<G, C>> mutate( final Phenotype<G, C> phenotype, final long generation, final double p, final Random random ) { return mutate(phenotype.getGenotype(), p, random) .map(gt -> phenotype.newInstance(gt, generation)); }
java
@SuppressWarnings("deprecation") protected MutatorResult<Phenotype<G, C>> mutate( final Phenotype<G, C> phenotype, final long generation, final double p, final Random random ) { return mutate(phenotype.getGenotype(), p, random) .map(gt -> phenotype.newInstance(gt, generation)); }
[ "@", "SuppressWarnings", "(", "\"deprecation\"", ")", "protected", "MutatorResult", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "mutate", "(", "final", "Phenotype", "<", "G", ",", "C", ">", "phenotype", ",", "final", "long", "generation", ",", "final",...
Mutates the given phenotype. @see #mutate(Genotype, double, Random) @see #mutate(Chromosome, double, Random) @see #mutate(Gene, Random) @param phenotype the phenotype to mutate @param generation the actual generation @param p the mutation probability for the underlying genetic objects @param random the random engine used for the phenotype mutation @return the mutation result
[ "Mutates", "the", "given", "phenotype", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/Mutator.java#L144-L153
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/Mutator.java
Mutator.mutate
protected MutatorResult<Genotype<G>> mutate( final Genotype<G> genotype, final double p, final Random random ) { final int P = probability.toInt(p); final ISeq<MutatorResult<Chromosome<G>>> result = genotype.toSeq() .map(gt -> random.nextInt() < P ? mutate(gt, p, random) : MutatorResult.of(gt)); return MutatorResult.of( Genotype.of(result.map(MutatorResult::getResult)), result.stream().mapToInt(MutatorResult::getMutations).sum() ); }
java
protected MutatorResult<Genotype<G>> mutate( final Genotype<G> genotype, final double p, final Random random ) { final int P = probability.toInt(p); final ISeq<MutatorResult<Chromosome<G>>> result = genotype.toSeq() .map(gt -> random.nextInt() < P ? mutate(gt, p, random) : MutatorResult.of(gt)); return MutatorResult.of( Genotype.of(result.map(MutatorResult::getResult)), result.stream().mapToInt(MutatorResult::getMutations).sum() ); }
[ "protected", "MutatorResult", "<", "Genotype", "<", "G", ">", ">", "mutate", "(", "final", "Genotype", "<", "G", ">", "genotype", ",", "final", "double", "p", ",", "final", "Random", "random", ")", "{", "final", "int", "P", "=", "probability", ".", "to...
Mutates the given genotype. @see #mutate(Chromosome, double, Random) @see #mutate(Gene, Random) @param genotype the genotype to mutate @param p the mutation probability for the underlying genetic objects @param random the random engine used for the genotype mutation @return the mutation result
[ "Mutates", "the", "given", "genotype", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/Mutator.java#L166-L181
train
jenetics/jenetics
jenetics.example/src/main/java/io/jenetics/example/image/EvolvingImagesWorker.java
EvolvingImagesWorker.start
public void start( final BiConsumer< EvolutionResult<PolygonGene, Double>, EvolutionResult<PolygonGene, Double>> callback ) { final Thread thread = new Thread(() -> { final MinMax<EvolutionResult<PolygonGene, Double>> best = MinMax.of(); _engine.stream() .limit(result -> !Thread.currentThread().isInterrupted()) .peek(best) .forEach(r -> { waiting(); if (callback != null) { callback.accept(r, best.getMax()); } }); }); thread.start(); _thread = thread; }
java
public void start( final BiConsumer< EvolutionResult<PolygonGene, Double>, EvolutionResult<PolygonGene, Double>> callback ) { final Thread thread = new Thread(() -> { final MinMax<EvolutionResult<PolygonGene, Double>> best = MinMax.of(); _engine.stream() .limit(result -> !Thread.currentThread().isInterrupted()) .peek(best) .forEach(r -> { waiting(); if (callback != null) { callback.accept(r, best.getMax()); } }); }); thread.start(); _thread = thread; }
[ "public", "void", "start", "(", "final", "BiConsumer", "<", "EvolutionResult", "<", "PolygonGene", ",", "Double", ">", ",", "EvolutionResult", "<", "PolygonGene", ",", "Double", ">", ">", "callback", ")", "{", "final", "Thread", "thread", "=", "new", "Thread...
Starts the evolution worker with the given evolution result callback. The callback may be null. @param callback the {@code EvolutionResult} callback. The first parameter contains the current result and the second the best.
[ "Starts", "the", "evolution", "worker", "with", "the", "given", "evolution", "result", "callback", ".", "The", "callback", "may", "be", "null", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.example/src/main/java/io/jenetics/example/image/EvolvingImagesWorker.java#L163-L183
train
jenetics/jenetics
jenetics.example/src/main/java/io/jenetics/example/image/EvolvingImagesWorker.java
EvolvingImagesWorker.stop
public void stop() { resume(); final Thread thread = _thread; if (thread != null) { thread.interrupt(); try { thread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { _thread = null; } } }
java
public void stop() { resume(); final Thread thread = _thread; if (thread != null) { thread.interrupt(); try { thread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { _thread = null; } } }
[ "public", "void", "stop", "(", ")", "{", "resume", "(", ")", ";", "final", "Thread", "thread", "=", "_thread", ";", "if", "(", "thread", "!=", "null", ")", "{", "thread", ".", "interrupt", "(", ")", ";", "try", "{", "thread", ".", "join", "(", ")...
Stops the current evolution, if running.
[ "Stops", "the", "current", "evolution", "if", "running", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.example/src/main/java/io/jenetics/example/image/EvolvingImagesWorker.java#L203-L216
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/AltererResult.java
AltererResult.of
public static <G extends Gene<?, G>, C extends Comparable<? super C>> AltererResult<G, C> of( final ISeq<Phenotype<G, C>> population, final int alterations ) { return new AltererResult<>(population, alterations); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> AltererResult<G, C> of( final ISeq<Phenotype<G, C>> population, final int alterations ) { return new AltererResult<>(population, alterations); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "AltererResult", "<", "G", ",", "C", ">", "of", "(", "final", "ISeq", "<", "Phenotype", "<", "G", ",", ...
Return a new alter result for the given arguments. @param population the altered population @param alterations the number of altered individuals @param <G> the gene type @param <C> the result type @return a new alterer for the given arguments @throws NullPointerException if the given population is {@code null} @throws IllegalArgumentException if the given {@code alterations} is negative
[ "Return", "a", "new", "alter", "result", "for", "the", "given", "arguments", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/AltererResult.java#L120-L126
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/LongChromosome.java
LongChromosome.toArray
public long[] toArray(final long[] array) { final long[] a = array.length >= length() ? array : new long[length()]; for (int i = length(); --i >= 0;) { a[i] = longValue(i); } return a; }
java
public long[] toArray(final long[] array) { final long[] a = array.length >= length() ? array : new long[length()]; for (int i = length(); --i >= 0;) { a[i] = longValue(i); } return a; }
[ "public", "long", "[", "]", "toArray", "(", "final", "long", "[", "]", "array", ")", "{", "final", "long", "[", "]", "a", "=", "array", ".", "length", ">=", "length", "(", ")", "?", "array", ":", "new", "long", "[", "length", "(", ")", "]", ";"...
Returns an long array containing all of the elements in this chromosome in proper sequence. If the chromosome fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the length of this chromosome. @since 3.0 @param array the array into which the elements of this chromosomes are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose. @return an array containing the elements of this chromosome @throws NullPointerException if the given {@code array} is {@code null}
[ "Returns", "an", "long", "array", "containing", "all", "of", "the", "elements", "in", "this", "chromosome", "in", "proper", "sequence", ".", "If", "the", "chromosome", "fits", "in", "the", "specified", "array", "it", "is", "returned", "therein", ".", "Otherw...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/LongChromosome.java#L167-L174
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/MathExpr.java
MathExpr.eval
public double eval(final double... args) { final double val = apply( DoubleStream.of(args) .boxed() .toArray(Double[]::new) ); return val == -0.0 ? 0.0 : val; }
java
public double eval(final double... args) { final double val = apply( DoubleStream.of(args) .boxed() .toArray(Double[]::new) ); return val == -0.0 ? 0.0 : val; }
[ "public", "double", "eval", "(", "final", "double", "...", "args", ")", "{", "final", "double", "val", "=", "apply", "(", "DoubleStream", ".", "of", "(", "args", ")", ".", "boxed", "(", ")", ".", "toArray", "(", "Double", "[", "]", "::", "new", ")"...
Convenient method, which lets you apply the program function without explicitly create a wrapper array. <pre>{@code final double result = MathExpr.parse("2*z + 3*x - y").eval(3, 2, 1); assert result == 9.0; }</pre> @see #apply(Double[]) @see #eval(String, double...) @param args the function arguments @return the evaluated value @throws NullPointerException if the given variable array is {@code null} @throws IllegalArgumentException if the length of the arguments array is smaller than the program arity
[ "Convenient", "method", "which", "lets", "you", "apply", "the", "program", "function", "without", "explicitly", "create", "a", "wrapper", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/MathExpr.java#L148-L155
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/MathExpr.java
MathExpr.simplify
public static Tree<? extends Op<Double>, ?> simplify(final Tree<? extends Op<Double>, ?> tree) { return MathExprRewriter.prune(TreeNode.ofTree(tree)); }
java
public static Tree<? extends Op<Double>, ?> simplify(final Tree<? extends Op<Double>, ?> tree) { return MathExprRewriter.prune(TreeNode.ofTree(tree)); }
[ "public", "static", "Tree", "<", "?", "extends", "Op", "<", "Double", ">", ",", "?", ">", "simplify", "(", "final", "Tree", "<", "?", "extends", "Op", "<", "Double", ">", ",", "?", ">", "tree", ")", "{", "return", "MathExprRewriter", ".", "prune", ...
Tries to simplify the given math tree. <pre>{@code final Tree<? extends Op<Double>, ?> tree = MathExpr.parseTree("4.0 + 4.0 + x*(5.0 + 13.0)"); final Tree<? extends Op<Double>, ?> simplified = MathExpr.simplify(tree) System.out.println(simplified); }</pre> The simplified tree will be look like this: <pre> {@code add ├── 8.0 └── mul ├── x └── 18.0 }</pre> @see #prune(TreeNode) @see #simplify() @param tree the math tree to simplify @return the new simplified tree @throws NullPointerException if the given {@code tree} is {@code null}
[ "Tries", "to", "simplify", "the", "given", "math", "tree", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/MathExpr.java#L408-L411
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/TreeCrossover.java
TreeCrossover.crossover
private <A> void crossover( final MSeq<Chromosome<G>> c1, final MSeq<Chromosome<G>> c2, final int index ) { @SuppressWarnings("unchecked") final TreeNode<A> tree1 = (TreeNode<A>)TreeNode.ofTree(c1.get(index).getGene()); @SuppressWarnings("unchecked") final TreeNode<A> tree2 = (TreeNode<A>)TreeNode.ofTree(c2.get(index).getGene()); crossover(tree1, tree2); final FlatTreeNode<A> flat1 = FlatTreeNode.of(tree1); final FlatTreeNode<A> flat2 = FlatTreeNode.of(tree2); @SuppressWarnings("unchecked") final TreeGene<A, ?> template = (TreeGene<A, ?>)c1.get(0).getGene(); final ISeq<G> genes1 = flat1.map(tree -> gene(template, tree)); final ISeq<G> genes2 = flat2.map(tree -> gene(template, tree)); c1.set(index, c1.get(index).newInstance(genes1)); c2.set(index, c2.get(index).newInstance(genes2)); }
java
private <A> void crossover( final MSeq<Chromosome<G>> c1, final MSeq<Chromosome<G>> c2, final int index ) { @SuppressWarnings("unchecked") final TreeNode<A> tree1 = (TreeNode<A>)TreeNode.ofTree(c1.get(index).getGene()); @SuppressWarnings("unchecked") final TreeNode<A> tree2 = (TreeNode<A>)TreeNode.ofTree(c2.get(index).getGene()); crossover(tree1, tree2); final FlatTreeNode<A> flat1 = FlatTreeNode.of(tree1); final FlatTreeNode<A> flat2 = FlatTreeNode.of(tree2); @SuppressWarnings("unchecked") final TreeGene<A, ?> template = (TreeGene<A, ?>)c1.get(0).getGene(); final ISeq<G> genes1 = flat1.map(tree -> gene(template, tree)); final ISeq<G> genes2 = flat2.map(tree -> gene(template, tree)); c1.set(index, c1.get(index).newInstance(genes1)); c2.set(index, c2.get(index).newInstance(genes2)); }
[ "private", "<", "A", ">", "void", "crossover", "(", "final", "MSeq", "<", "Chromosome", "<", "G", ">", ">", "c1", ",", "final", "MSeq", "<", "Chromosome", "<", "G", ">", ">", "c2", ",", "final", "int", "index", ")", "{", "@", "SuppressWarnings", "(...
the abstract "crossover" method usually don't have to do additional casts.
[ "the", "abstract", "crossover", "method", "usually", "don", "t", "have", "to", "do", "additional", "casts", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/TreeCrossover.java#L105-L128
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/Const.java
Const.of
public static <T> Const<T> of(final String name, final T value) { return new Const<>(requireNonNull(name), value); }
java
public static <T> Const<T> of(final String name, final T value) { return new Const<>(requireNonNull(name), value); }
[ "public", "static", "<", "T", ">", "Const", "<", "T", ">", "of", "(", "final", "String", "name", ",", "final", "T", "value", ")", "{", "return", "new", "Const", "<>", "(", "requireNonNull", "(", "name", ")", ",", "value", ")", ";", "}" ]
Return a new constant with the given name and value. @param name the constant name @param value the constant value @param <T> the constant type @return a new constant @throws NullPointerException if the given constant {@code name} is {@code null}
[ "Return", "a", "new", "constant", "with", "the", "given", "name", "and", "value", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/Const.java#L119-L121
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/CharacterGene.java
CharacterGene.of
public static CharacterGene of(final CharSeq validCharacters) { return new CharacterGene( validCharacters, RandomRegistry.getRandom().nextInt(validCharacters.length()) ); }
java
public static CharacterGene of(final CharSeq validCharacters) { return new CharacterGene( validCharacters, RandomRegistry.getRandom().nextInt(validCharacters.length()) ); }
[ "public", "static", "CharacterGene", "of", "(", "final", "CharSeq", "validCharacters", ")", "{", "return", "new", "CharacterGene", "(", "validCharacters", ",", "RandomRegistry", ".", "getRandom", "(", ")", ".", "nextInt", "(", "validCharacters", ".", "length", "...
Create a new CharacterGene with a randomly chosen character from the set of valid characters. @param validCharacters the valid characters for this gene. @return a new valid, <em>random</em> gene, @throws NullPointerException if the {@code validCharacters} are {@code null}.
[ "Create", "a", "new", "CharacterGene", "with", "a", "randomly", "chosen", "character", "from", "the", "set", "of", "valid", "characters", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/CharacterGene.java#L201-L206
train
jenetics/jenetics
jenetics.tool/src/main/java/io/jenetics/tool/evaluation/Diagram.java
Diagram.create
public static void create( final Path input, final Template template, final Params<?> params, final Path output, final SampleSummary summary, final SampleSummary... summaries ) throws IOException { final Stream<SampleSummary> summaryStream = Stream.concat( Stream.of(summary), Stream.of(summaries) ); summaryStream.forEach(s -> { if (params.size() != s.parameterCount()) { throw new IllegalArgumentException(format( "Parameters have different size: %d", params.size() )); } }); final Path templatePath = tempPath(); try { IO.write(template.content(), templatePath); final Path dataPath = tempPath(); try { final String data = IntStream.range(0, params.size()) .mapToObj(i -> toLineString(i, params, summary, summaries)) .collect(Collectors.joining("\n")); IO.write(data, dataPath); final Gnuplot gnuplot = new Gnuplot(templatePath); gnuplot.setEnv(params(input)); gnuplot.create(dataPath, output); } finally { deleteIfExists(dataPath); } } finally { deleteIfExists(templatePath); } }
java
public static void create( final Path input, final Template template, final Params<?> params, final Path output, final SampleSummary summary, final SampleSummary... summaries ) throws IOException { final Stream<SampleSummary> summaryStream = Stream.concat( Stream.of(summary), Stream.of(summaries) ); summaryStream.forEach(s -> { if (params.size() != s.parameterCount()) { throw new IllegalArgumentException(format( "Parameters have different size: %d", params.size() )); } }); final Path templatePath = tempPath(); try { IO.write(template.content(), templatePath); final Path dataPath = tempPath(); try { final String data = IntStream.range(0, params.size()) .mapToObj(i -> toLineString(i, params, summary, summaries)) .collect(Collectors.joining("\n")); IO.write(data, dataPath); final Gnuplot gnuplot = new Gnuplot(templatePath); gnuplot.setEnv(params(input)); gnuplot.create(dataPath, output); } finally { deleteIfExists(dataPath); } } finally { deleteIfExists(templatePath); } }
[ "public", "static", "void", "create", "(", "final", "Path", "input", ",", "final", "Template", "template", ",", "final", "Params", "<", "?", ">", "params", ",", "final", "Path", "output", ",", "final", "SampleSummary", "summary", ",", "final", "SampleSummary...
Create a performance diagram. @param input the input data @param template the Gnuplot template to use @param params the diagram parameters (x-axis) @param output the output file @param summary the first summary data @param summaries the rest of the summary data @throws IOException if the diagram generation fails @throws NullPointerException of one of the parameters is {@code null} @throws IllegalArgumentException if the {@code params}, {@code generation} and {@code fitness} doesn't have the same parameter count
[ "Create", "a", "performance", "diagram", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.tool/src/main/java/io/jenetics/tool/evaluation/Diagram.java#L146-L187
train
jenetics/jenetics
jenetics.tool/src/main/java/io/jenetics/tool/trial/Data.java
Data.summary
public SampleSummary summary() { return _samples.stream() .filter(Sample::isFull) .collect(toSampleSummary(sampleSize())); }
java
public SampleSummary summary() { return _samples.stream() .filter(Sample::isFull) .collect(toSampleSummary(sampleSize())); }
[ "public", "SampleSummary", "summary", "(", ")", "{", "return", "_samples", ".", "stream", "(", ")", ".", "filter", "(", "Sample", "::", "isFull", ")", ".", "collect", "(", "toSampleSummary", "(", "sampleSize", "(", ")", ")", ")", ";", "}" ]
Calculate the sample summary of this data object. @return the sample summary of this data object
[ "Calculate", "the", "sample", "summary", "of", "this", "data", "object", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.tool/src/main/java/io/jenetics/tool/trial/Data.java#L127-L131
train
jenetics/jenetics
jenetics.tool/src/main/java/io/jenetics/tool/trial/Params.java
Params.of
public static <T> Params<T> of( final String name, final ISeq<T> params ) { return new Params<>(name, params); }
java
public static <T> Params<T> of( final String name, final ISeq<T> params ) { return new Params<>(name, params); }
[ "public", "static", "<", "T", ">", "Params", "<", "T", ">", "of", "(", "final", "String", "name", ",", "final", "ISeq", "<", "T", ">", "params", ")", "{", "return", "new", "Params", "<>", "(", "name", ",", "params", ")", ";", "}" ]
Return a new parameters object. @param name the name of the parameters @param params the actual parameters @param <T> the parameter type @throws NullPointerException if one of the parameters is {@code null} @return a new parameters object
[ "Return", "a", "new", "parameters", "object", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.tool/src/main/java/io/jenetics/tool/trial/Params.java#L134-L139
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/AnyGene.java
AnyGene.seq
static <A> ISeq<AnyGene<A>> seq( final IntRange lengthRange, final Supplier<? extends A> supplier, final Predicate<? super A> validator ) { return MSeq.<AnyGene<A>>ofLength(random.nextInt(lengthRange, getRandom())) .fill(() -> of(supplier.get(), supplier, validator)) .toISeq(); }
java
static <A> ISeq<AnyGene<A>> seq( final IntRange lengthRange, final Supplier<? extends A> supplier, final Predicate<? super A> validator ) { return MSeq.<AnyGene<A>>ofLength(random.nextInt(lengthRange, getRandom())) .fill(() -> of(supplier.get(), supplier, validator)) .toISeq(); }
[ "static", "<", "A", ">", "ISeq", "<", "AnyGene", "<", "A", ">", ">", "seq", "(", "final", "IntRange", "lengthRange", ",", "final", "Supplier", "<", "?", "extends", "A", ">", "supplier", ",", "final", "Predicate", "<", "?", "super", "A", ">", "validat...
Create gene sequence.
[ "Create", "gene", "sequence", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/AnyGene.java#L209-L217
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/bit.java
bit.swap
public static void swap( final byte[] data, final int start, final int end, final byte[] otherData, final int otherStart ) { for (int i = end - start; --i >= 0;) { final boolean temp = get(data, i + start); set(data, i + start, get(otherData, otherStart + i)); set(otherData, otherStart + i, temp); } }
java
public static void swap( final byte[] data, final int start, final int end, final byte[] otherData, final int otherStart ) { for (int i = end - start; --i >= 0;) { final boolean temp = get(data, i + start); set(data, i + start, get(otherData, otherStart + i)); set(otherData, otherStart + i, temp); } }
[ "public", "static", "void", "swap", "(", "final", "byte", "[", "]", "data", ",", "final", "int", "start", ",", "final", "int", "end", ",", "final", "byte", "[", "]", "otherData", ",", "final", "int", "otherStart", ")", "{", "for", "(", "int", "i", ...
Swap a given range with a range of the same size with another array. <pre> start end | | data: +---+---+---+---+---+---+---+---+---+---+---+---+ +---------------+ +---------------+ otherData: +---+---+---+---+---+---+---+---+---+---+---+---+ | otherStart </pre> @param data the first byte array which are used for swapping. @param start the start bit index of the {@code data} byte array, inclusively. @param end the end bit index of the {@code data} byte array, exclusively. @param otherData the other byte array to swap the elements with. @param otherStart the start index of the {@code otherData} byte array. @throws IndexOutOfBoundsException if {@code start > end} or if {@code start < 0 || end >= data.length*8 || otherStart < 0 || otherStart + (end - start) >= otherData.length*8}
[ "Swap", "a", "given", "range", "with", "a", "range", "of", "the", "same", "size", "with", "another", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/bit.java#L177-L186
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/bit.java
bit.flip
public static byte[] flip(final byte[] data, final int index) { return get(data, index) ? unset(data, index) : set(data, index); }
java
public static byte[] flip(final byte[] data, final int index) { return get(data, index) ? unset(data, index) : set(data, index); }
[ "public", "static", "byte", "[", "]", "flip", "(", "final", "byte", "[", "]", "data", ",", "final", "int", "index", ")", "{", "return", "get", "(", "data", ",", "index", ")", "?", "unset", "(", "data", ",", "index", ")", ":", "set", "(", "data", ...
Flip the bit at the given index. @param data the data array. @param index the index of the bit to flip. @return the input array, for command chaining @throws IndexOutOfBoundsException if the index is {@code index >= max || index < 0}. @throws NullPointerException if the {@code data} array is {@code null}.
[ "Flip", "the", "bit", "at", "the", "given", "index", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/bit.java#L342-L344
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/bit.java
bit.copy
public static byte[] copy(final byte[] data, final int start, final int end) { if (start > end) { throw new IllegalArgumentException(String.format( "start > end: %d > %d", start, end )); } if (start < 0 || start > data.length << 3) { throw new ArrayIndexOutOfBoundsException(String.format( "%d < 0 || %d > %d", start, start, data.length*8 )); } final int to = min(data.length << 3, end); final int byteStart = start >>> 3; final int bitStart = start & 7; final int bitLength = to - start; final byte[] copy = new byte[toByteLength(to - start)]; if (copy.length > 0) { // Perform the byte wise right shift. System.arraycopy(data, byteStart, copy, 0, copy.length); // Do the remaining bit wise right shift. shiftRight(copy, bitStart); // Add the 'lost' bits from the next byte, if available. if (data.length > copy.length + byteStart) { copy[copy.length - 1] |= (byte)(data[byteStart + copy.length] << (Byte.SIZE - bitStart)); } // Trim (delete) the overhanging bits. copy[copy.length - 1] &= 0xFF >>> ((copy.length << 3) - bitLength); } return copy; }
java
public static byte[] copy(final byte[] data, final int start, final int end) { if (start > end) { throw new IllegalArgumentException(String.format( "start > end: %d > %d", start, end )); } if (start < 0 || start > data.length << 3) { throw new ArrayIndexOutOfBoundsException(String.format( "%d < 0 || %d > %d", start, start, data.length*8 )); } final int to = min(data.length << 3, end); final int byteStart = start >>> 3; final int bitStart = start & 7; final int bitLength = to - start; final byte[] copy = new byte[toByteLength(to - start)]; if (copy.length > 0) { // Perform the byte wise right shift. System.arraycopy(data, byteStart, copy, 0, copy.length); // Do the remaining bit wise right shift. shiftRight(copy, bitStart); // Add the 'lost' bits from the next byte, if available. if (data.length > copy.length + byteStart) { copy[copy.length - 1] |= (byte)(data[byteStart + copy.length] << (Byte.SIZE - bitStart)); } // Trim (delete) the overhanging bits. copy[copy.length - 1] &= 0xFF >>> ((copy.length << 3) - bitLength); } return copy; }
[ "public", "static", "byte", "[", "]", "copy", "(", "final", "byte", "[", "]", "data", ",", "final", "int", "start", ",", "final", "int", "end", ")", "{", "if", "(", "start", ">", "end", ")", "{", "throw", "new", "IllegalArgumentException", "(", "Stri...
Copies the specified range of the specified array into a new array. @param data the bits from which a range is to be copied @param start the initial index of the range to be copied, inclusive @param end the final index of the range to be copied, exclusive. @return a new array containing the specified range from the original array @throws ArrayIndexOutOfBoundsException if start &lt; 0 or start &gt; data.length*8 @throws IllegalArgumentException if start &gt; end @throws NullPointerException if the {@code data} array is {@code null}.
[ "Copies", "the", "specified", "range", "of", "the", "specified", "array", "into", "a", "new", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/bit.java#L376-L413
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/MutatorResult.java
MutatorResult.of
public static <T> MutatorResult<T> of(final T result, final int mutations) { return new MutatorResult<>(result, mutations); }
java
public static <T> MutatorResult<T> of(final T result, final int mutations) { return new MutatorResult<>(result, mutations); }
[ "public", "static", "<", "T", ">", "MutatorResult", "<", "T", ">", "of", "(", "final", "T", "result", ",", "final", "int", "mutations", ")", "{", "return", "new", "MutatorResult", "<>", "(", "result", ",", "mutations", ")", ";", "}" ]
Create a new mutation result with the given values. @param result the mutation result @param mutations the number of mutations @param <T> the mutation result type @return a new mutation result @throws IllegalArgumentException if the given {@code mutations} is negative @throws NullPointerException if the given mutation result is {@code null}
[ "Create", "a", "new", "mutation", "result", "with", "the", "given", "values", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/MutatorResult.java#L106-L108
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/SwapMutator.java
SwapMutator.mutate
@Override protected MutatorResult<Chromosome<G>> mutate( final Chromosome<G> chromosome, final double p, final Random random ) { final MutatorResult<Chromosome<G>> result; if (chromosome.length() > 1) { final MSeq<G> genes = chromosome.toSeq().copy(); final int mutations = (int)indexes(random, genes.length(), p) .peek(i -> genes.swap(i, random.nextInt(genes.length()))) .count(); result = MutatorResult.of( chromosome.newInstance(genes.toISeq()), mutations ); } else { result = MutatorResult.of(chromosome); } return result; }
java
@Override protected MutatorResult<Chromosome<G>> mutate( final Chromosome<G> chromosome, final double p, final Random random ) { final MutatorResult<Chromosome<G>> result; if (chromosome.length() > 1) { final MSeq<G> genes = chromosome.toSeq().copy(); final int mutations = (int)indexes(random, genes.length(), p) .peek(i -> genes.swap(i, random.nextInt(genes.length()))) .count(); result = MutatorResult.of( chromosome.newInstance(genes.toISeq()), mutations ); } else { result = MutatorResult.of(chromosome); } return result; }
[ "@", "Override", "protected", "MutatorResult", "<", "Chromosome", "<", "G", ">", ">", "mutate", "(", "final", "Chromosome", "<", "G", ">", "chromosome", ",", "final", "double", "p", ",", "final", "Random", "random", ")", "{", "final", "MutatorResult", "<",...
Swaps the genes in the given array, with the mutation probability of this mutation.
[ "Swaps", "the", "genes", "in", "the", "given", "array", "with", "the", "mutation", "probability", "of", "this", "mutation", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/SwapMutator.java#L70-L91
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/require.java
require.nonNegative
public static double nonNegative(final double value, final String message) { if (value < 0) { throw new IllegalArgumentException(format( "%s must not be negative: %f.", message, value )); } return value; }
java
public static double nonNegative(final double value, final String message) { if (value < 0) { throw new IllegalArgumentException(format( "%s must not be negative: %f.", message, value )); } return value; }
[ "public", "static", "double", "nonNegative", "(", "final", "double", "value", ",", "final", "String", "message", ")", "{", "if", "(", "value", "<", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "format", "(", "\"%s must not be negative: %f.\"",...
Check if the specified value is not negative. @param value the value to check. @param message the exception message. @return the given value. @throws IllegalArgumentException if {@code value < 0}.
[ "Check", "if", "the", "specified", "value", "is", "not", "negative", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/require.java#L42-L49
train
jenetics/jenetics
jenetics.doc/src/main/java/Knapsack.java
Knapsack.fitness
static Function<ISeq<Item>, Double> fitness(final double size) { return items -> { final Item sum = items.stream().collect(Item.toSum()); return sum.size <= size ? sum.value : 0; }; }
java
static Function<ISeq<Item>, Double> fitness(final double size) { return items -> { final Item sum = items.stream().collect(Item.toSum()); return sum.size <= size ? sum.value : 0; }; }
[ "static", "Function", "<", "ISeq", "<", "Item", ">", ",", "Double", ">", "fitness", "(", "final", "double", "size", ")", "{", "return", "items", "->", "{", "final", "Item", "sum", "=", "items", ".", "stream", "(", ")", ".", "collect", "(", "Item", ...
Creating the fitness function.
[ "Creating", "the", "fitness", "function", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.doc/src/main/java/Knapsack.java#L56-L62
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/stat/DoubleMoments.java
DoubleMoments.of
public static DoubleMoments of( final long count, final double min, final double max, final double sum, final double mean, final double variance, final double skewness, final double kurtosis ) { return new DoubleMoments( count, min, max, sum, mean, variance, skewness, kurtosis ); }
java
public static DoubleMoments of( final long count, final double min, final double max, final double sum, final double mean, final double variance, final double skewness, final double kurtosis ) { return new DoubleMoments( count, min, max, sum, mean, variance, skewness, kurtosis ); }
[ "public", "static", "DoubleMoments", "of", "(", "final", "long", "count", ",", "final", "double", "min", ",", "final", "double", "max", ",", "final", "double", "sum", ",", "final", "double", "mean", ",", "final", "double", "variance", ",", "final", "double...
Create an immutable object which contains statistical values. @param count the count of values recorded @param min the minimum value @param max the maximum value @param sum the sum of the recorded values @param mean the arithmetic mean of values @param variance the variance of values @param skewness the skewness of values @param kurtosis the kurtosis of values @return an immutable object which contains statistical values
[ "Create", "an", "immutable", "object", "which", "contains", "statistical", "values", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/stat/DoubleMoments.java#L222-L242
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/ProgramChromosome.java
ProgramChromosome.create
private static <A> ProgramChromosome<A> create( final Tree<? extends Op<A>, ?> program, final Predicate<? super ProgramChromosome<A>> validator, final ISeq<? extends Op<A>> operations, final ISeq<? extends Op<A>> terminals ) { final ISeq<ProgramGene<A>> genes = FlatTreeNode.of(program).stream() .map(n -> new ProgramGene<>( n.getValue(), n.childOffset(), operations, terminals)) .collect(ISeq.toISeq()); return new ProgramChromosome<>(genes, validator, operations, terminals); }
java
private static <A> ProgramChromosome<A> create( final Tree<? extends Op<A>, ?> program, final Predicate<? super ProgramChromosome<A>> validator, final ISeq<? extends Op<A>> operations, final ISeq<? extends Op<A>> terminals ) { final ISeq<ProgramGene<A>> genes = FlatTreeNode.of(program).stream() .map(n -> new ProgramGene<>( n.getValue(), n.childOffset(), operations, terminals)) .collect(ISeq.toISeq()); return new ProgramChromosome<>(genes, validator, operations, terminals); }
[ "private", "static", "<", "A", ">", "ProgramChromosome", "<", "A", ">", "create", "(", "final", "Tree", "<", "?", "extends", "Op", "<", "A", ">", ",", "?", ">", "program", ",", "final", "Predicate", "<", "?", "super", "ProgramChromosome", "<", "A", "...
Create the chromosomes without checks.
[ "Create", "the", "chromosomes", "without", "checks", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/ProgramChromosome.java#L212-L224
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/util/TreeParser.java
TreeParser.tokenize
static List<Token> tokenize(final String value) { final List<Token> tokens = new ArrayList<>(); char pc = '\0'; int pos = 0; final StringBuilder token = new StringBuilder(); for (int i = 0; i < value.length(); ++i) { final char c = value.charAt(i); if (isTokenSeparator(c) && pc != ESCAPE_CHAR) { tokens.add(new Token(unescape(token.toString()), pos)); tokens.add(new Token(Character.toString(c), i)); token.setLength(0); pos = i; } else { token.append(c); } pc = c; } if (token.length() > 0) { tokens.add(new Token(unescape(token.toString()), pos)); } return tokens; }
java
static List<Token> tokenize(final String value) { final List<Token> tokens = new ArrayList<>(); char pc = '\0'; int pos = 0; final StringBuilder token = new StringBuilder(); for (int i = 0; i < value.length(); ++i) { final char c = value.charAt(i); if (isTokenSeparator(c) && pc != ESCAPE_CHAR) { tokens.add(new Token(unescape(token.toString()), pos)); tokens.add(new Token(Character.toString(c), i)); token.setLength(0); pos = i; } else { token.append(c); } pc = c; } if (token.length() > 0) { tokens.add(new Token(unescape(token.toString()), pos)); } return tokens; }
[ "static", "List", "<", "Token", ">", "tokenize", "(", "final", "String", "value", ")", "{", "final", "List", "<", "Token", ">", "tokens", "=", "new", "ArrayList", "<>", "(", ")", ";", "char", "pc", "=", "'", "'", ";", "int", "pos", "=", "0", ";",...
Tokenize the given parentheses string. @param value the parentheses string @return the parentheses string tokens @throws NullPointerException if the given {@code value} is {@code null}
[ "Tokenize", "the", "given", "parentheses", "string", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/util/TreeParser.java#L63-L89
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/util/TreeParser.java
TreeParser.parse
static <B> TreeNode<B> parse( final String value, final Function<? super String, ? extends B> mapper ) { requireNonNull(value); requireNonNull(mapper); final TreeNode<B> root = TreeNode.of(); final Deque<TreeNode<B>> parents = new ArrayDeque<>(); TreeNode<B> current = root; for (Token token : tokenize(value.trim())) { switch (token.seq) { case "(": if (current == null) { throw new IllegalArgumentException(format( "Illegal parentheses tree string: '%s'.", value )); } final TreeNode<B> tn1 = TreeNode.of(); current.attach(tn1); parents.push(current); current = tn1; break; case ",": if (parents.isEmpty()) { throw new IllegalArgumentException(format( "Expect '(' at position %d.", token.pos )); } final TreeNode<B> tn2 = TreeNode.of(); assert parents.peek() != null; parents.peek().attach(tn2); current = tn2; break; case ")": if (parents.isEmpty()) { throw new IllegalArgumentException(format( "Unbalanced parentheses at position %d.", token.pos )); } current = parents.pop(); if (parents.isEmpty()) { current = null; } break; default: if (current == null) { throw new IllegalArgumentException(format( "More than one root element at pos %d: '%s'.", token.pos, value )); } if (current.getValue() == null) { current.setValue(mapper.apply(token.seq)); } break; } } if (!parents.isEmpty()) { throw new IllegalArgumentException("Unbalanced parentheses."); } return root; }
java
static <B> TreeNode<B> parse( final String value, final Function<? super String, ? extends B> mapper ) { requireNonNull(value); requireNonNull(mapper); final TreeNode<B> root = TreeNode.of(); final Deque<TreeNode<B>> parents = new ArrayDeque<>(); TreeNode<B> current = root; for (Token token : tokenize(value.trim())) { switch (token.seq) { case "(": if (current == null) { throw new IllegalArgumentException(format( "Illegal parentheses tree string: '%s'.", value )); } final TreeNode<B> tn1 = TreeNode.of(); current.attach(tn1); parents.push(current); current = tn1; break; case ",": if (parents.isEmpty()) { throw new IllegalArgumentException(format( "Expect '(' at position %d.", token.pos )); } final TreeNode<B> tn2 = TreeNode.of(); assert parents.peek() != null; parents.peek().attach(tn2); current = tn2; break; case ")": if (parents.isEmpty()) { throw new IllegalArgumentException(format( "Unbalanced parentheses at position %d.", token.pos )); } current = parents.pop(); if (parents.isEmpty()) { current = null; } break; default: if (current == null) { throw new IllegalArgumentException(format( "More than one root element at pos %d: '%s'.", token.pos, value )); } if (current.getValue() == null) { current.setValue(mapper.apply(token.seq)); } break; } } if (!parents.isEmpty()) { throw new IllegalArgumentException("Unbalanced parentheses."); } return root; }
[ "static", "<", "B", ">", "TreeNode", "<", "B", ">", "parse", "(", "final", "String", "value", ",", "final", "Function", "<", "?", "super", "String", ",", "?", "extends", "B", ">", "mapper", ")", "{", "requireNonNull", "(", "value", ")", ";", "require...
Parses the given parentheses tree string @since 4.3 @param <B> the tree node value type @param value the parentheses tree string @param mapper the mapper which converts the serialized string value to the desired type @return the parsed tree object @throws NullPointerException if one of the arguments is {@code null} @throws IllegalArgumentException if the given parentheses tree string doesn't represent a valid tree
[ "Parses", "the", "given", "parentheses", "tree", "string" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/util/TreeParser.java#L109-L179
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/ProgramGene.java
ProgramGene.newInstance
@Override public ProgramGene<A> newInstance(final Op<A> op) { if (getValue().arity() != op.arity()) { throw new IllegalArgumentException(format( "New operation must have same arity: %s[%d] != %s[%d]", getValue().name(), getValue().arity(), op.name(), op.arity() )); } return new ProgramGene<>(op, childOffset(), _operations, _terminals); }
java
@Override public ProgramGene<A> newInstance(final Op<A> op) { if (getValue().arity() != op.arity()) { throw new IllegalArgumentException(format( "New operation must have same arity: %s[%d] != %s[%d]", getValue().name(), getValue().arity(), op.name(), op.arity() )); } return new ProgramGene<>(op, childOffset(), _operations, _terminals); }
[ "@", "Override", "public", "ProgramGene", "<", "A", ">", "newInstance", "(", "final", "Op", "<", "A", ">", "op", ")", "{", "if", "(", "getValue", "(", ")", ".", "arity", "(", ")", "!=", "op", ".", "arity", "(", ")", ")", "{", "throw", "new", "I...
Create a new program gene with the given operation. @param op the operation of the new program gene @return a new program gene with the given operation @throws NullPointerException if the given {@code op} is {@code null} @throws IllegalArgumentException if the arity of the given operation is different from the arity of current operation. This restriction ensures that only valid program genes are created by this method.
[ "Create", "a", "new", "program", "gene", "with", "the", "given", "operation", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/ProgramGene.java#L170-L179
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Engine.java
Engine.selectSurvivors
private ISeq<Phenotype<G, C>> selectSurvivors(final ISeq<Phenotype<G, C>> population) { return _survivorsCount > 0 ?_survivorsSelector.select(population, _survivorsCount, _optimize) : ISeq.empty(); }
java
private ISeq<Phenotype<G, C>> selectSurvivors(final ISeq<Phenotype<G, C>> population) { return _survivorsCount > 0 ?_survivorsSelector.select(population, _survivorsCount, _optimize) : ISeq.empty(); }
[ "private", "ISeq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "selectSurvivors", "(", "final", "ISeq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "population", ")", "{", "return", "_survivorsCount", ">", "0", "?", "_survivorsSelector", ".", "...
Selects the survivors population. A new population object is returned.
[ "Selects", "the", "survivors", "population", ".", "A", "new", "population", "object", "is", "returned", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Engine.java#L373-L378
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Engine.java
Engine.selectOffspring
private ISeq<Phenotype<G, C>> selectOffspring(final ISeq<Phenotype<G, C>> population) { return _offspringCount > 0 ? _offspringSelector.select(population, _offspringCount, _optimize) : ISeq.empty(); }
java
private ISeq<Phenotype<G, C>> selectOffspring(final ISeq<Phenotype<G, C>> population) { return _offspringCount > 0 ? _offspringSelector.select(population, _offspringCount, _optimize) : ISeq.empty(); }
[ "private", "ISeq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "selectOffspring", "(", "final", "ISeq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "population", ")", "{", "return", "_offspringCount", ">", "0", "?", "_offspringSelector", ".", "...
Selects the offspring population. A new population object is returned.
[ "Selects", "the", "offspring", "population", ".", "A", "new", "population", "object", "is", "returned", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Engine.java#L381-L386
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Engine.java
Engine.filter
private FilterResult<G, C> filter( final Seq<Phenotype<G, C>> population, final long generation ) { int killCount = 0; int invalidCount = 0; final MSeq<Phenotype<G, C>> pop = MSeq.of(population); for (int i = 0, n = pop.size(); i < n; ++i) { final Phenotype<G, C> individual = pop.get(i); if (!_validator.test(individual)) { pop.set(i, newPhenotype(generation)); ++invalidCount; } else if (individual.getAge(generation) > _maximalPhenotypeAge) { pop.set(i, newPhenotype(generation)); ++killCount; } } return new FilterResult<>(pop.toISeq(), killCount, invalidCount); }
java
private FilterResult<G, C> filter( final Seq<Phenotype<G, C>> population, final long generation ) { int killCount = 0; int invalidCount = 0; final MSeq<Phenotype<G, C>> pop = MSeq.of(population); for (int i = 0, n = pop.size(); i < n; ++i) { final Phenotype<G, C> individual = pop.get(i); if (!_validator.test(individual)) { pop.set(i, newPhenotype(generation)); ++invalidCount; } else if (individual.getAge(generation) > _maximalPhenotypeAge) { pop.set(i, newPhenotype(generation)); ++killCount; } } return new FilterResult<>(pop.toISeq(), killCount, invalidCount); }
[ "private", "FilterResult", "<", "G", ",", "C", ">", "filter", "(", "final", "Seq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "population", ",", "final", "long", "generation", ")", "{", "int", "killCount", "=", "0", ";", "int", "invalidCount", "...
Filters out invalid and old individuals. Filtering is done in place.
[ "Filters", "out", "invalid", "and", "old", "individuals", ".", "Filtering", "is", "done", "in", "place", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Engine.java#L389-L410
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/Engine.java
Engine.newPhenotype
private Phenotype<G, C> newPhenotype(final long generation) { int count = 0; Phenotype<G, C> phenotype; do { phenotype = Phenotype.of( _genotypeFactory.newInstance(), generation, _fitnessFunction, _fitnessScaler ); } while (++count < _individualCreationRetries && !_validator.test(phenotype)); return phenotype; }
java
private Phenotype<G, C> newPhenotype(final long generation) { int count = 0; Phenotype<G, C> phenotype; do { phenotype = Phenotype.of( _genotypeFactory.newInstance(), generation, _fitnessFunction, _fitnessScaler ); } while (++count < _individualCreationRetries && !_validator.test(phenotype)); return phenotype; }
[ "private", "Phenotype", "<", "G", ",", "C", ">", "newPhenotype", "(", "final", "long", "generation", ")", "{", "int", "count", "=", "0", ";", "Phenotype", "<", "G", ",", "C", ">", "phenotype", ";", "do", "{", "phenotype", "=", "Phenotype", ".", "of",...
Create a new and valid phenotype
[ "Create", "a", "new", "and", "valid", "phenotype" ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/Engine.java#L413-L427
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java
Program.eval
@SafeVarargs public static <T> T eval( final Tree<? extends Op<T>, ?> tree, final T... variables ) { requireNonNull(tree); requireNonNull(variables); final Op<T> op = tree.getValue(); return op.isTerminal() ? eval(op, variables) : eval(op, tree.childStream() .map(child -> eval(child, variables)) .toArray(size -> newArray(variables.getClass(), size)) ); }
java
@SafeVarargs public static <T> T eval( final Tree<? extends Op<T>, ?> tree, final T... variables ) { requireNonNull(tree); requireNonNull(variables); final Op<T> op = tree.getValue(); return op.isTerminal() ? eval(op, variables) : eval(op, tree.childStream() .map(child -> eval(child, variables)) .toArray(size -> newArray(variables.getClass(), size)) ); }
[ "@", "SafeVarargs", "public", "static", "<", "T", ">", "T", "eval", "(", "final", "Tree", "<", "?", "extends", "Op", "<", "T", ">", ",", "?", ">", "tree", ",", "final", "T", "...", "variables", ")", "{", "requireNonNull", "(", "tree", ")", ";", "...
Evaluates the given operation tree with the given variables. @param <T> the argument type @param tree the operation tree @param variables the input variables @return the result of the operation tree evaluation @throws NullPointerException if one of the arguments is {@code null} @throws IllegalArgumentException if the length of the variable array is smaller than the program arity
[ "Evaluates", "the", "given", "operation", "tree", "with", "the", "given", "variables", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java#L164-L180
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java
Program.check
public static void check(final Tree<? extends Op<?>, ?> program) { requireNonNull(program); program.forEach(Program::checkArity); }
java
public static void check(final Tree<? extends Op<?>, ?> program) { requireNonNull(program); program.forEach(Program::checkArity); }
[ "public", "static", "void", "check", "(", "final", "Tree", "<", "?", "extends", "Op", "<", "?", ">", ",", "?", ">", "program", ")", "{", "requireNonNull", "(", "program", ")", ";", "program", ".", "forEach", "(", "Program", "::", "checkArity", ")", "...
Validates the given program tree. @param program the program to validate @throws NullPointerException if the given {@code program} is {@code null} @throws IllegalArgumentException if the given operation tree is invalid, which means there is at least one node where the operation arity and the node child count differ.
[ "Validates", "the", "given", "program", "tree", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java#L207-L210
train
jenetics/jenetics
jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java
Program.offsets
static int[] offsets(final ISeq<? extends FlatTree<? extends Op<?>, ?>> nodes) { final int[] offsets = new int[nodes.size()]; int offset = 1; for (int i = 0; i < offsets.length; ++i) { final Op<?> op = nodes.get(i).getValue(); offsets[i] = op.isTerminal() ? -1 : offset; offset += op.arity(); } return offsets; }
java
static int[] offsets(final ISeq<? extends FlatTree<? extends Op<?>, ?>> nodes) { final int[] offsets = new int[nodes.size()]; int offset = 1; for (int i = 0; i < offsets.length; ++i) { final Op<?> op = nodes.get(i).getValue(); offsets[i] = op.isTerminal() ? -1 : offset; offset += op.arity(); } return offsets; }
[ "static", "int", "[", "]", "offsets", "(", "final", "ISeq", "<", "?", "extends", "FlatTree", "<", "?", "extends", "Op", "<", "?", ">", ",", "?", ">", ">", "nodes", ")", "{", "final", "int", "[", "]", "offsets", "=", "new", "int", "[", "nodes", ...
Create the offset array for the given nodes. The offsets are calculated using the arity of the stored operations. @param nodes the flattened tree nodes @return the offset array for the given nodes
[ "Create", "the", "offset", "array", "for", "the", "given", "nodes", ".", "The", "offsets", "are", "calculated", "using", "the", "arity", "of", "the", "stored", "operations", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.prog/src/main/java/io/jenetics/prog/op/Program.java#L449-L462
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/math/base.java
base.divide
public static void divide(final double[] values, final double divisor) { for (int i = values.length; --i >= 0;) { values[i] /= divisor; } }
java
public static void divide(final double[] values, final double divisor) { for (int i = values.length; --i >= 0;) { values[i] /= divisor; } }
[ "public", "static", "void", "divide", "(", "final", "double", "[", "]", "values", ",", "final", "double", "divisor", ")", "{", "for", "(", "int", "i", "=", "values", ".", "length", ";", "--", "i", ">=", "0", ";", ")", "{", "values", "[", "i", "]"...
Component wise division of the given double array. @param values the double values to divide. @param divisor the divisor. @throws NullPointerException if the given double array is {@code null}.
[ "Component", "wise", "division", "of", "the", "given", "double", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/math/base.java#L71-L75
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/math/base.java
base.pow
public static long pow(final long b, final long e) { long base = b; long exp = e; long result = 1; while (exp != 0) { if ((exp & 1) != 0) { result *= base; } exp >>>= 1; base *= base; } return result; }
java
public static long pow(final long b, final long e) { long base = b; long exp = e; long result = 1; while (exp != 0) { if ((exp & 1) != 0) { result *= base; } exp >>>= 1; base *= base; } return result; }
[ "public", "static", "long", "pow", "(", "final", "long", "b", ",", "final", "long", "e", ")", "{", "long", "base", "=", "b", ";", "long", "exp", "=", "e", ";", "long", "result", "=", "1", ";", "while", "(", "exp", "!=", "0", ")", "{", "if", "...
Binary exponentiation algorithm. @param b the base number. @param e the exponent. @return {@code b^e}.
[ "Binary", "exponentiation", "algorithm", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/math/base.java#L84-L98
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/TruncationSelector.java
TruncationSelector.select
@Override public ISeq<Phenotype<G, C>> select( final Seq<Phenotype<G, C>> population, final int count, final Optimize opt ) { requireNonNull(population, "Population"); requireNonNull(opt, "Optimization"); if (count < 0) { throw new IllegalArgumentException(format( "Selection count must be greater or equal then zero, but was %s", count )); } final MSeq<Phenotype<G, C>> selection = MSeq .ofLength(population.isEmpty() ? 0 : count); if (count > 0 && !population.isEmpty()) { final MSeq<Phenotype<G, C>> copy = population.asISeq().copy(); copy.sort((a, b) -> opt.<C>descending().compare(a.getFitness(), b.getFitness())); int size = count; do { final int length = min(min(copy.size(), size), _n); for (int i = 0; i < length; ++i) { selection.set((count - size) + i, copy.get(i)); } size -= length; } while (size > 0); } return selection.toISeq(); }
java
@Override public ISeq<Phenotype<G, C>> select( final Seq<Phenotype<G, C>> population, final int count, final Optimize opt ) { requireNonNull(population, "Population"); requireNonNull(opt, "Optimization"); if (count < 0) { throw new IllegalArgumentException(format( "Selection count must be greater or equal then zero, but was %s", count )); } final MSeq<Phenotype<G, C>> selection = MSeq .ofLength(population.isEmpty() ? 0 : count); if (count > 0 && !population.isEmpty()) { final MSeq<Phenotype<G, C>> copy = population.asISeq().copy(); copy.sort((a, b) -> opt.<C>descending().compare(a.getFitness(), b.getFitness())); int size = count; do { final int length = min(min(copy.size(), size), _n); for (int i = 0; i < length; ++i) { selection.set((count - size) + i, copy.get(i)); } size -= length; } while (size > 0); } return selection.toISeq(); }
[ "@", "Override", "public", "ISeq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "select", "(", "final", "Seq", "<", "Phenotype", "<", "G", ",", "C", ">", ">", "population", ",", "final", "int", "count", ",", "final", "Optimize", "opt", ")", "{",...
This method sorts the population in descending order while calculating the selection probabilities. If the selection size is greater the the population size, the whole population is duplicated until the desired sample size is reached. @throws NullPointerException if the {@code population} or {@code opt} is {@code null}.
[ "This", "method", "sorts", "the", "population", "in", "descending", "order", "while", "calculating", "the", "selection", "probabilities", ".", "If", "the", "selection", "size", "is", "greater", "the", "the", "population", "size", "the", "whole", "population", "i...
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/TruncationSelector.java#L92-L127
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/internal/util/Concurrency.java
Concurrency.with
public static Concurrency with(final Executor executor) { if (executor instanceof ForkJoinPool) { return new ForkJoinPoolConcurrency((ForkJoinPool)executor); } else if (executor instanceof ExecutorService) { return new ExecutorServiceConcurrency((ExecutorService)executor); } else if (executor == SERIAL_EXECUTOR) { return SERIAL_EXECUTOR; } else { return new ExecutorConcurrency(executor); } }
java
public static Concurrency with(final Executor executor) { if (executor instanceof ForkJoinPool) { return new ForkJoinPoolConcurrency((ForkJoinPool)executor); } else if (executor instanceof ExecutorService) { return new ExecutorServiceConcurrency((ExecutorService)executor); } else if (executor == SERIAL_EXECUTOR) { return SERIAL_EXECUTOR; } else { return new ExecutorConcurrency(executor); } }
[ "public", "static", "Concurrency", "with", "(", "final", "Executor", "executor", ")", "{", "if", "(", "executor", "instanceof", "ForkJoinPool", ")", "{", "return", "new", "ForkJoinPoolConcurrency", "(", "(", "ForkJoinPool", ")", "executor", ")", ";", "}", "els...
Return an new Concurrency object from the given executor. @param executor the underlying Executor @return a new Concurrency object
[ "Return", "an", "new", "Concurrency", "object", "from", "the", "given", "executor", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/internal/util/Concurrency.java#L73-L83
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java
EvolutionResult.getGenotypes
public ISeq<Genotype<G>> getGenotypes() { return _population.stream() .map(Phenotype::getGenotype) .collect(ISeq.toISeq()); }
java
public ISeq<Genotype<G>> getGenotypes() { return _population.stream() .map(Phenotype::getGenotype) .collect(ISeq.toISeq()); }
[ "public", "ISeq", "<", "Genotype", "<", "G", ">", ">", "getGenotypes", "(", ")", "{", "return", "_population", ".", "stream", "(", ")", ".", "map", "(", "Phenotype", "::", "getGenotype", ")", ".", "collect", "(", "ISeq", ".", "toISeq", "(", ")", ")",...
Return the current list of genotypes of this evolution result. @since 3.9 @return the list of genotypes of this evolution result.
[ "Return", "the", "current", "list", "of", "genotypes", "of", "this", "evolution", "result", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java#L146-L150
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java
EvolutionResult.toBestEvolutionResult
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, EvolutionResult<G, C>> toBestEvolutionResult() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().withTotalGenerations(mm.getCount()) : null ); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, EvolutionResult<G, C>> toBestEvolutionResult() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().withTotalGenerations(mm.getCount()) : null ); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Collector", "<", "EvolutionResult", "<", "G", ",", "C", ">", ",", "?", ",", "EvolutionResult", "<", "G",...
Return a collector which collects the best result of an evolution stream. <pre>{@code final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final EvolutionResult<EnumGene<Point>, Double> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestEvolutionResult()); }</pre> If the collected {@link EvolutionStream} is empty, the collector returns <b>{@code null}</b>. @param <G> the gene type @param <C> the fitness type @return a collector which collects the best result of an evolution stream
[ "Return", "a", "collector", "which", "collects", "the", "best", "result", "of", "an", "evolution", "stream", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java#L355-L366
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java
EvolutionResult.toBestPhenotype
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, Phenotype<G, C>> toBestPhenotype() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() : null ); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, Phenotype<G, C>> toBestPhenotype() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() : null ); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Collector", "<", "EvolutionResult", "<", "G", ",", "C", ">", ",", "?", ",", "Phenotype", "<", "G", ","...
Return a collector which collects the best phenotype of an evolution stream. <pre>{@code final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final Phenotype<EnumGene<Point>, Double> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestPhenotype()); }</pre> If the collected {@link EvolutionStream} is empty, the collector returns <b>{@code null}</b>. @param <G> the gene type @param <C> the fitness type @return a collector which collects the best phenotype of an evolution stream
[ "Return", "a", "collector", "which", "collects", "the", "best", "phenotype", "of", "an", "evolution", "stream", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java#L389-L400
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java
EvolutionResult.toBestGenotype
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, Genotype<G>> toBestGenotype() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() != null ? mm.getMax().getBestPhenotype().getGenotype() : null : null ); }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G, C>, ?, Genotype<G>> toBestGenotype() { return Collector.of( MinMax::<EvolutionResult<G, C>>of, MinMax::accept, MinMax::combine, mm -> mm.getMax() != null ? mm.getMax().getBestPhenotype() != null ? mm.getMax().getBestPhenotype().getGenotype() : null : null ); }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "Collector", "<", "EvolutionResult", "<", "G", ",", "C", ">", ",", "?", ",", "Genotype", "<", "G", ">",...
Return a collector which collects the best genotype of an evolution stream. <pre>{@code final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final Genotype<EnumGene<Point>> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestGenotype()); }</pre> If the collected {@link EvolutionStream} is empty, the collector returns <b>{@code null}</b>. @param <G> the gene type @param <C> the fitness type @return a collector which collects the best genotype of an evolution stream
[ "Return", "a", "collector", "which", "collects", "the", "best", "genotype", "of", "an", "evolution", "stream", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java#L423-L436
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java
EvolutionResult.toUniquePopulation
public static <G extends Gene<?, G>, C extends Comparable<? super C>> UnaryOperator<EvolutionResult<G, C>> toUniquePopulation(final int maxRetries) { return result -> { final Factory<Genotype<G>> factory = result .getPopulation().get(0) .getGenotype(); final UnaryOperator<EvolutionResult<G, C>> unifier = toUniquePopulation(factory, maxRetries); return unifier.apply(result); }; }
java
public static <G extends Gene<?, G>, C extends Comparable<? super C>> UnaryOperator<EvolutionResult<G, C>> toUniquePopulation(final int maxRetries) { return result -> { final Factory<Genotype<G>> factory = result .getPopulation().get(0) .getGenotype(); final UnaryOperator<EvolutionResult<G, C>> unifier = toUniquePopulation(factory, maxRetries); return unifier.apply(result); }; }
[ "public", "static", "<", "G", "extends", "Gene", "<", "?", ",", "G", ">", ",", "C", "extends", "Comparable", "<", "?", "super", "C", ">", ">", "UnaryOperator", "<", "EvolutionResult", "<", "G", ",", "C", ">", ">", "toUniquePopulation", "(", "final", ...
Return a mapping function, which removes duplicate individuals from the population and replaces it with newly created one by the existing genotype factory. <pre>{@code final Problem<Double, DoubleGene, Integer> problem = ...; final Engine<DoubleGene, Integer> engine = Engine.builder(problem) .mapping(EvolutionResult.toUniquePopulation(10)) .build(); final Genotype<DoubleGene> best = engine.stream() .limit(100); .collect(EvolutionResult.toBestGenotype(5)); }</pre> @since 4.0 @see Engine.Builder#mapping(Function) @param maxRetries the maximal number of genotype creation tries @param <G> the gene type @param <C> the fitness function result type @return a mapping function, which removes duplicate individuals from the population @throws NullPointerException if the given genotype {@code factory} is {@code null}
[ "Return", "a", "mapping", "function", "which", "removes", "duplicate", "individuals", "from", "the", "population", "and", "replaces", "it", "with", "newly", "created", "one", "by", "the", "existing", "genotype", "factory", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/engine/EvolutionResult.java#L643-L655
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/SingleNodeCrossover.java
SingleNodeCrossover.swap
static <A> int swap(final TreeNode<A> that, final TreeNode<A> other) { assert that != null; assert other != null; final Random random = RandomRegistry.getRandom(); final ISeq<TreeNode<A>> seq1 = that.breadthFirstStream() .collect(ISeq.toISeq()); final ISeq<TreeNode<A>> seq2 = other.breadthFirstStream() .collect(ISeq.toISeq()); final int changed; if (seq1.length() > 1 && seq2.length() > 1) { final TreeNode<A> n1 = seq1.get(random.nextInt(seq1.length() - 1) + 1); final TreeNode<A> p1 = n1.getParent().orElseThrow(AssertionError::new); final TreeNode<A> n2 = seq2.get(random.nextInt(seq2.length() - 1) + 1); final TreeNode<A> p2 = n2.getParent().orElseThrow(AssertionError::new); final int i1 = p1.getIndex(n1); final int i2 = p2.getIndex(n2); p1.insert(i1, n2.detach()); p2.insert(i2, n1.detach()); changed = 2; } else { changed = 0; } return changed; }
java
static <A> int swap(final TreeNode<A> that, final TreeNode<A> other) { assert that != null; assert other != null; final Random random = RandomRegistry.getRandom(); final ISeq<TreeNode<A>> seq1 = that.breadthFirstStream() .collect(ISeq.toISeq()); final ISeq<TreeNode<A>> seq2 = other.breadthFirstStream() .collect(ISeq.toISeq()); final int changed; if (seq1.length() > 1 && seq2.length() > 1) { final TreeNode<A> n1 = seq1.get(random.nextInt(seq1.length() - 1) + 1); final TreeNode<A> p1 = n1.getParent().orElseThrow(AssertionError::new); final TreeNode<A> n2 = seq2.get(random.nextInt(seq2.length() - 1) + 1); final TreeNode<A> p2 = n2.getParent().orElseThrow(AssertionError::new); final int i1 = p1.getIndex(n1); final int i2 = p2.getIndex(n2); p1.insert(i1, n2.detach()); p2.insert(i2, n1.detach()); changed = 2; } else { changed = 0; } return changed; }
[ "static", "<", "A", ">", "int", "swap", "(", "final", "TreeNode", "<", "A", ">", "that", ",", "final", "TreeNode", "<", "A", ">", "other", ")", "{", "assert", "that", "!=", "null", ";", "assert", "other", "!=", "null", ";", "final", "Random", "rand...
The static method makes it easier to test.
[ "The", "static", "method", "makes", "it", "easier", "to", "test", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/SingleNodeCrossover.java#L94-L126
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.sortAndRevert
static double[] sortAndRevert(final double[] array) { final int[] indexes = sort(array); // Copy the elements in reversed order. final double[] result = new double[array.length]; for (int i = 0; i < result.length; ++i) { result[indexes[result.length - 1 - i]] = array[indexes[i]]; } return result; }
java
static double[] sortAndRevert(final double[] array) { final int[] indexes = sort(array); // Copy the elements in reversed order. final double[] result = new double[array.length]; for (int i = 0; i < result.length; ++i) { result[indexes[result.length - 1 - i]] = array[indexes[i]]; } return result; }
[ "static", "double", "[", "]", "sortAndRevert", "(", "final", "double", "[", "]", "array", ")", "{", "final", "int", "[", "]", "indexes", "=", "sort", "(", "array", ")", ";", "// Copy the elements in reversed order.", "final", "double", "[", "]", "result", ...
Package private for testing.
[ "Package", "private", "for", "testing", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L159-L169
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.checkAndCorrect
private static void checkAndCorrect(final double[] probabilities) { boolean ok = true; for (int i = probabilities.length; --i >= 0 && ok;) { ok = Double.isFinite(probabilities[i]); } if (!ok) { final double value = 1.0/probabilities.length; for (int i = probabilities.length; --i >= 0;) { probabilities[i] = value; } } }
java
private static void checkAndCorrect(final double[] probabilities) { boolean ok = true; for (int i = probabilities.length; --i >= 0 && ok;) { ok = Double.isFinite(probabilities[i]); } if (!ok) { final double value = 1.0/probabilities.length; for (int i = probabilities.length; --i >= 0;) { probabilities[i] = value; } } }
[ "private", "static", "void", "checkAndCorrect", "(", "final", "double", "[", "]", "probabilities", ")", "{", "boolean", "ok", "=", "true", ";", "for", "(", "int", "i", "=", "probabilities", ".", "length", ";", "--", "i", ">=", "0", "&&", "ok", ";", "...
Checks if the given probability values are finite. If not, all values are set to the same probability. @param probabilities the probabilities to check.
[ "Checks", "if", "the", "given", "probability", "values", "are", "finite", ".", "If", "not", "all", "values", "are", "set", "to", "the", "same", "probability", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L202-L214
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.sum2one
static boolean sum2one(final double[] probabilities) { final double sum = probabilities.length > 0 ? DoubleAdder.sum(probabilities) : 1.0; return abs(ulpDistance(sum, 1.0)) < MAX_ULP_DISTANCE; }
java
static boolean sum2one(final double[] probabilities) { final double sum = probabilities.length > 0 ? DoubleAdder.sum(probabilities) : 1.0; return abs(ulpDistance(sum, 1.0)) < MAX_ULP_DISTANCE; }
[ "static", "boolean", "sum2one", "(", "final", "double", "[", "]", "probabilities", ")", "{", "final", "double", "sum", "=", "probabilities", ".", "length", ">", "0", "?", "DoubleAdder", ".", "sum", "(", "probabilities", ")", ":", "1.0", ";", "return", "a...
Check if the given probabilities sum to one. @param probabilities the probabilities to check. @return {@code true} if the sum of the probabilities are within the error range, {@code false} otherwise.
[ "Check", "if", "the", "given", "probabilities", "sum", "to", "one", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L223-L228
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.indexOfBinary
static int indexOfBinary(final double[] incr, final double v) { int imin = 0; int imax = incr.length; int index = -1; while (imax > imin && index == -1) { final int imid = (imin + imax) >>> 1; if (imid == 0 || (incr[imid] >= v && incr[imid - 1] < v)) { index = imid; } else if (incr[imid] <= v) { imin = imid + 1; } else if (incr[imid] > v) { imax = imid; } } return index; }
java
static int indexOfBinary(final double[] incr, final double v) { int imin = 0; int imax = incr.length; int index = -1; while (imax > imin && index == -1) { final int imid = (imin + imax) >>> 1; if (imid == 0 || (incr[imid] >= v && incr[imid - 1] < v)) { index = imid; } else if (incr[imid] <= v) { imin = imid + 1; } else if (incr[imid] > v) { imax = imid; } } return index; }
[ "static", "int", "indexOfBinary", "(", "final", "double", "[", "]", "incr", ",", "final", "double", "v", ")", "{", "int", "imin", "=", "0", ";", "int", "imax", "=", "incr", ".", "length", ";", "int", "index", "=", "-", "1", ";", "while", "(", "im...
Perform a binary-search on the summed probability array.
[ "Perform", "a", "binary", "-", "search", "on", "the", "summed", "probability", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L243-L261
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.indexOfSerial
static int indexOfSerial(final double[] incr, final double v) { int index = -1; for (int i = 0; i < incr.length && index == -1; ++i) { if (incr[i] >= v) { index = i; } } return index; }
java
static int indexOfSerial(final double[] incr, final double v) { int index = -1; for (int i = 0; i < incr.length && index == -1; ++i) { if (incr[i] >= v) { index = i; } } return index; }
[ "static", "int", "indexOfSerial", "(", "final", "double", "[", "]", "incr", ",", "final", "double", "v", ")", "{", "int", "index", "=", "-", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "incr", ".", "length", "&&", "index", "==", ...
Perform a serial-search on the summed probability array.
[ "Perform", "a", "serial", "-", "search", "on", "the", "summed", "probability", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L266-L275
train
jenetics/jenetics
jenetics/src/main/java/io/jenetics/ProbabilitySelector.java
ProbabilitySelector.incremental
static double[] incremental(final double[] values) { final DoubleAdder adder = new DoubleAdder(values[0]); for (int i = 1; i < values.length; ++i) { values[i] = adder.add(values[i]).doubleValue(); } return values; }
java
static double[] incremental(final double[] values) { final DoubleAdder adder = new DoubleAdder(values[0]); for (int i = 1; i < values.length; ++i) { values[i] = adder.add(values[i]).doubleValue(); } return values; }
[ "static", "double", "[", "]", "incremental", "(", "final", "double", "[", "]", "values", ")", "{", "final", "DoubleAdder", "adder", "=", "new", "DoubleAdder", "(", "values", "[", "0", "]", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", ...
In-place summation of the probability array.
[ "In", "-", "place", "summation", "of", "the", "probability", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics/src/main/java/io/jenetics/ProbabilitySelector.java#L280-L286
train
jenetics/jenetics
jenetics.ext/src/main/java/io/jenetics/ext/util/TreeNode.java
TreeNode.getChild
@Override public TreeNode<T> getChild(final int index) { if (_children == null) { throw new ArrayIndexOutOfBoundsException(format( "Child index is out of bounds: %s", index )); } return _children.get(index); }
java
@Override public TreeNode<T> getChild(final int index) { if (_children == null) { throw new ArrayIndexOutOfBoundsException(format( "Child index is out of bounds: %s", index )); } return _children.get(index); }
[ "@", "Override", "public", "TreeNode", "<", "T", ">", "getChild", "(", "final", "int", "index", ")", "{", "if", "(", "_children", "==", "null", ")", "{", "throw", "new", "ArrayIndexOutOfBoundsException", "(", "format", "(", "\"Child index is out of bounds: %s\""...
Returns the child at the specified index in this node's child array. @param index an index into this node's child array @return the tree-node in this node's child array at the specified index @throws ArrayIndexOutOfBoundsException if the {@code index} is out of bounds
[ "Returns", "the", "child", "at", "the", "specified", "index", "in", "this", "node", "s", "child", "array", "." ]
ee516770c65ef529b27deb283f071c85f344eff4
https://github.com/jenetics/jenetics/blob/ee516770c65ef529b27deb283f071c85f344eff4/jenetics.ext/src/main/java/io/jenetics/ext/util/TreeNode.java#L122-L131
train
jasminb/jsonapi-converter
src/main/java/com/github/jasminb/jsonapi/ValidationUtils.java
ValidationUtils.ensureValidResource
public static void ensureValidResource(JsonNode resource) { if (!resource.has(JSONAPISpecConstants.DATA) && !resource.has(JSONAPISpecConstants.META)) { throw new InvalidJsonApiResourceException(); } }
java
public static void ensureValidResource(JsonNode resource) { if (!resource.has(JSONAPISpecConstants.DATA) && !resource.has(JSONAPISpecConstants.META)) { throw new InvalidJsonApiResourceException(); } }
[ "public", "static", "void", "ensureValidResource", "(", "JsonNode", "resource", ")", "{", "if", "(", "!", "resource", ".", "has", "(", "JSONAPISpecConstants", ".", "DATA", ")", "&&", "!", "resource", ".", "has", "(", "JSONAPISpecConstants", ".", "META", ")",...
Asserts that provided resource has required 'data' or 'meta' node. @param resource resource
[ "Asserts", "that", "provided", "resource", "has", "required", "data", "or", "meta", "node", "." ]
73b41c3b9274e70e62b3425071ca8afdc7bddaf6
https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ValidationUtils.java#L25-L29
train
jasminb/jsonapi-converter
src/main/java/com/github/jasminb/jsonapi/ValidationUtils.java
ValidationUtils.ensureNotError
public static void ensureNotError(ObjectMapper mapper, JsonNode resourceNode) { if (resourceNode != null && resourceNode.hasNonNull(JSONAPISpecConstants.ERRORS)) { try { throw new ResourceParseException(ErrorUtils.parseError(mapper, resourceNode, Errors.class)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }
java
public static void ensureNotError(ObjectMapper mapper, JsonNode resourceNode) { if (resourceNode != null && resourceNode.hasNonNull(JSONAPISpecConstants.ERRORS)) { try { throw new ResourceParseException(ErrorUtils.parseError(mapper, resourceNode, Errors.class)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }
[ "public", "static", "void", "ensureNotError", "(", "ObjectMapper", "mapper", ",", "JsonNode", "resourceNode", ")", "{", "if", "(", "resourceNode", "!=", "null", "&&", "resourceNode", ".", "hasNonNull", "(", "JSONAPISpecConstants", ".", "ERRORS", ")", ")", "{", ...
Ensures that provided node does not hold 'errors' attribute. @param resourceNode resource node @throws ResourceParseException
[ "Ensures", "that", "provided", "node", "does", "not", "hold", "errors", "attribute", "." ]
73b41c3b9274e70e62b3425071ca8afdc7bddaf6
https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/ValidationUtils.java#L46-L54
train
jasminb/jsonapi-converter
src/main/java/com/github/jasminb/jsonapi/JSONAPIDocument.java
JSONAPIDocument.createErrorDocument
@NotNull public static JSONAPIDocument<?> createErrorDocument(Iterable<? extends Error> errors) { JSONAPIDocument<?> result = new JSONAPIDocument(); result.errors = errors; return result; }
java
@NotNull public static JSONAPIDocument<?> createErrorDocument(Iterable<? extends Error> errors) { JSONAPIDocument<?> result = new JSONAPIDocument(); result.errors = errors; return result; }
[ "@", "NotNull", "public", "static", "JSONAPIDocument", "<", "?", ">", "createErrorDocument", "(", "Iterable", "<", "?", "extends", "Error", ">", "errors", ")", "{", "JSONAPIDocument", "<", "?", ">", "result", "=", "new", "JSONAPIDocument", "(", ")", ";", "...
Factory method for creating JSONAPIDocument that holds the Error object. <p> This method should be used in case error response is being built by the server side. </p> @param errors
[ "Factory", "method", "for", "creating", "JSONAPIDocument", "that", "holds", "the", "Error", "object", "." ]
73b41c3b9274e70e62b3425071ca8afdc7bddaf6
https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/JSONAPIDocument.java#L114-L119
train
jasminb/jsonapi-converter
src/main/java/com/github/jasminb/jsonapi/JSONAPIDocument.java
JSONAPIDocument.addLink
public void addLink(String linkName, Link link) { if (links == null) { links = new Links(new HashMap<String, Link>()); } links.addLink(linkName, link); }
java
public void addLink(String linkName, Link link) { if (links == null) { links = new Links(new HashMap<String, Link>()); } links.addLink(linkName, link); }
[ "public", "void", "addLink", "(", "String", "linkName", ",", "Link", "link", ")", "{", "if", "(", "links", "==", "null", ")", "{", "links", "=", "new", "Links", "(", "new", "HashMap", "<", "String", ",", "Link", ">", "(", ")", ")", ";", "}", "lin...
Adds a named link. @param linkName the named link to add @param link the link to add
[ "Adds", "a", "named", "link", "." ]
73b41c3b9274e70e62b3425071ca8afdc7bddaf6
https://github.com/jasminb/jsonapi-converter/blob/73b41c3b9274e70e62b3425071ca8afdc7bddaf6/src/main/java/com/github/jasminb/jsonapi/JSONAPIDocument.java#L173-L178
train