Example #1
0
def fuzzynot_node(name):
	g = NodeGroup("FuzzyNOT", True);
	g.addNode(fNOT, "FuzzyNOT", "java");
	module = NeuralModule(name+'_FuzzyNOT', g)
	module.createEncoder("logic/gates/ina", "float", 1)
	module.createDecoder("logic/gates/outa", "float", 1)
	return module
Example #2
0
def sync_timeaware_node(name):
	g = NodeGroup("SynMinMaxFloat", True);        			
	g.addNode(time, "SynMinMaxFloat", "java");     		
	module = NeuralModule(name+'_SynMinMaxFloat', g)    	
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)  			
	module.createDecoder("org/hanns/demonodes/pubsub/OUT", "float", 2)    		
	return module
Example #3
0
def async_minmaxfloat_node(name):
	g = NodeGroup("AsynMinMaxFloat", True);        			
	g.addNode(mmf, "AsynMinMaxFloat", "java");     		
	module = NeuralModule(name+'_AsynMinMaxFloat', g, False)    	
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)  			
	module.createDecoder("org/hanns/demonodes/pubsub/OUT", "float", 2)    		
	return module
Example #4
0
def async_timeaware_node(name):
	g = NodeGroup("AsynTimeAwareNode", True);        			
	g.addNode(time, "AsynTimeAwareNode", "java");     		
	module = NeuralModule(name+'_AsynTimeAwareNode', g, False)    	
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)			
	module.createDecoder("org/hanns/demonodes/pubsub/OUT", "float", 2)
	return module
Example #5
0
def sync_minmaxfloat_node(name):
	g = NodeGroup("SynMinMaxFloat", True);        			
	g.addNode(mmf, "SynMinMaxFloat", "java");     		
	module = NeuralModule(name+'_SynMinMaxFloat', g)    	# here: Nengo waits each step for response from node
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)  			
	neuron.createDecoder("org/hanns/demonodes/pubsub/OUT", "float", 2)  # add FLOAT publisher
	return module
Example #6
0
def sync_minmaxint_node(name):
	g = NodeGroup("SynMinMaxInt", True);        			
	g.addNode(minmaxint, "SynMinMaxInt", "java");     		
	module = NeuralModule(name+'_SynMinMaxInt', g)    	# here: Nengo waits each step for response from node
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)  			
	module.createDecoder("org/hanns/demonodes/pubsub/OUT", "int", 2)    			
	return module
Example #7
0
def not_node(name):
	g = NodeGroup("NOT", True);
	g.addNode(NOT, "NOT", "java");
	module = NeuralModule(name+'_NOT', g)
	module.createEncoder("logic/gates/ina", "bool", 1)
	module.createDecoder("logic/gates/outa", "bool", 1)
	return module
Example #8
0
def or_node(name):
	g = NodeGroup("OR", True);
	g.addNode(OR, "OR", "java");
	module = NeuralModule(name+'_OR', g)
	module.createEncoder("logic/gates/ina", "bool", 1)
	module.createEncoder("logic/gates/inb", "bool", 1)
	module.createDecoder("logic/gates/outa", "bool", 1)
	return module
Example #9
0
def fuzzyand_node(name):
	g = NodeGroup("FuzzyAND", True);
	g.addNode(fAND, "FuzzyAND", "java");
	module = NeuralModule(name+'_FuzzyAND', g)
	module.createEncoder("logic/gates/ina", "float", 1)
	module.createEncoder("logic/gates/inb", "float", 1)
	module.createDecoder("logic/gates/outa", "float", 1)
	return module
Example #10
0
def nand_node(name):
	g = NodeGroup("NAND", True);
	g.addNode(NAND, "NAND", "java");
	module = NeuralModule(name+'_NAND', g)
	module.createEncoder("logic/gates/ina", "bool", 1)
	module.createEncoder("logic/gates/inb", "bool", 1)
	module.createDecoder("logic/gates/outa", "bool", 1)
	return module
