In [14]:
from physlearn.NeuralNet.NeuralNet import NeuralNet
import numpy
import tensorflow as tf
from math import pi
import matplotlib.pyplot as plt
from physlearn.Optimizer import NelderMead
from scipy.optimize import minimize
%matplotlib inline

In [15]:
x_train = numpy.linspace(0, 2 * pi, 30).reshape(1, 30)
y_train = numpy.sin(x_train[0]).reshape(1, 30)

In [16]:
x_cv = numpy.linspace(0, 2 * pi, 1000).reshape(1, 1000)
y_cv = numpy.sin(x_cv[0]).reshape(1, 1000)

In [17]:
plt.plot(x_train[0], y_train[0], 'x', color='red')


Out[17]:
[<matplotlib.lines.Line2D at 0x237eff6d400>]

In [18]:
net = NeuralNet(-1, 1)

In [19]:
net.add_input_layer(1)
net.add(10, tf.sigmoid)

In [20]:
net.compile()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-8a0a8f14e21e> in <module>()
----> 1 net.compile()

~\Documents\GitKraken\SPBU_COMP_PHYS_NN_QM\first_stage\test\physlearntest\physlearn\NeuralNet\NeuralNetAbstract.py in compile(self)
     83         self.y = tf.placeholder(tf.double)  # ...и обучающих выходов
     84 
---> 85         self.tf_matrixes = self.create_tf_matrixes()  # Создание матриц
     86         self.init = tf.global_variables_initializer()  # Инициализатор переменных
     87         self.sess.run(self.init)  # Инициализация переменных

~\Documents\GitKraken\SPBU_COMP_PHYS_NN_QM\first_stage\test\physlearntest\physlearn\NeuralNet\NeuralNet.py in create_tf_matrixes(self)
     24             current_layer_units = self.design[index][0]
     25             next_layer_units = self.design[index + 1][0]
---> 26             size = current_layer_units * next_layer_units  # Количество элементов матрицы
     27             weight_breaker = size + self.unroll_breaks[index][1]  # Индекс конца матрицы весов в unroll векторе -
     28             # ее размер, плюс сдвиг, связанный с предыдущими матрицами

TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'

In [ ]:
dim = net.return_unroll_dim()

In [ ]:
def cost(params):
    params = numpy.array(params)
    #print(params.shape)
    net.roll_matrixes(params)
    return net.calculate_cost(x_train, y_train)

In [ ]:
#res = OptimizerLib.NelderMeadLib.NelderMead.optimize(cost, dim, 5000, end_method='max_iter')
#res = OptimizerLib.NelderMeadLib.NelderMead.optimize(cost, dim, 1e-9)
x0 = net.unroll_matrixes()[2]
res = minimize(cost, x0, method='nelder-mead', options={'xtol': 1e-8, 'disp': True})

In [ ]:
net.roll_matrixes(res.x)

In [ ]:
y_pred = net.run(x_cv)
plt.plot(x_train[0], y_train[0], 'x', color='red')
plt.plot(x_cv[0], y_pred[0])

In [ ]:
net.calculate_cost(x_train, y_train)

In [ ]:
net.unroll_matrixes()[2]

In [ ]: