Menu

#14 distSquared becomes distSquaf2 because red becomes f2

open
nobody
None
2
2014-08-05
2009-08-29
BenRayfield
No

It does not break anything, but the code transformations must be predictable.

The default SimpleFuncInfo class (which will be replaced by dynamic Func descriptions) changes all "red" to "f2", all "left" to "f0", etc. Then f2 becomes flos[f+2].

Log file contains:

Parsing path: /classpath/anyfiles/evolvefunc/hypercube/DistanceXYXYLinearNormalize_noTimeVar.func
Parsed path: [classpath, anyfiles, evolvefunc, hypercube, DistanceXYXYLinearNormalize_noTimeVar.func]
Loaded default hypercube code:
//If the distance from [f0,f1] to [f2,f3] is more than 1, moves them toward eachother.
//TODO test this
{
double dx = f2 - f0;
double dy = f3 - f1;
double distSquared = dx*dx + dy*dy;
if(distSquared > 1){
double dist = Math.sqrt(distSquared);
double moveEach = (dist - 1)/2; //move each point toward the other this distance
double normDx = dx / dist;
double normDy = dy / dist; //distance from [0,0] to [normDx,normDy] is 1
double moveX = moveEach*normDx;
double moveY = moveEach*normDy;
f2 -= moveX;
f0 += moveX;
f3 -= moveY;
f1 += moveY;
}
}
Removed comments from default hypercube code:

{
double dx = f2 - f0;
double dy = f3 - f1;
double distSquared = dx*dx + dy*dy;
if(distSquared > 1){
double dist = Math.sqrt(distSquared);
double moveEach = (dist - 1)/2;
double normDx = dx / dist;
double normDy = dy / dist;
double moveX = moveEach*normDx;
double moveY = moveEach*normDy;
f2 -= moveX;
f0 += moveX;
f3 -= moveY;
f1 += moveY;
}
}
codeOfRunFunction before translation to Java is:

{
double dx = f0 - f1;
double dy = f2 - f3;
double distSquaf2 = dx*dx + dy*dy;
if(distSquaf2 > 1){
double dist = Math.sqrt(distSquaf2);
double moveEach = (dist - 1)/2;
double normDx = dx / dist;
double normDy = dy / dist;
double moveX = moveEach*normDx;
double moveY = moveEach*normDy;
f0 -= moveX;
f1 += moveX;
f2 -= moveY;
f3 += moveY;
}
}
codeOfRunFunction after translation to Java is:
{
double dx = flos[f] - flos[f+1];
double dy = flos[f+2] - flos[f+3];
double distSquaf2 = dx*dx + dy*dy;
if(distSquaf2 > 1){
double dist = Math.sqrt(distSquaf2);
double moveEach = (dist - 1)/2;
double normDx = dx / dist;
double normDy = dy / dist;
double moveX = moveEach*normDx;
double moveY = moveEach*normDy;
flos[f] -= moveX;
flos[f+1] += moveX;
flos[f+2] -= moveY;
flos[f+3] += moveY;
}
}
getting CtClass java.lang.Object
creating CtClass Javassist970531108Func
New CtClass javassist.CtNewClass@29c58e[changed public class Javassist970531108Func fields= constructors= methods=] frozen=false
getting interface CtClass: audivolv.Func
adding interface to the new class
added interface
javaFuncCode = public void run(double flos[], int f, Object obs[], int o) throws Exception{
{
double dx = flos[f] - flos[f+1];
double dy = flos[f+2] - flos[f+3];
double distSquaf2 = dx*dx + dy*dy;
if(distSquaf2 > 1){
double dist = Math.sqrt(distSquaf2);
double moveEach = (dist - 1)/2;
double normDx = dx / dist;
double normDy = dy / dist;
double moveX = moveEach*normDx;
double moveY = moveEach*normDy;
flos[f] -= moveX;
flos[f+1] += moveX;
flos[f+2] -= moveY;
flos[f+3] += moveY;
}
}
}
javaFuncCode = public int flos(){ return 25; }
javaFuncCode = public int obs(){ return 0; }
javaFuncCode = public boolean stateless(){ return true; }
Creating class from CtClass: javassist.CtNewClass@29c58e[changed public class Javassist970531108Func implements audivolv.Func, fields= constructors= methods=javassist.CtMethod@67b7ca54[public run ([DI[Ljava/lang/Object;I)V], javassist.CtMethod@b43463ab[public flos ()I], javassist.CtMethod@64a7201[public obs ()I], javassist.CtMethod@70dff82b[public stateless ()Z], ]
Created new class: Javassist970531108Func but have not verified it can be instantiated.
Testing new Class object: class Javassist970531108Func
Constructor 0 is public Javassist970531108Func()
Basic testing of class Javassist970531108Func passes.
Verifying Func stays hypercube range (with 30000 tests): Javassist970531108Func@1568fb5
Done verifying Func stays hypercube range (with 30000 tests): Javassist970531108Func@1568fb5

Discussion

MongoDB Logo MongoDB