BallJoint set-joint-velocity method.

I cannot figure out how to use the set-joint-velocity. Can someone tell me what is wrong with the instance in the following code...

set-joint-velocity to rotationalVelocity (vector)

Sets the desired joint velocity to rotationalVelocity. As a ball joint allows rotation on three axes, rotationalVelocity is a vector.

%KittensErgoMan
%breve ergobody by Correy Kowall (http://brevecluster.nmu.edu/) and Katy Tresedder (ktresedd@nmu.edu)
#@use Braitenberg7.
@use Spring.
@use MultiBody.
@use Link.
@use PhysicalControl.
@use Stationary.
@use Joint.
@use NeuralNetwork5.

@define NUMLINKS 100.
@define GAUGE 1.0.
@define SEGLENGTH 1.5.
@define SIDES 10.
@define STRENGTH 100.
@define STARTALT 12.95.
@define DECAY 0.07.
@define MAXSFORCE 1000.

Controller BodyController.

PhysicalControl: BodyController {
+ variables:
bodyA(object).
floor(object).
brainA(object).
outputSize(int).
brainSize(int).
+ to init:
prts(list).
tmp(object).

self enable-lighting.
self enable-smooth-drawing.

#self enable-fast-physics.
self set-fast-physics-iterations to 50.

# Create the floor for the critter to walk on.

floor = new Floor.
floor catch-shadows.
floor set-eT to 0.2.
floor set-mu to 1.0.

self set-background-texture-image to (new Image load from "images/clouds.png").

self enable-reflections.

self set-background-color to (.4, .6, .9).
bodyA = new ErgoBody.
#bodyA set-links to NUMLINKS.
#bodyA init-floppy.
#bodyA init-rigid.
bodyA init-fusion.
brainA = new NeuralNetwork4.

outputSize = (3 * |(bodyA get-joints)|).
brainSize = (2 * outputSize).
brainA init-with neuron-count brainSize.
brainA init-fully-connected-structure with-autapses 0.
brainA randomize-weights between -1.0.
bodyA set-brain to brainA.
#self zero-gravity.
self half-gravity.
self watch item bodyA.

prts = (bodyA get-segs).
foreach tmp in prts:{
tmp get-max-force.
#tmp set-label.
tmp set-e to 0.2.
#tmp iterate.
}
self watch item (prts{0}).
#bodyA move to ( 0, 20, 0).
#super init.
+ to iterate:
prts(list).
tmp(object).
#prts = (bodyA get-segs).
foreach tmp in prts:{
#tmp get-max-force.
#tmp set-label.
#tmp set-e to 0.2.
#tmp set-velocity to (0, 0, 0).
tmp iterate.
}
bodyA control-at time 0.
super iterate.
}
MultiBody : ErgoBody {
% This is a basic multibody emulation of a kinematic human
+ variables:
brain(object). #NeuralNetwork5.tz
segs(list). #A list of elements of the class BodySegment
sizes(list). #A list of the sizes of those elements
joints(list). #A list of controllable joints.
commands(list).
torques(list).
velocities(list).
springs(list).
sensors(list). #of class
head(object).
neck1(object).
neck2(object).
torso1(object). #Top
torso2(object).
shoulder1(object). #Left
shoulder2(object).
arm11(object). #LeftTop
arm21(object). #RightTop
elbow1(object). #Left
elbow2(object).
arm12(object). #LeftBottom
arm22(object).
wrist1(object). #Left
wrist2(object).
palm1(object).
palm2(object).
#fingers later
hip1(object). #Left
hip2(object).
leg11(object). #LeftTop
leg12(object).
knee1(object).
knee2(object).
leg21(object).
leg22(object).
ankle1(object).
ankle2(object).
foot1(object).
foot2(object).
#toes later

+ to init-fusion:
theRadius(double).
sideCount(int).
theHeight(double).
theSize(vector).
biOff(double).
holder1(double).
other(object).
gapLength(double).
localPoint(vector).
otherPoint(vector).
temp(object).
temp2(object).
tmpL(list).
dirSet(list).
temp3(object).
temp4(vector).
temp5(object).
head = new BodySegment.
neck1 = new BodySegment.
neck2 = new BodySegment.
torso1 = new BodySegment. #Top
torso2 = new BodySegment.
shoulder1 = new BodySegment. #Left
shoulder2 = new BodySegment.
arm11 = new BodySegment. #LeftTop
arm21 = new BodySegment. #RightTop
elbow1 = new BodySegment. #Left
elbow2 = new BodySegment.
arm12 = new BodySegment. #LeftBottom
arm22 = new BodySegment.
wrist1 = new BodySegment. #Left
wrist2 = new BodySegment.
palm1 = new BodySegment.
palm2 = new BodySegment.
#fingers later
hip1 = new BodySegment. #Left
hip2 = new BodySegment.
leg11 = new BodySegment. #LeftTop
leg12 = new BodySegment.
knee1 = new BodySegment.
knee2 = new BodySegment.
leg21 = new BodySegment.
leg22 = new BodySegment.
ankle1 = new BodySegment.
ankle2 = new BodySegment.
foot1 = new BodySegment.
foot2 = new BodySegment.
#toes later
head set-id name "Head".
neck1 set-id name "Upper neck".
neck2 set-id name "Lower neck".
torso1 set-id name "Upper torso". #Top
torso2 set-id name "Lower torso".
shoulder1 set-id name "Left shoulder". #Left
shoulder2 set-id name "Right shoulder".
arm11 set-id name "Left upper arm". #LeftTop
arm21 set-id name "Right upper arm". #RightTop
elbow1 set-id name "Left Elbow" . #Left
elbow2 set-id name "Right Elbow" .
arm12 set-id name "Left forearm". #LeftBottom
arm22 set-id name "Right forearm".
wrist1 set-id name "Left wrist". #Left
wrist2 set-id name "Right wrist".
palm1 set-id name "Left palm".
palm2 set-id name "Right palm".
#fingers later
hip1 set-id name "Left hip". #Left
hip2 set-id name "Right hip".
leg11 set-id name "Left thigh". #LeftTop
leg12 set-id name "Right thigh".
knee1 set-id name "Left knee".
knee2 set-id name "Right knee".
leg21 set-id name "Left calf".
leg22 set-id name "Right calf".
ankle1 set-id name "Left ankle".
ankle2 set-id name "Right ankle".
foot1 set-id name "Left foot".
foot2 set-id name "Right foot".

sideCount = SIDES.
theHeight = SEGLENGTH.
theRadius = GAUGE.
theSize = ( (0.25 * theHeight), (0.5 * theHeight), (0.5 * theHeight)).
head init-sphere radius (theHeight * 1.0).
neck1 init-disk radius (theRadius * 0.5) sides sideCount height (theHeight * 0.25).
neck2 init-disk radius (theRadius * 0.5) sides sideCount height (theHeight * 0.25).
torso1 init-disk radius (theRadius * 1.0) sides sideCount height (theHeight * 1.5). #Top
torso2 init-disk radius (theRadius * 1.0) sides sideCount height (theHeight * 1.5).
shoulder1 init-sphere radius (0.25 * theHeight). #Left
shoulder2 init-sphere radius (0.25 * theHeight).
arm11 init-disk radius (0.25 * theRadius) sides sideCount height (theHeight * 0.75). #LeftTop
arm21 init-disk radius (0.25 * theRadius) sides sideCount height (theHeight * 0.75). #RightTop
elbow1 init-sphere radius (0.25 * theHeight). #Left
elbow2 init-sphere radius (0.25 * theHeight).
arm12 init-disk radius (0.25 * theRadius) sides sideCount height (theHeight * 0.75). #LeftBottom
arm22 init-disk radius (0.25 * theRadius) sides sideCount height (theHeight * 0.75).
wrist1 init-sphere radius (0.25 * theHeight). #Left
wrist2 init-sphere radius (0.25 * theHeight).
palm1 init-cube of theSize.
palm2 init-cube of theSize.
#fingers later
hip1 init-sphere radius (0.25 * theHeight). #Left
hip2 init-sphere radius (0.25 * theHeight).
leg11 init-disk radius (0.5 * theRadius) sides sideCount height theHeight. #LeftTop
leg12 init-disk radius (0.5 * theRadius) sides sideCount height theHeight.
knee1 init-sphere radius (0.25 * theHeight).
knee2 init-sphere radius (0.25 * theHeight).
leg21 init-disk radius (0.25 * theRadius) sides sideCount height theHeight.
leg22 init-disk radius (0.25 * theRadius) sides sideCount height theHeight.
ankle1 init-sphere radius (0.25 * theHeight).
ankle2 init-sphere radius (0.25 * theHeight).
theSize = ( (0.5 * theHeight), (0.25 * theHeight), (1.0 * theHeight)).
foot1 init-cube of theSize.
foot2 init-cube of theSize.

#note that in the following section theHeight is used to increment height
biOff = 0.0.
theHeight = (STARTALT).
head move to ( biOff, theHeight, 0.0).
theHeight -= ( (neck1 get-height) / 2.0 + ( (head get-height) / 2.0)).#((head get-radius))
neck1 move to ( biOff, theHeight, 0.0).
theHeight -= (( (neck1 get-height) / 2.0) + ((neck2 get-height) / 2.0) ).
neck2 move to ( biOff, theHeight, 0.0).
theHeight -= (( (torso1 get-height) / 2.0) + ((neck2 get-height) / 2.0) ).
print "moveing the upper torso to $theHeight".
torso1 move to ( biOff, theHeight, 0.0). #Top
theHeight -= (( (torso1 get-height) / 2.0) + ((torso2 get-height) / 2.0) ).
print "moveing the lower torso to $theHeight".
torso2 move to ( biOff, theHeight, 0.0).
biOff = ((torso1 get-radius) + (shoulder1 get-radius)).
theHeight = (STARTALT - (2.0 * SEGLENGTH)).
shoulder1 move to ( biOff, theHeight, 0.0). #Left
shoulder2 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (shoulder1 get-height) / 2.0) + ((arm11 get-height) / 2.0) ).
arm11 move to ( biOff, theHeight, 0.0). #LeftTop
arm21 move to ( -biOff, theHeight, 0.0). #RightTop
theHeight -= (( (elbow1 get-height) / 2.0) + ((arm11 get-height) / 2.0) ).
elbow1 move to ( biOff, theHeight, 0.0). #Left
elbow2 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (elbow1 get-height) / 2.0) + ((arm12 get-height) / 2.0) ).
arm12 move to ( biOff, theHeight, 0.0). #LeftBottom
arm22 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (wrist1 get-height) / 2.0) + ((arm12 get-height) / 2.0) ).
wrist1 move to ( biOff, theHeight, 0.0). #Left
wrist2 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (wrist1 get-height) / 2.0) + ((palm1 get-height) / 2.0) ).
palm1 move to ( biOff, theHeight, 0.0).
palm2 move to ( -biOff, theHeight, 0.0).
#fingers later
theHeight = (STARTALT - ( (head get-radius) + (neck1 get-height) + (neck2 get-height) + (torso1 get-height) + (torso2 get-height) + (hip1 get-height))).
biOff = (torso1 get-radius).
hip1 move to ( biOff, theHeight, 0.0). #Left
hip2 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (hip1 get-height) / 2.0) + ((leg11 get-height) / 2.0) ).
leg11 move to ( biOff, theHeight, 0). #LeftTop
leg12 move to ( -biOff, theHeight, 0).
theHeight -= (( (knee1 get-height) / 2.0) + ((leg11 get-height) / 2.0) ).
knee1 move to ( biOff, theHeight, 0).
knee2 move to ( -biOff, theHeight, 0).
theHeight -= (( (knee1 get-height) / 2.0) + ((leg21 get-height) / 2.0) ).
leg21 move to ( biOff, theHeight, 0.0).
leg22 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (ankle1 get-height) / 2.0) + ((leg21 get-height) / 2.0) ).
ankle1 move to ( biOff, theHeight, 0.0).
ankle2 move to ( -biOff, theHeight, 0.0).
theHeight -= (( (ankle1 get-height) / 2.0) + ((foot1 get-height) / 2.0) ).
foot1 move to ( biOff, theHeight, 0.0).
foot2 move to ( -biOff, theHeight, 0.0).

