/** * Deep copies a state, useful in mutation. */ public State<T, U> copy() { State<T, U> r = new State<T, U>(); r.params = Arrays.copyOf(this.params, this.params.length); r.omni = this.omni; r.step = Arrays.copyOf(this.step, this.step.length); r.maps = Arrays.copyOf(this.maps, this.maps.length); if (this.payload != null) { r.payload = (T) this.payload.copy(); } r.gen = this.gen; return r; }
/** * Clones this state with a random change in position. Copies the payload and * lets it know about the change. * * @return A new state. */ public State<T, U> mutate() { double sum = 0; for (double v : step) { sum += v * v; } sum = Math.sqrt(sum); double lambda = 1 + gen.nextGaussian(); State<T, U> r = this.copy(); double magnitude = 0.9 * omni + sum / 10; r.omni = magnitude * -Math.log1p(-gen.nextDouble()); for (int i = 0; i < step.length; i++) { r.step[i] = lambda * step[i] + r.omni * gen.nextGaussian(); r.params[i] += r.step[i]; } if (this.payload != null) { r.payload.update(r.getMappedParams()); } return r; }
/** * Clones this state with a random change in position. Copies the payload and * lets it know about the change. * * @return A new state. */ public State<T, U> mutate() { double sum = 0; for (double v : step) { sum += v * v; } sum = Math.sqrt(sum); double lambda = 1 + gen.nextGaussian(); State<T, U> r = this.copy(); double magnitude = 0.9 * omni + sum / 10; r.omni = magnitude * -Math.log1p(-gen.nextDouble()); for (int i = 0; i < step.length; i++) { r.step[i] = lambda * step[i] + r.omni * gen.nextGaussian(); r.params[i] += r.step[i]; } if (this.payload != null) { r.payload.update(r.getMappedParams()); } return r; }
/** * Deep copies a state, useful in mutation. */ public State<T, U> copy() { State<T, U> r = new State<>(); r.params = Arrays.copyOf(this.params, this.params.length); r.omni = this.omni; r.step = Arrays.copyOf(this.step, this.step.length); r.maps = Arrays.copyOf(this.maps, this.maps.length); if (this.payload != null) { r.payload = (T) this.payload.copy(); } r.gen = this.gen; return r; }
/** * Clones this state with a random change in position. Copies the payload and * lets it know about the change. * * @return A new state. */ public State<T, U> mutate() { double sum = 0; for (double v : step) { sum += v * v; } sum = Math.sqrt(sum); double lambda = 1 + gen.nextGaussian(); State<T, U> r = this.copy(); double magnitude = 0.9 * omni + sum / 10; r.omni = magnitude * -Math.log1p(-gen.nextDouble()); for (int i = 0; i < step.length; i++) { r.step[i] = lambda * step[i] + r.omni * gen.nextGaussian(); r.params[i] += r.step[i]; } if (this.payload != null) { r.payload.update(r.getMappedParams()); } return r; }
/** * Deep copies a state, useful in mutation. */ public State<T, U> copy() { State<T, U> r = new State<T, U>(); r.params = Arrays.copyOf(this.params, this.params.length); r.omni = this.omni; r.step = Arrays.copyOf(this.step, this.step.length); r.maps = Arrays.copyOf(this.maps, this.maps.length); if (this.payload != null) { r.payload = (T) this.payload.copy(); } r.gen = this.gen; return r; }