-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvolve.java
More file actions
41 lines (33 loc) · 1.09 KB
/
Copy pathEvolve.java
File metadata and controls
41 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package s6regen;
public abstract class Evolve {
private final Reservoir reservoir;
private long precision;
private final float[] parent;
private float parentCost;
// Use fully perpared reservoir. Higher precision equals lower mutation rate.
public Evolve(Reservoir r, long precision) {
reservoir = r;
this.precision = precision;
parent = new float[r.getWeightSize()];
parentCost = Float.POSITIVE_INFINITY;
}
// Next evolution evaluation.
public void iterate() {
reservoir.resetHeldStateAll(); // Clear all associative memory etc.
reservoir.getWeights(parent);
reservoir.mutate(precision); // Reservoir now contains child weights
float childCost = evaluateCost(reservoir);
if (childCost < parentCost) {
parentCost = childCost;
} else {
reservoir.setWeights(parent);
}
}
public void setPrecision(long pre) {
precision = pre;
}
public long getPrecision() {
return precision;
}
public abstract float evaluateCost(Reservoir r);
}