gapLength = 0.01.
localPoint = (head get-point-on-shape on (0, -1, 0)).
other = neck1.
otherPoint = (other get-point-on-shape on (0, 1, 0)).
head attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (neck1 get-point-on-shape on (0, -1, 0)).
other = neck2.
otherPoint = (other get-point-on-shape on (0, 1, 0)).
neck1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (neck2 get-point-on-shape on (0, -1, 0)).
other = torso1.
otherPoint = (other get-point-on-shape on (0, 1, 0)).
neck2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (torso1 get-point-on-shape on (0, -1, 0)).
other = torso2.
otherPoint = (other get-point-on-shape on (0, 1, 0)).
print "attaching to other $other at $otherPoint from $localPoint".

torso1 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #Top
localPoint = (torso2 get-point-on-shape on (0, -1, 0)).
other = hip1.
localPoint = (hip1 get-point-on-shape on (0, 1, 0)).
#torso2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (shoulder1 get-point-on-shape on (-1, 0, 0)).
other = torso1.
otherPoint = (other get-point-on-shape on (1, 1, 0)).
shoulder1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (shoulder2 get-point-on-shape on (1, 0, 0)).
other = torso1.
otherPoint = (other get-point-on-shape on (-1, 1, 0)). #Left
shoulder2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (arm11 get-point-on-shape on (0, 1, 0)).
other = shoulder1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
#print "attaching to other $other at $otherPoint from $localPoint".
arm11 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #LeftTop
localPoint = (arm21 get-point-on-shape on (0, 1, 0)).
other = shoulder2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
arm21 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #RightTop
localPoint = (elbow1 get-point-on-shape on (0, 1, 0)).
other = arm11.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
elbow1 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #Left
localPoint = (elbow2 get-point-on-shape on (0, 1, 0)).
other = arm21.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
elbow2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (arm12 get-point-on-shape on (0, 1, 0)).
other = elbow1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
arm12 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #LeftBottom
localPoint = (arm22 get-point-on-shape on (0, 1, 0)).
other = elbow2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
arm22 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (wrist1 get-point-on-shape on (0, 1, 0)).
other = arm12.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
wrist1 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #Left
localPoint = (wrist2 get-point-on-shape on (0, 1, 0)).
other = arm22.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
wrist2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (palm1 get-point-on-shape on (0, 1, 0)).
other = wrist1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
palm1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (palm2 get-point-on-shape on (0, 1, 0)).
other = wrist2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
palm2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
#fingers later
localPoint = (hip1 get-point-on-shape on (0, 1, 0)).
other = torso2.
otherPoint = (other get-point-on-shape on (0.8, -1, 0)).
hip1 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #Left
localPoint = (hip2 get-point-on-shape on (0, 1, 0)).
other = torso2.
otherPoint = (other get-point-on-shape on (-0.8, -1, 0)).
hip2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (leg11 get-point-on-shape on (0, 1, 0)).
other = hip1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
leg11 attach-joint-from here localPoint to-an other at otherPoint over gapLength. #LeftTop
localPoint = (leg12 get-point-on-shape on (0, 1, 0)).
other = hip2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
leg12 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (knee1 get-point-on-shape on (0, 1, 0)).
other = leg11.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
knee1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (knee2 get-point-on-shape on (0, 1, 0)).
other = leg12.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
knee2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (leg21 get-point-on-shape on (0, 1, 0)).
other = knee1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
leg21 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (leg22 get-point-on-shape on (0, 1, 0)).
other = knee2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
leg22 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (ankle1 get-point-on-shape on (0, 1, 0)).
other = leg21.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
ankle1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (ankle2 get-point-on-shape on (0, 1, 0)).
other = leg22.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
ankle2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (foot1 get-point-on-shape on (0, 1, 0)).
other = ankle1.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
foot1 attach-joint-from here localPoint to-an other at otherPoint over gapLength.
localPoint = (foot1 get-point-on-shape on (0, 1, 0)).
other = ankle2.
otherPoint = (other get-point-on-shape on (0, -1, 0)).
foot2 attach-joint-from here localPoint to-an other at otherPoint over gapLength.

