Skip to main content

Cascade Correlation Network Simulator

Project description

PyCasCor

Description

A python implementation of a Cascade Correlation Network Simulator

Installation

Easiest Option - Install from PyPi

pip install pycascor

Using the source repository

  1. Clone the repository locally
    1. git clone --recurse-submodules https://gitlab.com/cpsimpson/cascade-correlation-network-simulator.git
      1. If you clone without the --recurse-submodules the proben1 repository will not be cloned. You can pull this file after cloning with the following commands git submodule init and git submodule update.
  2. Create and activate virtual environment
    1. python -m venv venv
    2. . venv/bin/activate
  3. Install dependencies
    1. pip install .

Usage

Example of Training on XOR

Cascade Correlation Network

from pycascor.network import CCNetwork
from pycascor.activation_functions import Sigmoid
from pycascor.trainer import Trainer

xor_inputs = [[0, 0], [0, 1], [1, 0], [1, 1]]
xor_targets = [[-0.5], [0.5], [0.5], [-0.5]]
      
trainer = Trainer([(8, Sigmoid())])
net = CCNetwork(2, 1, Sigmoid())

net = trainer.train_network(xor_inputs, xor_targets, net)

for x in xor_inputs:
    net.full_forward_pass(x)

output_values = [node.value for node in net.output_nodes]

Small Magnitude Weight Pruning

from pycascor.network import PrunableCCNetwork
from pycascor.activation_functions import Sigmoid
from pycascor.trainer import PruneTrainer

xor_inputs = [[0, 0], [0, 1], [1, 0], [1, 1]]
xor_targets = [[-0.5], [0.5], [0.5], [-0.5]]
      
trainer = PruneTrainer([(8, Sigmoid())])
net = PrunableCCNetwork(2, 1, Sigmoid())

net = trainer.train_network(xor_inputs, xor_targets, net)

for x in xor_inputs:
    net.full_forward_pass(x)

output_values = [node.value for node in net.output_nodes]

Optimal Brain Damage Pruning

from pycascor.network import PrunableCCNetwork
from pycascor.activation_functions import Sigmoid
from pycascor.trainer import OptimalBrainDamageTrainer

xor_inputs = [[0, 0], [0, 1], [1, 0], [1, 1]]
xor_targets = [[-0.5], [0.5], [0.5], [-0.5]]
      
trainer = OptimalBrainDamageTrainer([(8, Sigmoid())])
net = PrunableCCNetwork(2, 1, Sigmoid())

net = trainer.train_network(xor_inputs, xor_targets, net)

for x in xor_inputs:
    net.full_forward_pass(x)

output_values = [node.value for node in net.output_nodes]

Simulator Examples

In addition to the library code pycascor, you will find an examples directory this repository. This contains a simulator script simulation.py which is able to run multiple trials of various datasets across the 3 versions of the network training algorithms. This includes some data which comes from the Proben1 benchmarking dataset project originally compiled by Lutz Prechelt. A copy of the data is linked as a submodule.

. venv/bin/activate
pip install .
python examples/simulation.py <example> <number-of-trials>

Example options: spirals, cancer, glass, xor

Various output files will be written to a result folder for your analysis.

spirals trains the networks on a subset of the two-spirals classification problem. The resulting networks are then validated and tested on the remaining points

cancer trains the networks on the "Wisconsin breast cancer database" from the UCI machine learning dataset included in the Proben1 repository.

glass trains the networks on the "glass" from the UCI machine learning dataset included in the Proben1 repository.

xor trains and tests the networks on the XOR dataset.

Support

Feel free to create an Issue or MR if you find a bug or want to add a contribution.

Contributing

Running Tests

To run the tests you can run pytest from the project root directory.

Authors and acknowledgment

This implementation is based on the code of Scott Fahlman and Thomas Shultz. Thanks to Dr. Britt Anderson, Hanbin Go, James Houle, Julia Schirmeister, Vivian DiBerardino, and Ciaran Neely for contributing to my understanding of the algorithm and inspiring this project.

License

This code and related materials is made available under the MIT License.

Project status

This is a project that I created for a directed studies course at while studying at University of Waterloo.

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

pycascor-0.1.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

pycascor-0.1.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file pycascor-0.1.2.tar.gz.

File metadata

  • Download URL: pycascor-0.1.2.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pycascor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f84382718809f7cdc17e009771ce0825fcad9172836e4bf2cc328635d4ff1ca7
MD5 bed1a704cad093e4f6b93c71d0e2c48d
BLAKE2b-256 bfc1408d64bb7941a01c351334890a005ca80b8c1ec779946e19dd9fe6ab5bc4

See more details on using hashes here.

File details

Details for the file pycascor-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pycascor-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pycascor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b94df4c2bd264d2a87ae6e7c018341908dfa50c5aecc95dc95e5bcd0a7d3f7bc
MD5 b3b95fd53fdf3d25113e108783a3e26d
BLAKE2b-256 4cb4611b6bd249c16ccffe169b151f1b525317a9466031fd7b3d68adc7fdd827

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