本文整理汇总了Python中nengo.builder.signal.SignalDict.reset方法的典型用法代码示例。如果您正苦于以下问题:Python SignalDict.reset方法的具体用法?Python SignalDict.reset怎么用?Python SignalDict.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nengo.builder.signal.SignalDict
的用法示例。
在下文中一共展示了SignalDict.reset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_signaldict_reset
# 需要导入模块: from nengo.builder.signal import SignalDict [as 别名]
# 或者: from nengo.builder.signal.SignalDict import reset [as 别名]
def test_signaldict_reset():
"""Tests SignalDict's reset function."""
signaldict = SignalDict()
two_d = Signal([[1], [1]])
signaldict.init(two_d)
two_d_view = two_d[0, :]
signaldict[two_d_view] = -0.5
assert np.allclose(signaldict[two_d], np.array([[-0.5], [1]]))
signaldict[two_d] = np.array([[-1], [-1]])
assert np.allclose(signaldict[two_d], np.array([[-1], [-1]]))
assert np.allclose(signaldict[two_d_view], np.array([-1]))
signaldict.reset(two_d_view)
assert np.allclose(signaldict[two_d_view], np.array([1]))
assert np.allclose(signaldict[two_d], np.array([[1], [-1]]))
signaldict.reset(two_d)
assert np.allclose(signaldict[two_d], np.array([[1], [1]]))
示例2: Simulator
# 需要导入模块: from nengo.builder.signal import SignalDict [as 别名]
# 或者: from nengo.builder.signal.SignalDict import reset [as 别名]
class Simulator(object):
"""Reference simulator for Nengo models."""
def __init__(self, network, dt=0.001, seed=None, model=None):
"""Initialize the simulator with a network and (optionally) a model.
Most of the time, you will pass in a network and sometimes a dt::
sim1 = nengo.Simulator(my_network) # Uses default 0.001s dt
sim2 = nengo.Simulator(my_network, dt=0.01) # Uses 0.01s dt
For more advanced use cases, you can initialize the model yourself,
and also pass in a network that will be built into the same model
that you pass in::
sim = nengo.Simulator(my_network, model=my_model)
If you want full control over the build process, then you can build
your network into the model manually. If you do this, then you must
explicitly pass in ``None`` for the network::
sim = nengo.Simulator(None, model=my_model)
Parameters
----------
network : nengo.Network instance or None
A network object to the built and then simulated.
If a fully built ``model`` is passed in, then you can skip
building the network by passing in network=None.
dt : float, optional
The length of a simulator timestep, in seconds.
seed : int, optional
A seed for all stochastic operators used in this simulator.
model : nengo.builder.Model instance or None, optional
A model object that contains build artifacts to be simulated.
Usually the simulator will build this model for you; however,
if you want to build the network manually, or to inject some
build artifacts in the Model before building the network,
then you can pass in a ``nengo.builder.Model`` instance.
"""
if model is None:
dt = float(dt) # make sure it's a float (for division purposes)
self.model = Model(dt=dt,
label="%s, dt=%f" % (network, dt),
decoder_cache=get_default_decoder_cache())
else:
self.model = model
if network is not None:
# Build the network into the model
self.model.build(network)
self.model.decoder_cache.shrink()
# -- map from Signal.base -> ndarray
self.signals = SignalDict(__time__=np.asarray(0.0, dtype=np.float64))
for op in self.model.operators:
op.init_signals(self.signals)
# Order the steps (they are made in `Simulator.reset`)
self.dg = operator_depencency_graph(self.model.operators)
self._step_order = [op for op in toposort(self.dg)
if hasattr(op, 'make_step')]
# Add built states to the probe dictionary
self._probe_outputs = self.model.params
# Provide a nicer interface to probe outputs
self.data = ProbeDict(self._probe_outputs)
seed = np.random.randint(npext.maxint) if seed is None else seed
self.reset(seed=seed)
@property
def dt(self):
"""The time step of the simulator"""
return self.model.dt
@dt.setter
def dt(self, dummy):
raise AttributeError("Cannot change simulator 'dt'. Please file "
"an issue at http://github.com/nengo/nengo"
"/issues and describe your use case.")
@property
def time(self):
"""The current time of the simulator"""
return self.signals['__time__'].copy()
def trange(self, dt=None):
"""Create a range of times matching probe data.
Note that the range does not start at 0 as one might expect, but at
the first timestep (i.e., dt).
Parameters
----------
dt : float (optional)
The sampling period of the probe to create a range for. If empty,
will use the default probe sampling period.
#.........这里部分代码省略.........
示例3: Simulator
# 需要导入模块: from nengo.builder.signal import SignalDict [as 别名]
# 或者: from nengo.builder.signal.SignalDict import reset [as 别名]
class Simulator(object):
"""Reference simulator for Nengo models."""
def __init__(self, network, dt=0.001, seed=None, model=None):
"""Initialize the simulator with a network and (optionally) a model.
Most of the time, you will pass in a network and sometimes a dt::
sim1 = nengo.Simulator(my_network) # Uses default 0.001s dt
sim2 = nengo.Simulator(my_network, dt=0.01) # Uses 0.01s dt
For more advanced use cases, you can initialize the model yourself,
and also pass in a network that will be built into the same model
that you pass in::
sim = nengo.Simulator(my_network, model=my_model)
If you want full control over the build process, then you can build
your network into the model manually. If you do this, then you must
explicitly pass in ``None`` for the network::
sim = nengo.Simulator(None, model=my_model)
Parameters
----------
network : nengo.Network instance or None
A network object to the built and then simulated.
If a fully built ``model`` is passed in, then you can skip
building the network by passing in network=None.
dt : float
The length of a simulator timestep, in seconds.
seed : int
A seed for all stochastic operators used in this simulator.
Note that there are not stochastic operators implemented
currently, so this parameters does nothing.
model : nengo.builder.Model instance or None
A model object that contains build artifacts to be simulated.
Usually the simulator will build this model for you; however,
if you want to build the network manually, or to inject some
build artifacts in the Model before building the network,
then you can pass in a ``nengo.builder.Model`` instance.
"""
dt = float(dt) # make sure it's a float (for division purposes)
if model is None:
self.model = Model(dt=dt,
label="%s, dt=%f" % (network, dt),
decoder_cache=get_default_decoder_cache())
else:
self.model = model
if network is not None:
# Build the network into the model
self.model.build(network)
self.model.decoder_cache.shrink()
self.seed = np.random.randint(npext.maxint) if seed is None else seed
self.rng = np.random.RandomState(self.seed)
# -- map from Signal.base -> ndarray
self.signals = SignalDict(__time__=np.asarray(0.0, dtype=np.float64))
for op in self.model.operators:
op.init_signals(self.signals)
self.dg = operator_depencency_graph(self.model.operators)
self._step_order = [node for node in toposort(self.dg)
if hasattr(node, 'make_step')]
self._steps = [node.make_step(self.signals, dt, self.rng)
for node in self._step_order]
# Add built states to the probe dictionary
self._probe_outputs = self.model.params
# Provide a nicer interface to probe outputs
self.data = ProbeDict(self._probe_outputs)
self.reset()
@property
def dt(self):
"""The time step of the simulator"""
return self.model.dt
@dt.setter
def dt(self, dummy):
raise AttributeError("Cannot change simulator 'dt'. Please file "
"an issue at http://github.com/ctn-waterloo/nengo"
"/issues and describe your use case.")
@property
def time(self):
"""The current time of the simulator"""
return self.signals['__time__'].copy()
def trange(self, dt=None):
"""Create a range of times matching probe data.
Parameters
----------
#.........这里部分代码省略.........
示例4: Simulator
# 需要导入模块: from nengo.builder.signal import SignalDict [as 别名]
# 或者: from nengo.builder.signal.SignalDict import reset [as 别名]
class Simulator(object):
"""Reference simulator for Nengo models.
The simulator takes a `.Network` and builds internal data structures to
run the model defined by that network. Run the simulator with the
`~.Simulator.run` method, and access probed data through the
``data`` attribute.
Building and running the simulation may allocate resources like files
and sockets. To properly free these resources, call the `.Simulator.close`
method. Alternatively, `.Simulator.close` will automatically be called
if you use the ``with`` syntax::
with nengo.Simulator(my_network) as sim:
sim.run(0.1)
print(sim.data[my_probe])
Note that the ``data`` attribute is still accessible even when a simulator
has been closed. Running the simulator, however, will raise an error.
Parameters
----------
network : Network or None
A network object to be built and then simulated. If None,
then a `.Model` with the build model must be provided instead.
dt : float, optional (Default: 0.001)
The length of a simulator timestep, in seconds.
seed : int, optional (Default: None)
A seed for all stochastic operators used in this simulator.
model : Model, optional (Default: None)
A `.Model` that contains build artifacts to be simulated.
Usually the simulator will build this model for you; however, if you
want to build the network manually, or you want to inject build
artifacts in the model before building the network, then you can
pass in a `.Model` instance.
Attributes
----------
closed : bool
Whether the simulator has been closed.
Once closed, it cannot be reopened.
data : ProbeDict
The `.ProbeDict` mapping from Nengo objects to the data associated
with those objects. In particular, each `.Probe` maps to the data
probed while running the simulation.
dg : dict
A dependency graph mapping from each `.Operator` to the operators
that depend on that operator.
model : Model
The `.Model` containing the signals and operators necessary to
simulate the network.
signals : SignalDict
The `.SignalDict` mapping from `.Signal` instances to NumPy arrays.
"""
# 'unsupported' defines features unsupported by a simulator.
# The format is a list of tuples of the form `(test, reason)` with `test`
# being a string with wildcards (*, ?, [abc], [!abc]) matched against Nengo
# test paths and names, and `reason` is a string describing why the feature
# is not supported by the backend. For example:
# unsupported = [('test_pes*', 'PES rule not implemented')]
# would skip all test whose names start with 'test_pes'.
unsupported = []
def __init__(self, network, dt=0.001, seed=None, model=None):
self.closed = False
if model is None:
dt = float(dt) # make sure it's a float (for division purposes)
self.model = Model(dt=dt,
label="%s, dt=%f" % (network, dt),
decoder_cache=get_default_decoder_cache())
else:
self.model = model
if network is not None:
# Build the network into the model
self.model.build(network)
self.model.decoder_cache.shrink()
# -- map from Signal.base -> ndarray
self.signals = SignalDict()
for op in self.model.operators:
op.init_signals(self.signals)
# Order the steps (they are made in `Simulator.reset`)
self.dg = operator_depencency_graph(self.model.operators)
self._step_order = [op for op in toposort(self.dg)
if hasattr(op, 'make_step')]
# Add built states to the probe dictionary
self._probe_outputs = self.model.params
# Provide a nicer interface to probe outputs
self.data = ProbeDict(self._probe_outputs)
seed = np.random.randint(npext.maxint) if seed is None else seed
self.reset(seed=seed)
#.........这里部分代码省略.........
示例5: Simulator
# 需要导入模块: from nengo.builder.signal import SignalDict [as 别名]
# 或者: from nengo.builder.signal.SignalDict import reset [as 别名]
class Simulator(object):
"""Reference simulator for Nengo models."""
# 'unsupported' defines features unsupported by a simulator.
# The format is a list of tuples of the form `(test, reason)` with `test`
# being a string with wildcards (*, ?, [abc], [!abc]) matched against Nengo
# test paths and names, and `reason` is a string describing why the feature
# is not supported by the backend. For example:
# unsupported = [('test_pes*', 'PES rule not implemented')]
# would skip all test whose names start with 'test_pes'.
unsupported = []
def __init__(self, network, dt=0.001, seed=None, model=None):
"""Initialize the simulator with a network and (optionally) a model.
Most of the time, you will pass in a network and sometimes a dt::
sim1 = nengo.Simulator(my_network) # Uses default 0.001s dt
sim2 = nengo.Simulator(my_network, dt=0.01) # Uses 0.01s dt
For more advanced use cases, you can initialize the model yourself,
and also pass in a network that will be built into the same model
that you pass in::
sim = nengo.Simulator(my_network, model=my_model)
If you want full control over the build process, then you can build
your network into the model manually. If you do this, then you must
explicitly pass in ``None`` for the network::
sim = nengo.Simulator(None, model=my_model)
Parameters
----------
network : nengo.Network instance or None
A network object to the built and then simulated.
If a fully built ``model`` is passed in, then you can skip
building the network by passing in network=None.
dt : float, optional
The length of a simulator timestep, in seconds.
seed : int, optional
A seed for all stochastic operators used in this simulator.
model : nengo.builder.Model instance or None, optional
A model object that contains build artifacts to be simulated.
Usually the simulator will build this model for you; however,
if you want to build the network manually, or to inject some
build artifacts in the Model before building the network,
then you can pass in a ``nengo.builder.Model`` instance.
"""
self.closed = False
if model is None:
dt = float(dt) # make sure it's a float (for division purposes)
self.model = Model(dt=dt,
label="%s, dt=%f" % (network, dt),
decoder_cache=get_default_decoder_cache())
else:
self.model = model
if network is not None:
# Build the network into the model
self.model.build(network)
self.model.decoder_cache.shrink()
# -- map from Signal.base -> ndarray
self.signals = SignalDict()
for op in self.model.operators:
op.init_signals(self.signals)
# Order the steps (they are made in `Simulator.reset`)
self.dg = operator_depencency_graph(self.model.operators)
self._step_order = [op for op in toposort(self.dg)
if hasattr(op, 'make_step')]
# Add built states to the probe dictionary
self._probe_outputs = self.model.params
# Provide a nicer interface to probe outputs
self.data = ProbeDict(self._probe_outputs)
seed = np.random.randint(npext.maxint) if seed is None else seed
self.reset(seed=seed)
def __del__(self):
"""Raise a ResourceWarning if we are deallocated while open."""
if not self.closed:
warnings.warn(
"Simulator with model=%s was deallocated while open. Please "
"close simulators manually to ensure resources are properly "
"freed." % self.model, ResourceWarning)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
@property
def dt(self):
#.........这里部分代码省略.........