{Model}=require('flatnet')
A model is an object type containing a map, output pointers and variables, and fitness score
Model.New(ptr_count=2,map=[])
ptr_count
- Sets the length of
model.o
- Sets pointer actions between output variables:
model.out[]
- Sets the length of
- Include
map
to copy pre-existing map to a new model - Returns a new model object
model={
map:[] action list
,o:[] output pointers
,out:[] output variables
,fit:0 fitness score
}
Model.Reset(model,ptr_count=2)
- Sets
model.fit
to 0 - Sets each pointer
model.o
to an incremental integermodel.o[0]=0
model.o[1]=1
- ...etc
- Sets output variables
model.output
to 0 - Returns the reset model object
Model.LoadMap(name='model')
- Loads a map from a file with extension
name
+.fnet
- Returns map array if file found
- Return empty array if no file found
Model.SaveMap(model,name='model')
- Saves a map to a file with extension
name
+.fnet
- Returns false if the map has 0 length
- Returns true if file write is attempted
Model.Mutate(model,count=3,ratio=0.45,actions=[])
- Mutates
model.map
according tocount
andratio
count
is the number of times the model is mutatedratio
is the pivot point for deleting or adding actions in mutation- A random float (max=1,min=0) is compared to
ratio
during each mutationcount
- If
float <= ratio
, an action will be added - If
float > ratio
, an action will be deleted
- A random float (max=1,min=0) is compared to
actions
should be initialized with the sameptr_count
as the model- Returns the model object
Model.Eval(model,input=0,actions=[])
- Runs the model map against an input
- Handles control flow returns
- If map action returns < 0, the next map action is skipped
- Otherwise the next action is called
actions
should be initialized with the sameptr_count
as the model- Returns the model object
Model._CLI(args=[])
- Simple command line functionality
- Also accessed by
node flatnet.js model
, see flatnet command line ptr_count=2
- Flag that can be entered any place after the first two arguments
- Any integer
- Calling format
- Accepts arguments as comma separated strings
node model.js "0,1,2,3,4" "0,1,2,3,4"
- Or will accept map argument as a file name without a file extension
node model.js mymapfile "0,1,2,3,4"
- Prints the
model.out
array - Returns the model object
//default ptr_count=2
~> node model.js "0,1,2,3,4" "5,6,7,8,9"
model.out: [ 0, 0 ]
//mymapfile = "0,1,2,3,4"
~> node model.js mymapfile "5,6,7,8,9"
model.out: [ 0, 0 ]