Example #11
0
def make(net,name='NeuralModule which interfaces demoSubscriber with the Nengo simulator', independent=True, useQuick=True):

    node = "org.hanns.demonodes.pubsub.DemoSubscriber";
    
    g = NodeGroup(name, independent);    			# Create group of nodes (represented as SimpleNode in the GUI)
    g.addNode(node, "subscriber", "java");  	    # start java node and name it subscriber in the ROS network
    module = NeuralModule('Subscriber_'+name, g, False) 	# Construct the neural module in the asynchronous mode
    module.createEncoder("org/hanns/demonodes/pubsub", "float", 7) # Define IO: termination = input of neuron (n*int)

    many=net.add(module)                    		# add it into Nengo simulator
Example #12
0
def async_minmaxint_node(name):
	g = NodeGroup("AsynMinMaxInt", True);        			# create independent (True) group called..
	g.addNode(minmaxint, "AsynMinMaxInt", "java");     		# start java node and name it finder
	module = NeuralModule(name+'_AsynMinMaxInt', g, False)   # construct the Neural Module
	# add encoder to the module (input)
	# It is output on modem which is connected to input (topic name) to the ROS node
	module.createEncoder("org/hanns/demonodes/pubsub/IN", "float", 4)  	# ..called TERMINATION of SimpleNode
	# Add decoder to the module (output):
	# It is input if modem which is connected to output (topic name) of the ROS node
	module.createDecoder("org/hanns/demonodes/pubsub/OUT", "int", 2)    # ..called ORIGIN of SimpleNode
	return module
Example #13
0
def fuzzyMemTriangle(name):									# ____|\____
	g = NodeGroup("FuzzyMemTriangle", True);
	g.addNode(ftriangle,"FuzzyMemTriangle","java");
	module = NeuralModule(name+'_FuzzyMemTriangle', g)
	module.createEncoder("logic/gates/ina", "float", 1)		# x
	module.createEncoder("logic/gates/confa", "float", 1) 	# alpha
	module.createEncoder("logic/gates/confb", "float", 1) 	# beta
	module.createEncoder("logic/gates/confc", "float", 1) 	# gamma
	module.createDecoder("logic/gates/outa", "float", 1)	# y
	return module
Example #14
0
def fuzzyMemTriangle(name):  # ____|\____
    g = NodeGroup("FuzzyMemTriangle", True)
    g.addNode(ftriangle, "FuzzyMemTriangle", "java")
    module = NeuralModule(name + '_FuzzyMemTriangle', g)
    module.createEncoder("logic/gates/ina", "float", 1)  # x
    module.createEncoder("logic/gates/confa", "float", 1)  # alpha
    module.createEncoder("logic/gates/confb", "float", 1)  # beta
    module.createEncoder("logic/gates/confc", "float", 1)  # gamma
    module.createDecoder("logic/gates/outa", "float", 1)  # y
    return module
Example #15
0
def make(net,name='NeuralModule which implements logical NOT operation', 
independent=True, useQuick=True):

    finder = "org.hanns.logic.crisp.gates.impl.NOT";

    # create group with a name
    g = NodeGroup(name, independent);    	# create independent group called..
    g.addNode(finder, "logic_crisp_gates_NOT", "java");      # start java node and name it finder
    neuron = NeuralModule(name+"_logic_crisp_gates_not", g) # construct the neural module 

    neuron.createEncoder("logic/gates/ina", "bool",1)   # termination = input of neuron (4xfloat)
    neuron.createDecoder("logic/gates/outa", "bool",1)  # origin = output of neuron (min and max)

    many=net.add(neuron)                    # add it into the network
Example #16
0
def benchmarkTwoR(name, mapName="benchmark", logPeriod=200, synchronous=True):

    command = [bench, "_" + World.logPeriodConf + ":=" + str(logPeriod)]

    noActions = 4
    # hardcoded
    noStateVars = 2

    g = NodeGroup(mapName, True)
    g.addNode(command, name, "java")
    module = NeuralModule(name + "_GridWorld", g, synchronous)
    module.createEncoder(QLambda.topicDataOut, "float", noActions)  # decode actions
    module.createDecoder(QLambda.topicDataIn, "float", noStateVars + 2)  # encode states (first is reward)
    return module
