Skip to main content
# NetPy

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/maclinchy/netpy/blob/master/LICENSE)

## Installation

### We recommended to install NetPy in virtual env.
To get started, you should install ```virtualenv``` tool with ```pip```.

```sh
pip install virtualenv
```
New directory to work with:
```sh
mkdir python-virtual-environments && cd python-virtual-environments
```
Create a new virtual environment inside the directory:
```sh
python -m venv netpy_env
```
You need to "activate" it.
```sh
source netpy_env/bin/activate
```
If your system is windows:
```sh
netpy_env\Scripts\activate
```

Then you need to install NetPy. There is two ways to install:

- **Install NetPy from PyPI (recommended):**

```sh
sudo pip install netpy
```

- **Install NetPy from GitHub source:**

```sh
git clone https://github.com/maclinchy/netpy.git
cd netpy
sudo python setup.py install
```

------------------
## Getting started

Let's create the net:
```sh
nhm newnet myFirstNet
```

`netpy-manager` will create folder `myFirstNet`, which contains a directory structure similar to this:

```sh
├── data_set
│ ├── data_X.txt
│ └── data_Y.txt
├── net_data
│ └── arch.json
├── conf.json
├── network.py
├── test.py
└── train.py

```

`data_set` is folder which contains data for learning.

`net_data` is folder which contains data about our net.

`conf.json` is file with settings.

`network.py` is main file for init the net.

`train.py` is file for train the net

`test.py` is file for test the net.

Let's create net with 3 layers.
------------------
`network.py`
```python
from netpy.nets import FeedForwardNet
from netpy.modules import LinearLayer,SigmoidLayer, FullRelation
from netpy.teachers import BackPropTeacher
import numpy as np

# Import file with settings
import conf

net = FeedForwardNet()

# Add your layers here
input_layer = LinearLayer()
hidden_layer = SigmoidLayer()
output_layer = SigmoidLayer()

# Add your layers to the net here
net.add_Input_Layer(input_layer)
net.add_Layer(hidden_layer)
net.add_Output_Layer(output_layer)

# Add your connections here
rel_in_hid = FullRelation(input_layer, hidden_layer)
rel_hid_out = FullRelation(hidden_layer, output_layer)

# Add your connections to the net here
net.add_Relation(rel_in_hid)
net.add_Relation(rel_hid_out)
```

`train.py`
```python
from netpy.teachers import BackPropTeacher
from network import net
import numpy as np
import conf

num_of_epoch = 8

# Your data set
train_X = np.loadtxt(conf.data_set_dir_X)
train_Y = np.loadtxt(conf.data_set_dir_Y)

# Config your teacher
teacher = BackPropTeacher(net,
error = 'MSE',
learning_rate = 1e-5,
alpha = 0.0001)


# Teach your net here
teacher.train(X, Y, num_of_epoch, load_data = False)
```

`test.py`
```python

from network import net

test = []

net.load()

print(net.forward(test))
```

We need to add neurons to the net:
```python
input_layer = LinearLayer(3)
hidden_layer = SigmoidLayer(20)
output_layer = SigmoidLayer(1)
```

Then we need to add the data:
`data_X.txt`
```sh
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
```
`data_Y.txt`
```sh
0
0
0
1
0
1
1
1
```

Let's train the net!
```sh
python train.py
```

In `net_data` two files - `weights.h5` and `arch.json`.

- In `weights.h5` we have save our weights.
- In `arch.json` we have save data about the net.
- In `myFirstNet.log` we have history of net's actions.

If you want to continue learning you should change parameter of train function:
```python
teacher.train(X, Y, 100, load_data = True)
```

Let's test the net!

```sh
python test.py
```

`test.py`
```python

from network import net

test = [0,0,0]

net.load()

print(net.forward(test))
```

You can fork your net:
```sh
nhm fork myFirstNet mySecondNet
```

You can rename your net:
```sh
nhm rename mySecondNet myAwesomeNet
```

Metadata

Release files for netpy 0.0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netpy 0.0.0.1
File Size Uploaded Provenance Actions
netpy-0.0.0.1.tar.gz 10.7 kB Without provenance Details for netpy-0.0.0.1.tar.gz

Release files / netpy-0.0.0.1.tar.gz

Download URL netpy-0.0.0.1.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8f9dbdfc82bbf70d19ad4c4c29833ea2ac12b0ca54590ec676ff827ecf71dd9f
BLAKE2b-256 checksum
How to use checksums
04cee6ab58716b53d12013132d2cd841b9d5213af024647afe363e8e8c039a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

Security for netpy 0.0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page