Revert "Merge branch 'cristian_lenta-ba_code' into 'master'"

This reverts merge request !1
This commit is contained in:
Cristian Lenta
2021-05-03 08:37:31 +02:00
parent 46307610bc
commit 5e5bf9d7d9
111 changed files with 8338 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
import unittest
import numpy as np
from src.FeatureReduction import FeatureReduction
class TestFeatureReduction(unittest.TestCase):
def testfft(self):
data = np.array([1,2,3,4])
d = FeatureReduction("mean").mean(FeatureReduction('mean').shuffelVec(data,4),2)
print(d)
def testVecMean(self):
data = np.array([1,2,3,4,5,6,7,8,9])
d = FeatureReduction("mean").mean(data, 1)
self.assertEqual(np.array([45/9]),d)
d = FeatureReduction("mean").mean(data, 2)
np.testing.assert_array_equal(np.array([round(12.5/4.5,6), round(32.5/4.5,6)]), d)
d = FeatureReduction("mean").mean(data, 3)
np.testing.assert_array_equal(np.array([2, 5, 8]), d)
d = FeatureReduction("mean").mean(data, 4)
np.testing.assert_array_equal(np.array([round(3.75/2.25,6), round(8.75/2.25,6), round(13.75 / 2.25,6), round(18.75/2.25,6)]), d)
d = FeatureReduction("mean").mean(data, 5)
np.testing.assert_array_equal(np.array([round(2.6 / 1.8,6), round(5.8 / 1.8,6), round(9 / 1.8,6),
round(12.2 / 1.8,6), round(15.4/1.8,6)]), d)
d = FeatureReduction("mean").mean(data, 6)
np.testing.assert_array_equal(np.array([round(2 / 1.5,6), round(4 / 1.5,6), round(6.5 / 1.5,6),
round(8.5 / 1.5,6), round(11/1.5,6),round(13/1.5,6)]), d)
d = FeatureReduction("mean").mean(data, 9)
np.testing.assert_array_equal(np.array([1,2,3,4,5,6,7,8,9]), d)
def testWeigthsToVec(self):
test =np.array([[ 0.04457645, -0.03319572]], dtype=np.float32), np.array([ 0., 0.], dtype=np.float32), np.array([[-0.03747094],
[ 0.01189486]], dtype=np.float32), np.array([ 0.], dtype=np.float32)
FeatureReduction("mean").calc(test, 1)
def testShuffelVec(self):
vec = np.array([1,2,3,4,5,6,7,8,9,10])
print(FeatureReduction('mean').shuffelVec(vec,2))
def testPP(self):
vec = np.array([1., 5., 3.])
print(FeatureReduction('mean').calc(vec, 1))

View File

@@ -0,0 +1,29 @@
import unittest
import numpy as np
import src.Functions
class TestFunctions(unittest.TestCase):
def testcalcMeanSquaredError(self):
a = np.array([1, 2, 3, 4, 5])
b = np.array([1.1, 2.05, 2.95, 4.01, 4.5])
self.assertEqual(0.05, src.Functions.calcMeanSquaredError(a, b))
a = np.array(['1', '2', '3', '4', '5'])
b = np.array(['1.1', '2.05', '2.95', '4.01', '4.5'])
self.assertEqual(0.05, src.Functions.calcMeanSquaredError(a, b))
def testGetRandomLayer(self):
layer = (1, 3)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))
layer = (3, 1)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))
layer = (8, 2)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))
layer = (100, 1)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))
layer = (1, 1)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))
layer = (4, 50)
self.assertEqual(layer, np.shape(src.Functions.getRandomLayer(layer)))

View File

@@ -0,0 +1,41 @@
import unittest
import numpy as np
from src.PltData import PltData
class TestPlotData(unittest.TestCase):
def testPlotNNModel(self):
#[2, 3, 5] Netz
nn = np.array([[-0.00862074, -0.00609563], [ 0.03935056, 0.0159397 ]], dtype=np.float32),\
np.array([ 0., 0.], dtype=np.float32),\
np.array([[ 0.01351449, 0.04824072, 0.04954299], [ 0.04268739, -0.04188565, 0.03875775]], dtype=np.float32),\
np.array([ 0., 0., 0.], dtype=np.float32),\
np.array([[ 0.01074128, -0.00355459, 0.00787288, -0.02870593, -0.0204265 ], [ 0.01399798, -0.0096233 , 0.03152497, 0.03874204, -0.0466414 ], [ 0.04445429, -0.02976017, 0.00065653, -0.04210887, -0.02864893]], dtype=np.float32),\
np.array([ 0., 0., 0., 0., 0.], dtype=np.float32)
#[2, 1, 2] Netz
nn2 =np.array([[ 0.01390548, -0.01149112], [ 0.02786468, -0.02605006]], dtype=np.float32), \
np.array([ 0., 0.], dtype=np.float32), \
np.array([[-0.03265964],[ 0.013609 ]], dtype=np.float32), \
np.array([ 0.], dtype=np.float32), \
np.array([[ 0.02287653, 0.02650055]], dtype=np.float32), \
np.array([ 0., 0.], dtype=np.float32)
#[4,2,2]
nn3 = np.array([[ 0.03519103, -0.04059422, 0.04508766, -0.04067679], [ 0.01457861, 0.01178179, -0.01784203, 0.00051603], [-0.00807861, 0.01152407, 0.0136507 , 0.02639047], [ 0.04526602, -0.01604335, 0.00661949, 0.0434478 ]], dtype=np.float32), \
np.array([ 0., 0., 0., 0.], dtype=np.float32),\
np.array([[ 0.03728329, -0.01507163], [ 0.00789828, 0.0494065 ], [-0.00945786, -0.04301547], [-0.01999701, -0.01306728]], dtype=np.float32),\
np.array([ 0., 0.], dtype=np.float32),\
np.array([[-0.03051615, -0.03279487], [ 0.01100482, -0.02652025]], dtype=np.float32),\
np.array([ 0., 0.], dtype=np.float32)
# [1, 1, 2] Netz
nn4 = np.array([[0.01390548]], dtype=np.float32), \
np.array([0.], dtype=np.float32), \
np.array([[-0.03265964]], dtype=np.float32), \
np.array([0.], dtype=np.float32), \
np.array([[0.02287653, 0.02650055]], dtype=np.float32), \
np.array([0., 0.], dtype=np.float32)
PltData(None).plotNNModel(nn3, "test.png")