Example #17
0
def buildModule(name):
    minmaxint =   	"ctu.nengoros.testsuit.demo.nodes.minmax.F2FPubSub"
    g = NodeGroup("MinMaxFloat", True);        			# create independent (True) group called..
    g.addNode(minmaxint, "MinMaxFloatNode", "java");     	# start java node and name it finder
    module = NeuralModule(name+'_MinMaxFloat', g, True)  # construct the Neural Module and run it as synchrnonous (True)
    
    # Add an Encoder to the module (input), which receives 4 floats and sends them to the ROS node 
    # This adds one (correspondingly named) Termination to the NeuralModule 
    module.createEncoder(F2FPubSub.ann2ros, "float", 4) 
    
    # Add a Decoder to the module (output)
    # The Decoder receives ROS messages (topic name==first parameter), decodes them into Nengo RealOutputImpl data,
    # and places values on the (correspondingly named) Origin
    # In case of synchronous usage of NeuralModule, the Nengo simulator waits for new ROS messages each sim. step
    module.createDecoder(F2FPubSub.ros2ann, "float", 2)
    return module
Example #18
0
def benchmarkTwoR(name, mapName="benchmark", logPeriod=200, synchronous=True):

    command = [bench, '_' + World.logPeriodConf + ':=' + str(logPeriod)]

    noActions = 4
    # hardcoded
    noStateVars = 2

    g = NodeGroup(mapName, True)
    g.addNode(command, name, "java")
    module = NeuralModule(name + '_GridWorld', g, synchronous)
    module.createEncoder(QLambda.topicDataOut, "float",
                         noActions)  # decode actions
    module.createDecoder(QLambda.topicDataIn, "float",
                         noStateVars + 2)  # encode states (first is reward)
    return module
Example #19
0
def example(name, logPeriod=200):

    command = [nodep, "_" + World.logPeriodConf + ":=" + str(logPeriod)]

    noActions = 4
    # hardcoded
    noStateVars = 2

    g = NodeGroup("GridWorld", True)
    g.addNode(command, "GridWorld", "java")
    module = NeuralModule(name + "_GridWorld", g, True)

    module.createEncoder(QLambda.topicDataOut, "float", noActions)  # decode actions
    module.createDecoder(QLambda.topicDataIn, "float", noStateVars + 1)  # encode states (first is reward)

    return module
Example #20
0
def example(name, logPeriod=200):

    command = [nodep, '_' + World.logPeriodConf + ':=' + str(logPeriod)]

    noActions = 4
    # hardcoded
    noStateVars = 2

    g = NodeGroup("GridWorld", True)
    g.addNode(command, "GridWorld", "java")
    module = NeuralModule(name + '_GridWorld', g, True)

    module.createEncoder(QLambda.topicDataOut, "float",
                         noActions)  # decode actions
    module.createDecoder(QLambda.topicDataIn, "float",
                         noStateVars + 1)  # encode states (first is reward)

    return module
Example #21
0
def fuzzyMemIncLin(name):									# ____|----
	g = NodeGroup("FuzzyMemIncLin", True);
	g.addNode(flininc,"FuzzyMemIncLin","java");
	module = NeuralModule(name+'_FuzzyMemIncLin', g)
	module.createEncoder("logic/gates/ina", "float", 1)		# x
	module.createEncoder("logic/gates/confa", "float", 1) 	# alpha
	module.createEncoder("logic/gates/confb", "float", 1) 	# beta
	module.createDecoder("logic/gates/outa", "float", 1)	# y
	return module
def make(net,name='NeuralModule which implements FuzzyMembership function - Triangular', 
independent=True, useQuick=True):

    finder = "org.hanns.logic.fuzzy.membership.impl.Triangular";

    # create group with a name
    g = NodeGroup(name, independent);   
    g.addNode(finder, "FuzzyMemTriangular", "java");     

    neuron = NeuralModule(name+"_FuzzyMemTriangular", g) 
    neuron.createEncoder("logic/gates/ina", "float",1)   	# termination = data input x 
    neuron.createEncoder("logic/gates/confa", "float",1)	# termination - config input alpha
    neuron.createEncoder("logic/gates/confb", "float",1)	# termination - config input betaa
    neuron.createEncoder("logic/gates/confc", "float",1)	# termination - config input gamma
    neuron.createDecoder("logic/gates/outa", "float",1)  	# origin = output of neuron = data output y


    many=net.add(neuron)                    # add it into the network
