def update(self, value, dt=1.0):
        check_all_finite(value)

        if self.accum is None:
            self.accum = value * dt
            self.accum_mass = dt
            self.needs_normalization = True
            self.buf = np.empty_like(value)
            self.buf.fill(np.NaN)
            self.result = np.empty_like(value)
            self.result.fill(np.NaN)
        else:
            if self.extremely_fast:
                np.multiply(value, dt, self.buf)  # buf = value * dt
                np.add(self.buf, self.accum, self.accum)  # accum += buf
            else:
                self.buf = value * dt
                self.accum += self.buf

            self.needs_normalization = True
            self.accum_mass += dt

        if self.max_window and self.accum_mass > self.max_window:
            self.accum = self.max_window * self.get_value()
            self.accum_mass = self.max_window

        
        # Do not let pass too much before normalization
        if self.accum_mass > ExpectationFast.MAX_MASS:
            self.get_value()
    def update(self, y, u, y_dot, w):
        self.once = True
        self.nsamples += 1
        
        check_all_finite(y)
        check_all_finite(u)
        check_all_finite(y_dot)
        check_all_finite(w)
        
        self.n = y.size
        self.k = u.size   

        self.y_stats.update(y)  # TODO: make robust 
        self.u_stats.update(u)
        
        # remove mean
        u_n = u - self.u_stats.get_mean()
        self.y_mean.update(y, w)  # TODO: make robust
        y_n = y - self.y_mean.get_value(fill_value=0.5)
        
        # weights
        y_n_w = w
        y_dot_w = w
        u_n_w = np.ones(u.shape)
        
        T_k = outer(outer(y_n, y_dot), u_n)
        T_k_w = outer(outer(y_n_w, y_dot_w), u_n_w)
        
        U_k = outer(y_dot, u_n)
        U_k_w = outer(y_dot_w, u_n_w) 

        assert T_k.shape == (self.n, self.n, self.k)
        assert U_k.shape == (self.n, self.k)
        
        # update tensor
        self.T.update(T_k, T_k_w)
        self.U.update(U_k, U_k_w)
    def update(self, y, y_dot, u, w):
        self.once = True
        
        M = y.shape[0]
        check_all_finite(y)
        check_all_finite(y_dot)
        check_all_finite(u)
        # TODO: check shape is conserved
        self.is1D = y.ndim == 1
        self.is2D = y.ndim == 2
 
        gy = generalized_gradient(y)
  
        y_dot_w = w
        u_w = np.ones(u.shape)         
        gy_w = w.reshape((1, M)) 
        assert gy.shape == gy_w.shape
        
        Qi = outer(u, u)
        Qi_w = outer(u_w, u_w)
        self.Q.update(Qi, Qi_w)
        
        Pi = outer_first_dim(gy)
        Pi_w = outer_first_dim(gy_w)
         
        self.P.update(Pi, Pi_w)
        self.R_needs_update = True
 
        Gi = outer(u, gy * y_dot)
        Gi_w = outer(u_w, gy_w * y_dot_w)
        
        self.G.update(Gi, Gi_w)
        self.H_needs_update = True
 
        Bk = outer(u, y_dot)
        Bk_w = outer(u_w, y_dot_w)
        self.B.update(Bk, Bk_w)
        self.C_needs_update = True
 
        self.last_y = y
        self.last_gy = gy
        self.last_y_dot = y_dot
        self.last_u = u
        self.last_w = w