Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshdk/pyceptron
An n-dimensional hyperplanar perceptron, written in Python
https://github.com/joshdk/pyceptron
Last synced: about 4 hours ago
JSON representation
An n-dimensional hyperplanar perceptron, written in Python
- Host: GitHub
- URL: https://github.com/joshdk/pyceptron
- Owner: joshdk
- Created: 2012-09-12T13:56:41.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-10-14T22:46:02.000Z (about 12 years ago)
- Last Synced: 2023-03-11T03:48:12.862Z (over 1 year ago)
- Language: Python
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
pyceptron
=========An n-dimensional hyperplanar perceptron
Usage
-----### Importing
```python
from pyceptron import Pyceptron
````### Constructing
```python
# Constructor assumes 2 dimensions
tron = Pyceptron()# Or, if you want a perceptron in some other dimension
tron = Pyceptron(4)
```### Creating points
```python
# Each data point is a combination of an n-dimensional array, and a classification (-1 or 1)# 2-dimensional data
points1d = [
([0.25], 1),
([0.50], 1),
([1.00], -1),
([1.25], -1)
]# 2-dimensional data
points2d = [
([0, 3], 1),
([1, 2], 1),
([2, 1], -1),
([3, 0], -1)
]# 3-dimensional data
points3d = [
([1, 2, 3], 1),
([2, 4, 6], 1),
([4, 8, 12), -1),
([8, 16, 24), -1)
]
```### Populating
```python
tron.populate(points2d)
```### Training
```python
# By default, the algorithm rill run until it finds a solution
tron.train()# Or, you can give it a max number of steps
if tron.train(100) != True:
print('No solution was found in 100 iterations...')
else:
print('A solution was found!')# Of course, you can keep training without losing state
if tron.train(100) != True:
print('No solution was found in 100 iterations...')
if tron.train(50) != True:
print('No solution was found in 150 iterations...')
else:
print('A solution was found within 150 iterations!')
else:
print('A solution was found within 100 iterations!')
```### Weights
``` python
# Getting weights
weights = tron.weights()# Setting weights
# Note - For n-dimensional data points, you have n+1 weights
tron.weights([12, 33, 56])
```