Beispiel #1
0
    def __init__(
            self, stim_provider, items, contexts, n_pos, rng=None,
            extra_pos=3):
        super(Vocabularies, self).__init__()

        vocabs = Config.default(spa.Network, 'vocabs')
        if vocabs is None:
            vocabs = VocabularyMap(rng=rng)
        self.vocabs = vocabs

        self.items = items
        if is_integer(contexts):
            contexts = spa.Vocabulary(contexts, rng=rng)
        self.contexts = contexts
        self.positions = spa.Vocabulary(self.items.dimensions, rng=rng)

        self.items.populate(';'.join(stim_provider.get_all_items()))
        if stim_provider.n_distractors_per_epoch > 0:
            self.items.populate(';'.join(stim_provider.get_all_distractors()))

        for i in range(self.items.dimensions):
            self.contexts.populate('CTX' + str(i))

        for i in range(n_pos + extra_pos):
            self.positions.populate('P' + str(i))
Beispiel #2
0
 def coerce(self, conn, solver):
     if solver is ConnectionDefault:
         solver = Config.default(Connection, 'solver')
     solver = super().coerce(conn, solver)
     if solver is not None and solver.weights:
         raise ValidationError("weight solvers only work for ensemble to "
                               "ensemble connections, not probes",
                               attr=self.name, obj=conn)
     return solver
Beispiel #3
0
 def coerce(self, conn, solver):
     if solver is ConnectionDefault:
         solver = Config.default(Connection, 'solver')
     solver = super().coerce(conn, solver)
     if solver is not None and solver.weights:
         raise ValidationError(
             "weight solvers only work for ensemble to "
             "ensemble connections, not probes",
             attr=self.name,
             obj=conn)
     return solver
Beispiel #4
0
 def __setattr__(self, name, val):
     if hasattr(self, '_initialized') and not hasattr(self, name):
         warnings.warn(
             "Creating new attribute '%s' on '%s'. "
             "Did you mean to change an existing attribute?" % (name, self),
             SyntaxWarning)
     if val is Default:
         val = Config.default(type(self), name)
     try:
         super(NengoObject, self).__setattr__(name, val)
     except Exception as e:
         arg0 = '' if len(e.args) == 0 else e.args[0]
         arg0 = ("Validation error when setting '%s.%s': %s" %
                 (self.__class__.__name__, name, arg0))
         e.args = (arg0, ) + e.args[1:]
         raise
Beispiel #5
0
 def __setattr__(self, name, val):
     if hasattr(self, '_initialized') and not hasattr(self, name):
         warnings.warn(
             "Creating new attribute '%s' on '%s'. "
             "Did you mean to change an existing attribute?" % (name, self),
             SyntaxWarning)
     if val is Default:
         val = Config.default(type(self), name)
     try:
         super(NengoObject, self).__setattr__(name, val)
     except Exception as e:
         arg0 = '' if len(e.args) == 0 else e.args[0]
         arg0 = ("Validation error when setting '%s.%s': %s"
                 % (self.__class__.__name__, name, arg0))
         e.args = (arg0,) + e.args[1:]
         raise
Beispiel #6
0
    def __setattr__(self, name, val):
        if hasattr(self, '_initialized') and not hasattr(self, name):
            warnings.warn(
                "Creating new attribute '%s' on '%s'. "
                "Did you mean to change an existing attribute?" % (name, self),
                SyntaxWarning)
        if val is Default:
            val = Config.default(type(self), name)

        if rc.getboolean('exceptions', 'simplified'):
            try:
                super(NengoObject, self).__setattr__(name, val)
            except ValidationError:
                exc_info = sys.exc_info()
                reraise(exc_info[0], exc_info[1], None)
        else:
            super(NengoObject, self).__setattr__(name, val)
Beispiel #7
0
    def __setattr__(self, name, val):
        if hasattr(self, '_initialized') and not hasattr(self, name):
            warnings.warn(
                "Creating new attribute '%s' on '%s'. "
                "Did you mean to change an existing attribute?" % (name, self),
                SyntaxWarning)
        if val is Default:
            val = Config.default(type(self), name)

        if rc.getboolean('exceptions', 'simplified'):
            try:
                super(NengoObject, self).__setattr__(name, val)
            except ValidationError:
                exc_info = sys.exc_info()
                reraise(exc_info[0], exc_info[1], None)
        else:
            super(NengoObject, self).__setattr__(name, val)
    def __init__(self,
                 label=None,
                 seed=None,
                 add_to_container=None,
                 vocabs=None):
        super(Network, self).__init__(label, seed, add_to_container)
        self.config.configures(Network)

        if vocabs is None:
            vocabs = Config.default(Network, 'vocabs')
            if vocabs is None and len(Network.context) > 0:
                vocabs = self._master_vocabs.get(Network.context[0], None)
            if vocabs is None:
                if seed is not None:
                    rng = np.random.RandomState(seed)
                else:
                    rng = None
                vocabs = VocabularyMap(rng=rng)
                if len(Network.context) > 0:
                    self.__class__._master_vocabs[Network.context[0]] = vocabs
        self.vocabs = vocabs
        self.config[Network].vocabs = vocabs

        self._stimuli = None
Beispiel #9
0
 def coerce(self, conn, solver):  # pylint: disable=arguments-renamed
     if solver is ConnectionDefault:
         solver = Config.default(Connection, "solver")
     return super().coerce(conn, solver)
Beispiel #10
0
    def __set__(self, instance, value):
        if value is ConnectionDefault:
            value = Config.default(Connection, "solver")

        super(ProbeSolverParam, self).__set__(instance, value)
Beispiel #11
0
 def coerce(self, conn, solver):
     if solver is ConnectionDefault:
         solver = Config.default(Connection, "solver")
     return super().coerce(conn, solver)
Beispiel #12
0
    def __set__(self, instance, value):
        if value is ConnectionDefault:
            value = Config.default(Connection, 'solver')

        super(ProbeSolverParam, self).__set__(instance, value)