In [1]:
# Необходмые команды импорта.
import sys
sys.path.append('../physlearn/')
sys.path.append('../source')
import numpy as np
from numpy import linalg as LA
import tensorflow as tf
from matplotlib import pylab as plt
import numpy.random as rand
from physlearn.NeuralNet.NeuralNet import NeuralNet
from physlearn.Optimizer.NelderMead.NelderMead import NelderMead
import d1_osc
import ann_constructor
import math_util
from lagaris2d import LagarisSolver2d
from lagaris_mc import LagarisSolver_mc
from visualiser import Visualiser
from mpl_toolkits.mplot3d.axes3d import Axes3D
%matplotlib notebook
def grid_vect(a,b,N):
x = np.linspace(a, b, N, endpoint=True)
h = x[1] - x[0]
return np.mgrid[a:b+h:h, a:b+h:h].reshape(2,-1).T
def get_meshgrid(a,b,N):
x = np.linspace(a, b, N, endpoint=True)
return np.meshgrid(x,x)
n_sig = 55
a = -5
b = 5
mc_n = 30000
#m_train = 35
#m_trapz = 25
#train_x = np.linspace(a, b, m_train, endpoint = True).reshape(1, m_train)
#trapz_x = np.linspace(a, b, m_trapz, endpoint = True)
#obs_x = np.linspace(a, b, 200, endpoint = True).reshape(1, 200)
N = 100
xy = grid_vect(a,b,N)
xg,yg = get_meshgrid(a,b,N)
train_xy = np.transpose(xy)
trapz_xy = train_xy
In [2]:
lagar = LagarisSolver_mc(2)
lagar.define_psi(n_sig)
net_x = lagar.get_net_x()
dim = lagar.get_dim()
sess = lagar.get_sess()
V = tf.square(net_x)
lagar.define_H_psi(V)
In [3]:
J_mc = lagar.get_cost_func(a,b, train_xy, mc_n)
opt_nm = NelderMead(-2.5,2.5)
opt_nm.set_epsilon_and_sd(0.3, 100)
def opt(J, dim, n_it, eps):
optimisation_result = opt_nm.optimize(J, dim+1, n_it, eps)
return optimisation_result
In [4]:
optimisation_result = opt(J_mc, dim, int(1e5), 1e-4)
print("J after optimisation: ", J_mc(optimisation_result.x))
print("Информация: ", optimisation_result)
In [5]:
Z = lagar.calc_psi(train_xy, optimisation_result.x[-1])
#print(Z)
print(Z.shape)
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_wireframe(xy[:,0], xy[:,1], Z)
Out[5]:
In [6]:
Z.shape
Out[6]:
In [ ]:
In [13]:
%matplotlib notebook
In [12]:
Z2 = d1_osc.wf_nd([0,0], xy)
Z2 = Z2.reshape(1,Z2.size)
math_util.std_err(Z+Z2)
Out[12]:
In [15]:
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_wireframe(xy[:,0], xy[:,1], Z+Z2)
Out[15]:
In [16]:
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_wireframe(xy[:,0], xy[:,1], Z2)
Out[16]:
In [17]:
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_wireframe(xy[:,0], xy[:,1], -Z)
Out[17]: