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 = 25
a = -5
b = 5
mc_n = 30000
dim = 1

N = 60
xy = np.linspace(a, b, N, endpoint=True)
xy = xy.reshape(dim,xy.size)
#train_xy = np.transpose(xy)
train_xy = 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(dim)
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(9e3), 1e-6)
print("J after optimisation: ", J_mc(optimisation_result.x))
print("Информация: ", optimisation_result)


..   9000 (100%) 4.232 it\s
J after optimisation:  0.0005651661917990637
Информация:  Is converge: False
Amount of iterations: 9000
Total time: 2125.91 s
Reached function value: 0.000519581989634821
Reason of break: Maximum iterations reached


In [7]:
xy.shape


Out[7]:
(1, 60)

In [8]:
Z = lagar.calc_psi(xy, optimisation_result.x[-1])
#print(Z)
print(Z.shape)
plt.plot(np.transpose(xy), np.transpose(Z))


(1, 60)
Out[8]:
[<matplotlib.lines.Line2D at 0x2931b616c50>]

In [10]:
Z2 = d1_osc.wf(0, xy)
Z2 = Z2.reshape(1,Z2.size)
math_util.std_err(Z+Z2)


Out[10]:
0.0008660215247862432

In [13]:
fig = plt.figure(figsize=(10,7))
plt.plot(np.transpose(xy),np.transpose(Z+Z2))
plt.plot(np.transpose(xy),np.transpose(Z))
plt.plot(np.transpose(xy),np.transpose(Z2))


Out[13]:
[<matplotlib.lines.Line2D at 0x2931b8efbe0>]