push head onto segs.
push neck1 onto segs.
push neck2 onto segs.
push torso1 onto segs. #Top
push torso2 onto segs.
push shoulder1 onto segs. #Left
push shoulder2 onto segs.
push arm11 onto segs. #LeftTop
push arm21 onto segs. #RightTop
push elbow1 onto segs. #Left
push elbow2 onto segs.
push arm12 onto segs. #LeftBottom
push arm22 onto segs.
push wrist1 onto segs. #Left
push wrist2 onto segs.
push palm1 onto segs.
push palm2 onto segs.
#fingers later
push hip1 onto segs. #Left
push hip2 onto segs.
push leg11 onto segs. #LeftTop
push leg12 onto segs.
push knee1 onto segs.
push knee2 onto segs.
push leg21 onto segs.
push leg22 onto segs.
push ankle1 onto segs.
push ankle2 onto segs.
push foot1 onto segs.
push foot2 onto segs.

gapLength = (SEGLENGTH * 0.75).
dirSet = { (1, 1, 0), (-1, 1, 0), (0, 1, 1), (0, 1, -1) }.
foreach temp2 in segs:{
tmpL = (temp2 get-conjoints).
foreach temp3 in tmpL:{
other = temp3.
if ((other != segs{3} && temp2 != segs{4}) || (other != segs{4} && temp2 != segs{3})):{
foreach temp4 in dirSet:{
localPoint = ( temp2 get-point-on-shape on temp4).
otherPoint = ( other get-point-on-shape on (temp4 * -1.0)).
gapLength = (|localPoint| + |otherPoint|).
gapLength *= 10.0.
#temp5 = temp2 attach-spring-from here localPoint to-an other at otherPoint over gapLength.
push temp5 onto springs.
localPoint = ( temp2 get-point-on-shape on temp4).
otherPoint = ( other get-point-on-shape on (temp4::x, (-1.0 * temp4::y), temp4::z)).
gapLength = (|localPoint| + |otherPoint|).
gapLength *= 0.1.
#temp5 = temp2 attach-spring-from here localPoint to-an other at otherPoint over gapLength.
push temp5 onto springs.
}
} else: {
foreach temp4 in dirSet:{
localPoint = ( temp2 get-point-on-shape on temp4).
otherPoint = ( other get-point-on-shape on (temp4 * -1.0)).
gapLength = (|localPoint| + |otherPoint|).
gapLength *= 1.0.
#temp5 = temp2 attach-spring-from here localPoint to-an other at otherPoint over gapLength.
#temp5 set
push temp5 onto springs.
localPoint = ( temp2 get-point-on-shape on temp4).
otherPoint = ( other get-point-on-shape on (temp4::x, (-1.0 * temp4::y), temp4::z)).
gapLength = (|localPoint| + |otherPoint|).
gapLength *= 1.0.
#temp5 = temp2 attach-spring-from here localPoint to-an other at otherPoint over gapLength.
push temp5 onto springs.
}
}
}
}
self set-joints.
self add-eyes.
+ to add-eyes:
cent(vector).
eye1(object).
eye2(object).
eye1 = new EyeSegment.
eye2 = new EyeSegment.
cent = (head get-location).
eye1 move to cent.
eye2 move to cent.
push (eye1 attach-joint-from here (eye1 get-point-on-shape on (0, 0, 1)) to-an head at (head get-point-on-shape on (-0.6, 0.6, 0.6)) over 0) onto joints.
push (eye2 attach-joint-from here (eye2 get-point-on-shape on (0, 0, 1)) to-an head at (head get-point-on-shape on (0.6, 0.6, 0.6)) over 0) onto joints.
push eye1 onto sensors.
push eye2 onto sensors.
push eye1 onto segs.
push eye2 onto segs.
#+ to twitch-muscle between boneA(object) and boneB(object):
# transl
+ to set-brain to brainA(object):
brain = brainA.
+ to get-segs:
return segs.
+ to get-joints:
return joints.
+ to set-joints:
temp(object).
temp2(list).
temp3(object).
foreach temp in segs:{
temp2 = temp get-joints.
foreach temp3 in temp2:{
#temp3 set-joint-limits a1-min -2.0 a1-max 2.0 a2-min -2.0 a2-max 2.0 a3-min -2.0 a3-max 2.0.
push temp3 onto joints.
}
}
+ to get-conjoints:
conjoints(list).
temp(object).
foreach temp in segs:{
temp = (temp get-conjoints).
push temp onto conjoints.
}
return conjoints.
+ to control-at time t(double):
tmpj(object).
tmps(object).
si(int).
ji(int).
val(double).
val2(double).
val3(double).

si = 0.
val = 100.0.
brain perturb-neuron-state at si to val.
foreach tmps in joints:{
val = ((tmps get-joint-angles)::x).
brain perturb-neuron-state at si to val.
si++.
val = ((tmps get-joint-angles)::y).
brain perturb-neuron-state at si to val.
si++.
val = ((tmps get-joint-angles)::z).
print "val in $val".
brain perturb-neuron-state at si to val.
si++.
}
brain update-state.
ji = ((brain get-neuron-count) / 2).
foreach tmpj in joints:{
val = (brain get-neuron-state at ji).
ji++.
val2 = (brain get-neuron-state at ji).
ji++.
val3 = (brain get-neuron-state at ji).
ji++.
print "val out $val $tmpj".
tmpj set-joint-velocity to (val,val2,val3).
tmpj iterate.
#tmpj set-joint-velocity to (( (val, val2, val3)) + (tmpj get-joint-angles)).
}
brain decay-by ratio DECAY.
}

Link : BodySegment {
+ variables:
springs(list). #list of type Spring
joints(list). #list of type Joint
conjoints(list). #list of type BodySegment
id(string). #human readable unique id for labeling system
idState(int). #flag to make labels visible
theShape(object).
theSize(vector).
theSideCount(int).
theColor(vector).
theRadius(float).
theHeight(float).
+ to init:
self set-e to 0.0.
+ to iterate:
self get-max-force.
#super iterate.
#+ to control-at-time t(double):

+ to init-disk radius aRadius(float) sides sideCount(int) height aHeight(float):
theShape = new Shape.
theSideCount = sideCount.
theRadius = aRadius.
theHeight = aHeight.
theSize = (aRadius, sideCount, theHeight).
theShape init-with-polygon-disk radius theRadius sides sideCount height theHeight.
super set-shape to theShape.
+ to init-cone radius aRadius (float) sides sideCount (int) height aHeight (float):
theShape = new Shape.
theSideCount = sideCount.
theRadius = aRadius.
theHeight = aHeight.
theSize = (aRadius, sideCount, theHeight).
theShape init-with-polygon-cone radius theRadius sides sideCount height theHeight.
super set-shape to theShape.
+ to init-cube of dims(vector):
theShape = new Shape.
theSize = dims.
theHeight = (theSize::y).
theRadius = ((theSize::x) / 2.0).
theShape init-with-cube size dims.
super set-shape to theShape.
+ to init-sphere radius r(float):
theShape = new Shape.
theSize = (0, 0, r ).
theRadius = r.
theHeight = (2.0 * r).
theShape init-with-sphere radius r.
super set-shape to theShape.
+ to set-id name named(string):
id = named.
+ to get-radius: #half horizontal span
return theRadius.
+ to get-height: #full vertical span; these are used because of bilateral symetry.
return theHeight.
+ to get-sides:
return theSideCount.
+ to get-id:
return id.
+ to get-conjoints:
return conjoints.
+ to get-joints:
return joints.
+ to get-point-on-shape on dir(vector):
return (theShape get-point-on-shape on-vector dir).
+ to set-label:
mx(double).
tmp(string).
#mx = (self get-max-force).
#tmp = (id + " : " + mx).
tmp = id.
self set-label to tmp.
+ to attach-spring-from here localPoint(vector) to-an other(object) at otherPoint(vector) over gapLength(float):
spr(object).
tmpid(string).
spr = new Spring.
if !otherPoint: print "the otherPoint does not exist".
tmpid = other get-id.
print "attaching spring from $id at $localPoint to $tmpid at $otherPoint".
spr connect from self to other from-point localPoint
to-point otherPoint with-length gapLength with-strength STRENGTH.
push spr onto springs.
return spr.
+ to attach-joint-from here localPoint(vector) to-an other(object) at otherPoint(vector) over gapLength(float):
jnt(object).
tmpid(string).
jnt = new BallJoint.
if !otherPoint: print "the otherPoint does not exist".
tmpid = other get-id.
print "attaching joint from $id at $localPoint to $tmpid at $otherPoint".
jnt link parent self to-child other with-parent-point localPoint with-child-point otherPoint
with-normal (1, 0, 0) use-current-relative-rotation 0.
push jnt onto joints.
push other onto conjoints.
return jnt.
+ to get-max-force:
max(double).
hold(object).
temp(double).
vect(vector).
max = 0.0.
theShape set-mass to 0.1.
foreach hold in springs:{
temp = hold get-force.
hold set-maximum-force to MAXSFORCE.
#hold set-contract-only.
#hold set-expand-only.
if (temp > max): max = temp.
}
if (id == "Head"):{
theShape set-mass to 0.0.
}
#print "Id $id force $max".
return max.
}
BodySegment : EyeSegment {
+ variables:
eyeDir(vector). #direction of joint
+ to init:
super init.
self init-cone radius 0.2 sides 10 height 0.3.
+ to set-array of size(int):
+ to sense:
#self raytrace from-location theLocation (vector) with-direction theDirection (vector)
#Computes the vector from theLocation towards theDirection that hits the shape of this object.
#If the object was not hit vector (0, 0, 0) will be returned.
#The location and direction vector must be given relative to the world's coordinate frame.
}

and you will need...

#Hosing meta-layers
@include "Data.tz"

@use Abstract.
@use Matrix.
@use Vector.
@use Genome.

@use Mobile.

@define UTIL 1.
@define UTIL2 1.

