Esempio n. 1
0
 def __init__(self, numberOfInputs, quanta):
     "Create a new random lookup table"
     PersistentList.__init__(self)
     self.quanta = quanta
     for _ in range(int(round(quanta**numberOfInputs))):
         self.append(self.getRandomValue())
     log.debug('MultiValueLogicFunction created %d entries', len(self))
Esempio n. 2
0
    def __init__(self, num_nodes, num_inputs, num_outputs, new_node_class,
                 new_node_args, topology, update_style, radius, uniform):
        # what about k, quanta, nodes_per_input
        PersistentList.__init__(self)
        log.debug('Network.__init__()')
        self.outputs = PersistentList()
        self.domains = {'bias': (-5, 5), 'state': (0, 1), 'weight': (-7, 7)}
        self.quanta = None
        assert update_style in ['sync', 'async']
        self.update_style = update_style
        # num_nodes must be bigger than inputs+outputs
        assert num_nodes >= num_inputs
        assert num_nodes >= num_outputs
        assert isinstance(radius, int) and radius > 0
        self.radius = radius
        assert topology in TOPOLOGIES
        # create nodes
        inputsPerNode = self.getNumberOfInputsPerNode(topology, radius,
                                                      num_nodes)
        if new_node_class == LogicalNode:
            new_node_args['numberOfInputs'] = inputsPerNode
        self.uniform = uniform
        if not uniform:
            for _ in range(num_nodes):
                n = new_node_class(par=1, **dict(new_node_args))
                self.append(n)
        else:
            n0 = new_node_class(par=1, **dict(new_node_args))
            self.append(n0)
            for _ in range(1, num_nodes):
                n = new_node_class(par=n0.par, **dict(new_node_args))
                self.append(n)

        # select input nodes
        self.inputs = PersistentList()
        for _ in range(num_inputs):
            n = choice(list(set(self) - set(self.inputs)))
            self.inputs.append(n)
        # select output nodes
        self.outputs = PersistentList()
        for _ in range(num_outputs):
            n = choice(list(set(self) - set(self.outputs)))
            self.outputs.append(n)

        self.connect(topology, radius)
        for n in self:
            assert len(n.inputs) == inputsPerNode
        self.topology = topology
Esempio n. 3
0
 def __init__(self, size=5):
     PersistentList.__init__(self)
     for i in range(size):
         self.append(None)
Esempio n. 4
0
 def __init__(self, *args):
     #        list.__init__(self, args) # extended list (works)
     PersistentList.__init__(self, args)
Esempio n. 5
0
 def __init__(self, size=5):
     PersistentList.__init__(self)
     for i in range(size):
         self.append(None)