Example #23
0
def basic(name, noInputs=Motivation.DEF_NOINPUTS, decay=Motivation.DEF_DECAY, logPeriod=Motivation.DEF_LOGPERIOD,
rewVal=Motivation.DEF_REWARD, rewThr=Motivation.DEF_REWTHRESHOLD, synchronous=True):

    # configure the node during startup from "the commandline"
	command = [classs, '_'+Motivation.noInputsConf+ ':=' + str(noInputs), 
	'_'+Motivation.decayConf+':='+str(decay),
	'_'+Motivation.logPeriodConf+':='+str(logPeriod)]

	g = NodeGroup("Motivation", True);
	g.addNode(command, "Motivation", "java");
	module = NeuralModule(name+'_Motivation', g, synchronous)

    # connect the decay parameter to the Nengoros network (changed online)
	module.createConfigEncoder(Motivation.topicDecay,"float", 1); 		# decay config (unconneced=Motivation.DEF_DECAY)

	module.createDecoder(Motivation.topicDataOut, "float", 2)           # decode float[]{reward,motivation}
	module.createEncoder(Motivation.topicDataIn, "float", noInputs) 	# encode input data (sum rewards here)
	
	module.createDecoder(Motivation.topicProsperity,"float", 1);		# float[]{prosperity}  = MSD from the limbo area

	return module
Example #24
0
net=nef.Network('Create a simple Neural Module which is configured by this Jython script')
net.add_to_nengo()  # here: delete old (toplevel) network and replace it with the newly CREATED one

################# setup the ROS utils (optional) 
#RosUtils.setTimeIgnore() 	
#RosUtils.setTimeMaster() 	# used by default
#RosUtils.setTimeSlave() 	# note: experimental, TODO
#RosUtils.setAutorun(False)     # Do we want to autorun roscore and rxgraph? (tru by default)
#RosUtils.prefferJroscore(True)  # preffer jroscore before the roscore? 


################# add ROS node with configuration stored in `command`

rosparam =   	"org.hanns.demonodes.privateParams.SetPrivateParameters"
command = [rosparam, '_a:=2', '_b:=3', 'shouldLog:=true']


g = NodeGroup("Sinus", True);        			# create independent (True) group called..
g.addNode(command, "Sinus", "java");     		# start java node and name it finder
module = NeuralModule("Configured Neural Module", g)# construct the Neural Module

# connect output
module.createDecoder("org/hanns/demonodes/params/", "float", 1)    # ..called ORIGIN of SimpleNode
many = net.add(module)

# create ANN with 100 neurons which approximates it's input 
A=net.make('A',neurons=50,dimensions=2,radius=8)    				# identity transformation implemented by population of neurons
net.connect(many.getOrigin('org/hanns/demonodes/params/'),A)		# connect the origin on our module to the network

print 'Configuration complete.'
Example #25
0
from ctu.nengoros.comm.rosutils import RosUtils as RosUtils

# creates nef network and adds it to nengo (this must be first in the script) 
net=nef.Network('Random Turtle Control Demo')
net.add_to_nengo()  # here: delete old (toplevel) network and replace it with the newly CREATED one

################################## 
#RosUtils.setAutorun(False)     # Do we want to autorun roscore and rxgraph? (tru by default)
RosUtils.prefferJroscore(False) # Turlte prefers roscore before jroscore (don't know why..) 

################################## 
turtlesim = "rosrun turtlesim turtlesim_node"   # command to start turtle installed in ROS
act = "resender.turtle.Controller";             
g = NodeGroup("Turtlesim", True);        # create group of ROS nodes (equals to one neural subsystem)
g.addNode(turtlesim, "Turtlesim", "native");  # add Node Configuration (turtle) to the group of nodes
module = NeuralModule('TurtleController', g)  

# configure modem, that is:
# -createDecoder = create origin (output) of Nengo module 
#   -what comes from ROS modules is decoded and passed to the output of subsystem in Nengo
# -createEncoder = create termination (input) of Nengo module
#   -what comes from ANN in Nengo is encoded into messages and sent to ROS modules
# modem should be able to encode/decode (all) messages used in own NodeGroup
module.createDecoder("turtle1/pose", "pose")                 # origin
module.createDecoder("turtle1/color_sensor", "color")        # origin
module.createEncoder("turtle1/cmd_vel", "geometry_msgs/Twist") # termination
subsystem=net.add(module)


