Shape Network (Python Edition)
An experimental neural network architecture ported from Java that utilizes sophisticated feature extraction and "shaping" functions. This network is designed for reliable classification tasks, such as facial recognition, by leveraging cosine similarity measures.
Unlike traditional backpropagation-based networks, this architecture performs well with single-class/label training, eliminating the need for complex weight balancing to achieve accurate predictions.
Features
- Shaping Functions: Uses mathematical "shapes" (Mean, Log-Mean, Min, Max) to adapt weights.
- Cosine Similarity: Measures the orientation of vectors rather than just magnitude, providing robustness against scaling.
- Partition Layers: Automatically selects and optimizes the best-fitting neurons for specific features.
- NumPy Backend: Optimized for numerical vector operations in Python.
Installation
This project requires NumPy.
pip install numpy
Usage
1. Build the Network
Use the ShapingNetworkBuilder to define the architecture. You can connect layers to specific target ranges.
from shape_network import ShapingNetworkBuilder, LayerBuilder, Shapes
model = ShapingNetworkBuilder() \
.connect_in_range(0, 1, # Adds layers for targets 0 through 1
LayerBuilder()
.add_layer(Shapes.MEAN, 2) # Shaping function and number of nodes
).build()
2. Initialize and Randomize
Set the input dimension (number of features) and randomize the initial sum vectors.
# Initialize with 3 input nodes
model.initialize(3)
model.randomize()
3. Prepare Training Data
Data is fed into the model using ContextVector objects.
from shape_network import ContextVector
training_data = {
0: [ # Class 0
ContextVector([0.001, 2.531, 1.523]),
ContextVector([0.009, 2.231, 1.241])
],
1: [ # Class 1
ContextVector([1.8, 0.001, 4.9]),
ContextVector([2.5, 0.002, 4.5])
]
}
4. Training
Training is performed by "feeding" vectors to the model along with their target labels.
epochs = 100
for i in range(epochs):
for target, vectors in training_data.items():
for vec in vectors:
model.feed(vec, target) # Adjusts the weights/shapes for that target
5. Predict
The predict method returns a list of probabilities (similarity scores) for each layer/class.
prediction = model.predict(test_vector)
# Get the index of the highest probability
max_index = prediction.index(max(prediction))
print(f"Predicted Class: {max_index}")
Example Output
The network converges quickly to high accuracy:
Accuracy: 0.998521
Class 0:
Index=0, Probability=0.999873
Class 1:
Index=1, Probability=0.997032
Mathematical Overview
The core of the network is the Shaping Function. Instead of traditional gradient descent, neurons maintain a sum_vector and a shape_vector. When feed() is called:
- The
sum_vectoraccumulates the input data. - The
shaping_function(e.g.,LOG_MEAN) is applied to derive a newshape_vector. - Prediction is calculated as the Cosine Similarity between the input vector and the neuron's
shape_vector.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for shaping-network 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| shaping_network-0.1.1.tar.gz | 7.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shaping_network-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / shaping_network-0.1.1.tar.gz
| Download URL | shaping_network-0.1.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c8fc67f91fb8f2d17eb6f3b88319c54a878e93bf07a84f7a802877dde2851ed
|
|
BLAKE2b-256 checksum How to use checksums |
9ec5e157411315943f7dc58898b1ec9086f661c1c68b8bfe1245ac9300adf8bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / shaping_network-0.1.1-py3-none-any.whl
| Download URL | shaping_network-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ff747a19ea300798e1213c88b14cf1aa75a7422f2ec3baa723e5f0f2bb51ea2
|
|
BLAKE2b-256 checksum How to use checksums |
aaea5d4b03176ef52ba6fcbcf6c1bef39c5d21431b52f588b8ccb9c88252d800
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for shaping-network 0.1.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.