Abstract : NeuralNetwork4 [version 2.3] {
% An experimental neural network class for different types of neural
% networks whose goal is to provide efficient computation and the
% ability to manipulate the parameters and connections using evolution

+ variables:
network (pointer).
nodes (object).
inputNodes (object).
outputNodes (object).
weights (object).
connections (object).
neuronCount (int).
inputNeuronCount (int).
outputNeuronCount (int).
iterationStep (float).
timeConstant (float).
stateBoundLower (float).
stateBoundUpper (float).

homeland (string).
fitness(double).
parentAfitness(double).
parentBfitness(double).

meta-neuronCount(int).
meta-connectionCount(int).#count of under-net connections
meta-network(pointer).
meta-nodes(object).
meta-connections(object).
meta-weights(object).
hosing(int).

+ to destroy:
if network: free network.
if nodes: free nodes.
if inputNodes: free inputNodes.
if outputNodes: free outputNodes.
if weights: free weights.
if connections: free connections.
if meta-connections: free meta-connections.
if meta-weights: free meta-weights.
if meta-nodes: free meta-nodes.
if meta-network: free meta-network.
super destroy.
+ to init:
iterationStep = 1.0.
timeConstant = 1.0.
parentAfitness = 0.
parentBfitness = 0.
fitness = 0.
#self disable-auto-free.

+ to init-with neuron-count theNetworkSize (int):
network = neuralNetworkNew(theNetworkSize).
neuronCount = theNetworkSize.
#print "neuronCount $neuronCount".
nodes = new Vector.
nodes set-vector-pointer to neuralNetworkGetNeuronStateVector(network) with-size neuronCount.
weights = new Matrix2D.
weights set-matrix-pointer to neuralNetworkGetConnectionWeightMatrix(network) x-size neuronCount y-size neuronCount.
connections = new Matrix2D.
connections set-matrix-pointer to neuralNetworkGetConnectionStructureMatrix(network) x-size neuronCount y-size neuronCount.
return self.
+ to init-meta-with neuron-count theNetworkSize (int) hose h(int):
n(int).
i(int).
j(int).
val(double).
hosing = h.
meta-connectionCount = ((neuronCount - 1) * (neuronCount - 1)).
if hosing == 0:{
meta-neuronCount = (neuronCount + meta-connectionCount).#((neuronCount + meta-connectionCount) / 2)
} else {
meta-neuronCount = (neuronCount * 4) + 1.
}
meta-network = neuralNetworkNew(meta-neuronCount).
meta-nodes = new Vector.
meta-nodes set-vector-pointer to neuralNetworkGetNeuronStateVector(meta-network) with-size meta-neuronCount.
meta-weights = new Matrix2D.
meta-weights set-matrix-pointer to neuralNetworkGetConnectionWeightMatrix(meta-network) x-size meta-neuronCount y-size meta-neuronCount.
meta-connections = new Matrix2D.
meta-connections set-matrix-pointer to neuralNetworkGetConnectionStructureMatrix(meta-network) x-size meta-neuronCount y-size meta-neuronCount.

for i = 0, i < meta-neuronCount, i++:{
for j = 0, j < meta-neuronCount, j++:{
#if i != j:{
val = random[2.0] - 1.0.
meta-connections set-value to 1.0 at-x i at-y j.
meta-weights set-value to val at-x i at-y j.
#}
#else: meta-connections set-value to 0.0 at-x i at-y j.
}
}
return self.

+ to start-with-genome genome gene(object):
n(int).
m(int).
o (int).
val (double).
neuronCount = gene get-size.
if network: free network.
network = neuralNetworkNew(neuronCount).
if nodes: free nodes.
nodes = new Vector.
nodes set-vector-pointer to neuralNetworkGetNeuronStateVector(network) with-size neuronCount.
if weights: free weights.
weights = new Matrix2D.
weights set-matrix-pointer to neuralNetworkGetConnectionWeightMatrix(network) x-size neuronCount y-size neuronCount.
if connections: free connections.
connections = new Matrix2D.
connections set-matrix-pointer to neuralNetworkGetConnectionStructureMatrix(network) x-size neuronCount y-size neuronCount.
print "Start with genome $gene with neuronCount $neuronCount".
for m = 0, m < neuronCount, m++:{
for o = 0, o < neuronCount, o++:{
val = gene get-val at-x o at-y m.
weights set-value to val at-x o at-y m.
}
}
meta-neuronCount = gene get-meta-size.
print " meta-neuronCount $meta-neuronCount ".
if (meta-neuronCount):{
if meta-network: free meta-network.
meta-network = neuralNetworkNew(meta-neuronCount).
if meta-nodes: free meta-nodes.
meta-nodes = new Vector.
meta-nodes set-vector-pointer to neuralNetworkGetNeuronStateVector(meta-network) with-size meta-neuronCount.
if meta-weights: free meta-weights.
meta-weights = new Matrix2D.
meta-weights set-matrix-pointer to neuralNetworkGetConnectionWeightMatrix(meta-network) x-size meta-neuronCount y-size meta-neuronCount.
meta-connections = new Matrix2D.
meta-connections set-matrix-pointer to neuralNetworkGetConnectionStructureMatrix(meta-network) x-size meta-neuronCount y-size meta-neuronCount.
for m = 0, m < meta-neuronCount, m++:{
for o = 0, o < meta-neuronCount, o++:{
val = gene get-meta-val at-x o at-y m.
if val == 0.0: val = random[2.0]- 1.0.# if o!=m && val == 0.0:
meta-weights set-value to val at-x o at-y m.
}
}
}
self set-homeland of (gene get-homeland).
self set-parentA to (gene get-parentA).
self set-parentB to (gene get-parentB).
self set-fitness to (gene get-fitness).
#if gene: free gene.

- to get-network-pointer:
return network.

+ to get-neuron-state-vector:
return nodes.
#+ to save-with-dialog:
# self archive-as-xml file fileName (string).
#show-dialog with-title title (string) with-message message (string) with-yes-button yesString (string) with-no-button noString (string)
+ section "Network Parameter Accessors":
+ to get-genome:
rtn (object).
n (int).

rtn = new NeuralGenome2.
rtn set-weights of-matrix weights of-size neuronCount.
print "get-genome has weights $weights and neuronCount $neuronCount $rtn".
if (meta-neuronCount):{
rtn set-meta-weights of-matrix meta-weights of-size meta-neuronCount.
}
rtn set-homeland of homeland.
rtn set-parentA to parentAfitness.
rtn set-parentB to parentBfitness.
rtn set-fitness to fitness.
return rtn.
+ to set-hosing to h (int):
hosing = h.
+ to get-neuron-count:
return neuronCount.
+ to get-meta-neuron-count:
return meta-neuronCount.

+ to get-iteration-step:
return iterationStep.

+ to set-iteration-step to newTimeStep (float):
iterationStep = newTimeStep.
neuralNetworkSetTimeStep(network, newTimeStep).
neuralNetworkSetTimeStep(meta-network, newTimeStep).

+ to get-time-constant:
return timeConstant.

+ to set-time-constant to newTimeConstant (float):
timeConstant = newTimeConstant.
neuralNetworkSetTimeConstant(network, newTimeConstant).
neuralNetworkSetTimeConstant(meta-network, newTimeConstant).
+ to get-lower-saturation-boundry:
return stateBoundLower.

+ to get-upper-saturation-boundry:
return stateBoundUpper.

+ to set-saturation-bounds between lower (float)
and upper (float):
stateBoundLower = lower.
stateBoundUpper = upper.
neuralNetworkSetNeuronStateBounds(network, lower, upper).
neuralNetworkSetNeuronStateBounds(meta-network, lower, upper).

+ section "Network State Variable and Vector Accessors":

+ to set-neuron-state at index (int) to value (float):
neuralNetworkSetNeuronState(network, index, value).

+ to perturb-neuron-state at index (int) to value (float):
oldVal(float).
newVal(float).
oldVal = neuralNetworkGetNeuronState(network, index).
newVal = oldVal + value.
if (newVal > 1):{
newVal = 1.
}
if (newVal < -1):{
newVal = -1.
}
# print "pertubing state $oldVal to $newVal at $index".
neuralNetworkSetNeuronState(network, index, newVal).

+ to get-neuron-state at index (int):
return neuralNetworkGetNeuronState(network, index).

+ to set-input-state-vector from first (int) to last (int):
% returns a vector which contains the input nodes
inputNodes = new Vector.
inputNodes set-vector-pointer to neuralNetworkSetInputNeurons(network, first, (last - first)) with-size (last - first).
inputNeuronCount = (last - first).
return inputNodes.

+ to get-input-state-vector:
% returns a vector which contains the input nodes
return inputNodes.

+ to set-output-state-vector from first (int) to last (int):
% returns a vector which contains the output nodes
outputNodes = new Vector.
outputNodes set-vector-pointer to neuralNetworkSetInputNeurons(network, first, (last - first)) with-size (last - first).
outputNeuronCount = (last - first).
return outputNodes.

+ to get-output-state-vector:
% returns a vector which contains the output nodes
return outputNodes.

+ to get-connection-structure-matrix:
% returns a matrix of synaptic connections [0,1]
return connections.

+ to apply-structure-to-weights:
neuralNetworkApplyStructure(network).

+ to get-connection-weight-matrix:
% returns a matrix of the synaptic strengths
return weights.

+ to get-meta-connection-weight-matrix:
return meta-weights.

+ to set-connection-weight-matrix to val (double) at-x i (int) at-y m (int):
#if i != m:{
connections set-value to 1.0 at-x i at-y m.
weights set-value to val at-x i at-y m.
#}

+ to set-meta-connection-weight-matrix to val (double) at-x i (int) at-y m (int):
#if i != m:{
meta-connections set-value to 1.0 at-x i at-y m.
meta-weights set-value to val at-x i at-y m.
#}

+ to get-weight at-x x (int) at-y y (int):
return (weights get-value at-x x at-y y).

+ to get-meta-weight at-x x (int) at-y y (int):
return (meta-weights get-value at-x x at-y y).

+ to perturb-weight to val(double) at-x x(int) at-y y (int):
tempval(double).
tempval = (weights get-value at-x x at-y y).
tempval = tempval + val.
weights set-value to tempval at-x x at-y y.

+ to get-edge at-x x (int) at-y y (int):
return (connections get-value at-x x at-y y).

+ to randomize-states between lowerBound = -1.0 (float)
and upperBound = 1.0 (float):
i (int).

for i = 0, i < neuronCount, i++:
nodes set-value to (lowerBound + random[(upperBound - lowerBound)]) at-x i.

+ to randomize-weights between lowerBound = -1.0 (float)
and upperBound = 1.0 (float)
with-autapses autapsesBool = 1 (int):
i, j (int).

for i = 0, i < neuronCount, i++:
for j = 0, j < neuronCount, j++:
if autapsesBool:
{
weights set-value to (lowerBound + random[(upperBound - lowerBound)]) at-x i at-y j.
}
else:
{
#if i == j: weights set-value to 0.0 at-x i at-y j.
#else:
weights set-value to (lowerBound + random[(upperBound - lowerBound)]) at-x i at-y j.
}
+ to randomize-meta-weights between lowerBound = -1.0 (float)
and upperBound = 1.0 (float)
with-autapses autapsesBool = 1 (int):
i, j (int).

for i = 0, i < meta-neuronCount, i++:
for j = 0, j < meta-neuronCount, j++:
if autapsesBool:
{
meta-weights set-value to (lowerBound + random[(upperBound - lowerBound)]) at-x i at-y j.
}
else:
{
#if i == j: meta-weights set-value to 0.0 at-x i at-y j.
#else:
meta-weights set-value to (lowerBound + random[(upperBound - lowerBound)]) at-x i at-y j.
}
+ to init-random-structure with-connectivity-percent thePercent = 0.5 (float) with-autapses autapsesBool = 0 (int):
i, j (int).
edge (int).

for i = 0, i < neuronCount, i++:
for j = 0, j < neuronCount, j++:
if autapsesBool:
{
if random[1.0] < thePercent:
edge = 1.0.
else:
edge = 0.0.
connections set-value to edge at-x i at-y j.
}
else:
{
#if i != j:
#{
if random[1.0] < thePercent:
edge = 1.0.
else:
edge = 0.0.
connections set-value to edge at-x i at-y j.
#}
#else: connections set-value to 0.0 at-x i at-y j.
}
+ to init-random-meta-structure with-connectivity-percent thePercent = 0.5 (float) with-autapses autapsesBool = 0 (int):
i, j (int).
edge (int).

for i = 0, i < meta-neuronCount, i++:
for j = 0, j < meta-neuronCount, j++:
if autapsesBool:
{
if random[1.0] < thePercent:
edge = 1.0.
else:
edge = 0.0.
meta-connections set-value to edge at-x i at-y j.
}
else:
{
if i != j:
{
if random[1.0] < thePercent:
edge = 1.0.
else:
edge = 0.0.
meta-connections set-value to edge at-x i at-y j.
}
else: meta-connections set-value to 0.0 at-x i at-y j.
}
+ to init-fully-connected-structure with-autapses autapsesBool = 1 (int):
i, j (int).

for i = 0, i < neuronCount, i++:
for j = 0, j < neuronCount, j++:
if autapsesBool:
{
connections set-value to 1.0 at-x i at-y j.
}
else:
{
if i != j: connections set-value to 1.0 at-x i at-y j.
else: connections set-value to 0.0 at-x i at-y j.
}

+ to update-state:
% updates the network's state based on current state and
% inputs
neuralNetworkUpdateState(network).
+ to update-meta-state:
n (int).
m (int).
o (int).
val (double).
oldval (double).
top (double).
select (int).
cnt (int).
for n = 0, n < neuronCount, n++:{
val = neuralNetworkGetNeuronState(network, n).
oldval = neuralNetworkGetNeuronState(meta-network, n).
val = val + oldval.
neuralNetworkSetNeuronState(meta-network, n, val).
#print " hosing NeuralNetork underlying num $n activated $val".
}
neuralNetworkUpdateState(meta-network).
if (hosing == 0):{
for n = 0, n < neuronCount, n++:{
for m = 0, m < neuronCount, m++:{
#if n != m:{
o = (meta-neuronCount - ((n * neuronCount) + m)).
val = neuralNetworkGetNeuronState(meta-network, o).

if val > 1.0 : val = 1.0.
if val < -1.0 : val = -1.0.
oldval = (weights get-value at-x n at-y m).
val = val + oldval.
if val > 1.0 : val = 1.0.
if val < -1.0 : val = -1.0.
weights set-value to val at-x n at-y m.
#}
}
}
} else {
#m = (meta-neuronCount - neuronCount - 1).
#val = neuralNetworkGetNeuronState(meta-network, m).
#m = (|val| * neuronCount) % neuronCount.
top = 0.0.
cnt = 0.
select = 0.
for n = (meta-neuronCount - ( 2 * neuronCount )), n < (meta-neuronCount - neuronCount), n++ :{
val = neuralNetworkGetNeuronState(meta-network, n).
if (val > top):{
top = val.
select = cnt.
}
cnt += 1.
}
for n = 0, n < neuronCount, n++:{
o = (meta-neuronCount - (neuronCount) + n).
val = neuralNetworkGetNeuronState(meta-network, o).
if val > 2.0 : val = 2.0.
if val < -2.0 : val = -2.0.
#print "network at $n and $select is activated to $val".
oldval = (weights get-value at-x n at-y select).
val = val * oldval.
if val > 2.0 : val = 2.0.
if val < -2.0 : val = -2.0.
weights set-value to val at-x n at-y select.
#print " hose is adressing $n and $select with value $val".
}
}

+ to mutate:
% Implement this method to mutate the genes of this object. This method
% must be implemented by your subclass.
n (int).
m (int).
i (int).
val(double).

for i=0, i < 50, i++:{
n = random[neuronCount - 1].
m = random[neuronCount - 1].
val = random[2.0]- 1.0.
#if m != n:{
weights set-value to val at-x n at-y m.
#}
}
#die "The method \"mutate\" must be implemented in your GeneticAlgorithmIndividual subclass!".
+ to inject-zeros with-under z(int) with-meta wm(int):
% This is a utility method for use with specific manipulutations
% If it is called prior to get-copy etc. it will change the genome.
% This injection system is intended to provide added salience to improvement algorithms by reducing
% connection noise.
n, m, i (int).
val (double).
zl, wml (int).
wml = ((meta-neuronCount * meta-neuronCount) * (wm / 100)).
zl = ((neuronCount * neuronCount)* (z / 100)).
for i=0, i < zl, i++:{
n = random[neuronCount - 1].
m = random[neuronCount - 1].
val = 0.00001.
weights set-value to val at-x n at-y m.
}
for i=0, i < wml, i++:{
n = random[meta-neuronCount - 1].
m = random[meta-neuronCount - 1].
val = -0.00001.
meta-weights set-value to val at-x n at-y m.
}
+ to mutate-connections connects z(int):
% Implement this method to mutate the genes of this object. This method
% must be implemented by your subclass.
n (int).
m (int).
i (int).
t (int).
val(double).
t = ((neuronCount * neuronCount)* (z / 100)).
for i=0, i < t, i++:{
n = random[neuronCount - 1].
m = random[neuronCount - 1].
val = random[2.0]- 1.0.
#if m != n:{
weights set-value to val at-x n at-y m.
#}
}
+ to mutate-meta-connections connects z(int):
% Implement this method to mutate the genes of this object. This method
% must be implemented by your subclass.
n (int).
m (int).
i (int).
t (int).
val(double).
t = ((meta-neuronCount * meta-neuronCount) * (z / 100)).
for i=0, i < t, i++:{
n = random[meta-neuronCount - 1].
m = random[meta-neuronCount - 1].
val = random[2.0]- 1.0.
#if m != n:{
meta-weights set-value to val at-x n at-y m.
#}
}
+ to randomize-net:
% Implement this method to randomize the genes of this object. This method
% must be implemented by your subclass.
n (int).
#val(double).

self init-random-structure with-connectivity-percent 0.5 with-autapses 0.
self randomize-weights between -1.0
and 1.0
with-autapses 1.
#die "The method \"randomize\" must be implemented in your GeneticAlgorithmIndividual subclass!".
+ to randomize-meta:
% Implement this method to randomize the genes of this object. This method
% must be implemented by your subclass.
n (int).
#val(double).

self init-random-meta-structure with-connectivity-percent 0.5 with-autapses 0.
self randomize-meta-weights between -1.0
and 1.0
with-autapses 1.

+ to crossover-two-point from-parent-1 parent1 (object) from-parent-2 parent2 (object):
% Implement this method to make this object become a crossover of parent1
% and parent2. This method must be implemented by your subclass if
% crossover is enabled.

# Make 2 point crossover
# Ok here it is
n (int).
m (int).
o (int).
p (int).
#q (int).
r (int).
i (int).
val(double).
newhomeland (string).
n = random [neuronCount - 1].
m = random [neuronCount - 1].
o = random [neuronCount - 1 - n].
o = o + n.
p = random [neuronCount - 1].
print "crossover point 1 $n - $m : point 2 $o - $p".
for i=0, i < neuronCount, i++:{
for r=0, r < neuronCount, r++:{
#if i!=r:{
if (i > n && i < o && r > m && r < p):{
val = parent1 get-weight at-x i at-y r.
#connections set-value to 1.0 at-x i at-y r.
weights set-value to val at-x i at-y r.
#print "parent 1 $i $r".
}
else:{
val = parent2 get-weight at-x i at-y r.
#connections set-value to 1.0 at-x i at-y r.
weights set-value to val at-x i at-y r.
#print "parent 2 2 2".
}
#}
}
}
#homeland =
#newhomeland = (parent1 get-homeland).
#newhomeland = "($newhomeland X $homeland)".
#homeland = newhomeland.
#die "The method \"crossover\" must be implemented in your GeneticAlgorithmIndividual subclass!".
+ to crossover-omni-point from-parent-1 parent1 (object) from-parent-2 parent2 (object):
% Implement this method to make this object become a crossover of parent1
% and parent2. This method must be implemented by your subclass if
% crossover is enabled.
n (int).
m (int).
o (int).
p (int).
#q (int).
r (int).
i (int).
val(double).
newhomeland (string).
for i=0, i < neuronCount, i++:{
for r=0, r < neuronCount, r++:{
#if i!=r:{
if random[2.0]>1:{
val = parent1 get-weight at-x i at-y r.
#connections set-value to 1.0 at-x i at-y r.
weights set-value to val at-x i at-y r.
#print "parent 1 $i $r".
}
else:{
val = parent2 get-weight at-x i at-y r.
#connections set-value to 1.0 at-x i at-y r.
weights set-value to val at-x i at-y r.
#print "parent 2 2 2".
}
#}
}
}

#homeland =
#newhomeland = (parent1 get-homeland).
#newhomeland = "($newhomeland X $homeland)".
#homeland = newhomeland.
#die "The method \"crossover\" must be implemented in your GeneticAlgorithmIndividual subclass!".
+ to crossover-meta-two-point from-parent-1 parent1 (object) from-parent-2 parent2 (object):
% Implement this method to make this object become a crossover of parent1
% and parent2. This method must be implemented by your subclass if
% crossover is enabled.

# Make 2 point crossover
# Ok here it is
n (int).
m (int).
o (int).
p (int).
#q (int).
r (int).
i (int).
val(double).
newhomeland (string).
n = random [meta-neuronCount - 1].
m = random [meta-neuronCount - 1].
o = random [meta-neuronCount - 1 - n].
o = o + n.
p = random [neuronCount - 1].
print "crossover point 1 $n - $m : point 2 $o - $p".
for i=0, i < meta-neuronCount, i++:{
for r=0, r < meta-neuronCount, r++:{
#if i!=r:{
if (i > n && i < o && r > m && r < p):{
val = parent1 get-meta-weight at-x i at-y r.
#meta-connections set-value to 1.0 at-x i at-y r.
meta-weights set-value to val at-x i at-y r.
#print "parent 1 $i $r".
}
else{
val = parent2 get-meta-weight at-x i at-y r.
#meta-connections set-value to 1.0 at-x i at-y r.
meta-weights set-value to val at-x i at-y r.
#print "parent 2 2 2".
}
#}
}
}
+ to crossover-meta-omni-point from-parent-1 parent1 (object) from-parent-2 parent2 (object):
% Implement this method to make this object become a crossover of parent1
% and parent2. This method must be implemented by your subclass if
% crossover is enabled.

r (int).
i (int).
val(double).
for i=0, i < meta-neuronCount, i++:{
for r=0, r < meta-neuronCount, r++:{
#if i!=r:{
if random[2.0]>1:{
val = parent1 get-meta-weight at-x i at-y r.
#meta-connections set-value to 1.0 at-x i at-y r.
meta-weights set-value to val at-x i at-y r.
#print "parent 1 $i $r".
}
else{
val = parent2 get-meta-weight at-x i at-y r.
#meta-connections set-value to 1.0 at-x i at-y r.
meta-weights set-value to val at-x i at-y r.
#print "parent 2 2 2".
}
#}
}
}

+ to get-copy:
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxthis needs updated
#n (int).
m (int).
i (int).
val(double).
rtn (object).

rtn = new NeuralNetwork4.
rtn init-with neuron-count neuronCount.
for i=0, i 0):{
for i = 0, i < meta-size, i++:{
for j = 0, j < meta-size, j++:{
val1 = g get-meta-val at-x j at-y i. #row by row XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
val2 = self get-meta-val at-x j at-y i.
dif += |(val1 - val2)|.
}
}
}
return dif.

