diff --git a/NeuralNetworks-python/.editorconfig b/NeuralNetworks-python/.editorconfig new file mode 100644 index 0000000..b06d4c9 --- /dev/null +++ b/NeuralNetworks-python/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] + +charset = utf-8 +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf diff --git a/NeuralNetworks-python/.gitignore b/NeuralNetworks-python/.gitignore index 7bbc71c..832d03f 100644 --- a/NeuralNetworks-python/.gitignore +++ b/NeuralNetworks-python/.gitignore @@ -1,101 +1,6 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ .eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ *.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - -# virtualenv -.venv +__pycache__/ venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ +build/ +dist/ diff --git a/NeuralNetworks-python/Adaline.py b/NeuralNetworks-python/Adaline.py deleted file mode 100755 index 6d58ef8..0000000 --- a/NeuralNetworks-python/Adaline.py +++ /dev/null @@ -1,76 +0,0 @@ -import numpy as np -from _data import DataSets -from _math import ActivationFunctions, MathUtils -from _plot import PlotUtils - -class Adaline: - - def __init__(self, n, g, e): - self.n = n # learning rate - self.g = g # activation function - self.e = e # error variation tolerance - self.plot_data_x = [] # epochs for plotting - self.plot_data_y = [] # eqms for plotting - - def train(self, x, d): - k = len(x) - w = np.random.rand(len(x[0])) - epoch = 0 - while True: - mse_before = MathUtils.mean_squared_error(w, x, d) - for i in range(0, k): - v = np.dot(np.transpose(w), x[i]) - w = np.add(w, np.multiply(x[i], self.n * (d[i] - v))) - epoch = epoch + 1 - mse_after = MathUtils.mean_squared_error(w, x, d) - print(f"Epoch: {epoch}\tWeights: {w}\tError: {mse_after:.12f}") - self.plot_data_x.append(epoch) - self.plot_data_y.append(mse_after) - if abs(mse_after - mse_before) <= self.e: - break - return w - - def test(self, w, x): - v = np.dot(np.transpose(w), x) - y = self.g(v) - return y - - def evaluate(self, w, x, d): - correct = 0 - total = len(x) - for i in range(0, len(x)): - y = self.test(w, x[i]) - if (y == d[i]): - correct = correct + 1 - accuracy = 100.0 * (float(correct) / float(total)) - print(f"Accuracy: {accuracy:.2f}% ({correct}/{total})") - return accuracy - -if __name__ == "__main__": - - # set random number generator seed - np.random.seed(NUMERO_DE_MATRICULA) - - # set floating point formatting when printing - np.set_printoptions(formatter={"float": "{: 0.6f}".format}) - - # load data - x = DataSets.NOME_DO_DATASET.input - d = DataSets.NOME_DO_DATASET.output - - # define the network parameters - n = TAXA_DE_APRENDIZADO - g = ActivationFunctions.FUNCAO_DE_ATIVACAO - e = TOLERANCIA_DE_ERRO - - # create the neural network - nn = Adaline(n, g, e) - - # train the neural network - w = nn.train(x, d) - - # evaluate the neural network - acc = nn.evaluate(w, x, d) - - # plot epoch versus error data - PlotUtils.plot(nn.plot_data_x, "epoch", nn.plot_data_y, "mse") diff --git a/NeuralNetworks-python/LICENSE.md b/NeuralNetworks-python/LICENSE.md new file mode 100644 index 0000000..8c319f6 --- /dev/null +++ b/NeuralNetworks-python/LICENSE.md @@ -0,0 +1,18 @@ +Copyright (c) 2020, Marcelo Cysneiros and Danilo Peixoto. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/NeuralNetworks-python/Perceptron.py b/NeuralNetworks-python/Perceptron.py deleted file mode 100755 index f744a90..0000000 --- a/NeuralNetworks-python/Perceptron.py +++ /dev/null @@ -1,75 +0,0 @@ -import numpy as np -from _data import DataSets -from _math import ActivationFunctions -from _plot import PlotUtils - -class Perceptron: - - def __init__(self, n, g): - self.n = n # learning rate - self.g = g # activation function - self.plot_data_x = [] # epochs for plotting - self.plot_data_y = [] # error for plotting - - def train(self, x, d): - k = len(x) - w = np.random.rand(len(x[0])) - epoch = 0 - error = True - while error and epoch < 10000: - error = False - for i in range(0, k): - v = np.dot(np.transpose(w), x[i]) - y = self.g(v) - if y != d[i]: - w = np.add(w, np.multiply(self.n * (d[i] - y), x[i])) - error = True - epoch = epoch + 1 - print(f"Epoch: {epoch}\tWeights: {w}") - self.plot_data_x.append(epoch) - self.plot_data_y.append(1 if error else 0) - return w - - def test(self, w, x): - v = np.dot(np.transpose(w), x) - y = self.g(v) - return y - - def evaluate(self, w, x, d): - correct = 0 - total = len(x) - for i in range(0, len(x)): - y = self.test(w, x[i]) - if (y == d[i]): - correct = correct + 1 - accuracy = 100.0 * (float(correct) / float(total)) - print(f"Accuracy: {accuracy:.2f}% ({correct}/{total})") - return accuracy - -if __name__ == "__main__": - - # set random number generator seed - np.random.seed(NUMERO_DE_MATRICULA) - - # set floating point formatting when printing - np.set_printoptions(formatter={"float": "{: 0.6f}".format}) - - # load data - x = DataSets.NOME_DO_DATASET.input - d = DataSets.NOME_DO_DATASET.output - - # define the network parameters - n = TAXA_DE_APRENDIZADO - g = ActivationFunctions.FUNCAO_DE_ATIVACAO - - # create the neural network - nn = Perceptron(n, g) - - # train the neural network - w = nn.train(x, d) - - # evaluate the neural network - acc = nn.evaluate(w, x, d) - - # plot epoch versus error data - PlotUtils.plot(nn.plot_data_x, "epoch", nn.plot_data_y, "error") diff --git a/NeuralNetworks-python/README.md b/NeuralNetworks-python/README.md new file mode 100644 index 0000000..d1e7454 --- /dev/null +++ b/NeuralNetworks-python/README.md @@ -0,0 +1,33 @@ +# Blueprint + +A simple neural network package. + +## Installation + +Prerequisites: + +* [Python >=3.6.0](https://www.python.org) + +Install package: + +``` +pip install . +``` + +Use the `-e, --editable` flag to install package in development mode. + +## Usage + +Check the sample scripts available in the `scripts` directory. + +Run sample scripts: + +``` +python scripts/perceptron.py +``` + +## Copyright and license + +Copyright (c) 2020, Marcelo Cysneiros and Danilo Peixoto. All rights reserved. + +Project developed under a [MIT License](LICENSE.md). diff --git a/NeuralNetworks-python/_data/DataSets.py b/NeuralNetworks-python/_data/DataSets.py deleted file mode 100755 index ff2dc4a..0000000 --- a/NeuralNetworks-python/_data/DataSets.py +++ /dev/null @@ -1,53 +0,0 @@ -import numpy as np -import os, sys -from numpy.random import sample -from numpy import append, genfromtxt - -class DataSets: - - @staticmethod - def read(folder, filename, flatten): - filename_abs = os.path.join(os.path.dirname(__file__), folder, filename) - return genfromtxt(filename_abs, delimiter=',', dtype=float) - - @staticmethod - def add_bias(arr, bias = -1): - biased_arr = np.ndarray(shape=(arr.shape[0], arr.shape[1]+1), dtype=float) - for i in range(0, len(arr)): - biased_arr[i] = np.append(bias, arr[i]) - return biased_arr - -# https://en.wikipedia.org/wiki/AND_gate -class LOGIC_GATE_AND: - input = DataSets.add_bias(DataSets.read('logic-gate-and', 'input.txt', False)) - output = DataSets.read('logic-gate-and', 'output.txt', True) - -# https://en.wikipedia.org/wiki/OR_gate -class LOGIC_GATE_OR: - input = DataSets.add_bias(DataSets.read('logic-gate-or', 'input.txt', False)) - output = DataSets.read('logic-gate-or', 'output.txt', True) - -# https://en.wikipedia.org/wiki/XOR_gate -class LOGIC_GATE_XOR: - input = DataSets.add_bias(DataSets.read('logic-gate-xor', 'input.txt', False)) - output = DataSets.read('logic-gate-xor', 'output.txt', True) - -# http://archive.ics.uci.edu/ml/datasets/Blood+Transfusion+Service+Center -class BLOOD_TRANSFUSION: - input = DataSets.add_bias(DataSets.read('blood-transfusion', 'input.txt', False)) - output = DataSets.read('blood-transfusion', 'output.txt', True) - -# http://archive.ics.uci.edu/ml/datasets/Cryotherapy+Dataset+ -class CRYOTHERAPY: - input = DataSets.add_bias(DataSets.read('cryotherapy', 'input.txt', False)) - output = DataSets.read('cryotherapy', 'output.txt', True) - -# https://www.kaggle.com/kumargh/pimaindiansdiabetescsv -class DIABETES: - input = DataSets.add_bias(DataSets.read('diabetes', 'input.txt', False)) - output = DataSets.read('diabetes', 'output.txt', True) - -# https://archive.ics.uci.edu/ml/datasets/Tic-Tac-Toe+Endgame -class TIC_TAC_TOE_ENDGAME: - input = DataSets.add_bias(DataSets.read('tic-tac-toe-endgame', 'input.txt', False)) - output = DataSets.read('tic-tac-toe-endgame', 'output.txt', True) diff --git a/NeuralNetworks-python/_math/ActivationFunctions.py b/NeuralNetworks-python/_math/ActivationFunctions.py deleted file mode 100755 index 47053dd..0000000 --- a/NeuralNetworks-python/_math/ActivationFunctions.py +++ /dev/null @@ -1,13 +0,0 @@ -import numpy as np -import random as rnd - -class ActivationFunctions: - - def __init__(self): - pass - -def heaviside(v): - return 1 if v >= 0 else 0 - -def heaviside_symmetric(v): - return np.sign(v) diff --git a/NeuralNetworks-python/_math/MathUtils.py b/NeuralNetworks-python/_math/MathUtils.py deleted file mode 100644 index eadba89..0000000 --- a/NeuralNetworks-python/_math/MathUtils.py +++ /dev/null @@ -1,15 +0,0 @@ -import numpy as np -import random as rnd - -class MathUtils: - - def __init__(self): - pass - -def mean_squared_error(w, x, d): - mse = 0 - for i in range(0,len(x)): - v = np.dot(np.transpose(w), x[i]) - mse = mse + pow(d[i] - v, 2) - mse = mse / len(x) - return mse diff --git a/NeuralNetworks-python/_math/__init__.py b/NeuralNetworks-python/_math/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/NeuralNetworks-python/_plot/PlotUtils.py b/NeuralNetworks-python/_plot/PlotUtils.py deleted file mode 100644 index 738caa1..0000000 --- a/NeuralNetworks-python/_plot/PlotUtils.py +++ /dev/null @@ -1,34 +0,0 @@ -import matplotlib.pyplot as plt -from matplotlib.ticker import MaxNLocator -import datetime as dt -import numpy as np - -class PlotUtils: - - def __init__(self): - pass - -# https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes -def plot(x, _xlabel, y, _ylabel): - - # handle convergence in first training epoch - if len(x) == 1 and len(y) == 1: - print('Only one training epoch was performed; no plot to show.') - else: - # data - ax = plt.gca() - ax.plot(x, y, color='blue', linewidth=1.5) - ax.xaxis.set_major_locator(MaxNLocator(integer=True)) - - # limits - ax.set_xlim([np.min(x), np.max(x)]) - ax.set_ylim([np.min(y), np.max(y)]) - - # text - ax.set_xlabel(_xlabel) - ax.set_ylabel(_ylabel) - ax.set_title('{} vs {}'.format(_xlabel, _ylabel)) - - # display - ax.grid() - plt.show() diff --git a/NeuralNetworks-python/_plot/__init__.py b/NeuralNetworks-python/_plot/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/NeuralNetworks-python/blueprint/__init__.py b/NeuralNetworks-python/blueprint/__init__.py new file mode 100644 index 0000000..6495c7b --- /dev/null +++ b/NeuralNetworks-python/blueprint/__init__.py @@ -0,0 +1 @@ +from .package import * diff --git a/NeuralNetworks-python/blueprint/activation_functions.py b/NeuralNetworks-python/blueprint/activation_functions.py new file mode 100644 index 0000000..c50695c --- /dev/null +++ b/NeuralNetworks-python/blueprint/activation_functions.py @@ -0,0 +1,14 @@ +import numpy as np + + +def linear(x): + return x + +def gaussian(x, mu, sigma): + return np.exp(-np.divide(np.square(x - mu), 2 * np.square(sigma))) + +def heaviside(x): + return 1 if x >= 0 else 0 + +def heaviside_symmetric(x): + return np.sign(x) diff --git a/NeuralNetworks-python/_data/__init__.py b/NeuralNetworks-python/blueprint/data/__init__.py similarity index 100% rename from NeuralNetworks-python/_data/__init__.py rename to NeuralNetworks-python/blueprint/data/__init__.py diff --git a/NeuralNetworks-python/_data/blood-transfusion/blood-transfusion.csv b/NeuralNetworks-python/blueprint/data/blood_transfusion/blood-transfusion.csv similarity index 100% rename from NeuralNetworks-python/_data/blood-transfusion/blood-transfusion.csv rename to NeuralNetworks-python/blueprint/data/blood_transfusion/blood-transfusion.csv diff --git a/NeuralNetworks-python/_data/blood-transfusion/blood-transfusion.png b/NeuralNetworks-python/blueprint/data/blood_transfusion/blood-transfusion.png similarity index 100% rename from NeuralNetworks-python/_data/blood-transfusion/blood-transfusion.png rename to NeuralNetworks-python/blueprint/data/blood_transfusion/blood-transfusion.png diff --git a/NeuralNetworks-python/_data/blood-transfusion/input.txt b/NeuralNetworks-python/blueprint/data/blood_transfusion/input.txt similarity index 100% rename from NeuralNetworks-python/_data/blood-transfusion/input.txt rename to NeuralNetworks-python/blueprint/data/blood_transfusion/input.txt diff --git a/NeuralNetworks-python/_data/blood-transfusion/output.txt b/NeuralNetworks-python/blueprint/data/blood_transfusion/output.txt similarity index 100% rename from NeuralNetworks-python/_data/blood-transfusion/output.txt rename to NeuralNetworks-python/blueprint/data/blood_transfusion/output.txt diff --git a/NeuralNetworks-python/_data/cryotherapy/input.txt b/NeuralNetworks-python/blueprint/data/cryotherapy/input.txt similarity index 100% rename from NeuralNetworks-python/_data/cryotherapy/input.txt rename to NeuralNetworks-python/blueprint/data/cryotherapy/input.txt diff --git a/NeuralNetworks-python/_data/cryotherapy/output.txt b/NeuralNetworks-python/blueprint/data/cryotherapy/output.txt similarity index 100% rename from NeuralNetworks-python/_data/cryotherapy/output.txt rename to NeuralNetworks-python/blueprint/data/cryotherapy/output.txt diff --git a/NeuralNetworks-python/_data/diabetes/diabetes.csv b/NeuralNetworks-python/blueprint/data/diabetes/diabetes.csv similarity index 100% rename from NeuralNetworks-python/_data/diabetes/diabetes.csv rename to NeuralNetworks-python/blueprint/data/diabetes/diabetes.csv diff --git a/NeuralNetworks-python/_data/diabetes/diabetes.png b/NeuralNetworks-python/blueprint/data/diabetes/diabetes.png similarity index 100% rename from NeuralNetworks-python/_data/diabetes/diabetes.png rename to NeuralNetworks-python/blueprint/data/diabetes/diabetes.png diff --git a/NeuralNetworks-python/_data/diabetes/input.txt b/NeuralNetworks-python/blueprint/data/diabetes/input.txt similarity index 100% rename from NeuralNetworks-python/_data/diabetes/input.txt rename to NeuralNetworks-python/blueprint/data/diabetes/input.txt diff --git a/NeuralNetworks-python/_data/diabetes/output.txt b/NeuralNetworks-python/blueprint/data/diabetes/output.txt similarity index 100% rename from NeuralNetworks-python/_data/diabetes/output.txt rename to NeuralNetworks-python/blueprint/data/diabetes/output.txt diff --git a/NeuralNetworks-python/_data/logic-gate-and/input.txt b/NeuralNetworks-python/blueprint/data/logic_gate_and/input.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-and/input.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_and/input.txt diff --git a/NeuralNetworks-python/_data/logic-gate-and/output.txt b/NeuralNetworks-python/blueprint/data/logic_gate_and/output.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-and/output.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_and/output.txt diff --git a/NeuralNetworks-python/_data/logic-gate-or/input.txt b/NeuralNetworks-python/blueprint/data/logic_gate_or/input.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-or/input.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_or/input.txt diff --git a/NeuralNetworks-python/_data/logic-gate-or/output.txt b/NeuralNetworks-python/blueprint/data/logic_gate_or/output.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-or/output.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_or/output.txt diff --git a/NeuralNetworks-python/_data/logic-gate-xor/input.txt b/NeuralNetworks-python/blueprint/data/logic_gate_xor/input.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-xor/input.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_xor/input.txt diff --git a/NeuralNetworks-python/_data/logic-gate-xor/output.txt b/NeuralNetworks-python/blueprint/data/logic_gate_xor/output.txt old mode 100755 new mode 100644 similarity index 100% rename from NeuralNetworks-python/_data/logic-gate-xor/output.txt rename to NeuralNetworks-python/blueprint/data/logic_gate_xor/output.txt diff --git a/NeuralNetworks-python/_data/tic-tac-toe-endgame/input.txt b/NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/input.txt similarity index 100% rename from NeuralNetworks-python/_data/tic-tac-toe-endgame/input.txt rename to NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/input.txt diff --git a/NeuralNetworks-python/_data/tic-tac-toe-endgame/output.txt b/NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/output.txt similarity index 100% rename from NeuralNetworks-python/_data/tic-tac-toe-endgame/output.txt rename to NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/output.txt diff --git a/NeuralNetworks-python/_data/tic-tac-toe-endgame/tic-tac-toe-endgame.csv b/NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/tic-tac-toe-endgame.csv similarity index 100% rename from NeuralNetworks-python/_data/tic-tac-toe-endgame/tic-tac-toe-endgame.csv rename to NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/tic-tac-toe-endgame.csv diff --git a/NeuralNetworks-python/_data/tic-tac-toe-endgame/tic-tac-toe-engame.png b/NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/tic-tac-toe-engame.png similarity index 100% rename from NeuralNetworks-python/_data/tic-tac-toe-endgame/tic-tac-toe-engame.png rename to NeuralNetworks-python/blueprint/data/tic_tac_toe_endgame/tic-tac-toe-engame.png diff --git a/NeuralNetworks-python/blueprint/data/tsne_2d/input.txt b/NeuralNetworks-python/blueprint/data/tsne_2d/input.txt new file mode 100644 index 0000000..672b7cf --- /dev/null +++ b/NeuralNetworks-python/blueprint/data/tsne_2d/input.txt @@ -0,0 +1,300 @@ +8.36856841e-01, 2.13635938e+00 +-1.41365810e+00, 7.40962324e+00 +1.15521298e+00, 5.09961887e+00 +-1.01861632e+00, 7.81491465e+00 +1.27135141e+00, 1.89254207e+00 +3.43761754e+00, 2.61654166e-01 +-1.80822253e+00, 1.59701749e+00 +1.41372442e+00, 4.38117707e+00 +-2.04932168e-01, 8.43209665e+00 +-7.11099611e-01, 8.66043846e+00 +-1.71237268e+00, 2.77780226e+00 +-2.67000792e+00, 8.35389140e+00 +1.24258802e+00, 4.50399192e+00 +-2.22783649e+00, 6.89479938e+00 +1.45513831e+00, -2.91989981e-02 +4.53791789e-01, 3.95647753e+00 +1.06923853e+00, 4.53068484e+00 +2.56936589e+00, 5.07048304e-01 +-1.06690610e+00, 3.13165795e+00 +-1.07859101e+00, 2.20451529e+00 +2.71506328e+00, 1.29082190e+00 +1.77710994e+00, 1.18655254e+00 +7.34363910e-01, 5.03725437e+00 +-1.99648151e+00, 2.85164868e+00 +-1.91828017e+00, 2.60516867e+00 +-5.55523811e-01, 4.69595848e+00 +1.69747910e+00, 8.66123282e-01 +5.94762432e-01, 4.70964730e+00 +-2.88024255e+00, 2.30437816e+00 +1.86725632e-01, 4.02683656e+00 +-5.13333436e-01, 7.87437368e+00 +-2.05701103e+00, 7.37851598e+00 +1.87271752e+00, 4.18069237e+00 +-1.13121396e+00, 6.76652230e+00 +-1.64428957e+00, 7.94095139e+00 +-2.41933824e+00, 7.43952498e+00 +-2.01606928e+00, 7.48420129e+00 +-2.62142780e+00, 7.98635066e+00 +-2.20299950e+00, 2.47947561e+00 +1.66382237e+00, 6.63091635e-01 +6.69786996e-01, 3.59540802e+00 +-1.98539037e+00, 2.05520738e+00 +-4.74920358e-02, 5.47425256e+00 +1.54462126e+00, 4.21078127e+00 +-1.70200643e+00, 2.46098693e+00 +-1.02192525e+00, 2.76820711e+00 +-1.37842552e+00, 8.10269597e+00 +-1.55220688e+00, 2.74574995e+00 +-1.47904303e+00, 7.56915836e+00 +1.98894313e+00, 1.50976729e+00 +-1.94972418e+00, 3.48383870e+00 +2.45509737e+00, 6.21231788e-01 +-8.94327882e-01, 7.61714473e+00 +1.69687788e+00, 7.54910622e-01 +1.75644805e+00, 2.05538289e+00 +-1.11064012e+00, 2.82213820e+00 +-4.15017659e-02, 7.80870276e+00 +-1.14091533e+00, 1.97550822e+00 +-1.80634968e+00, 7.72830656e+00 +1.39263752e+00, 9.28962707e-01 +-2.25698670e+00, 7.30207720e+00 +5.71670482e-01, 4.32288566e+00 +-1.54994580e+00, 9.28293222e+00 +-1.03819212e+00, 2.95323761e+00 +-2.10956676e+00, 3.10677258e+00 +-1.18652985e+00, 2.78427720e+00 +-2.45809975e+00, 7.51178724e+00 +2.36960214e+00, 9.50716912e-01 +-2.66676007e+00, 7.84766052e+00 +-1.49720702e+00, 3.21418433e+00 +1.32222457e+00, 4.17880807e+00 +-4.87271301e-01, 3.32858293e+00 +-1.03718771e+00, 8.06300134e+00 +-1.60496819e+00, 2.97425420e+00 +-1.50372568e+00, 1.92385320e+00 +-7.85412206e-01, 8.45312331e+00 +-1.75783190e+00, 2.97449321e+00 +1.19008992e+00, 4.72773123e+00 +2.14043942e+00, 7.06066610e-01 +-1.03540116e+00, 8.20559195e+00 +1.25471244e+00, 8.96331565e-02 +5.95676822e-01, 4.08614263e+00 +1.27955338e+00, 1.05789418e+00 +1.72955064e+00, 1.14729369e+00 +-9.49041610e-01, 8.46424331e+00 +9.35325115e-01, 5.33179296e+00 +2.36923352e+00, 7.94735861e-01 +4.28576743e-01, 4.97399710e+00 +-2.04758277e+00, 6.65428520e+00 +-1.45672617e+00, 7.48669893e+00 +5.29417185e-01, 3.80792420e+00 +1.78194802e+00, 9.08151155e-01 +-1.95575053e+00, 8.61631686e+00 +-1.74572014e+00, 3.01190457e+00 +-1.17979111e+00, 3.12767494e+00 +1.16411070e+00, 3.79132988e+00 +1.36155806e+00, 1.36638252e+00 +2.60137487e+00, 1.08799459e+00 +2.72396035e-01, 5.46996004e+00 +-3.12240736e+00, 3.28167398e+00 +-5.88085172e-01, 8.61427320e+00 +1.66909648e+00, -4.36378231e-01 +-6.82774903e-01, 7.67490317e+00 +2.36790645e+00, 5.52190878e-01 +1.05241733e+00, 4.54498095e+00 +2.22707373e+00, 1.26296996e+00 +2.43934644e+00, -7.25099666e-02 +1.34471770e+00, 4.85711133e+00 +-1.31454942e+00, 6.83904013e+00 +9.82570091e-01, 5.37530962e+00 +-1.06295223e+00, 2.20755388e+00 +-1.60712495e+00, 3.56452854e+00 +1.57322172e+00, 4.83933793e-01 +-2.17851338e+00, 8.08585131e+00 +1.83375842e+00, 7.54036153e-01 +2.10616050e+00, 3.49513189e+00 +-1.64338755e+00, 7.52691964e+00 +1.10550448e+00, 1.26389129e+00 +1.61152972e+00, 1.82347242e+00 +4.59534668e-01, 5.44982630e+00 +-5.38023054e-01, 3.01641891e+00 +1.67841499e+00, 6.09047389e-01 +-1.01214966e+00, 3.60254338e+00 +1.34195197e+00, 5.93573847e-01 +1.42811550e+00, 1.62435083e+00 +2.04505527e+00, 1.12515470e+00 +1.67280531e+00, 6.59300571e-01 +-1.35863899e+00, 2.32200809e+00 +1.13078931e+00, 9.35620856e-01 +-1.73896306e+00, 1.94799775e+00 +-3.40258925e-01, 8.16733925e+00 +-1.63793622e+00, 2.43329317e+00 +-1.68754414e+00, 2.24107546e+00 +2.43040639e+00, -6.35709334e-02 +-1.37998039e+00, 7.18503804e+00 +-1.25245465e+00, 2.33911505e+00 +-2.39482483e+00, 3.39806103e+00 +-2.09183352e+00, 7.48142543e+00 +4.88382309e-01, 3.26801777e+00 +-5.39428614e-01, 7.45631776e+00 +-2.59201821e+00, 8.07635945e+00 +-1.04656513e+00, 2.96483837e+00 +1.25566754e+00, 3.38204112e+00 +-1.62150422e+00, 4.27191636e+00 +1.86922139e+00, 5.44132083e+00 +-1.76404140e+00, 2.22222995e+00 +-1.38181918e+00, 7.28761248e+00 +7.93137001e-03, 4.17614316e+00 +-1.10298500e+00, 7.30222786e+00 +-1.79351372e+00, 7.58086944e+00 +-1.51176949e+00, 7.94426307e+00 +9.59360742e-01, 4.56078645e+00 +-6.01337393e-01, 6.29994922e+00 +2.24592863e-01, 4.77028154e+00 +1.56724897e+00, 1.78090633e-02 +-1.03395259e+00, 2.92105785e+00 +-9.22268640e-01, 8.09888579e+00 +-1.88609638e+00, 2.24834407e+00 +1.86873582e+00, 9.56103760e-01 +1.10123507e+00, 4.88977075e+00 +-1.93213725e+00, 8.30643453e+00 +6.70478769e-01, 4.04094275e+00 +7.43873988e-01, 4.12240568e+00 +1.64003761e+00, 1.81948989e+00 +8.15468056e-01, 4.78526116e+00 +-2.63274574e+00, 2.63109786e+00 +-9.61076361e-01, 1.27407596e+00 +2.13979079e-01, 4.88542535e+00 +1.43472182e+00, 1.30662037e+00 +1.21387411e+00, 3.64795042e+00 +1.08272576e+00, 4.06271877e+00 +-1.22605234e+00, 8.29620146e+00 +1.48170052e+00, 6.90074595e-01 +1.89593761e+00, 5.18540259e+00 +-1.32356154e+00, 4.13050840e+00 +-1.14989863e+00, 7.89325283e+00 +2.46915842e+00, 1.67877140e+00 +2.31102276e+00, 1.30380848e+00 +5.72793810e-01, 4.08805543e+00 +-9.67794989e-01, 3.12186125e+00 +2.62492001e+00, 9.50194405e-01 +1.68353782e+00, 4.19583243e+00 +-2.22131717e+00, 2.73050691e+00 +-1.57846247e+00, 3.03445802e+00 +8.15155229e-02, 4.56742235e+00 +1.43289271e+00, 4.37679234e+00 +1.06269622e+00, 5.17635143e+00 +7.67522789e-01, 4.39759671e+00 +2.47019077e+00, 1.31451315e+00 +-1.73163168e+00, 7.16447286e+00 +3.47138300e-01, 3.45177657e+00 +-1.00140436e+00, 2.84881778e+00 +1.01618041e+00, 4.48527047e+00 +5.59529363e-01, 4.21400660e+00 +-2.11821046e+00, 2.03478126e+00 +-1.36219420e+00, 2.38333321e+00 +-2.78366586e+00, 2.99211541e+00 +1.65225163e+00, 3.65582842e+00 +-1.93960658e+00, 2.18943582e+00 +-1.81487687e+00, 7.97832190e+00 +1.20212540e+00, 3.64414685e+00 +-9.69200946e-01, 3.26721702e+00 +1.86985974e+00, -1.07938624e-01 +-1.80701134e+00, 2.06773859e+00 +1.21767506e+00, 3.89290127e+00 +-1.48368917e+00, 6.00777418e+00 +-1.56387985e+00, 2.85349910e+00 +-6.86210297e-01, 8.68285664e+00 +1.07627418e+00, 4.68480619e+00 +-9.75986627e-01, 6.73761577e+00 +1.37964693e+00, 4.54826443e+00 +-1.64129611e+00, 2.68097255e+00 +-1.84892963e-03, 4.58145668e+00 +1.71444449e+00, 5.02521524e+00 +-1.40524304e+00, 7.72611315e+00 +-7.08184904e-01, 2.50421275e+00 +-8.85798374e-01, 2.64585078e+00 +1.98436909e+00, 4.89556738e-01 +2.95195825e+00, -3.44327355e-01 +4.31891060e-01, 4.33495456e+00 +-1.86621694e+00, 7.62549400e+00 +2.52706430e+00, 6.17812202e-01 +2.04067185e+00, 4.54845114e-01 +-2.58043836e+00, 3.18844294e+00 +1.61990909e+00, 6.76452867e-02 +-2.58802708e+00, 3.13117134e+00 +4.43598630e-01, 3.11530945e+00 +-4.56773649e-01, 7.30600872e+00 +-1.12867566e+00, 7.80509789e+00 +2.13003529e+00, 5.19209620e+00 +1.00372519e+00, 4.19147702e+00 +-1.39346767e+00, 8.74641672e+00 +7.28098690e-01, 3.85531444e+00 +8.93499638e-01, 1.01093082e+00 +-1.10782972e+00, 2.92014479e+00 +7.89338559e-01, 4.33748653e+00 +1.97553917e+00, 7.18989132e-01 +-1.24902582e+00, 3.08533972e+00 +-1.07768797e+00, 8.88106128e+00 +-1.86849125e+00, 3.07982487e+00 +2.76808540e+00, 1.08782923e+00 +2.77180174e-01, 4.84428322e+00 +3.41085289e+00, 8.72309369e-01 +-1.58084155e+00, 7.55307742e+00 +-1.53027550e+00, 7.70542113e+00 +-1.82455840e+00, 7.35958960e+00 +-1.68568257e+00, 7.95339446e+00 +-1.65104622e+00, 3.44598961e+00 +-1.30440901e+00, 3.00311934e+00 +-7.30698168e-01, 6.24208856e+00 +2.40615694e+00, 4.87047502e+00 +-1.53631328e+00, 3.01443916e+00 +1.48859977e+00, 6.51633844e-01 +5.14320434e-01, 4.62733684e+00 +-1.81469750e+00, 3.29009724e+00 +-1.93731055e+00, 3.91361274e+00 +-6.14907097e-01, 3.94963585e+00 +2.03169783e+00, 1.96807561e-01 +2.14917144e+00, 1.03697228e+00 +-1.36999388e+00, 7.76953035e+00 +9.14338767e-01, 4.55014643e+00 +3.33818506e-01, 4.93645836e+00 +-2.15968109e+00, 3.41003096e+00 +1.36678633e+00, 6.34971633e-01 +-5.71099336e-01, 8.13306058e+00 +-1.00552592e+00, 3.08400540e+00 +1.49493180e+00, 3.85848832e+00 +-5.90447667e-01, 7.69493053e+00 +7.15177948e-01, 5.41334556e+00 +2.11390250e+00, 1.24743587e+00 +1.20083098e+00, 6.01671730e-01 +-2.54576750e+00, 3.15025055e+00 +-1.95866665e+00, 2.43008647e+00 +2.33812285e+00, 3.43116792e+00 +3.35320909e+00, 1.69958043e+00 +1.84287117e+00, 7.26928839e-02 +1.32000621e+00, 1.40428145e+00 +2.09680545e+00, 4.84741412e+00 +-1.24307904e+00, 8.15166254e+00 +-1.85908090e+00, 7.78874716e+00 +2.74666646e+00, 1.54543482e+00 +2.60778282e+00, 1.08890025e+00 +1.65991049e+00, 3.56289184e+00 +2.35151259e+00, 8.28001297e-01 +2.22322228e+00, 8.38773426e-01 +3.22881491e+00, 1.13171965e+00 +-1.55876720e+00, 7.24816210e+00 +-6.46956784e-01, 3.42941343e+00 +-1.32688818e+00, 8.51530794e+00 +9.17198564e-01, 3.90570036e+00 +2.29469533e+00, -7.65891994e-01 +1.81559810e+00, 1.11969719e+00 +-1.12016775e+00, 7.11031582e+00 +-1.65507124e+00, 8.61416749e+00 +-1.27567815e+00, 7.96776461e+00 +1.97369770e+00, 1.57979848e+00 +2.51834185e+00, 1.39176615e+00 +4.38990142e-01, 4.53592883e+00 +3.69478657e-01, 7.79110522e+00 +-1.79145759e+00, 2.74966896e+00 diff --git a/NeuralNetworks-python/blueprint/data/tsne_2d/output.txt b/NeuralNetworks-python/blueprint/data/tsne_2d/output.txt new file mode 100644 index 0000000..759ffdc --- /dev/null +++ b/NeuralNetworks-python/blueprint/data/tsne_2d/output.txt @@ -0,0 +1,300 @@ +1 +3 +0 +3 +1 +1 +2 +0 +3 +3 +2 +3 +0 +3 +1 +0 +0 +1 +2 +2 +1 +1 +0 +2 +2 +0 +1 +0 +2 +0 +3 +3 +0 +3 +3 +3 +3 +3 +2 +1 +0 +2 +0 +0 +2 +2 +3 +2 +3 +1 +2 +1 +3 +1 +1 +2 +3 +2 +3 +1 +3 +0 +3 +2 +2 +2 +3 +1 +3 +2 +0 +2 +3 +2 +2 +3 +2 +0 +1 +3 +1 +0 +1 +1 +3 +0 +1 +0 +3 +3 +0 +1 +3 +2 +2 +0 +1 +1 +0 +2 +3 +1 +3 +1 +0 +1 +1 +0 +3 +0 +2 +2 +1 +3 +1 +0 +3 +1 +1 +0 +2 +1 +2 +1 +1 +1 +1 +2 +1 +2 +3 +2 +2 +1 +3 +2 +2 +3 +0 +3 +3 +2 +0 +2 +0 +2 +3 +0 +3 +3 +3 +0 +3 +0 +1 +2 +3 +2 +1 +0 +3 +0 +0 +1 +0 +2 +2 +0 +1 +0 +0 +3 +1 +0 +2 +3 +1 +1 +0 +2 +1 +0 +2 +2 +0 +0 +0 +0 +1 +3 +0 +2 +0 +0 +2 +2 +2 +0 +2 +3 +0 +2 +1 +2 +0 +3 +2 +3 +0 +3 +0 +2 +0 +0 +3 +2 +2 +1 +1 +0 +3 +1 +1 +2 +1 +2 +0 +3 +3 +0 +0 +3 +0 +1 +2 +0 +1 +2 +3 +2 +1 +0 +1 +3 +3 +3 +3 +2 +2 +3 +0 +2 +1 +0 +2 +2 +2 +1 +1 +3 +0 +0 +2 +1 +3 +2 +0 +3 +0 +1 +1 +2 +2 +0 +1 +1 +1 +0 +3 +3 +1 +1 +0 +1 +1 +1 +3 +2 +3 +0 +1 +1 +3 +3 +3 +1 +1 +0 +3 +2 diff --git a/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.csv b/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.csv new file mode 100644 index 0000000..2385c7b --- /dev/null +++ b/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.csv @@ -0,0 +1,301 @@ +tsne1,tsne2,y +8.36856841e-01, 2.13635938e+00, 1 +-1.41365810e+00, 7.40962324e+00, 3 +1.15521298e+00, 5.09961887e+00, 0 +-1.01861632e+00, 7.81491465e+00, 3 +1.27135141e+00, 1.89254207e+00, 1 +3.43761754e+00, 2.61654166e-01, 1 +-1.80822253e+00, 1.59701749e+00, 2 +1.41372442e+00, 4.38117707e+00, 0 +-2.04932168e-01, 8.43209665e+00, 3 +-7.11099611e-01, 8.66043846e+00, 3 +-1.71237268e+00, 2.77780226e+00, 2 +-2.67000792e+00, 8.35389140e+00, 3 +1.24258802e+00, 4.50399192e+00, 0 +-2.22783649e+00, 6.89479938e+00, 3 +1.45513831e+00, -2.91989981e-02, 1 +4.53791789e-01, 3.95647753e+00, 0 +1.06923853e+00, 4.53068484e+00, 0 +2.56936589e+00, 5.07048304e-01, 1 +-1.06690610e+00, 3.13165795e+00, 2 +-1.07859101e+00, 2.20451529e+00, 2 +2.71506328e+00, 1.29082190e+00, 1 +1.77710994e+00, 1.18655254e+00, 1 +7.34363910e-01, 5.03725437e+00, 0 +-1.99648151e+00, 2.85164868e+00, 2 +-1.91828017e+00, 2.60516867e+00, 2 +-5.55523811e-01, 4.69595848e+00, 0 +1.69747910e+00, 8.66123282e-01, 1 +5.94762432e-01, 4.70964730e+00, 0 +-2.88024255e+00, 2.30437816e+00, 2 +1.86725632e-01, 4.02683656e+00, 0 +-5.13333436e-01, 7.87437368e+00, 3 +-2.05701103e+00, 7.37851598e+00, 3 +1.87271752e+00, 4.18069237e+00, 0 +-1.13121396e+00, 6.76652230e+00, 3 +-1.64428957e+00, 7.94095139e+00, 3 +-2.41933824e+00, 7.43952498e+00, 3 +-2.01606928e+00, 7.48420129e+00, 3 +-2.62142780e+00, 7.98635066e+00, 3 +-2.20299950e+00, 2.47947561e+00, 2 +1.66382237e+00, 6.63091635e-01, 1 +6.69786996e-01, 3.59540802e+00, 0 +-1.98539037e+00, 2.05520738e+00, 2 +-4.74920358e-02, 5.47425256e+00, 0 +1.54462126e+00, 4.21078127e+00, 0 +-1.70200643e+00, 2.46098693e+00, 2 +-1.02192525e+00, 2.76820711e+00, 2 +-1.37842552e+00, 8.10269597e+00, 3 +-1.55220688e+00, 2.74574995e+00, 2 +-1.47904303e+00, 7.56915836e+00, 3 +1.98894313e+00, 1.50976729e+00, 1 +-1.94972418e+00, 3.48383870e+00, 2 +2.45509737e+00, 6.21231788e-01, 1 +-8.94327882e-01, 7.61714473e+00, 3 +1.69687788e+00, 7.54910622e-01, 1 +1.75644805e+00, 2.05538289e+00, 1 +-1.11064012e+00, 2.82213820e+00, 2 +-4.15017659e-02, 7.80870276e+00, 3 +-1.14091533e+00, 1.97550822e+00, 2 +-1.80634968e+00, 7.72830656e+00, 3 +1.39263752e+00, 9.28962707e-01, 1 +-2.25698670e+00, 7.30207720e+00, 3 +5.71670482e-01, 4.32288566e+00, 0 +-1.54994580e+00, 9.28293222e+00, 3 +-1.03819212e+00, 2.95323761e+00, 2 +-2.10956676e+00, 3.10677258e+00, 2 +-1.18652985e+00, 2.78427720e+00, 2 +-2.45809975e+00, 7.51178724e+00, 3 +2.36960214e+00, 9.50716912e-01, 1 +-2.66676007e+00, 7.84766052e+00, 3 +-1.49720702e+00, 3.21418433e+00, 2 +1.32222457e+00, 4.17880807e+00, 0 +-4.87271301e-01, 3.32858293e+00, 2 +-1.03718771e+00, 8.06300134e+00, 3 +-1.60496819e+00, 2.97425420e+00, 2 +-1.50372568e+00, 1.92385320e+00, 2 +-7.85412206e-01, 8.45312331e+00, 3 +-1.75783190e+00, 2.97449321e+00, 2 +1.19008992e+00, 4.72773123e+00, 0 +2.14043942e+00, 7.06066610e-01, 1 +-1.03540116e+00, 8.20559195e+00, 3 +1.25471244e+00, 8.96331565e-02, 1 +5.95676822e-01, 4.08614263e+00, 0 +1.27955338e+00, 1.05789418e+00, 1 +1.72955064e+00, 1.14729369e+00, 1 +-9.49041610e-01, 8.46424331e+00, 3 +9.35325115e-01, 5.33179296e+00, 0 +2.36923352e+00, 7.94735861e-01, 1 +4.28576743e-01, 4.97399710e+00, 0 +-2.04758277e+00, 6.65428520e+00, 3 +-1.45672617e+00, 7.48669893e+00, 3 +5.29417185e-01, 3.80792420e+00, 0 +1.78194802e+00, 9.08151155e-01, 1 +-1.95575053e+00, 8.61631686e+00, 3 +-1.74572014e+00, 3.01190457e+00, 2 +-1.17979111e+00, 3.12767494e+00, 2 +1.16411070e+00, 3.79132988e+00, 0 +1.36155806e+00, 1.36638252e+00, 1 +2.60137487e+00, 1.08799459e+00, 1 +2.72396035e-01, 5.46996004e+00, 0 +-3.12240736e+00, 3.28167398e+00, 2 +-5.88085172e-01, 8.61427320e+00, 3 +1.66909648e+00, -4.36378231e-01, 1 +-6.82774903e-01, 7.67490317e+00, 3 +2.36790645e+00, 5.52190878e-01, 1 +1.05241733e+00, 4.54498095e+00, 0 +2.22707373e+00, 1.26296996e+00, 1 +2.43934644e+00, -7.25099666e-02, 1 +1.34471770e+00, 4.85711133e+00, 0 +-1.31454942e+00, 6.83904013e+00, 3 +9.82570091e-01, 5.37530962e+00, 0 +-1.06295223e+00, 2.20755388e+00, 2 +-1.60712495e+00, 3.56452854e+00, 2 +1.57322172e+00, 4.83933793e-01, 1 +-2.17851338e+00, 8.08585131e+00, 3 +1.83375842e+00, 7.54036153e-01, 1 +2.10616050e+00, 3.49513189e+00, 0 +-1.64338755e+00, 7.52691964e+00, 3 +1.10550448e+00, 1.26389129e+00, 1 +1.61152972e+00, 1.82347242e+00, 1 +4.59534668e-01, 5.44982630e+00, 0 +-5.38023054e-01, 3.01641891e+00, 2 +1.67841499e+00, 6.09047389e-01, 1 +-1.01214966e+00, 3.60254338e+00, 2 +1.34195197e+00, 5.93573847e-01, 1 +1.42811550e+00, 1.62435083e+00, 1 +2.04505527e+00, 1.12515470e+00, 1 +1.67280531e+00, 6.59300571e-01, 1 +-1.35863899e+00, 2.32200809e+00, 2 +1.13078931e+00, 9.35620856e-01, 1 +-1.73896306e+00, 1.94799775e+00, 2 +-3.40258925e-01, 8.16733925e+00, 3 +-1.63793622e+00, 2.43329317e+00, 2 +-1.68754414e+00, 2.24107546e+00, 2 +2.43040639e+00, -6.35709334e-02, 1 +-1.37998039e+00, 7.18503804e+00, 3 +-1.25245465e+00, 2.33911505e+00, 2 +-2.39482483e+00, 3.39806103e+00, 2 +-2.09183352e+00, 7.48142543e+00, 3 +4.88382309e-01, 3.26801777e+00, 0 +-5.39428614e-01, 7.45631776e+00, 3 +-2.59201821e+00, 8.07635945e+00, 3 +-1.04656513e+00, 2.96483837e+00, 2 +1.25566754e+00, 3.38204112e+00, 0 +-1.62150422e+00, 4.27191636e+00, 2 +1.86922139e+00, 5.44132083e+00, 0 +-1.76404140e+00, 2.22222995e+00, 2 +-1.38181918e+00, 7.28761248e+00, 3 +7.93137001e-03, 4.17614316e+00, 0 +-1.10298500e+00, 7.30222786e+00, 3 +-1.79351372e+00, 7.58086944e+00, 3 +-1.51176949e+00, 7.94426307e+00, 3 +9.59360742e-01, 4.56078645e+00, 0 +-6.01337393e-01, 6.29994922e+00, 3 +2.24592863e-01, 4.77028154e+00, 0 +1.56724897e+00, 1.78090633e-02, 1 +-1.03395259e+00, 2.92105785e+00, 2 +-9.22268640e-01, 8.09888579e+00, 3 +-1.88609638e+00, 2.24834407e+00, 2 +1.86873582e+00, 9.56103760e-01, 1 +1.10123507e+00, 4.88977075e+00, 0 +-1.93213725e+00, 8.30643453e+00, 3 +6.70478769e-01, 4.04094275e+00, 0 +7.43873988e-01, 4.12240568e+00, 0 +1.64003761e+00, 1.81948989e+00, 1 +8.15468056e-01, 4.78526116e+00, 0 +-2.63274574e+00, 2.63109786e+00, 2 +-9.61076361e-01, 1.27407596e+00, 2 +2.13979079e-01, 4.88542535e+00, 0 +1.43472182e+00, 1.30662037e+00, 1 +1.21387411e+00, 3.64795042e+00, 0 +1.08272576e+00, 4.06271877e+00, 0 +-1.22605234e+00, 8.29620146e+00, 3 +1.48170052e+00, 6.90074595e-01, 1 +1.89593761e+00, 5.18540259e+00, 0 +-1.32356154e+00, 4.13050840e+00, 2 +-1.14989863e+00, 7.89325283e+00, 3 +2.46915842e+00, 1.67877140e+00, 1 +2.31102276e+00, 1.30380848e+00, 1 +5.72793810e-01, 4.08805543e+00, 0 +-9.67794989e-01, 3.12186125e+00, 2 +2.62492001e+00, 9.50194405e-01, 1 +1.68353782e+00, 4.19583243e+00, 0 +-2.22131717e+00, 2.73050691e+00, 2 +-1.57846247e+00, 3.03445802e+00, 2 +8.15155229e-02, 4.56742235e+00, 0 +1.43289271e+00, 4.37679234e+00, 0 +1.06269622e+00, 5.17635143e+00, 0 +7.67522789e-01, 4.39759671e+00, 0 +2.47019077e+00, 1.31451315e+00, 1 +-1.73163168e+00, 7.16447286e+00, 3 +3.47138300e-01, 3.45177657e+00, 0 +-1.00140436e+00, 2.84881778e+00, 2 +1.01618041e+00, 4.48527047e+00, 0 +5.59529363e-01, 4.21400660e+00, 0 +-2.11821046e+00, 2.03478126e+00, 2 +-1.36219420e+00, 2.38333321e+00, 2 +-2.78366586e+00, 2.99211541e+00, 2 +1.65225163e+00, 3.65582842e+00, 0 +-1.93960658e+00, 2.18943582e+00, 2 +-1.81487687e+00, 7.97832190e+00, 3 +1.20212540e+00, 3.64414685e+00, 0 +-9.69200946e-01, 3.26721702e+00, 2 +1.86985974e+00, -1.07938624e-01, 1 +-1.80701134e+00, 2.06773859e+00, 2 +1.21767506e+00, 3.89290127e+00, 0 +-1.48368917e+00, 6.00777418e+00, 3 +-1.56387985e+00, 2.85349910e+00, 2 +-6.86210297e-01, 8.68285664e+00, 3 +1.07627418e+00, 4.68480619e+00, 0 +-9.75986627e-01, 6.73761577e+00, 3 +1.37964693e+00, 4.54826443e+00, 0 +-1.64129611e+00, 2.68097255e+00, 2 +-1.84892963e-03, 4.58145668e+00, 0 +1.71444449e+00, 5.02521524e+00, 0 +-1.40524304e+00, 7.72611315e+00, 3 +-7.08184904e-01, 2.50421275e+00, 2 +-8.85798374e-01, 2.64585078e+00, 2 +1.98436909e+00, 4.89556738e-01, 1 +2.95195825e+00, -3.44327355e-01, 1 +4.31891060e-01, 4.33495456e+00, 0 +-1.86621694e+00, 7.62549400e+00, 3 +2.52706430e+00, 6.17812202e-01, 1 +2.04067185e+00, 4.54845114e-01, 1 +-2.58043836e+00, 3.18844294e+00, 2 +1.61990909e+00, 6.76452867e-02, 1 +-2.58802708e+00, 3.13117134e+00, 2 +4.43598630e-01, 3.11530945e+00, 0 +-4.56773649e-01, 7.30600872e+00, 3 +-1.12867566e+00, 7.80509789e+00, 3 +2.13003529e+00, 5.19209620e+00, 0 +1.00372519e+00, 4.19147702e+00, 0 +-1.39346767e+00, 8.74641672e+00, 3 +7.28098690e-01, 3.85531444e+00, 0 +8.93499638e-01, 1.01093082e+00, 1 +-1.10782972e+00, 2.92014479e+00, 2 +7.89338559e-01, 4.33748653e+00, 0 +1.97553917e+00, 7.18989132e-01, 1 +-1.24902582e+00, 3.08533972e+00, 2 +-1.07768797e+00, 8.88106128e+00, 3 +-1.86849125e+00, 3.07982487e+00, 2 +2.76808540e+00, 1.08782923e+00, 1 +2.77180174e-01, 4.84428322e+00, 0 +3.41085289e+00, 8.72309369e-01, 1 +-1.58084155e+00, 7.55307742e+00, 3 +-1.53027550e+00, 7.70542113e+00, 3 +-1.82455840e+00, 7.35958960e+00, 3 +-1.68568257e+00, 7.95339446e+00, 3 +-1.65104622e+00, 3.44598961e+00, 2 +-1.30440901e+00, 3.00311934e+00, 2 +-7.30698168e-01, 6.24208856e+00, 3 +2.40615694e+00, 4.87047502e+00, 0 +-1.53631328e+00, 3.01443916e+00, 2 +1.48859977e+00, 6.51633844e-01, 1 +5.14320434e-01, 4.62733684e+00, 0 +-1.81469750e+00, 3.29009724e+00, 2 +-1.93731055e+00, 3.91361274e+00, 2 +-6.14907097e-01, 3.94963585e+00, 2 +2.03169783e+00, 1.96807561e-01, 1 +2.14917144e+00, 1.03697228e+00, 1 +-1.36999388e+00, 7.76953035e+00, 3 +9.14338767e-01, 4.55014643e+00, 0 +3.33818506e-01, 4.93645836e+00, 0 +-2.15968109e+00, 3.41003096e+00, 2 +1.36678633e+00, 6.34971633e-01, 1 +-5.71099336e-01, 8.13306058e+00, 3 +-1.00552592e+00, 3.08400540e+00, 2 +1.49493180e+00, 3.85848832e+00, 0 +-5.90447667e-01, 7.69493053e+00, 3 +7.15177948e-01, 5.41334556e+00, 0 +2.11390250e+00, 1.24743587e+00, 1 +1.20083098e+00, 6.01671730e-01, 1 +-2.54576750e+00, 3.15025055e+00, 2 +-1.95866665e+00, 2.43008647e+00, 2 +2.33812285e+00, 3.43116792e+00, 0 +3.35320909e+00, 1.69958043e+00, 1 +1.84287117e+00, 7.26928839e-02, 1 +1.32000621e+00, 1.40428145e+00, 1 +2.09680545e+00, 4.84741412e+00, 0 +-1.24307904e+00, 8.15166254e+00, 3 +-1.85908090e+00, 7.78874716e+00, 3 +2.74666646e+00, 1.54543482e+00, 1 +2.60778282e+00, 1.08890025e+00, 1 +1.65991049e+00, 3.56289184e+00, 0 +2.35151259e+00, 8.28001297e-01, 1 +2.22322228e+00, 8.38773426e-01, 1 +3.22881491e+00, 1.13171965e+00, 1 +-1.55876720e+00, 7.24816210e+00, 3 +-6.46956784e-01, 3.42941343e+00, 2 +-1.32688818e+00, 8.51530794e+00, 3 +9.17198564e-01, 3.90570036e+00, 0 +2.29469533e+00 , -7.65891994e-01, 1 +1.81559810e+00, 1.11969719e+00, 1 +-1.12016775e+00, 7.11031582e+00, 3 +-1.65507124e+00, 8.61416749e+00, 3 +-1.27567815e+00, 7.96776461e+00, 3 +1.97369770e+00, 1.57979848e+00, 1 +2.51834185e+00, 1.39176615e+00, 1 +4.38990142e-01, 4.53592883e+00, 0 +3.69478657e-01, 7.79110522e+00, 3 +-1.79145759e+00, 2.74966896e+00, 2 diff --git a/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.png b/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.png new file mode 100644 index 0000000..5ece8af Binary files /dev/null and b/NeuralNetworks-python/blueprint/data/tsne_2d/tsne_2d.png differ diff --git a/NeuralNetworks-python/blueprint/datasets/__init__.py b/NeuralNetworks-python/blueprint/datasets/__init__.py new file mode 100644 index 0000000..6caf0d8 --- /dev/null +++ b/NeuralNetworks-python/blueprint/datasets/__init__.py @@ -0,0 +1,14 @@ +from pathlib import Path + +from .dataset import Dataset +from .. import data + + +logic_gate_and = Dataset('logic_gate_and', Path(data.__file__).parent.resolve() / 'logic_gate_and', bias = -1) +logic_gate_or = Dataset('logic_gate_or', Path(data.__file__).parent.resolve() / 'logic_gate_or', bias = -1) +logic_gate_xor = Dataset('logic_gate_xor', Path(data.__file__).parent.resolve() / 'logic_gate_xor', bias = -1) +blood_transfusion = Dataset('blood_transfusion', Path(data.__file__).parent.resolve() / 'blood_transfusion', bias = -1) +cryotherapy = Dataset('cryotherapy', Path(data.__file__).parent.resolve() / 'cryotherapy', bias = -1) +diabetes = Dataset('diabetes', Path(data.__file__).parent.resolve() / 'diabetes', bias = -1) +tic_tac_toe_endgame = Dataset('tic_tac_toe_endgame', Path(data.__file__).parent.resolve() / 'tic_tac_toe_endgame', bias = -1) +tsne_2d = Dataset('tsne_2d', Path(data.__file__).parent.resolve() / 'tsne_2d', output_type = int) diff --git a/NeuralNetworks-python/blueprint/datasets/dataset.py b/NeuralNetworks-python/blueprint/datasets/dataset.py new file mode 100644 index 0000000..b95b65a --- /dev/null +++ b/NeuralNetworks-python/blueprint/datasets/dataset.py @@ -0,0 +1,16 @@ +from . import utils + + +class Dataset: + def __init__(self, name, path, input_type = float, output_type = float, bias = None): + self.name = name + self.path = path + self.input_type = input_type + self.output_type = output_type + self.bias = bias + + self.input = utils.read(self.path / 'input.txt', dtype = self.input_type) + self.output = utils.read(self.path / 'output.txt', dtype = self.output_type) + + if bias is not None: + utils.bias(self.input, self.bias) diff --git a/NeuralNetworks-python/blueprint/datasets/utils.py b/NeuralNetworks-python/blueprint/datasets/utils.py new file mode 100644 index 0000000..68d60e1 --- /dev/null +++ b/NeuralNetworks-python/blueprint/datasets/utils.py @@ -0,0 +1,13 @@ +import numpy as np + + +def read(filename, delimiter = ',', dtype = float): + return np.genfromtxt(filename, delimiter = delimiter, dtype = dtype) + +def bias(x, value): + biased_x = np.ndarray(shape = (x.shape[0], x.shape[1] + 1), dtype = x.dtype) + + for i in range(len(x)): + biased_x[i] = np.append(value, x[i]) + + return biased_x diff --git a/NeuralNetworks-python/blueprint/estimators/__init__.py b/NeuralNetworks-python/blueprint/estimators/__init__.py new file mode 100644 index 0000000..f7b3ab4 --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/__init__.py @@ -0,0 +1,4 @@ +from .estimator import * +from .perceptron import * +from .adaline import * +from .kmeans import * diff --git a/NeuralNetworks-python/blueprint/estimators/adaline.py b/NeuralNetworks-python/blueprint/estimators/adaline.py new file mode 100644 index 0000000..02b6275 --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/adaline.py @@ -0,0 +1,66 @@ +import numpy as np + +from .estimator import Estimator + + +class Adaline(Estimator): + def __init__(self, learning_rate, activation_function, loss_function, loss_variation_tolerance): + super().__init__() + + self.learning_rate = learning_rate + self.activation_function = activation_function + self.loss_function = loss_function + self.loss_variation_tolerance = loss_variation_tolerance + + def train(self, x, d): + k = len(x) + w = np.random.rand(len(x[0])) + epoch = 0 + + while True: + mse_before = self.loss_function(x, d, w) + + if epoch == 0: + print(f'Epoch: {epoch}\tWeights: {w}\tLoss: {mse_before:.5f}') + + self.plot_data_x.append(epoch) + self.plot_data_y.append(mse_before) + + for i in range(k): + v = np.dot(np.transpose(w), x[i]) + w = np.add(w, np.multiply(x[i], self.learning_rate * (d[i] - v))) + + epoch = epoch + 1 + mse_after = self.loss_function(x, d, w) + + print(f'Epoch: {epoch}\tWeights: {w}\tLoss: {mse_after:.5f}') + + self.plot_data_x.append(epoch) + self.plot_data_y.append(mse_after) + + if abs(mse_after - mse_before) <= self.loss_variation_tolerance: + break + + return w + + def predict(self, x, w): + v = np.dot(np.transpose(w), x) + y = self.activation_function(v) + + return y + + def evaluate(self, x, d, w): + total = len(x) + correct = 0 + + for i in range(len(x)): + y = self.predict(x[i], w) + + if y == d[i]: + correct = correct + 1 + + accuracy = correct / total + + print(f'Accuracy: {accuracy * 100:.5f}% ({accuracy:.5f})') + + return accuracy diff --git a/NeuralNetworks-python/blueprint/estimators/estimator.py b/NeuralNetworks-python/blueprint/estimators/estimator.py new file mode 100644 index 0000000..4bd086d --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/estimator.py @@ -0,0 +1,16 @@ +class Estimator: + def __init__(self, *args, **kwargs): + if type(self) is Estimator: + raise NotImplementedError + + self.plot_data_x = [] + self.plot_data_y = [] + + def train(self, *args, **kwargs): + raise NotImplementedError + + def predict(self, *args, **kwargs): + raise NotImplementedError + + def evaluate(self, *args, **kwargs): + raise NotImplementedError diff --git a/NeuralNetworks-python/blueprint/estimators/kmeans.py b/NeuralNetworks-python/blueprint/estimators/kmeans.py new file mode 100644 index 0000000..09279f3 --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/kmeans.py @@ -0,0 +1,54 @@ +import numpy as np + +from . import utils +from .estimator import Estimator + + +# https://github.com/Yangyangii/MachineLearningTutorial/blob/master/Numpy/RBF-Network-with-Kmeans-clustering.ipynb +# https://jakevdp.github.io/PythonDataScienceHandbook/05.11-k-means.html +class KMeans(Estimator): + def __init__(self, k, maximum_iterations, epsilon): + self.k = k + self.maximum_iterations = maximum_iterations + self.epsilon = epsilon + + def train(self, x): + c = utils.kmeans_plus_plus(x, self.k) + dist = np.zeros([self.k, x.shape[0]]) + eps2 = self.epsilon * self.epsilon + it = 0 + + while it < self.maximum_iterations: + for i, centroid in enumerate(c): + dist[i] = np.sum(np.square(np.subtract(np.broadcast_to(centroid, x.shape), x)), axis = 1) + + y = np.argmin(dist, axis = 0) + + prev_c = c + c = np.array([np.mean(x[y == i], axis = 0) for i in range(self.k)]) + + if np.all(np.square(c - prev_c) < eps2): + break + + it += 1 + + return c + + def predict(self, x, c): + dist = np.zeros([self.k, x.shape[0]]) + + for i, centroid in enumerate(c): + dist[i] = np.sum(np.square(np.subtract(np.broadcast_to(centroid, x.shape), x)), axis = 1) + + y = np.argmin(dist, axis = 0) + + return y + + def evaluate(self, x, d, c): + y = self.predict(x, c) + + accuracy = utils.rand_index_score(y, d) + + print(f'Accuracy: {accuracy * 100:.5f}% ({accuracy:.5f})') + + return accuracy diff --git a/NeuralNetworks-python/blueprint/estimators/perceptron.py b/NeuralNetworks-python/blueprint/estimators/perceptron.py new file mode 100644 index 0000000..e4f9195 --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/perceptron.py @@ -0,0 +1,65 @@ +import numpy as np + +from .estimator import Estimator + + +class Perceptron(Estimator): + def __init__(self, learning_rate, activation_function, epochs): + super().__init__() + + self.learning_rate = learning_rate + self.activation_function = activation_function + self.epochs = epochs + + def train(self, x, d): + k = len(x) + w = np.random.rand(len(x[0])) + epoch = 0 + error = True + + print(f'Epoch: {epoch}\tWeights: {w}') + + self.plot_data_x.append(epoch) + self.plot_data_y.append(1 if error else 0) + + while error and epoch < self.epochs: + error = False + + for i in range(k): + v = np.dot(np.transpose(w), x[i]) + y = self.activation_function(v) + + if y != d[i]: + w = np.add(w, np.multiply(self.learning_rate * (d[i] - y), x[i])) + error = True + + epoch = epoch + 1 + + print(f'Epoch: {epoch}\tWeights: {w}') + + self.plot_data_x.append(epoch) + self.plot_data_y.append(1 if error else 0) + + return w + + def predict(self, x, w): + v = np.dot(np.transpose(w), x) + y = self.activation_function(v) + + return y + + def evaluate(self, x, d, w): + total = len(x) + correct = 0 + + for i in range(len(x)): + y = self.predict(x[i], w) + + if y == d[i]: + correct = correct + 1 + + accuracy = correct / total + + print(f'Accuracy: {accuracy * 100:.5f}% ({accuracy:.5f})') + + return accuracy diff --git a/NeuralNetworks-python/blueprint/estimators/utils.py b/NeuralNetworks-python/blueprint/estimators/utils.py new file mode 100644 index 0000000..e8e9bdd --- /dev/null +++ b/NeuralNetworks-python/blueprint/estimators/utils.py @@ -0,0 +1,38 @@ +import numpy as np +from scipy.special import comb + + +# https://stats.stackexchange.com/a/157385 +def rand_index_score(y, d): + tp_fp = comb(np.bincount(y), 2).sum() + tp_fn = comb(np.bincount(d), 2).sum() + + A = np.c_[(y, d)] + + tp = sum(comb(np.bincount(A[A[:, 0] == i, 1]), 2).sum() for i in set(y)) + + fp = tp_fp - tp + fn = tp_fn - tp + + tn = comb(len(A), 2) - tp - fp - fn + + return (tp + tn) / (tp + fp + fn + tn) + +# https://www.kdnuggets.com/2020/06/centroid-initialization-k-means-clustering.html +def kmeans_plus_plus(x, k): + c = [x[0]] + + for _ in range(1, k): + dist = np.array([min([np.inner(c - xi, c - xi) for c in c]) for xi in x]) + probs = dist / dist.sum() + cumulative_probs = probs.cumsum() + r = np.random.rand() + + for j, p in enumerate(cumulative_probs): + if r < p: + i = j + break + + c.append(x[i]) + + return np.array(c) diff --git a/NeuralNetworks-python/blueprint/loss_functions.py b/NeuralNetworks-python/blueprint/loss_functions.py new file mode 100644 index 0000000..b028648 --- /dev/null +++ b/NeuralNetworks-python/blueprint/loss_functions.py @@ -0,0 +1,13 @@ +import numpy as np + + +def mean_squared_error(x, d, w): + mse = 0 + + for i in range(0, len(x)): + v = np.dot(np.transpose(w), x[i]) + mse = mse + pow(d[i] - v, 2) + + mse = mse / len(x) + + return mse diff --git a/NeuralNetworks-python/blueprint/package.py b/NeuralNetworks-python/blueprint/package.py new file mode 100644 index 0000000..46616e3 --- /dev/null +++ b/NeuralNetworks-python/blueprint/package.py @@ -0,0 +1,18 @@ +__title__ = 'Blueprint' +__version__ = '2.0.0' +__description__ = 'A simple neural network package.' +__author__ = 'Marcelo Cysneiros and Danilo Peixoto' +__email__ = 'marcelovca90@inatel.br' +__license__ = 'MIT License' +__copyright__ = 'Copyright (c) 2020, Marcelo Cysneiros and Danilo Peixoto. All rights reserved.' + + +__all__ = [ + '__title__', + '__version__', + '__description__', + '__author__', + '__email__', + '__license__', + '__copyright__' +] diff --git a/NeuralNetworks-python/blueprint/plot_utils.py b/NeuralNetworks-python/blueprint/plot_utils.py new file mode 100644 index 0000000..9f6e49e --- /dev/null +++ b/NeuralNetworks-python/blueprint/plot_utils.py @@ -0,0 +1,34 @@ +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.ticker import MaxNLocator + + +def line(x, y, x_label = 'x', y_label = 'y', color = 'blue', title = None): + ax = plt.gca() + ax.plot(x, y, color = color, linewidth = 1.5) + ax.xaxis.set_major_locator(MaxNLocator(integer = True)) + + ax.set_xlim([np.min(x), np.max(x)]) + ax.set_ylim([np.min(y), np.max(y)]) + + ax.set_xlabel(x_label) + ax.set_ylabel(y_label) + ax.set_title('{} vs {}'.format(x_label, y_label) if title is None else title) + + ax.grid() + plt.show() + +def scatter(x, y, x_label = 'x', y_label = 'y', colors = None, title = None): + ax = plt.gca() + ax.scatter(x, y, c = colors, s = 10) + ax.xaxis.set_major_locator(MaxNLocator(integer = True)) + + ax.set_xlim([np.min(x), np.max(x)]) + ax.set_ylim([np.min(y), np.max(y)]) + + ax.set_xlabel(x_label) + ax.set_ylabel(y_label) + ax.set_title('{} vs {}'.format(x_label, y_label) if title is None else title) + + ax.grid() + plt.show() diff --git a/NeuralNetworks-python/scripts/adaline.py b/NeuralNetworks-python/scripts/adaline.py new file mode 100644 index 0000000..ae3a7f7 --- /dev/null +++ b/NeuralNetworks-python/scripts/adaline.py @@ -0,0 +1,35 @@ +import numpy as np + +from blueprint import datasets, estimators, activation_functions, loss_functions, plot_utils + + +if __name__ == '__main__': + # set random number generator seed + np.random.seed(0) + + # set floating point formatting when printing + np.set_printoptions(formatter = {'float': '{:.5f}'.format}) + + # load data + dataset = datasets.logic_gate_and + + x = dataset.input + d = dataset.output + + # define the estimator parameters + n = 1e-3 + g = activation_functions.heaviside + l = loss_functions.mean_squared_error + e = 1e-6 + + # create the estimator + estimator = estimators.Adaline(n, g, l, e) + + # train the estimator + w = estimator.train(x, d) + + # evaluate the estimator + accuracy = estimator.evaluate(x, d, w) + + # plot epoch vs loss (mse) + plot_utils.line(estimator.plot_data_x, estimator.plot_data_y, x_label = 'epoch', y_label = 'loss (mse)') diff --git a/NeuralNetworks-python/scripts/kmeans.py b/NeuralNetworks-python/scripts/kmeans.py new file mode 100644 index 0000000..12c90b2 --- /dev/null +++ b/NeuralNetworks-python/scripts/kmeans.py @@ -0,0 +1,35 @@ +import numpy as np + +from blueprint import datasets, estimators, plot_utils + + +if __name__ == '__main__': + # set random number generator seed + np.random.seed(0) + + # set floating point formatting when printing + np.set_printoptions(formatter = {'float': '{:.5f}'.format}) + + # load data + dataset = datasets.tsne_2d + + x = dataset.input + d = dataset.output + + # define the estimator parameters + k = 4 + iterations = 1e3 + eps = 1e-6 + + # create the estimator + estimator = estimators.KMeans(k, iterations, eps) + + # train the estimator + c = estimator.train(x) + + # evaluate the estimator + accuracy = estimator.evaluate(x, d, c) + + # plot clusters + y = estimator.predict(x, c) + plot_utils.scatter(x[:, 0], x[:, 1], x_label = 'tsne-1', y_label = 'tsne-2', colors = y) diff --git a/NeuralNetworks-python/scripts/perceptron.py b/NeuralNetworks-python/scripts/perceptron.py new file mode 100644 index 0000000..13e52f0 --- /dev/null +++ b/NeuralNetworks-python/scripts/perceptron.py @@ -0,0 +1,34 @@ +import numpy as np + +from blueprint import datasets, estimators, activation_functions, loss_functions, plot_utils + + +if __name__ == '__main__': + # set random number generator seed + np.random.seed(0) + + # set floating point formatting when printing + np.set_printoptions(formatter = {'float': '{:.5f}'.format}) + + # load data + dataset = datasets.logic_gate_and + + x = dataset.input + d = dataset.output + + # define the estimator parameters + n = 1e-3 + g = activation_functions.heaviside + epochs = 1e3 + + # create the estimator + estimator = estimators.Perceptron(n, g, epochs) + + # train the estimator + w = estimator.train(x, d) + + # evaluate the estimator + accuracy = estimator.evaluate(x, d, w) + + # plot epoch vs error + plot_utils.line(estimator.plot_data_x, estimator.plot_data_y, x_label = 'epoch', y_label = 'error') diff --git a/NeuralNetworks-python/setup.py b/NeuralNetworks-python/setup.py new file mode 100644 index 0000000..026d25c --- /dev/null +++ b/NeuralNetworks-python/setup.py @@ -0,0 +1,27 @@ +from distutils.util import convert_path +from setuptools import setup, find_packages + + +package_name = 'blueprint' +package_info = {} + +with open(convert_path(f'{package_name}/package.py'), 'r') as file: + exec(file.read(), package_info) + +requirements = [ + 'numpy>=1.18.0', + 'scipy>=1.5.4', + 'matplotlib>=3.3.0' +] + +setup( + name = package_name, + version = package_info['__version__'], + description = package_info['__description__'], + author = package_info['__author__'], + author_email = package_info['__email__'], + license = package_info['__license__'], + python_requires = '>=3.6.0', + install_requires = requirements, + packages = find_packages(), + zip_safe = False)