Exemplo n.º 1
0
    def __init__(self, nodenet, parent_nodespace, position, state=None, activation=0,
                 name="", type="Concept", uid=None, index=None, parameters=None, gate_activations={}, gate_configuration=None, **_):

        Node.__init__(self, nodenet, type, nodenet.get_nodetype(type))

        NetEntity.__init__(self, nodenet, parent_nodespace,
            name=name, entitytype="nodes", uid=uid, index=index)
        self.position = position

        self._state = {}
        self.__activation = activation

        self.__gates = {}
        self.__slots = {}
        self._gate_configuration = gate_configuration or {}

        self.__parameters = dict((key, self.nodetype.parameter_defaults.get(key)) for key in self.nodetype.parameters)
        if parameters is not None:
            for key in parameters:
                if parameters[key] is not None and key in self.nodetype.parameters:
                    self.set_parameter(key, parameters[key])

        for gate in self.nodetype.gatetypes:
            self.__gates[gate] = DictGate(gate, self)
            if gate in gate_activations:
                self.__gates[gate].activation = gate_activations[gate]
        for slot in self.nodetype.slottypes:
            self.__slots[slot] = DictSlot(slot, self)
        if state:
            self._state = state
        nodenet._register_node(self)
Exemplo n.º 2
0
 def __init__(self, nodenet, parent_nodespace, position, name="", uid=None, index=None):
     """create a node space at a given position and within a given node space"""
     self.__activators = {}
     self.__netentities = {}
     uid = uid or micropsi_core.tools.generate_uid()
     NetEntity.__init__(self, nodenet, parent_nodespace, position, name, "nodespaces", uid, index)
     nodenet._register_nodespace(self)
Exemplo n.º 3
0
 def __init__(self, nodenet, parent_nodespace, name="", uid=None, index=None):
     """create a node space at a given position and within a given node space"""
     self.__activators = {}
     self.__netentities = {}
     NetEntity.__init__(self, nodenet, parent_nodespace, name, "nodespaces", uid, index)
     self.last_changed = nodenet.current_step
     self.contents_last_changed = nodenet.current_step
     nodenet._register_nodespace(self)
Exemplo n.º 4
0
 def __init__(self, nodenet, parent_nodespace, position, name="", uid=None, index=None, gatefunction_strings=None):
     """create a node space at a given position and within a given node space"""
     self.__activators = {}
     self.__netentities = {}
     uid = uid or micropsi_core.tools.generate_uid()
     NetEntity.__init__(self, nodenet, parent_nodespace, position, name, "nodespaces", uid, index)
     nodenet._register_nodespace(self)
     self.__gatefunctions = {}
     self.__gatefunction_strings = gatefunction_strings or {}
     for nodetype in self.__gatefunction_strings:
         for gatetype in self.__gatefunction_strings[nodetype]:
             self.set_gate_function_string(nodetype, gatetype, self.__gatefunction_strings[nodetype][gatetype])
Exemplo n.º 5
0
 def __init__(self,
              nodenet,
              parent_nodespace,
              position,
              name="",
              uid=None,
              index=None):
     """create a node space at a given position and within a given node space"""
     self.__activators = {}
     self.__netentities = {}
     uid = uid or micropsi_core.tools.generate_uid()
     NetEntity.__init__(self, nodenet, parent_nodespace, position, name,
                        "nodespaces", uid, index)
     nodenet._register_nodespace(self)