+ to get-val at-x x (int) at-y y (int):
val (double).
i (int).
i = (y * size) + (x).
val = weights{i}.
return val.
+ to get-meta-val at-x x (int) at-y y (int):
val (double).
i (int).
i = (y * meta-size) + (x).
val = meta-weights{i}.
return val.

+ to get-size:
return size.

+ to get-meta-size:
return meta-size.

+ to set-homeland of h(string):
#print "setting homeland in genome of $h".
homeland = h.
+ to get-homeland:
#print "getting homeland in genome of $homeland".
return homeland.
+ to get-fitness:
return fitness.
+ to get-parentA:
return parentA.
+ to get-parentB:
return parentB.
+ to set-fitness to fit(double):
fitness = fit.
+ to set-parentA to rent(double):
parentA = rent.
+ to set-parentB to rent(double):
parentB = rent.
+ to save-as-text named fileName(string):
f(object).
record(double).
f = new File.
f open-for-writing with-file fileName.
f write text "$homeland\n".
if UTIL2:{
f write text "$parentA\n".
f write text "$parentB\n".
f write text "$fitness\n".
}
f write text "$size\n".
f write text "$meta-size\n".
foreach record in weights:{
f write text "$record\n".
}
#f write text "\n".
foreach record in meta-weights:{
f write text "$record\n".
}
#f write text "\n"
f close.
+ to load-from-text named fileName(string):
f(object).
record(string).
caster(double).
trip(int).
step(int).
stat(int).
trip = 0.
step = 0.
stat = 0.
#record{0} = 0.
f = new File.
f open-for-reading with-file fileName.
while (trip != 5):{ #
record = (f read-line).
if (trip == 4):{
if (step < (meta-size * meta-size)):{
caster = record.
#push caster onto meta-weights.
meta-weights{step}=caster.
step+=1.
#print"$record meta $step $caster".
} else {
#print "$meta-weights".
trip += 1.
}
}
if (trip == 3):{
#print "size in load $size".
if (step < (size * size)):{
caster = record.
#push caster onto weights.
weights{step} = caster.
step += 1.
#print"$record weights $step $caster".

} else {
trip += 1.
step = 0.
#print"$weights".
}
}
if (trip == 2):{
meta-size = record.
trip += 1.
}
if (trip == 1):{
size = record.
while (size != "75"):{
record = (f read-line).
print "reading in load trip is 1 and looking for size".
size = record.
}
#size -= 1.
trip += 1.
print"size $size".
}
if (trip == 0):{
if UTIL:{
if stat == 3:{
fitness = record.
trip += 1.
}
if stat == 2:{
parentB = record.
stat += 1.
}
if stat == 1:{
parentA = record.
stat += 1.
}
}
if stat == 0:{
homeland = record.
#print "just read homeland from file $homeland".
if |homeland|>6: homeland{6} = "".
stat += 1.
if !(UTIL):{
#trip += 1.
}
}
#print"homeland in stat $stat load $homeland".
}

}

