Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions Axon.pde
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
class Axon{
final double MUTABILITY_MUTABILITY = 0.7;
final int mutatePower = 9;
final double MUTATE_MULTI;

double weight;
double mutability;
public Axon(double w, double m){
weight = w;
mutability = m;
MUTATE_MULTI = Math.pow(0.5,mutatePower);
}

public Axon mutateAxon(){
double mutabilityMutate = Math.pow(0.5,pmRan()*MUTABILITY_MUTABILITY);
return new Axon(weight+r()*mutability/MUTATE_MULTI,mutability*mutabilityMutate);
}
public double r(){
return Math.pow(pmRan(),mutatePower);
}
public double pmRan(){
return (Math.random()*2-1);
}
}
class Axon implements ISavable{
final double MUTABILITY_MUTABILITY = 0.7;
final int mutatePower = 9;
final double MUTATE_MULTI;

double weight;
double mutability;
public Axon(double w, double m){
weight = w;
mutability = m;
MUTATE_MULTI = Math.pow(0.5,mutatePower);
}

public Axon mutateAxon(){
double mutabilityMutate = Math.pow(0.5,pmRan()*MUTABILITY_MUTABILITY);
return new Axon(weight+r()*mutability/MUTATE_MULTI,mutability*mutabilityMutate);
}
public double r(){
return Math.pow(pmRan(),mutatePower);
}
public double pmRan(){
return (Math.random()*2-1);
}

public JSONObject saveToJson(){
JSONObject object = new JSONObject();
object.setDouble("weight", weight);
object.setDouble("mutability", mutability);
return object;
}

public void loadFromJson(JSONObject parent){
weight = parent.getDouble("weight", weight);
mutability = parent.getDouble("mutability", mutability);
}
}
Loading