Everything related to data science.
Project description
SnoScience
A package optimised for building small neural networks.
The MNIST dataset has been used for training. Each network is trained by using 64 samples from this dataset per epoch for 200 epochs. As can be seen from the graph, use Tensorflow or equivalent for networks with more than 3 layers (n>3) and/or more than 20 neurons per layer. SnScience networks with one (n=2) or no hidden layers (n=1) are extremely fast.
Installation
To install the SnoScience package either:
- run the command 'pip install snoscience' in the command line.
- install the package via your IDE.
Features
SnoScience.networks module
- The user is able to create a neural network capable of being trained and making predictions:
- this network is able to process an arbitrary number of inputs.
- this network can consist of an arbitrary number of layers.
- each layer in this network can consist of an arbitrary number of neurons.
- The neural network supports the following activation functions:
- sigmoid.
- The neural network supports the following loss functions:
- mean squared error (MSE).
- The neural network supports the following optimisers:
- stochastic gradient descent (SGD).
- The user can train the neural network with a single command:
- all inputs are checked for validity before the training proceeds.
- The user can let the network make predictions with a single command:
- all inputs are checked for validity before predictions are given.
- these predictions can be regressions of an arbitrary size.
- these predictions can be classifications of an arbitrary size.
SnoScience.metrics module
- The user is able to calculate the mean squared error of a regression.
- The user is able to calculate the accuracy of a classification.
Usage
from snoscience.networks import NeuralNetwork
from snoscience.metrics import calculate_mse, calculate_accuracy
# Create model.
model = NeuralNetwork(inputs=9, loss="MSE", optimiser="SGD")
model.add_layer(neurons=2, activation="sigmoid")
model.add_layer(neurons=1, activation="sigmoid")
# Define optimizer hyperparameters.
rate = 0.01
# Train model.
model.train(x=x_train, y=y_train, epochs=1000, samples=32, rate=rate, log=False)
# Make predictions (classification).
y_calc = model.predict(x=x_test, classify=True)
# Make predictions (regression).
y_calc = model.predict(x=x_test, classify=False)
# Calculate performance.
mse = calculate_mse(calc=y_calc, true=y_test)
accuracy = calculate_accuracy(calc=y_calc, true=y_test)
Calculations
Total derivative for neuron
dL / dy_1 = (dy_2_1 / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_1) +
(dy_2_1 / dy_1) * (dy_3_2 / dy_2) ... (dL / dy_M_1) +
(dy_2_1 / dy_1) * (dy_3_P / dy_2) ... (dL / dy_M_1) +
...
(dy_2_1 / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_1) +
(dy_2_1 / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_2) +
(dy_2_1 / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_N) +
...
(dy_2_Q / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_1) +
(dy_2_Q / dy_1) * (dy_3_2 / dy_2) ... (dL / dy_M_1) +
(dy_2_Q / dy_1) * (dy_3_P / dy_2) ... (dL / dy_M_1) +
...
(dy_2_Q / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_1) +
(dy_2_Q / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_2) +
(dy_2_Q / dy_1) * (dy_3_1 / dy_2) ... (dL / dy_M_N) +
...
(dy_2_Q / dy_1) * (dy_3_P / dy_2) ... (dL / dy_M_N)
L = loss
y_X = neuron in layer X.
M = last layer.
N = last neuron in last layer.
P = last neuron in third layer.
Q = last neuron in second layer.
Applicable chain rule:
dy_A / dy_B = y_dot_A * w_A[position_B]
A = current neuron
B = neuron from previous layer
Chain rule needs to be applied everywhere except for the starting neuron.
Total derivative for neuron weights and bias
dL / db = sum(dL / dy_A)
dL / dw = sum((dL / dy_A) * y_B)
A = current neuron
B = previous layer
Example
-------
y_B = [[1, 2, 3],
[4, 5, 6]]
dL / dy_A = [[1],
[2]]
dL / db = 3
dL / dw = [[9],
[12],
[15]]
Stochastic gradient descent
b_new = b_old - (learn * dL / db)
w_new = w_old - (learn * dL / dw)
Example
-------
rate = 0.1
b_old = 1
w_old = [[1],
[1],
[1]]
dL / db = 3
dL / dw = [[9],
[12],
[15]]
b_new = 0.7
w_new = [[0.1],
[-0.2],
[-0.5]]
Changelog
v1.0.0
- SnoScience.networks features 1 through 6 added.
- SnoScience.metrics features 1 and 2 added.
v0.1.0
- Initial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SnoScience-1.0.0.tar.gz.
File metadata
- Download URL: SnoScience-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c7eab210e7c8eae37fa632092907424370dd9720e0e5785380cfc38a4b12f41
|
|
| MD5 |
d393468a0e45a86c61772bc33112b2d2
|
|
| BLAKE2b-256 |
c39973355cedf8ab01d74e299ecde3d429bdc74a75512218cec1ef5a3eb92337
|
File details
Details for the file SnoScience-1.0.0-py3-none-any.whl.
File metadata
- Download URL: SnoScience-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8a64e7045bd13861d735ec489d055bfa9de191af63eda700adc3f49688050ec
|
|
| MD5 |
8384dc328704ac727b25f55865ac4582
|
|
| BLAKE2b-256 |
239ad63a0c39fc74029289faecb4f56dcf34bca90eddc80ac7983340788b9193
|