/MarkovNetwork

Python implementation of Markov Networks for neural computing.

Primary LanguagePythonMIT LicenseMIT

Build Status Code Health Coverage Status Python 2.7 Python 3.5 License PyPI version

Markov Network

Join the chat at https://gitter.im/rhiever/MarkovNetwork

Python implementation of Markov Networks for neural computing.

License

Please see the repository license for the licensing and usage information for datacleaner.

Generally, we have licensed the MarkovNetwork package to make it as widely usable as possible.

Installation

MarkovNetwork is built to use NumPy arrays for fast array processing. As such, we recommend installing the Anaconda Python distribution prior to installing MarkovNetwork. However, MarkovNetwork should work fine with any basic install of Python.

Once the prerequisites are installed, datacleaner can be installed with a simple pip command:

pip install MarkovNetwork

Usage

When creating an instance of a MarkovNetwork, you can pass the following parameters:

num_input_states: int (required)
    The number of input states in the Markov Network
num_memory_states: int (required)
    The number of internal memory states in the Markov Network
num_output_states: int (required)
    The number of output states in the Markov Network
seed_num_markov_gates: int (default: 4)
    The number of Markov Gates with which to seed the Markov Network
    It is important to ensure that randomly-generated Markov Networks have at least a few Markov Gates to begin with
    May sometimes result in fewer Markov Gates if the Markov Gates are randomly seeded in the same location
probabilistic: bool (default: True)
    Flag indicating whether the Markov Gates are probabilistic or deterministic
genome: array-like (default=None)
    An array representation of the Markov Network to construct
    All values in the array must be integers in the range [0, 255]
    If None, then a random Markov Network will be generated

The following code creatives a deterministic MarkovNetwork, provides some input, activates the network, then retrieves the output:

from MarkovNetwork import MarkovNetwork
import numpy as np

my_mn = MarkovNetwork(num_input_states=2,
                      num_memory_states=4,
                      num_output_states=2,
                      seed_num_markov_gates=5,
                      probabilistic=False)

my_mn.update_input_states([1, 0])
my_mn.activate_network()
output_states = my_mn.get_output_states()

You can repeat this process multiple times with different input:

from MarkovNetwork import MarkovNetwork
import numpy as np

my_mn = MarkovNetwork(num_input_states=2,
                      num_memory_states=4,
                      num_output_states=2,
                      seed_num_markov_gates=5,
                      probabilistic=False)

my_mn.update_input_states([1, 0])
my_mn.activate_network()
output_states1 = my_mn.get_output_states()

my_mn.update_input_states([0, 1])
my_mn.activate_network()
output_states2 = my_mn.get_output_states()

If you want to allow the MarkovNetwork to activate multiple times with the same inputs, you can pass a num_activations parameter to activate_network():

from MarkovNetwork import MarkovNetwork
import numpy as np

my_mn = MarkovNetwork(num_input_states=2,
                      num_memory_states=4,
                      num_output_states=2,
                      seed_num_markov_gates=5,
                      probabilistic=False)

my_mn.update_input_states([1, 0])
my_mn.activate_network(num_activations=20)
output_states = my_mn.get_output_states()

Finally, you can seed a MarkovNetwork with a pre-existing byte string by passing the genome parameter:

from MarkovNetwork import MarkovNetwork
import numpy as np

my_mn_genome = np.random.randint(0, 256, 15000)
my_mn = MarkovNetwork(num_input_states=2,
                      num_memory_states=4,
                      num_output_states=2,
                      probabilistic=False,
                      genome=my_mn_genome)

Having problems with the MarkovNetwork package?

Before you file a bug report, please check the existing issues to make sure that your issue hasn't already been filed or solved. If the bug is unreported, please file a new issue and describe your bug in detail.

Contributing to the MarkovNetwork package

We welcome you to check the existing issues for bugs or enhancements to work on. If you have an idea for an extension to the MarkovNetwork package, please file a new issue so we can discuss it.

Citing MarkovNetwork

If you use the MarkovNetwork package as part of your workflow in a scientific publication, please consider citing the following publication that describes Markov Networks in detail.

Randal S. Olson, David B. Knoester, and Christoph Adami. "Evolution of swarming behavior is shaped by how predators attack." Artificial Life Journal, to appear in Spring 2016.

@misc{Olson2016SelfishHerd,
author = {Olson, Randal S. and Knoester, David B. and Adami, Christoph},
title = {Evolution of swarming behavior is shaped by how predators attack},
howpublished={arXiv e-print. http://arxiv.org/abs/1310.6012},
year={2016}
}

You can also cite the repository directly using the following DOI:

DOI