#print"Made it through load".
f close.
}
NeuralNetwork4 : RecurrentNetwork2 [version 2.3] {

+ to update-state:
% updates the network's state based on current state and
% inputs
neuralRecurrentUpdateState(network).

}

NeuralNetwork4 : FeedForwardNetwork2 [version 2.3] {

}

Mobile : NeuronImage2 [version 2.3] {

+ variables:
texture (object).
neurons (object).
myShape (object).

+ to init-with nodes theVector (object)
color theColor = "Green" (string)
shape-scale shapeScale = 1 (int)
value-scale valueScale = 1.0 (float):

neurons = theVector.
texture = ((new VectorImage) init-with the-vector neurons scale valueScale).
myShape = ((new Cube) init-with size ((shapeScale * ((neurons get-dimension) / 10.0)), (shapeScale * (neurons get-dimension)), 1)).
self set-shape to myShape.
self set-texture-image to texture.
self set-texture-scale to (((neurons get-dimension) * shapeScale)).

if theColor == "Red":
texture set-red to neurons.
else: if theColor == "Green":
texture set-green to neurons.
else: if theColor == "Blue":
texture set-blue to neurons.
else: print "Please use 'Green,' 'Red' or 'Blue' for NodeImage.".

self add-menu named "Print Activity" for-method "print-neuron-activity".

return self.

+ to destroy:
free(texture).
free(myShape).
free(neurons).
super destroy.

+ to update-display:
texture iterate.

+ to print-neuron-activity:
neurons print-matlab-style.
}

