Changeset 64 for cpp/gdk/neuroimpl.cpp


Ignore:
Timestamp:
01/28/11 23:29:40 (13 years ago)
Author:
Maciej Komosinski
Message:

a lot of minor fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/neuroimpl.cpp

    r5 r64  
    1 // This file is a part of Framsticks GDK library.
    2 // Copyright (C) 2002-2006  Szymon Ulatowski.  See LICENSE.txt for details.
    3 // Refer to http://www.frams.alife.pl/ for further information.
     1// This file is a part of the Framsticks GDK library.
     2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
     3// Refer to http://www.framsticks.com/ for further information.
    44
    55#include "neuroimpl.h"
     
    2323{
    2424{"Creature: Neurons",1,2,"nnsim",},
    25 {"randinit",1,0,"Random initialization","f 0 10 0.01",FIELD(randominit),"Initialize all neuron states with uniform distribution random numbers"},
     25{"randinit",1,0,"Random initialization","f 0 10 0.01",FIELD(randominit),"Allowed range for initializing all neuron states with uniform distribution random numbers and zero mean. Set 0 for deterministic initialization."},
    2626{"touchrange",1,0,"T receptor range","f 0 100 1",FIELD(touchrange),},
    2727{0,0,0,},
     
    277277ParamEntry neuroimpl_tab[]=
    278278{
    279 {"Neuro",1,26+NEUROIMPL_SIGNAL_PROPS,"Neuro","Live Neuron object."},
    280 
    281 {"getInputState",0,0,"get input signal","p f(d input)",PROCEDURE(p_get),},
    282 {"getInputWeight",0,0,"get input weight","p f(d input)",PROCEDURE(p_getweight),},
    283 {"getWeightedInputState",0,0,"get weighted input signal","p f(d input)",PROCEDURE(p_getw),},
    284 {"getInputSum",0,0,"get signal sum","p f(d input)",PROCEDURE(p_getsum),},
    285 {"getWeightedInputSum",0,0,"get weighted signal sum","p f(d input)",PROCEDURE(p_getwsum),"uses any number of inputs starting with the specified input. getWeightedInputSum(0)=weightedInputSum"},
    286 {"getInputCount",0,0,"get input count","d",GETONLY(count),},
    287 {"inputSum",0,0,"full signal sum","f",GETONLY(sum),},
    288 {"weightedInputSum",0,0,"full weighted signal sum","f",GETONLY(wsum),},
    289 {"getInputChannelCount",0,0,"get channel count for input","p d(d input)",PROCEDURE(p_getchancount),},
    290 {"getInputStateChannel",0,0,"get input signal from channel","p f(d input,d channel)",PROCEDURE(p_getchan),},
    291 {"getWeightedInputStateChannel",0,0,"get weighted input signal from channel","p f(d input,d channel)",PROCEDURE(p_getwchan),},
    292 {"state",0,0,"neuron state (channel 0)","f",GETSET(state),"when read, returns the current neuron state.\nWhen written, sets the next neuron state (for use in the neuron definition)"},
    293 {"channelCount",0,0,"number of output channels","d",GETSET(channels),},
    294 {"getStateChannel",0,0,"get output state for channel","p f(d channel)",PROCEDURE(p_getstate),},
    295 {"setStateChannel",0,0,"set output state for channel","p(d channel,f value)",PROCEDURE(p_setstate),},
    296 {"hold",0,0,"Hold state","d 0 1",GETSET(hold),"",},
    297 {"currState",0,0,"neuron state (channel 0)","f",GETSET(cstate),"the only difference from the \"state\" field is that currState, when written, changes the internal neuron state immediately (which disturbs the regular synchronous NN operation). This feature should only be used while controlling the neuron 'from outside' (like a neuro probe) and not in the neuron definition.",},
    298 {"setCurrStateChannel",0,0,"set neuron for channel","p(d channel,f value)",PROCEDURE(p_setcstate),"like \"currState\""},
    299 {"position_x",0,0,"position x","f",GETONLY(position_x),},
    300 {"position_y",0,0,"position y","f",GETONLY(position_y),},
    301 {"position_z",0,0,"position z","f",GETONLY(position_z),},
    302 {"creature",0,0,"get owner creature","o Creature",GETONLY(creature),},
    303 {"part",0,0,"the Part object where this neuron is located","o MechPart",GETONLY(part),},
    304 {"joint",0,0,"the Joint object where this neuron is located","o MechJoint",GETONLY(joint),},
    305 {"fields",0,0,"custom neuron fields","o Fields",GETONLY(fields),
     279{"Neuro",1,27+NEUROIMPL_SIGNAL_PROPS,"Neuro","Live Neuron object."},
     280
     281{"getInputState",0,0,"Get input signal","p f(d input)",PROCEDURE(p_get),},
     282{"getInputWeight",0,0,"Get input weight","p f(d input)",PROCEDURE(p_getweight),},
     283{"getWeightedInputState",0,0,"Get weighted input signal","p f(d input)",PROCEDURE(p_getw),},
     284{"getInputSum",0,0,"Get signal sum","p f(d input)",PROCEDURE(p_getsum),},
     285{"getWeightedInputSum",0,0,"Get weighted signal sum","p f(d input)",PROCEDURE(p_getwsum),"Uses any number of inputs starting with the specified input. getWeightedInputSum(0)=weightedInputSum"},
     286{"getInputCount",0,0,"Get input count","d",GETONLY(count),},
     287{"inputSum",0,0,"Full signal sum","f",GETONLY(sum),},
     288{"weightedInputSum",0,0,"Full weighted signal sum","f",GETONLY(wsum),},
     289{"getInputChannelCount",0,0,"Get channel count for input","p d(d input)",PROCEDURE(p_getchancount),},
     290{"getInputStateChannel",0,0,"Get input signal from channel","p f(d input,d channel)",PROCEDURE(p_getchan),},
     291{"getWeightedInputStateChannel",0,0,"Get weighted input signal from channel","p f(d input,d channel)",PROCEDURE(p_getwchan),},
     292{"state",0,0,"Neuron state (channel 0)","f",GETSET(state),"When read, returns the current neuron state.\nWhen written, sets the next neuron state (for use in the neuron definition)"},
     293{"channelCount",0,0,"Number of output channels","d",GETSET(channels),},
     294{"getStateChannel",0,0,"Get output state for channel","p f(d channel)",PROCEDURE(p_getstate),},
     295{"setStateChannel",0,0,"Set output state for channel","p(d channel,f value)",PROCEDURE(p_setstate),},
     296{"hold",0,0,"Hold state","d 0 1",GETSET(hold),"\"Holding\" means keeping the neuron state as is, blocking the regular neuron operation. This is useful when your script needs to inject some control signals into the NN. Without \"holding\", live neurons would be constantly overwriting your changes, and the rest of the NN could see inconsistent states, depending on the connections. Setting hold=1 ensures the neuron state will be only set by you, and not by the neuron. The enforced signal value can be set using Neuro.currState before or after setting hold=1. Set hold=0 to resume normal operation.",},
     297{"currState",0,0,"Neuron state (channel 0)","f",GETSET(cstate),"The only difference from the \"state\" field is that currState, when written, changes the internal neuron state immediately (which disturbs the regular synchronous NN operation). This feature should only be used while controlling the neuron 'from outside' (like a neuro probe) and not in the neuron definition. See also: Neuro.hold",},
     298{"setCurrStateChannel",0,0,"Set neuron for channel","p(d channel,f value)",PROCEDURE(p_setcstate),"Analogous to \"currState\"."},
     299{"position_x",0,0,"Position x","f",GETONLY(position_x),},
     300{"position_y",0,0,"Position y","f",GETONLY(position_y),},
     301{"position_z",0,0,"Position z","f",GETONLY(position_z),},
     302{"creature",0,0,"Gets owner creature","o Creature",GETONLY(creature),},
     303{"part",0,0,"The Part object where this neuron is located","o MechPart",GETONLY(part),},
     304{"joint",0,0,"The Joint object where this neuron is located","o MechJoint",GETONLY(joint),},
     305{"fields",0,0,"Custom neuron fields","o Fields",GETONLY(fields),
    306306"Neurons can have different fields depending on their class. Script neurons have their fields defined using the \"prop:\" syntax. If you develop a custom neuron script you should use the Fields object for accessing your own neuron fields. The Neuro.fields property is meant for accessing the neuron fields from the outside script.\n"
    307307"Examples:\n"
    308 "var c=LiveLibrary.createFromString(\"X[N]\");\n"
     308"var c=Populations.createFromString(\"X[N]\");\n"
    309309"Simulator.print(\"standard neuron inertia=\"+c.getNeuro(0).fields.in);\n"
    310 "c=LiveLibrary.createFromString(\"X[Nn,e:0.1]\");\n"
     310"c=Populations.createFromString(\"X[Nn,e:0.1]\");\n"
    311311"Simulator.print(\"noisy neuron error rate=\"+c.getNeuro(0).fields.e);\n"
    312312"\n"
    313313"The Interface object can be used to discover which fields are available for a certain neuron object:\n"
    314 "c=LiveLibrary.createFromString(\"X[N]\");\n"
     314"c=Populations.createFromString(\"X[N]\");\n"
    315315"var iobj=Interface.makeFrom(c.getNeuro(0).fields);\n"
    316316"var i;\n"
     
    318318" Simulator.print(iobj.getId(i)+\" (\"+iobj.getName(i)+\")\");",},
    319319{"def",0,0,"Neuron definition from which this live neuron was built","o NeuroDef",GETONLY(neurodef),},
     320{"classObject",0,0,"Neuron class for this neuron","o NeuroClass",GETONLY(classObject),},
    320321#ifdef NEURO_SIGNALS
    321322{"signals",0,PARAM_READONLY,"Signals","o NeuroSignals",FIELD(sigs_obj),},
     
    332333
    333334#define FIELDSTRUCT NeuroSignals
    334 {"add",0,PARAM_NOSTATIC,"add","p(s channel)",PROCEDURE(p_add),"Create a new signal"},
    335 {"receive",0,PARAM_NOSTATIC,"receive","p f(s channel)",PROCEDURE(p_receive),"Receive the aggregated signal power in a given channel."},
    336 {"receiveSet",0,PARAM_NOSTATIC,"receive","p oVector(s channel,f max distance)",PROCEDURE(p_receiveSet),"Get all signals in the specified range. Returns a readonly vector object containing Signal objects (individual signals can be accessed as result[0] throught result[result.size-1])."},
     335{"add",0,PARAM_NOSTATIC,"Add","p(s channel)",PROCEDURE(p_add),"Create a new signal"},
     336{"receive",0,PARAM_NOSTATIC,"Receive","p f(s channel)",PROCEDURE(p_receive),"Receive the aggregated signal power in a given channel."},
     337{"receiveSet",0,PARAM_NOSTATIC,"Receive","p oVector(s channel,f max distance)",PROCEDURE(p_receiveSet),"Get all signals in the specified range. Returns a readonly vector object containing Signal objects (individual signals can be accessed as result[0] throught result[result.size-1])."},
    337338{"receiveFilter",0,PARAM_NOSTATIC,"receive","p f(s channel,f max distance,f flavor,f filter)",PROCEDURE(p_receiveFilter),"Receive the aggregated signal power in a given channel.\n\nAdditional filtering options:\n- Max distance only receives the neighbor signals (based on their physical location)\n- Flavor filtering: only signals having the flavor close to the specified one will be received. The filter value is the maximum allowed difference."},
    338 {"receiveSingle",0,PARAM_NOSTATIC,"receive","p oSignal(s channel,f range)",PROCEDURE(p_receiveSingle),"Find the signal source having the highest signal power (including the distance)"},
     339{"receiveSingle",0,PARAM_NOSTATIC,"Receive","p oSignal(s channel,f range)",PROCEDURE(p_receiveSingle),"Find the signal source having the highest signal power (including the distance)"},
    339340#undef FIELDSTRUCT
    340341
    341342#define FIELDSTRUCT SignalSet
    342 {"get",0,PARAM_NOSTATIC,"get","p oSignal(d index)",PROCEDURE(p_get),},
    343 {"size",0,1+PARAM_NOSTATIC,"size","d",GETONLY(size),},
    344 {"clear",0,1+PARAM_NOSTATIC,"clear","p()",PROCEDURE(p_clear),},
     343{"get",0,PARAM_NOSTATIC,"Get","p oSignal(d index)",PROCEDURE(p_get),},
     344{"size",0,1+PARAM_NOSTATIC,"Size","d",GETONLY(size),},
     345{"clear",0,1+PARAM_NOSTATIC,"Clear","p()",PROCEDURE(p_clear),},
    345346#undef FIELDSTRUCT
    346347{0,0,0,},
     
    383384void NeuroSignals::p_add(PARAMPROCARGS)
    384385{
    385 if (!owner->owner->channels) {ret->setEmpty();return;}
    386 SigChannel *ch=owner->owner->channels->getChannel(args->getString(),true);
    387386SigSource *s=new NeuroSigSource(owner,getCreature());
    388 ch->addSource(s);
     387if (owner->owner->channels)
     388        {
     389        SigChannel *ch=owner->owner->channels->getChannel(args->getString(),true);
     390        ch->addSource(s);
     391        }
     392else
     393        SigChannel::dummy_channel.addSource(s);
    389394sigs+=s;
    390395s->setupObject(ret);
     
    522527}
    523528
     529void NeuroImpl::get_classObject(ExtValue *ret)
     530{
     531NeuroClassExt::makeStaticObject(ret,neuroclass);
     532}
     533
    524534NeuroImpl::~NeuroImpl()
    525535{
Note: See TracChangeset for help on using the changeset viewer.