Exemplo n.º 6
0
    def __init__(self,
                 nodenet,
                 parent_nodespace,
                 position,
                 state=None,
                 activation=0,
                 name="",
                 type="Concept",
                 uid=None,
                 index=None,
                 parameters=None,
                 gate_parameters=None,
                 gate_activations=None,
                 gate_functions=None,
                 **_):
        if not gate_parameters:
            gate_parameters = {}

        if nodenet.is_node(uid):
            raise KeyError("Node with uid %s already exists" % uid)

        Node.__init__(self, type, nodenet.get_nodetype(type))

        NetEntity.__init__(self,
                           nodenet,
                           parent_nodespace,
                           position,
                           name=name,
                           entitytype="nodes",
                           uid=uid,
                           index=index)

        self.__non_default_gate_parameters = {}

        self.__state = {}

        self.__gates = {}
        self.__slots = {}
        self.__gatefunctions = {}
        if gate_functions is None:
            gate_functions = {}
        self.__parameters = dict(
            (key, self.nodetype.parameter_defaults.get(key))
            for key in self.nodetype.parameters)
        if parameters is not None:
            for key in parameters:
                if parameters[key] is not None:
                    self.set_parameter(key, parameters[key])

        for gate_name in gate_parameters:
            for key in gate_parameters[gate_name]:
                if gate_parameters[gate_name][
                        key] != self.nodetype.gate_defaults[gate_name].get(
                            key, None):
                    if gate_name not in self.__non_default_gate_parameters:
                        self.__non_default_gate_parameters[gate_name] = {}
                    self.__non_default_gate_parameters[gate_name][
                        key] = gate_parameters[gate_name][key]

        gate_parameters = copy.deepcopy(self.nodetype.gate_defaults)
        for gate_name in gate_parameters:
            if gate_name in self.__non_default_gate_parameters:
                gate_parameters[gate_name].update(
                    self.__non_default_gate_parameters[gate_name])

        gate_parameters_for_validation = copy.deepcopy(gate_parameters)
        for gate_name in gate_parameters_for_validation:
            for key in gate_parameters_for_validation[gate_name]:
                if key in self.nodetype.gate_defaults:
                    try:
                        gate_parameters[gate_name][key] = float(
                            gate_parameters[gate_name][key])
                    except:
                        self.logger.warn(
                            'Invalid gate parameter value for gate %s, param %s, node %s'
                            % (gate_name, key, self.uid))
                        gate_parameters[gate_name][
                            key] = self.nodetype.gate_defaults[gate_name].get(
                                key, 0)
                else:
                    gate_parameters[gate_name][key] = float(
                        gate_parameters[gate_name][key])

        for gate in self.nodetype.gatetypes:
            if gate not in gate_functions:
                self.__gatefunctions[gate] = gatefunctions.identity
            else:
                self.__gatefunctions[gate] = getattr(gatefunctions,
                                                     gate_functions[gate])
            if gate_activations is None or gate not in gate_activations:
                sheaves_to_use = None
            else:
                sheaves_to_use = gate_activations[gate]
            self.__gates[gate] = DictGate(gate,
                                          self,
                                          sheaves=sheaves_to_use,
                                          parameters=gate_parameters.get(gate))
        for slot in self.nodetype.slottypes:
            self.__slots[slot] = DictSlot(slot, self)
        if state:
            self.__state = state
        nodenet._register_node(self)
        self.sheaves = {"default": emptySheafElement.copy()}
        self.activation = activation
Exemplo n.º 7
0
    def __init__(self, nodenet, parent_nodespace, position, state=None, activation=0,
                 name="", type="Concept", uid=None, index=None, parameters=None, gate_parameters=None, gate_activations=None, **_):
        if not gate_parameters:
            gate_parameters = {}

        if nodenet.is_node(uid):
            raise KeyError("Node with uid %s already exists" % uid)

        Node.__init__(self, type, nodenet.get_nodetype(type))

        NetEntity.__init__(self, nodenet, parent_nodespace, position,
            name=name, entitytype="nodes", uid=uid, index=index)

        self.__non_default_gate_parameters = {}

        self.__state = {}

        self.__gates = {}
        self.__slots = {}

        self.__parameters = dict((key, None) for key in self.nodetype.parameters)
        if parameters is not None:
            for key in parameters:
                self.set_parameter(key, parameters[key])

        for gate_name in gate_parameters:
            for key in gate_parameters[gate_name]:
                if gate_parameters[gate_name][key] != self.nodetype.gate_defaults.get(key, None):
                    if gate_name not in self.__non_default_gate_parameters:
                        self.__non_default_gate_parameters[gate_name] = {}
                    self.__non_default_gate_parameters[gate_name][key] = gate_parameters[gate_name][key]

        gate_parameters = copy.deepcopy(self.nodetype.gate_defaults)
        for gate_name in gate_parameters:
            if gate_name in self.__non_default_gate_parameters:
                gate_parameters[gate_name].update(self.__non_default_gate_parameters[gate_name])

        gate_parameters_for_validation = copy.deepcopy(gate_parameters)
        for gate_name in gate_parameters_for_validation:
            for key in gate_parameters_for_validation[gate_name]:
                if key in self.nodetype.gate_defaults:
                    try:
                        gate_parameters[gate_name][key] = float(gate_parameters[gate_name][key])
                    except:
                        logging.getLogger('nodenet').warn('Invalid gate parameter value for gate %s, param %s, node %s' % (gate_name, key, self.uid))
                        gate_parameters[gate_name][key] = self.nodetype.gate_defaults[gate_name].get(key, 0)
                else:
                    gate_parameters[gate_name][key] = float(gate_parameters[gate_name][key])

        for gate in self.nodetype.gatetypes:
            if gate_activations is None or gate not in gate_activations:
                sheaves_to_use = None
            else:
                sheaves_to_use = gate_activations[gate]
            self.__gates[gate] = DictGate(gate, self, sheaves=sheaves_to_use, gate_function=None, parameters=gate_parameters.get(gate))
        for slot in self.nodetype.slottypes:
            self.__slots[slot] = DictSlot(slot, self)
        if state:
            self.__state = state
        nodenet._register_node(self)
        self.sheaves = {"default": emptySheafElement.copy()}

        self.activation = activation