Skip to main content

A lightweight basic neural networks library in Python

Project description

Parkr

A light weight neural network library

Python package

Parkr was created for my second year AI methods module at university.

It is very basic to get a neural network up and running and getting results quickly.

Installation

pip install parkr

Examples

Creating the network

To create a network you just need to specify how many input nodes, how many output nodes, a vector that contains the amount of nodes in each hidden layer, and the activation function you want to use.

from parkr import Network, ActivationMethods
my_network = Network(6, [4,4], 1, ActivationMethods.TANH)

This will create a network with 6 input nodes, 2 hidden layers, both with 4 nodes each and 2 output nodes and it will use the tanh activation function.

Training the network

To train the network you must pass a tuple where the first element is the training data and the second is the expected values for that training data.

Then when calling the train method the network will updates its bias' and weights on those values.

import numpy as np
training_data = np.array([
    [0.77,0.21,0.34,0.2,0.12,0.54],
    [0.43,0.12,0.65,0.12,0.76,0.34]
    ])

expected_data = np.array([
    [1],
    [0]
    ])

epochs = 10
my_network.train(epochs, (training_data, expected_data))

Performing a forward pass on the network

To perform a forward pass on the network you simply pass it a vector with each element as an input vaule.

my_result = my_network.forward_pass([0.54,0.32,0.12,0.46,0.68,0.43])

Saving and opening networks

Parkr supports saving networks to disk and loading them back in so that you do not have to retrain your network everytime it leaves memory.

Save

This will save the networks structure as a .json file

my_network.save("my_network_on_disk")

Load

This will load the network from the .json file

my_loaded_network = Network.open("my_network_on_disk")

Print

This will output the structure of the network along with the weights and bias' to the console.

my_network = Network(4,[6,2],2, ActivationMethods.SIGMOID)
my_network.print()

Would output the following

A(0) B(0) C(0) D(0) 

E(0.30882) F(-0.27833) G(0.74767) H(-0.20595) I(-0.54466) J(0.32999)

K(-1.64158) L(0.17655)

M(-0.02446) N(-0.23844)

A->E: 1.65803
A->F: 0.88988
A->G: -0.20031
A->H: 0.0684
A->I: 0.50825
A->J: 0.69463
B->E: 0.11407
B->F: 0.30879
B->G: -0.06734
B->H: 0.45021

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

parkr-1.0.2.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parkr-1.0.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file parkr-1.0.2.tar.gz.

File metadata

  • Download URL: parkr-1.0.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for parkr-1.0.2.tar.gz
Algorithm Hash digest
SHA256 004a4ac61407edb8c05b1e2016404609bce32c10966b42705acc1befb364ce75
MD5 a042ed9102f1d70a0dc4ab16358dd33d
BLAKE2b-256 d452bb1b17e2e26b29755c8b0245b4d0f3c41861b06e1b570050cec0ee03c424

See more details on using hashes here.

File details

Details for the file parkr-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: parkr-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for parkr-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 18e0cfae237a9b1f8fcf1d19a240f4579d7972acb786ffb3b80038875d2eda7f
MD5 c8bd6e2dcdf32cfbce664d07a4324bba
BLAKE2b-256 e7ac75781a14375226fb8387e502f46028610751820da9530192d4afffeadbdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page