def sym_calc(self, Vp, m, s2): # Equation parameters equation = eq.Fokker_Planck_1d x, f = equation.x, equation.f # Calculation of the solution new_q = hm.Quad.gauss_hermite quad = new_q(self.n_points_num, dim=1, mean=[m], cov=[[s2]]) # Potential for approximation Vq = sym.Rational(1, 2) * (x - m) * (x - m) / (self.β * s2) # Fokker Planck operator forward = equation.equation({'β': self.β, 'Vp': Vp}) # Map to appropriate space factor = sym.exp(-self.β / sym.Rational(2) * (Vq + Vp)) # Mapped operator backward = eq.map_operator(forward, f, factor) # Discretize factor factor = quad.discretize(factor) return quad, forward, backward, factor
def sym_calc(self, Vp, parameters, s2x, s2y, s2z, degree=10): # Number of quadrature points n_points_num = 2 * degree + 1 # Equation parameters β = parameters['β'] equation = eq.McKean_Vlasov_harmonic_noise x, y, z, f = self.x, self.y, self.z, self.f # Calculation of the solution new_q = hm.Quad.gauss_hermite cov = [[s2x, 0, 0], [0, s2y, 0], [0, 0, s2z]] quad = new_q(n_points_num, dim=3, mean=[0] * 3, cov=cov) # Potential for approximation Vqx = sym.Rational(1 / 2) * x * x / (β * s2x) Vqy = sym.Rational(1 / 2) * y * y / s2y Vqz = sym.Rational(1 / 2) * z * z / s2z # Fokker Planck for McKean-Vlasov equation parameters.update({'Vp': Vp}) forward = equation.equation(parameters) # Map to appropriate space factor_x = sym.exp(-β / 2 * (Vqx + Vp)) factor_y = sym.exp(-1 / 2 * (y * y / 2 + Vqy)) factor_z = sym.exp(-1 / 2 * (z * z / 2 + Vqz)) factor = factor_x * factor_y * factor_z # Mapped operator backward = eq.map_operator(forward, f, factor) return quad, forward, backward, factor, factor_x, factor_y, factor_z
def sym_calc(self, Vp, parameters, m, s2x, s2y, degree=None): # Defalut degree degree = degree or self.degree # Number of quadrature points n_points_num = 2 * degree + 1 # Equation parameters β = parameters['β'] equation = eq.McKean_Vlasov x, y, f = equation.x, equation.y, equation.f # Calculation of the solution new_q = hm.Quad.gauss_hermite quad = new_q(n_points_num, dim=2, mean=[m, 0], cov=[[s2x, 0], [0, s2y]]) # Potential for approximation Vqx = sym.Rational(1 / 2) * (x - m) * (x - m) / (β * s2x) Vqy = sym.Rational(1 / 2) * y * y / s2y # Fokker Planck for McKean-Vlasov equation parameters.update({'Vp': Vp}) forward = equation.equation(parameters) # Map to appropriate space factor_x = sym.exp(-β / 2 * (Vqx + Vp)) factor_y = sym.exp(-1 / 2 * (Vqy + sym.sqrt(2) * y * y / 2)) factor = factor_x * factor_y # Mapped operator backward = eq.map_operator(forward, f, factor) # Discretize factor factor_x = quad.project(0).discretize(factor_x) factor_y = quad.project(1).discretize(factor_y) factor = quad.discretize(factor) return quad, forward, backward, factor, factor_x, factor_y
import sympy as sym # Declare variables, operators and parameters {{{ sym.init_printing() equation = eq.McKean_Vlasov x, y, f = equation.x, equation.y, equation.f params = equation.params() params['γ'], params['θ'] = 0, 0 params.update({'γ': 0, 'θ': 0, 'Vy': y * y / 2}) forward = equation.equation(params) β, Vp, θ, m = (params[k] for k in ('β', 'Vp', 'θ', 'm')) # Map the forward operator to a "backward operator" factor = sym.exp(-sym.Rational(1, 2) * (y * y)) operator = eq.map_operator(forward, f, factor).expand() epsilon = params['ε'] L0 = (operator * epsilon**2).expand().subs(epsilon, 0) L1 = (operator * epsilon - L0 / epsilon).expand().subs(epsilon, 0) L2 = (operator - L1 / epsilon - L0 / epsilon**2).expand() # Quadrature used to solve cell problems degree, nquad, σy = 10, 20, 1 quad_num = quad.Quad.gauss_hermite(nquad, dirs=[1], mean=[0], cov=[[σy]]) # Discretization in Hermite space fy = sym.Function('fy')(y) op = quad_num.discretize_op(L0.subs(f, fy), degree, sparse=False)
# Potential for approximation Vqx = sym.Rational(1 / 2) * x * x / (β * s2x) Vqy = sym.Rational(1 / 2) * y * y / s2y Vqz = sym.Rational(1 / 2) * z * z / s2z # Fokker Planck for McKean-Vlasov equation params.update({'Vp': Vp}) forward = equation.equation(params) # Map to appropriate space factor_x = sym.exp(-β / 2 * (Vqx + Vp)) factor_pq = sym.exp(-1 / 2 * (y * y / 2 + Vqy + z * z / 2 + Vqz)) factor = factor_x * factor_pq # Mapped operator backward = eq.map_operator(forward, f, factor) # Discretize factor factor_x = quad.project(0).discretize(factor_x) factor = quad.discretize(factor) degrees = list(range(5, degree)) # Discretization of the operator mat = quad.discretize_op(backward, f, degrees[-1], 2, sparse=True) solutions = [] v0, eig_vec = None, None for d in degrees: print(d)