def __init__(self, nodenet, partition, parent_uid, uid, type, parameters={}, **_): self._numerictype = type self._id = node_from_id(uid) self._uid = uid self._parent_id = nodespace_from_id(parent_uid) self._nodenet = nodenet self._partition = partition self._state = {} self.__gatecache = {} self.__slotcache = {} self.parameters = None strtype = get_string_node_type(type, nodenet.native_modules) Node.__init__(self, strtype, nodenet.get_nodetype(strtype)) if strtype in nodenet.native_modules or strtype == "Comment": self.slot_activation_snapshot = {} self._state = {} if parameters is not None: self.parameters = parameters.copy() else: self.parameters = {}
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)
def __init__(self, nodenet, partition, parent_uid, uid, numerictype, parameters={}, **_): self._numerictype = numerictype self._id = node_from_id(uid) self._uid = uid self._parent_id = nodespace_from_id(parent_uid) self._partition = partition self._state = {} self.__gatecache = {} self.__slotcache = {} self.parameters = None strtype = get_string_node_type(numerictype, nodenet.native_modules) Node.__init__(self, nodenet, strtype, nodenet.get_nodetype(strtype)) self.is_highdimensional = type(self._nodetype) == HighdimensionalNodetype self.datafile = os.path.join(nodenet.persistency_path, '%s_node_%s.npz' % (self._nodenet.uid, self.uid)) if strtype in nodenet.native_modules or strtype == "Comment": self.slot_activation_snapshot = {} self.take_slot_activation_snapshot() self._state = {} if parameters is not None: self.parameters = parameters.copy() else: self.parameters = {} if self.is_highdimensional: self.slot_fat_snapshot = None
def __init__(self, nodenet, parent_uid, uid, type, parameters={}, **_): self._numerictype = type strtype = get_string_node_type(type, nodenet.native_modules) Node.__init__(self, strtype, nodenet.get_nodetype(strtype)) if strtype in nodenet.native_modules: self.slot_activation_snapshot = {} if parameters is not None: self.parameters = parameters.copy() else: self.parameters = {} self._nodenet = nodenet self._id = from_id(uid) self._parent_id = nodespace.from_id(parent_uid)
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
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