def test_json_dumps_loads(self): """ Tests class `MapAsJson.MapAsJsonEncoder` loads parameters correctly from JSON. """ input_parameters = {'a': 1, 'b': 1.0, 'c': 'd'} test_dict = { '1': 1, 'a': { '1': 'b' }, '2': { 'a': equations.Equation(parameters=input_parameters) } } json_string = json.dumps(test_dict, cls=MapAsJson.MapAsJsonEncoder) loaded_dict = json.loads(json_string, object_hook=MapAsJson.decode_map_as_json) eq_parameters = loaded_dict['2']['a'] assert input_parameters == eq_parameters.parameters, "parameters not loaded properly from json"
def test_equation(self): dt = equations.Equation() assert dt.parameters == {}
def test_equation(self): dt = equations.Equation() self.assertEqual(dt.parameters, {}) self.assertEqual(dt.ui_equation, '')
class Multiplicative(Noise): r""" With "external" fluctuations the intensity of the noise often depends on the state of the system. This results in the (general) stochastic differential formulation: .. math:: dX_t = a(X_t)\,dt + b(X_t)\,dW_t for appropriate coefficients :math:`a(x)` and :math:`b(x)`, which might be constants. From [KloedenPlaten_1995]_, Equation 1.9, page 104. .. automethod:: Multiplicative.__init__ .. automethod:: Multiplicative.gfun """ nsig = arrays.FloatArray( configurable_noise = True, label = ":math:`D`", required = True, default = numpy.array([1.0,]), order = 1, doc = """The noise dispersion, it is the standard deviation of the distribution from which the Gaussian random variates are drawn. NOTE: Sensible values are typically ~<< 1% of the dynamic range of a Model's state variables.""") b = equations.Equation( label = ":math:`b`", default = equations.Linear(parameters = {"a": 1.0, "b": 0.0}), doc = """A function evaluated on the state-variables, the result of which enters as the diffusion coefficient.""") def __init__(self, **kwargs): """Initialise a Multiplicative noise source.""" LOG.info('%s: initing...' % str(self)) super(Multiplicative, self).__init__(**kwargs) LOG.debug('%s: inited.' % repr(self)) def __str__(self): informal = "Multiplicative(**kwargs)" return informal def gfun(self, state_variables): """ Scale the noise by the noise dispersion and the diffusion coefficient. By default, the diffusion coefficient :math:`b` is a constant. It reduces to the simplest scheme of a linear SDE with Multiplicative Noise: homogeneous constant coefficients. See [KloedenPlaten_1995]_, Equation 4.6, page 119. """ self.b.pattern = state_variables g_x = numpy.sqrt(2.0 * self.nsig) * self.b.pattern return g_x
class SpatioTemporalPatternData(SpatialPatternData): """ Combine space and time equations. """ temporal = equations.Equation(label="Temporal Equation", order=3)