Time Domain Simulation - update differential equations
761741
def _compile_int_f(self):
        """"""
        string = '"""\n'
        string += 'system.dae.init_f()\n'

        # evaluate differential equations f
        for fcall, call in zip(self.fcall, self.fcalls):
            if fcall:
                string += call
        string += 'system.dae.reset_small_f()\n'
        string += '"""'
        self.int_f = compile(eval(string), '', 'exec')
201679
def update(self):
        
        con = self.subpars.pars.control
        self(con.eqd2*con.tind)
1253345
def modelstandardfunctions(self):
        """"""
        lines = Lines()
        lines.extend(self.doit)
        lines.extend(self.iofunctions)
        lines.extend(self.new2old)
        lines.extend(self.run)
        lines.extend(self.update_inlets)
        lines.extend(self.update_outlets)
        lines.extend(self.update_receivers)
        lines.extend(self.update_senders)
        return lines
114641
def _update(self):
        

        """
        # Step 4 from alg. 3
        self._grad.get_grad(self._x_old)
        self._u_new = self._x_old - self._beta * self._grad.grad

        # Step 5 from alg. 3
        self._t_new = 0.5 * (1 + np.sqrt(1 + 4 * self._t_old**2))

        # Step 6 from alg. 3
        t_shifted_ratio = (self._t_old - 1) / self._t_new
        sigma_t_ratio = self._sigma * self._t_old / self._t_new
        beta_xi_t_shifted_ratio = t_shifted_ratio * self._beta / self._xi
        self._z = - beta_xi_t_shifted_ratio * (self._x_old - self._z)
        self._z += self._u_new
        self._z += t_shifted_ratio * (self._u_new - self._u_old)
        self._z += sigma_t_ratio * (self._u_new - self._x_old)

        # Step 7 from alg. 3
        self._xi = self._beta * (1 + t_shifted_ratio + sigma_t_ratio)

        # Step 8 from alg. 3
        self._x_new = self._prox.op(self._z, extra_factor=self._xi)

        # Restarting and gamma-Decreasing
        # Step 9 from alg. 3
        self._g_new = self._grad.grad - (self._x_new - self._z) / self._xi

        # Step 10 from alg 3.
        self._y_new = self._x_old - self._beta * self._g_new

        # Step 11 from alg. 3
        restart_crit = np.vdot(- self._g_new, self._y_new - self._y_old) < 0
        if restart_crit:
            self._t_new = 1
            self._sigma = 1

        # Step 13 from alg. 3
        elif np.vdot(self._g_new, self._g_old) < 0:
            self._sigma *= self._sigma_bar

        # updating variables
        self._t_old = self._t_new
        np.copyto(self._u_old, self._u_new)
        np.copyto(self._x_old, self._x_new)
        np.copyto(self._g_old, self._g_new)
        np.copyto(self._y_old, self._y_new)

        # Test cost function for convergence.
        if self._cost_func:
            self.converge = self.any_convergence_flag() or \
                            self._cost_func.get_cost(self._x_new)
398697
def PartialDynamicSystem(self, ieq, variable):
        

        if ieq == 0:

            #            if variable==self.physical_nodes[0].variable:
            # print('1')
            #                # U1 is output
            #                # U1=i1/pC+U2
            #                Uc=Variable(hidden=True)
            #                block1=ODE(self.variables[0],Uc,[1],[0,self.C])
            #                sub1=Sum([self.physical_nodes[1].variable,Uc],variable)
            #                return [block1,sub1]
            #            elif variable==self.physical_nodes[1].variable:
            #                print('2')
            #                # U2 is output
            #                # U2=U1-i1/pC
            #                Uc=Variable(hidden=True)
            #                block1=ODE(self.variables[0],Uc,[-1],[0,self.C])
            #                sum1=Sum([self.physical_nodes[0].variable,Uc],variable)
            #                return [block1,sum1]
            if variable == self.variables[0]:  # i1=(u1-u2)/Lp
                print('3')
                # i1 is output
                # i1=pC(U1-U2)
                Uc = Variable(hidden=True)
                subs1 = Subtraction(
                    self.physical_nodes[0].variable, self.physical_nodes[1].variable, Uc)
                block1 = ODE(Uc, variable, [1], [0, self.L])
                return [block1, subs1]
        elif ieq == 1:
            # i1=-i2
            if variable == self.variables[0]:
                # i1 as output
                return [Gain(self.variables[1], self.variables[0], -1)]
            elif variable == self.variables[1]:
                # i2 as output
                return [Gain(self.variables[0], self.variables[1], -1)]
434682
def _updateA(X, A, R, P, Z, lmbdaA, orthogonalize):
    """"""
    n, rank = A.shape
    F = zeros((n, rank), dtype=A.dtype)
    E = zeros((rank, rank), dtype=A.dtype)

    AtA = dot(A.T, A)

    for i in range(len(X)):
        F += X[i].dot(dot(A, R[i].T)) + X[i].T.dot(dot(A, R[i]))
        E += dot(R[i], dot(AtA, R[i].T)) + dot(R[i].T, dot(AtA, R[i]))

    # regularization
    I = lmbdaA * eye(rank, dtype=A.dtype)

    # attributes
    for i in range(len(Z)):
        F += P[i].dot(Z[i].T)
        E += dot(Z[i], Z[i].T)

    # finally compute update for A
    A = solve(I + E.T, F.T).T
    return orth(A) if orthogonalize else A
1062964
def _update_phi(self):
        """"""
        self.phi = self._compute_empirical_phi(self.beta)
        _checkParam('phi', self.phi, self.PARAMLIMITS, self.PARAMTYPES)
        self._eta_from_phi()
        dbeta = 1.0e-3
        self.dphi_dbeta = scipy.misc.derivative(self._compute_empirical_phi,
                self.beta, dx=dbeta, n=1, order=5)
        dphi_dbeta_halfdx = scipy.misc.derivative(self._compute_empirical_phi,
                self.beta, dx=dbeta / 2, n=1, order=5)
        assert scipy.allclose(self.dphi_dbeta, dphi_dbeta_halfdx, atol=1e-5,
                rtol=1e-4), ("The numerical derivative dphi_dbeta differs "
                "considerably in value for step dbeta = {0} and a step "
                "half that size, giving values of {1} and {2}.").format(
                dbeta, self.dphi_dbeta, dphi_dbeta_halfdx)
137405
def update_computed_intervals(sinks, time_interval):
        
        for sink in sinks:
            sink.calculated_intervals += time_interval
            required_intervals = TimeIntervals([time_interval]) - sink.calculated_intervals
            if not required_intervals.is_empty:
                raise RuntimeError('Tool execution did not cover the time interval {}'
                                   .format(required_intervals))
1129753
def dtcurrent(self, value):
        """"""
        assert isinstance(value, bool)
        if value and self.dparamscurrent:
            raise RuntimeError("Can't set both dparamscurrent and dtcurrent True")
        if value != self.dtcurrent:
            self._dtcurrent = value
            self._updateInternals()
948059
function () {
        this.update = {
            velocity: function (entity, dt) {
                entity.c.position.x += hitagi.utils.delta(entity.c.velocity.xspeed, dt);
            }
        };
    }
1198237
def _integrate_fixed_trajectory(self, h, T, step, relax):
        """"""
        # initialize the solution using initial condition
        solution = np.hstack((self.t, self.y))

        while self.successful():

            self.integrate(self.t + h, step, relax)
            current_step = np.hstack((self.t, self.y))
            solution = np.vstack((solution, current_step))

            if (h > 0) and (self.t >= T):
                break
            elif (h < 0) and (self.t <= T):
                break
            else:
                continue

        return solution
1273057
function () {
			// generate random solution to t-SNE
			this.Y = randn2d(this.N, this.dim); // the solution
			this.gains = randn2d(this.N, this.dim, 1.0); // step gains to accelerate progress in unchanging directions
			this.ystep = randn2d(this.N, this.dim, 0.0); // momentum accumulator
			this.iter = 0;
		}
534290
def lm_deltaf(damping_times, modes):
    

    df = {}
    for lmn in modes:
        l, m, nmodes = int(lmn[0]), int(lmn[1]), int(lmn[2])
        for n in range(nmodes):
            df['%d%d%d' %(l,m,n)] = \
                1. / qnm_time_decay(damping_times['%d%d%d' %(l,m,n)], 1./1000)

    return min(df.values())
817564
def update(self):
        """"""
        # Update the simulated pricing data
        self.t += 1000 / INTERVAL
        self.average *= np.random.lognormal(0, 0.04)

        high = self.average * np.exp(np.abs(np.random.gamma(1, 0.03)))
        low = self.average / np.exp(np.abs(np.random.gamma(1, 0.03)))
        delta = high - low
        open = low + delta * np.random.uniform(0.05, 0.95)
        close = low + delta * np.random.uniform(0.05, 0.95)
        color = "darkgreen" if open < close else "darkred"

        for k, point in [('time', self.t),
                         ('average', self.average),
                         ('open', open),
                         ('high', high),
                         ('low', low),
                         ('close', close),
                         ('color', color)]:
            self.data[k].append(point)

        ema12 = self._ema(self.data['close'], self.kernel12)
        ema26 = self._ema(self.data['close'], self.kernel26)
        macd = ema12 - ema26

        self.data['ma'].append(ema12)
        self.data['macd'].append(macd)

        macd9 = self._ema(self.data['macd'], self.kernel9)

        self.data['macd9'].append(macd9)
        self.data['macdh'].append(macd - macd9)
1046551
def to_ode(self) -> HybridOde:
        """"""
        res_split = split_dae_alg(self.f_x, self.dx)
        alg = res_split['alg']
        dae = res_split['dae']

        x_rhs = tangent_approx(dae, self.dx, assert_linear=True)
        y_rhs = tangent_approx(alg, self.y, assert_linear=True)

        return HybridOde(
            c=self.c,
            dx=self.dx,
            f_c=self.f_c,
            f_i=self.f_i,
            f_m=self.f_m,
            f_x_rhs=x_rhs,
            y_rhs=y_rhs,
            m=self.m,
            ng=self.ng,
            nu=self.nu,
            p=self.p,
            pre_m=self.pre_m,
            pre_c=self.pre_c,
            prop=self.prop,
            sym=self.sym,
            t=self.t,
            x=self.x,
            y=self.y,
        )
1066930
def _update(self):
        

        """
        # Step 1 from eq.9.
        self._grad.get_grad(self._x_old)

        x_prox = self._prox.op(self._x_old - self._tau * self._grad.grad -
                               self._tau * self._linear.adj_op(self._y_old))

        # Step 2 from eq.9.
        y_temp = (self._y_old + self._sigma *
                  self._linear.op(2 * x_prox - self._x_old))

        y_prox = (y_temp - self._sigma * self._prox_dual.op(y_temp /
                  self._sigma, extra_factor=(1.0 / self._sigma)))

        # Step 3 from eq.9.
        self._x_new = self._rho * x_prox + (1 - self._rho) * self._x_old
        self._y_new = self._rho * y_prox + (1 - self._rho) * self._y_old

        del x_prox, y_prox, y_temp

        # Update old values for next iteration.
        np.copyto(self._x_old, self._x_new)
        np.copyto(self._y_old, self._y_new)

        # Update parameter values for next iteration.
        self._update_param()

        # Test cost function for convergence.
        if self._cost_func:
            self.converge = self.any_convergence_flag() or\
                            self._cost_func.get_cost(self._x_new, self._y_new)
179023
def update(self):
        """"""
        if self.single_channel:
            self.im.set_data(self.data[self.ind, :, :])
        else:
            self.im.set_data(self.data[self.ind, :, :, :])
        self.ax.set_ylabel('time frame %s' % self.ind)
        self.im.axes.figure.canvas.draw()