11"""
22## Simple Artificial Neural Networks
33
4- A naive Python implementation of an artificial neural network (ANN) that's
5- useful for educational purposes and clarifying the concepts of feed-forward
6- neural networks, backpropagation, neuro-evolution of weights and biases, and
7- genetic algorithms. This implementation is not intended for production use or
8- performance-critical applications. 😉
4+ Simple Artificial Neural Networks (SANN) is a naive Python implementation of
5+ an artificial neural network (ANN) that's useful for educational purposes
6+ and clarifying the concepts of feed-forward neural networks, backpropagation,
7+ neuro-evolution of weights and biases, and genetic algorithms. SANN is not
8+ intended for production use or performance-critical applications. Rather, use
9+ it for educational, playful or small-scale projects. 😉
910
1011See:
1112[https://ntoll.org/article/ai-curtain/](https://ntoll.org/article/ai-curtain/)
3839import random
3940
4041
41- __version__ = "1.0.1 "
42+ __version__ = "1.0.2 "
4243
4344
4445def sum_inputs (inputs : list [tuple [float , float ]]) -> float :
@@ -61,16 +62,6 @@ def sigmoid(
6162 return 1 / (1 + math .exp (- ((activation - threshold ) / shape )))
6263
6364
64- def tlu (activation : int | float , threshold : int | float = 0 ) -> int :
65- """
66- Calculate the output value of a threshold logic unit (TLU).
67-
68- If the `activation` is greater than the `threshold`, set the output
69- to `1` (truthy), else set it to `0` (falsey).
70- """
71- return 1 if activation >= threshold else 0
72-
73-
7465def create_network (structure : list ) -> dict :
7566 """
7667 Return a dict representing a simple artificial neural network (ANN).
@@ -87,7 +78,7 @@ def create_network(structure: list) -> dict:
8778 nor bias associated with it. There must be at least two layers (an input
8879 layer and an output layer) for the ANN to be valid.
8980
90- Other arbitrary properties are added to the returned dictionary, such as
81+ Other arbitrary properties are added to the returned dictionary, such as
9182 a `fitness` score, which can be used for training or evolution of the ANN,
9283 and a `structure` that defines the topology of the ANN (i.e. the number of
9384 nodes in each layer).
@@ -121,7 +112,7 @@ def run_network(ann: dict, inputs: list) -> list:
121112
122113 The inputs are a list of values that are fed into the first layer of the
123114 ANN. The output of each layer is calculated and passed to the next layer
124- until the final output is produced.
115+ until the final output is produced and returned as a list of values .
125116 """
126117 outputs = inputs
127118 for layer in ann ["layers" ]:
0 commit comments