In [1]:
from physlearn.NeuralNet.NeuralNetPro import NeuralNetPro
from physlearn.examples import Titanic
from physlearn.Optimizer import NelderMead
from physlearn.Optimizer import DifferentialEvolution
import tensorflow as tf
import matplotlib.pyplot as plt
import sys
import os
%matplotlib inline


C:\Work\Programms\Anaconda3\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
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-01028274b1a4> in <module>()
      1 from physlearn.NeuralNet.NeuralNetPro import NeuralNetPro
----> 2 from physlearn.examples import Titanic
      3 from physlearn.Optimizer import NelderMead
      4 from physlearn.Optimizer import DifferentialEvolution
      5 import tensorflow as tf

~\Documents\GitKraken\SPBU_COMP_PHYS_NN_QM\first_stage\test\physlearntest\physlearn\examples\Titanic.py in <module>()
      2 import sys
      3 import os
----> 4 from list2vector import list2vector, normalize_vector
      5 
      6 import numpy

ModuleNotFoundError: No module named 'list2vector'

In [ ]:
(learn_data, learn_output), (cv_data, cv_output) = Titanic.create_datasets(0.2)

In [ ]:
net = NeuralNetPro(-5, 5)

In [ ]:
net.add_input_layer(3)
net.add(5, net.sigmoid)
net.add_output_layer(1, net.sigmoid)

In [ ]:
net.compile()

In [ ]:
net.set_train_type('logistic')

In [ ]:
net.set_random_matrixes()

In [ ]:
dim = net.return_unroll_dim()

In [ ]:
net.calculate_cost(learn_data, learn_output)

In [ ]:
def cost(params):
    net.roll_matrixes(params)
    return net.calculate_cost(learn_data, learn_output)

In [ ]:
#res = NelderMead.optimize(cost, dim, 3000, end_method='max_iter', min_element=-7, max_element=7)
res = DifferentialEvolution.optimize(cost, 100, dim, 100)

In [ ]:
net.roll_matrixes(res)

In [ ]:
net.calculate_cost(learn_data, learn_output)

In [ ]:
net.calculate_cost(cv_data, cv_output)

In [ ]:
ok_class = 0
output = net.run(learn_data)[0]
pred_clases = []
for item in output:
    if item >= 0.5:
        pred_clases.append(1)
    else:
        pred_clases.append(0)
for index, _ in enumerate(pred_clases):
    if pred_clases[index] == learn_output[0][index]:
        ok_class += 1
        
ok_percent = (ok_class / output.shape[0]) * 100
print('ok percent on learn data: ', ok_percent, '%')

In [ ]:
ok_class = 0
output = net.run(cv_data)[0]
pred_clases = []
for item in output:
    if item >= 0.5:
        pred_clases.append(1)
    else:
        pred_clases.append(0)
for index, _ in enumerate(pred_clases):
    if pred_clases[index] == cv_output[0][index]:
        ok_class += 1
        
ok_percent = (ok_class / output.shape[0]) * 100
print('ok percent on cv data: ', ok_percent, '%')

In [ ]: