def test_add_at(self): ri = numpy.random.randint for nd in range(1, 5): m, n, rest = ri(3, 50), ri(51, 100), tuple(ri(3, 10, nd - 1)) source = ri(-100, 100, (n,) + rest) map = ri(0, m, n) expected, actual = numpy.zeros((2, m) + rest) numpy.add.at(expected, map, source) RefBase._add_at(actual, map, source) assert numpy.allclose(expected, actual)
def test_linear_interpolation(self): t_start = 0.0 t_end = 1.0 y_start = 4.0 y_end = 8.0 t_mid = 0.5 val = RefBase.linear_interp1d(t_start, t_end, y_start, y_end, t_mid) assert val == 6.0
def evaluate(self, var): """ Generate a discrete representation of the equation for the space represented by ``var``. """ _pattern = RefBase.evaluate(self.equation, global_dict=self.parameters) _pattern /= max(_pattern) _pattern *= self.parameters["a"] return _pattern
def evaluate(self, var): """ Generate a discrete representation of the equation for the space represented by ``var``. .. note: numexpr doesn't support gamma function """ # get gamma functions self.parameters["gamma_a_1"] = sp_gamma(self.parameters["a_1"]) self.parameters["gamma_a_2"] = sp_gamma(self.parameters["a_2"]) return RefBase.evaluate(self.equation, global_dict=self.parameters)
def evaluate(self, var): """ Generate a discrete representation of the equation for the space represented by ``var``. The argument ``var`` can represent a distance, or effective distance, for each node in a simulation. Or a time, or in principle any arbitrary `` space ``. ``var`` can be a single number, a numpy.ndarray or a ?scipy.sparse_matrix? TODO: think this last one is true, need to check as we need it for LocalConnectivity... """ ns = {'var': var} ns.update(self.parameters) return RefBase.evaluate(self.equation, ns)
def evaluate(self, var): """ Generate a discrete representation of the equation for the space represented by ``var``. .. note: numexpr doesn't support factorial yet """ # compute the factorial n = int(self.parameters["n"]) product = 1 for i in range(n - 1): product *= i + 1 self.parameters["factorial"] = product _pattern = RefBase.evaluate(self.equation, global_dict=self.parameters) _pattern /= max(_pattern) _pattern *= self.parameters["a"] return _pattern
def evaluate(self, var): """ Generate a discrete representation of the equation for the space represented by ``var``. The argument ``var`` can represent a distance, or effective distance, for each node in a simulation. Or a time, or in principle any arbitrary `` space ``. ``var`` can be a single number, a numpy.ndarray or a ?scipy.sparse_matrix? TODO: think this last one is true, need to check as we need it for LocalConnectivity... """ # rolling in the deep ... onset = self.parameters["onset"] off = var < onset var = numpy.roll(var, off.sum() + 1) var[..., off] = 0.0 _pattern = RefBase.evaluate(self.equation, global_dict=self.parameters) _pattern[..., off] = 0.0 return _pattern