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


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


.    100000 (100%) 2.015 it\s
J after optimisation:  27.81454672328223
Информация:  Is converge: False
Amount of iterations: 100000
Total time: 49625.09 s
Reached function value: 25.379695073704763
Reason of break: Maximum iterations reached


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)


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

In [6]:
Z.shape


Out[6]:
(1, 10000)

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]:
0.025251910244545404

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]:
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x200699ad470>

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]:
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x2006a373710>

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]:
<mpl_toolkits.mplot3d.art3d.Line3DCollection at 0x2006abb0588>