Mobile : WeightImage2 [version 2.3] {

+ variables:
texture (object).
weights (object).
weightColor (string).
weightToggle (int).
connections (object).
connectionColor (string).
connectionToggle (int).

+ to init:
weightToggle = 0.
connectionToggle = 0.

+ to destroy:
free(texture).
free(weights).
free(connections).
super destroy.

+ to init-with weights theWeights (object)
connections theConnections (object)
weight-color theWeightColor = "Blue" (string)
connection-color theConnectionColor = "Red" (string)
shape-scale shapeScale = 1.0 (float)
value-scale valueScale = 1.0 (float):

weights = theWeights.
weightColor = theWeightColor.
connections = theConnections.
connectionColor = theConnectionColor.

texture = ((new MatrixImage) init-with the-matrix weights scale valueScale).

self set-shape to ((new Cube) init-with size ((shapeScale * (weights get-x-dimension)), (shapeScale * (weights get-y-dimension)), 1)).
self set-texture-image to texture.
self set-texture-scale to (((weights get-x-dimension) * shapeScale)).

self toggle-weights.

self add-menu named "Print Weights" for-method "print-weights".
self add-menu named "Toggle Weight Display" for-method "toggle-weights".
self add-menu named "Print Connections" for-method "print-connections".
self add-menu named "Toggle Connection Display" for-method "toggle-connections".

return self.

+ to update-display:
texture iterate.

- to switch-display on-color theColor (string) to theObject (object):

if theColor == "Red":
texture set-red to theObject.
else: if theColor == "Green":
texture set-green to theObject.
else: if theColor == "Blue":
texture set-blue to theObject.
else: print "Please use 'Green,' 'Red' or 'Blue' for WeightImage.".

+ to toggle-weights:
if weightToggle:
{
self switch-display on-color weightColor to 0.
weightToggle = 0.
}
else:
{
self switch-display on-color weightColor to weights.
weightToggle = 1.
}

+ to toggle-connections:
if connectionToggle:
{
self switch-display on-color connectionColor to 0.
connectionToggle = 0.
}
else:
{
self switch-display on-color connectionColor to connections.
connectionToggle = 1.
}

+ to print-weights:
weights print-matlab-style.

+ to print-connections:
connections print-matlab-style.

}

Encode Vectors

try encoding vectors as objects or use a list. Sometimes breve will call an exception unless the type is passed to the method rather than the actual instance. Breve's compiler handles objects as method parameters allot better than scalars. What would we do if the vector was eight dimensions in the next build compared to three in the current?

I have not failed! I have only tried 100,000 ways that will not work. —Thomas Edison

Update Weights?

What effect does forcing the weights into a fixed state if x>2.0: x=2.0 have on the error convergence in the output layer? Compared to [-4,4] for instance. There is no one right way to do any one thing. I a curious what is the rationale for the conditional? Does this change the accuracy of the output, do we know if the best weight is out of range prior to input? If the error converged and required a weight of 5.4, would it not force the weight into a fixed state?

I have not failed! I have only tried 100,000 ways that will not work. —Thomas Edison

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.