#Create a white noise input function with parameters: baseFreq, maxFreq (rad/s), RMS, Seed
input=FunctionInput('Randomized input', [FourierFunction(.5, 10, 6, 12),
Example #26
0
pub = "org.hanns.demonodes.pubsub.DemoPublisher"
sub = "org.hanns.demonodes.pubsub.DemoSubscriber"

################# setup the ROS utils (optional) 
#RosUtils.setAutorun(False)     # Do we want to autorun roscore and rxgraph? (tru by default)
#RosUtils.prefferJroscore(True)  # preffer jroscore before the roscore

# creates nef network and adds it to nengo (this must be first in the script) 
net=nef.Network('Two Neural modules containing ROS nodes with communication shielded from each other')
net.add_to_nengo()  # here: delete old (toplevel) network and replace it with the newly CREATED one
					# any poteintial running ROS nodes are sopped here

################ Run two groups of nodes (conenct them in nengo)
g = NodeGroup("Publisher", True);        			
g.addNode(pub, "Publisher", "java");     	# add the publisher node
module = NeuralModule("Publisher", g)    		
module.createDecoder("org/hanns/demonodes/pubsub", "float", 7) 
net.add(module)	

g2 = NodeGroup("Subbscriber", True);        			
g2.addNode(sub, "Subbscriber", "java");     	# add the publisher node
module2 = NeuralModule("Subscriber", g2)    		
module2.createEncoder("org/hanns/demonodes/pubsub", "float", 7)
net.add(module2)	

net.connect(module.getOrigin('org/hanns/demonodes/pubsub'),module2.getTermination('org/hanns/demonodes/pubsub'))						

print 'Configuration complete - communication between ROS nodes is handled by the Nengo now'
print 'Note that both nodes are running:'
print '-Publisher periodically publishes data'
print '-Subscriber does not receive any data, because Nengo simulation is not running and data are not sent'
Example #27
0
def make(net,
         name='NeuralModule which implements RL SARSA algorithm',
         independent=True,
         useQuick=True,
         prospLen=3,
         noStateVars=2,
         noActions=4,
         sampleCount=30,
         logPeriod=100,
         maxDelay=1,
         synchronous=True):

    # full name of the reosjava node to be started
    classname = "org.hanns.rl.discrete.ros.sarsa.config.QlambdaCoverageReward"

    #command to launch and configure the RL rosjava node
    command = [
        classname, '_' + QLambda.noInputsConf + ':=' + str(noStateVars),
        '_' + QLambda.noOutputsConf + ':=' + str(noActions),
        '_' + QLambda.sampleCountConf + ':=' + str(sampleCount),
        '_' + QLambda.logPeriodConf + ':=' + str(logPeriod),
        '_' + QLambda.filterConf + ':=' + str(maxDelay)
    ]

    # create a group with a given name
    g = NodeGroup(name, independent)
    g.addNode(command, "rl_sarsa", "java")
    # start and configure the rosjava node
    module = NeuralModule(name + '_QLambda', g)
    # create the neural module representing the node

    # create config IO
    module.createConfigEncoder(QLambda.topicAlpha, "float", QLambda.DEF_ALPHA)
    # alpha config input, def. value is DEF_ALPHA
    module.createConfigEncoder(QLambda.topicGamma, "float", QLambda.DEF_GAMMA)
    module.createConfigEncoder(QLambda.topicLambda, "float",
                               QLambda.DEF_LAMBDA)
    module.createEncoder(QLambda.topicImportance, "float", 1)
    # default value is 0

    # QLambdaCoverageReward classname => float[]{prosperity, coverage, reward/step}
    module.createDecoder(QLambda.topicProsperity, "float", prospLen)

    # create data IO
    module.createDecoder(QLambda.topicDataOut, "float",
                         noActions)  # decode actions
    module.createEncoder(QLambda.topicDataIn, "float",
                         noStateVars + 1)  # encode states (first is reward)

    many = net.add(module)  # add it into the network
Example #28
0
def qlambdaASM(name, noStateVars=2, noActions=4, noValues=5, logPeriod=100, maxDelay=1,
classname="org.hanns.rl.discrete.ros.sarsa.config.QlambdaCoverageReward", prospLen=3,synchronous=True):
	"""Method that returns synchronous NeuralModule implementing the QLambda algorithm with 
	the ASM inbuilt. Configuration parameters of the node can be found in 
	the javadoc. Number of data inputs (size of the vector) to the module 
	is determined as 1+*noStateVars*, where the first element is the reward value.
	
	The parameter *maxDelay* describes the number of time-steps in the closed-loop learning, 
	that is: how many time steps the module should wait before change of the state
	to evalueate that the action had no-effect (state of the world has not changed).
	
	Note: if the configEncoders (config INs) are not connected, the default values
	are sent to the ROS node instead of zeros. So non-configured QLambda module
	will learn with use of predefined parameters. 
	
	:param string mame: name of the neural module (TODO) to be created
	:param integer noStateVars: number of state variables to be taken into account 
	:param integer noActions: number of actions the node can produce (encoding 1ofN is used)
	:param integer noValues: the number of values that is expected for each state variable (interval [0,1] is sampled)
	:param integer logPeriod: how often to print out the data
	:param integer maxDelay: max delay in the closed-loop learning
	:param string classname: full className of the ROS node to be launched
	:param integer prospLen: size of the vector expected from the nodes prosperity publisher
	:returns: NeuralModule that should be added into the network, the node represents the QLambda ROS node 
	"""
	# this command is used to launch the ROSjava node
	command = [classname, '_'+QLambda.noInputsConf+ ':=' + str(noStateVars), 
	'_'+QLambda.noOutputsConf+':='+str(noActions),
	'_'+QLambda.sampleCountConf+':='+str(noValues),
	'_'+QLambda.logPeriodConf+':='+str(logPeriod),
	'_'+QLambda.filterConf+':='+str(maxDelay)]

	# represent the ROS node by means of Neural Module
	g = NodeGroup("RL", True);
	g.addNode(command, "RL", "java");
	module = NeuralModule(name+'_QLambda', g, synchronous)

	# create config IO
	module.createConfigEncoder(QLambda.topicAlpha,"float",QLambda.DEF_ALPHA); 	# alpha config input, def. value is DEF_ALPHA
	module.createConfigEncoder(QLambda.topicGamma,"float",QLambda.DEF_GAMMA);
	module.createConfigEncoder(QLambda.topicLambda,"float",QLambda.DEF_LAMBDA);
	module.createEncoder(QLambda.topicImportance,"float",1);					# default value is 0

	# QLambdaCoverageReward classname => float[]{prosperity, coverage, reward/step}
	module.createDecoder(QLambda.topicProsperity, "float", prospLen);			

	# create data IO
	module.createDecoder(QLambda.topicDataOut, "float", noActions)  	# decode actions
	module.createEncoder(QLambda.topicDataIn, "float", noStateVars+1) 	# encode states (first is reward)

	return module
Example #29
0
def qlambdaMOO(name,
               noStateVars=2,
               noActions=4,
               noValues=5,
               logPeriod=100,
               maxDelay=1):
    command = [
        classMOO, '_' + QLambda.noInputsConf + ':=' + str(noStateVars),
        '_' + QLambda.noOutputsConf + ':=' + str(noActions),
        '_' + QLambda.sampleCountConf + ':=' + str(noValues),
        '_' + QLambda.logPeriodConf + ':=' + str(logPeriod),
        '_' + QLambda.filterConf + ':=' + str(maxDelay)
    ]
    g = NodeGroup("RL", True)
    g.addNode(command, "RL", "java")
    module = NeuralModule(name + '_QLambda', g, False)
    module.createEncoder(QLambda.topicAlpha, "float", 1)
    # alpha config
    module.createEncoder(QLambda.topicGamma, "float", 1)
    module.createEncoder(QLambda.topicLambda, "float", 1)
    module.createEncoder(QLambda.topicImportance, "float", 1)
    module.createDecoder(QLambda.topicProsperity, "float", 3)
    # float[]{prosperity, coverage, reward/step}
    module.createDecoder(QLambda.topicDataOut, "float",
                         noActions)  # decode actions
    module.createEncoder(QLambda.topicDataIn, "float",
                         noStateVars + 1)  # encode states (first is reward)
    return module
def qlambdaMOO(name, noStateVars=2, noActions=4, noValues=5, logPeriod=100, maxDelay=1):
	command = [classMOO, '_'+QLambda.noInputsConf+ ':=' + str(noStateVars), 
	'_'+QLambda.noOutputsConf+':='+str(noActions),
	'_'+QLambda.sampleCountConf+':='+str(noValues),
	'_'+QLambda.logPeriodConf+':='+str(logPeriod),
	'_'+QLambda.filterConf+':='+str(maxDelay)]
	g = NodeGroup("RL", True);
	g.addNode(command, "RL", "java");
	module = NeuralModule(name+'_QLambda', g, False)
	module.createEncoder(QLambda.topicAlpha,"float",1); 				# alpha config
	module.createEncoder(QLambda.topicGamma,"float",1);
	module.createEncoder(QLambda.topicLambda,"float",1);
	module.createEncoder(QLambda.topicImportance,"float",1);
	module.createDecoder(QLambda.topicProsperity,"float", 3);			# float[]{prosperity, coverage, reward/step}
	module.createDecoder(QLambda.topicDataOut, "float", noActions)  	# decode actions
	module.createEncoder(QLambda.topicDataIn, "float", noStateVars+1) 	# encode states (first is reward)
	return module
Example #31
0
def qlambdaASM(name, noStateVars=2, noActions=4, noValues=5, logPeriod=100, maxDelay=1,
classname="org.hanns.rl.discrete.ros.sarsa.config.QlambdaCoverageReward",prospLen=3,synchronous=True):
	"""Method that returns synchronous NeuralModule implementing the QLambda algorithm with 
	the ASM inbuilt. Configuration parameters of the node can be found in 
	the javadoc. Number of data inputs (size of the vector) to the module 
	is determined as 1+*noStateVars*, where the first element is the reward value.
	
	The parameter *maxDelay* describes the number of time-steps in the closed-loop learning, 
	that is: how many time steps the module should wait before change of the state
	to evalueate that the action had no-effect (state of the world has not changed).
	
	Note: if the configEncoders (config INs) are not connected, the default values
	are sent to the ROS node instead of zeros. So non-configured QLambda module
	will learn with use of predefined parameters. 
	
	:param string mame: name of the neural module (TODO) to be created
	:param integer noStateVars: number of state variables to be taken into account 
	:param integer noActions: number of actions the node can produce (encoding 1ofN is used)
	:param integer noValues: the number of values that is expected for each state variable (interval [0,1] is sampled)
	:param integer logPeriod: how often to print out the data
	:param integer maxDelay: max delay in the closed-loop learning
	:param string classname: full className of the ROS node to be launched
	:param integer prospLen: size of the vector expected from the nodes prosperity publisher
	:returns: NeuralModule that should be added into the network, the node represents the QLambda ROS node 
	"""
	# this command is used to launch the ROSjava node
	command = [classname, '_'+QLambda.noInputsConf+ ':=' + str(noStateVars), 
	'_'+QLambda.noOutputsConf+':='+str(noActions),
	'_'+QLambda.sampleCountConf+':='+str(noValues),
	'_'+QLambda.logPeriodConf+':='+str(logPeriod),
	'_'+QLambda.filterConf+':='+str(maxDelay)]

	# represent the ROS node by means of Neural Module
	g = NodeGroup("RL", True);
	g.addNode(command, "RL", "java");
	module = NeuralModule(name+'_QLambda', g, synchronous)

	# create config IO
	module.createConfigEncoder(QLambda.topicAlpha,"float",QLambda.DEF_ALPHA); 	# alpha config input, def. value is DEF_ALPHA
	module.createConfigEncoder(QLambda.topicGamma,"float",QLambda.DEF_GAMMA);
	module.createConfigEncoder(QLambda.topicLambda,"float",QLambda.DEF_LAMBDA);
	module.createEncoder(QLambda.topicImportance,"float",1);					# default value is 0

	# QLambdaCoverageReward classname => float[]{prosperity, coverage, reward/step}
	module.createDecoder(QLambda.topicProsperity,"float", prospLen);			

	# create data IO
	module.createDecoder(QLambda.topicDataOut, "float", noActions)  	# decode actions
	module.createEncoder(QLambda.topicDataIn, "float", noStateVars+1) 	# encode states (first is reward)

	return module