In [2]:
# Необходмые команды импорта.
import sys, os
sys.path.append(os.path.join(sys.path[0], '../source/'))
sys.path.append(os.path.join(sys.path[0], '../../'))
import numpy as np
from numpy import linalg as LA
import tensorflow as tf
from matplotlib import pylab as plt
from tqdm import tqdm_notebook
from IPython.display import clear_output
import numpy.random as rand
from physlearn.NeuralNet.NeuralNetPro import NeuralNetPro
from physlearn.DifferentialEvolution import DifferentialEvolution

from visualiser import Visualiser
import d1_osc
import ann_constructor
import math_util

In [3]:
f = open("outs_matrix_with_variance.txt", 'r')
A = np.loadtxt(f, delimiter=' ')
f.close()
B = np.matmul(A, np.transpose(A))
C = np.matmul(np.transpose(A), A)
print('Shape of B:', B.shape, ' Shape of C: ', C.shape)
print('Norm of B:', math_util.norm(B), ' Norm of C: ', math_util.norm(C))
print('Cond of B:', math_util.cond(B), ' Cond of C: ', math_util.cond(C))
print('Determinant of B:',  np.linalg.det(B), ' Determinant of C: ',  np.linalg.det(C))


Shape of B: (4, 4)  Shape of C:  (500, 500)
Norm of B: 712781935.0746685  Norm of C:  712781935.0746685
Cond of B: 364672.2980448991  Cond of C:  5.275769753090281e+39
Determinant of B: 3537644873938.431  Determinant of C:  0.0

In [4]:
gram_matrix = np.matmul(A, np.transpose(A))
print('Gram matrix: \n', gram_matrix)
M = np.diag(gram_matrix).size
diag_gram_matrix = np.eye(M)
diag_gram_matrix.flat[::M+1] += -1 + gram_matrix.diagonal()
print('Diag of gram matrix: \n', diag_gram_matrix)


Gram matrix: 
 [[ 7140.72740842  7458.91201803 -2797.64923501  7384.76079147]
 [ 7458.91201803  9133.38003354 -5618.27731225  8102.51432244]
 [-2797.64923501 -5618.27731225  6986.99811847 -3334.45934785]
 [ 7384.76079147  8102.51432244 -3334.45934785  8768.84116371]]
Diag of gram matrix: 
 [[7140.72740842    0.            0.            0.        ]
 [   0.         9133.38003354    0.            0.        ]
 [   0.            0.         6986.99811847    0.        ]
 [   0.            0.            0.         8768.84116371]]

In [5]:
normal_gram_matrix = np.matmul(LA.inv(diag_gram_matrix), gram_matrix)
print('Normal gram matrix: \n', normal_gram_matrix)
np.fill_diagonal(normal_gram_matrix, 0)
print('Normal gram matrix - diag: \n', normal_gram_matrix)
nonortho_factor = math_util.norm(normal_gram_matrix)
print('Measure of nonorthoganality: \n', nonortho_factor)


Normal gram matrix: 
 [[ 1.          1.04455913 -0.39178771  1.03417486]
 [ 0.81666502  1.         -0.61513671  0.88713207]
 [-0.4004079  -0.8041046   1.         -0.47723776]
 [ 0.84215926  0.92401198 -0.38026226  1.        ]]
Normal gram matrix - diag: 
 [[ 0.          1.04455913 -0.39178771  1.03417486]
 [ 0.81666502  0.         -0.61513671  0.88713207]
 [-0.4004079  -0.8041046   0.         -0.47723776]
 [ 0.84215926  0.92401198 -0.38026226  0.        ]]
Measure of nonorthoganality: 
 6.888753594948433

In [6]:
m = 1000
x = np.linspace(-10, 10, m, endpoint=True).reshape(1, m) 
Visualiser.show_wf_system(2, x)



In [7]:
def values(i):
    values_H = np.gradient(A[i,:])
    values_H = -np.gradient(values_H) + np.square(np.linspace(-7, 7, 500, endpoint=True))*(A[i,:].reshape(500,))
    values = values_H /  A[i,:]
    return values

for i in range(4):
    print('Mean of ', i, ' HN/N distr: ', math_util.mean(values(i)))
    print('Dispersion of ', i, ' H N / N distr: ', math_util.variance(values(i)))


Mean of  0  HN/N distr:  16.398767565074813
Dispersion of  0  H N / N distr:  215.13403559444833
Mean of  1  HN/N distr:  16.398780812321828
Dispersion of  1  H N / N distr:  215.13342415149276
Mean of  2  HN/N distr:  16.398701804876044
Dispersion of  2  H N / N distr:  215.1035345086665
Mean of  3  HN/N distr:  16.39870693549114
Dispersion of  3  H N / N distr:  215.12979096741475

In [8]:
s = np.random.normal(1000, 500, 15000)

count, bins, ignored = plt.hist(s, 50, normed=True)
sigma = np.sqrt(math_util.variance(s))
mu = math_util.mean(s)
plt.plot(bins, 1.0/(sigma*np.sqrt(2*np.pi))*np.exp(-(bins - mu)**2/(2 * sigma**2)), linewidth=2, color='r')
plt.show()



In [9]:
M = 5
num_sig = 500
num_h2 = 10000
a = -30
b = 30
x = np.linspace(a, b, m, endpoint=True).reshape(1, m) 
net, net_output, net_sum, sess = ann_constructor.return_deep_net_expressions(M, num_sig, num_h2)
vis = Visualiser(net, net_output, net_sum, M)
vis.plot_four(x)


<matplotlib.figure.Figure at 0x2ada24d9a20>

In [10]:
#vis.plot_four(x)

In [11]:
x = np.linspace(-10, 10, 500, endpoint=True).reshape(1, 500)
for i in range(3):
    y = A[i,:]
    plt.plot(x[0], y)



In [ ]:


In [ ]:


In [ ]: