Create and use Neural Networks
Project description
Neural Network Creator
Create and generate Neural Networks without using heavy modules like Keras
Table of contents
Example Code
>>> from neural import Neural
>>> nodes = [[0,0], # 2 Input Neurons
>>> [0,0,0,0,0,0], # 6 Hidden Neurons (Hidden Layer #1)
>>> [0,0,0,0,0,0], # 6 Hidden Neurons (Hidden Layer #2)
>>> [0,0,0,0]] # 4 Output Neurons
>>> n = Neural(nodes) # make Neural Object, __init__ requires nodes
>>> n.shuffle() # shuffle all weights to be random (using random module)
>>> print(n.input([1,2,3,4]) # print out output neurons with input list
>>> n.show() # visualize network using Tkinter
>>> n.save("my_neural_network.txt") # save network to file_name.txt
Setup
-
Download Python File/s
-
Installing them as Module using pip
Tutorial: http://www.discoversdk.com/blog/how-to-create-a-new-python-module
Exporting as a Public Module soon!
- Use as Class in your Project
- Copy the File/s into your Project Folder
- Import the Class using
from neural import Neural- Create Neural Object using
yourObj = Neural(nodes) # seeTutorialfor closer description
Tutorial
# setup network nodes with __init__(self, nodes)
# nodes has to be a two dimensional array, containing floats/integers, representing nodes
> nodes = [[0,0],[0,0,0,0],[0,0,0]] # 2 input neurons, 1 hidden layer containing 4 neurons, 3 output neurons
> network1 = Neural(nodes) # create Neural Object
# input values using
> network1.input([1,2]) # pass 1D list, len must be equal to number of input neurons
# show network (with Tkinter module, located in neuraldisplay.py) using
> network1.show() # opens 1400px * 700px window
> network1.show(size = [x,y]) # modify window size
# update every weight to be random from -1 to 1
> network1.shuffle() # uses random module
# update every weight to be in range of +- amount of given weights (of another neural network)
> network1.shuffle_amount(amount) # amount will be devided by 100
> network1.shuffle_amount(50) # to achieve a learning rate of 0.5
# save network to file_name.txt to be loaded in later
> network1.save(file_name) # file_name must be string ending in .txt (located in same directory)
# load network from file_name.txt to current network
> network1.load(file_name) # file_name must be string ending in .txt (located in same directory)
Accessing the Network
# Access Network List using
> network1.nodes
# Access individual layers using
> network1.nodes[layer_number]
# Access individual nodes dictionary using
> network1.nodes[layer_number][position_in_layer]
# Access output value of an individual node using
> network1.nodes[layer_number][position_in_layer]["output"]
# Access list of weights of an individual node using
> network1.nodes[layer_number][position_in_layer]["weights"]
Training using Backpropagation
# setup network nodes with __init__(self, nodes)
# nodes has to be a two dimensional array, containing floats/integers, representing nodes
> nodes = [[0,0],[0,0,0,0],[0,0]] # 2 input neurons, 1 hidden layer containing 4 neurons, 2 output neurons
> network1 = Neural(nodes) # create Neural Object
# load the training data using (see Training Data Formating)
> inputs, outputs = network1.load_training_data("training_example.txt") # must be .txt file in the same directory
# train the network using
> network1.train(l_rate, # learning rate (e.g. 0.2)
cycles, # how many cycles (epochs) the network will train through (e.g. 1000)
inputs, # inputs set from loading the training data
outputs, # outputs set from loading the training data
print_status=True) # (optional) print progress into console (Default is False)
# get the total score using (how many of your training examples it passes)
> score, max_score = network1.get_total_score(inputs, outputs) # set score and max_score
> print(f"{score}/{max_score}") # python 3 (f-strings)
Training Data Formatting
Training Data to be read must be located in yourfilename.txt file
Inputs must be seperated by Comma (e.g.1,2,3,4)
Outputs must be seperated by Comma (e.g.0,1,0)
Inputs and Outputs must be seperated by equal sign (e.g.1,2,3,4=0,1,0) ending in line break ("\n")
see "training_example.txt"
Screenshots
Status
Project is IN PROGRESS
todo list in PROJECT: Neural Network maker
https://github.com/noel-friedrich/neural/projects/1
Credits
Training Algorithm Code was heavily inspired by https://machinelearningmastery.com/implement-backpropagation-algorithm-scratch-python/
Project details
Release history Release notifications | RSS feed
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 noelnetwork-1.0.3.tar.gz.
File metadata
- Download URL: noelnetwork-1.0.3.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba5b8d3c8cb9603f7e93d400e9780b9ad2fb3203ae016dbdbf9f72bd7cfa48a6
|
|
| MD5 |
cc3e44ea41e4809dd62fb4e53ade04a1
|
|
| BLAKE2b-256 |
2d55258d31049b8266a9269191ed3043078df0c2db4719b38a8559d2570d5f85
|
File details
Details for the file noelnetwork-1.0.3-py3-none-any.whl.
File metadata
- Download URL: noelnetwork-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5576b20ada49c27694bd3a2ae6b2a1459071064ff3d9aff8f044b394aabf400e
|
|
| MD5 |
55c2d3d5f9f2ee73b9af805dc21be0b9
|
|
| BLAKE2b-256 |
f146858a0975251c41a944801f7ea036325f1e0e7aae4013ae628f140a3c2ae7
|