def update(self, value): if self.maximum is None: self.maximum = value else: self.maximum = numpy.maximum(value, self.maximum) if self.minimum is None: self.minimum = value else: self.minimum = numpy.minimum(value, self.minimum) self.mean_accum.update(value) self.mean = self.mean_accum.get_value() value_norm = value - self.mean P = outer(value_norm, value_norm) self.covariance_accum.update(P) self.covariance = self.covariance_accum.get_value() try: self.information = pinv(self.covariance, rcond=1e-2) except LinAlgError: filename = "pinv-failure" with open(filename + ".pickle", "w") as f: self.last_value = value pickle.dump(self, f) raise JobFailed("Did not converge; saved on %s" % filename)
def process_data(self, data): y = data.sensels y_dot = data.sensels_dot u = data.commands # n = y.shape[0] # k = u.shape[0] self.y_dot_stats.update(y_dot) self.y_stats.update(y) self.u_stats.update(u) y_norm = dot(self.y_stats.information, y - self.y_stats.mean) u_norm = dot(self.u_stats.information, u - self.u_stats.mean) # Assuming model of the form: # # y_dot = mu + M y + N u + T(y,u) # # assuming that mu = 0 and M = 0 # # Then: # N = E{ y_dot u~ } Ns = outer(y_dot, u_norm) self.N.update(Ns) N = self.N.get_value() Nu = dot(N, u) Ts = outer(u_norm, outer(y_norm, y_dot - Nu)) self.T.update(Ts) # this assumes the normal bilinear model bT = outer(u_norm, outer(y - self.y_stats.mean, y_dot)) self.bT.update(bT) # this assumes the normal bilinear model bTn = outer(u_norm, outer(y_norm, y_dot)) self.bTn.update(bTn)