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 inline

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 = 30
a = -5
b = 5
mc_n = 15000
#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 = 50
xy = grid_vect(a,b,N)
xg,yg = get_meshgrid(a,b,N)

train_xy = np.transpose(xy)
trapz_xy = train_xy


D:\Anaconda\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

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(5e4), 1e-6)
print("J after optimisation: ", J_mc(optimisation_result.x))
print("Информация: ", optimisation_result)


..   50000 (100%) 8.068 it\s
J after optimisation:  12.709054151837291
Информация:  Is converge: False
Amount of iterations: 50000
Total time: 6196.98 s
Reached function value: 11.85036739352633
Reason of break: Maximum iterations reached


In [5]:
Z = lagar.calc_psi(train_xy, optimisation_result.x[-1])
Z2 = d1_osc.wf(0, xy)
Z2 = Z2.reshape(1,Z2.size)
#print(Z)
print(Z.shape)
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
xg,yg = np.meshgrid(xy[:,0], xy[:,1])
ax.plot_wireframe(xy[:,0], xy[:,1], Z-Z2)


(1, 2601)
Out[5]:
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x10a90b02c88>

In [6]:
fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_wireframe(xy[:,0], xy[:,1], Z)
ax.plot_wireframe(xy[:,0], xy[:,1], Z2)


Out[6]:
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x10a973eb860>

In [7]:
math_util.std_err(Z-Z2)


Out[7]:
0.057313184078225214

In [5]:



Out[5]:
0

In [3]:


In [7]:
x = xy[:,1]
x = x.reshape(1,x.size)
plt.plot(xy[:,1], d1_osc.wf_nd([0],xy))


Out[7]:
[<matplotlib.lines.Line2D at 0x1e26600e780>]

In [ ]: