def process_observations(self, obs): y = obs['observations'] n = y.size # # XXX # which = np.array(range(y.size)) < 100 # y[which] = (y * y)[which] dt = obs['dt'].item() z = y == 0 y[z] = 0.5 yy = outer(y, y) dt = 1 logy = np.log(y) # TMP logy = y * y # logy[:int(n / 4)] = y[:int(n / 4)] ylogy = outer(logy, y) self.yy.update(yy, dt) self.ylogy.update(ylogy, dt) invy = 1.0 / y self.einvy.update(invy, dt) self.ey.update(y, dt) self.elogy.update(logy, dt) self.covy.update(y, dt) self.covfy.update(logy, dt)
def update(self, value, dt=1.0): self.num_samples += dt n = value.size if self.maximum is None: self.maximum = value.copy() self.minimum = value.copy() self.P_t = np.zeros(shape=(n, n), dtype=value.dtype) else: # TODO: check dimensions if not (value.shape == self.maximum.shape): raise ValueError('Value shape changed: %s -> %s' % (self.maximum.shape, value.shape)) self.maximum = np.maximum(value, self.maximum) self.minimum = np.minimum(value, self.minimum) self.mean_accum.update(value, dt) mean = self.mean_accum.get_value() value_norm = value - mean P = outer(value_norm, value_norm) self.covariance_accum.update(P, dt) self.last_value = value