Пример #1
0
	def step(self,t,u,h):
		system = self.system
		noise = np.random.normal(size=[len(system.noise(t,u).T)])
		def residual(v):
			return (system.mass(t+h,v) - system.mass(t,u))/h - system.deterministic(t+h,v) - np.sqrt(h)/h*np.dot(system.noise(t,u),noise)
		N = Newton(residual)
## 		N.xtol = min(N.xtol, h*1e-4)
		result = N.run(u)
		return t+h, result
Пример #2
0
    def step(self, t, u, h):
        system = self.system
        noise = np.random.normal(size=[len(system.noise(t, u).T)])

        def residual(v):
            return (
                (system.mass(t + h, v) - system.mass(t, u)) / h
                - system.deterministic(t + h, v)
                - np.sqrt(h) / h * np.dot(system.noise(t, u), noise)
            )

        N = Newton(residual)
        ## 		N.xtol = min(N.xtol, h*1e-4)
        result = N.run(u)
        return t + h, result
Пример #3
0
    opt = Newton(obj_func=obj_func,
                 gradient_func=gradient,
                 reg_inv_hessian=reg_inv_hessian)
    opt.log.setLevel(logging.INFO)

    x_rng = [-2, 2]
    y_rng = [-1, 1]

    fig_dir = "figures"
    Path(fig_dir).mkdir(parents=True, exist_ok=True)

    # params_init = get_random_uniform_in_range(x_rng, y_rng)
    # params_init = np.array([-1.55994695, -0.31833122])
    params_init = np.array([-1.1, -0.5])

    converged, no_opt_steps, final_update, traj, line_search_factors = opt.run(
        no_steps=10, params_init=params_init, tol=1e-8, store_traj=True)

    print("Converged: %s" % converged)
    print(traj)
    print(line_search_factors)

    trajs = {}
    trajs[0] = traj

    endpoints, counts = plot.get_endpoints_and_counts(trajs)
    for i in range(0, len(endpoints)):
        print(endpoints[i], " : ", counts[i])

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    # plot.plot_3d_endpoint_lines(ax, trajs)