core – core of Nodes system.

Platforms: Any

Module author: Alexander Sedov <Elec.Lomy.RU@gmail.com>

Node - base class for all Nodes.

class nodes.core.Node(inputs, outputs[, iweights[, oweights]][, sysname=None])

Base class for all Nodes. It provides all necessary interface except Globnet I/O interface. Constructor arguments: :param inputs, outputs: lists of Node inputs/outputs. :type inputs, outputs: lists of Synaps class instances

Note

They won’t be automatically Synaps.bind() to self.

Parameters:
  • iweights, oweights (lists/NumPy arrays) – input/output weights. Defaults to ones.
  • sysname (string) – Node system name. It is only for identification; there may be multiple Nodes with same sysnames.

Methods

init_prepare()
Finishing initialization. This may be overriden, but you should call the original version of init_prepare() in your own definition.
check_valid()
Checking after initialization. Originally, checks topology of Node to match its __shape__. When overriding this method, it is recommended to call original version from your implementation.
touch()
Touch Node for calculations. Whenever called, causes touch() es of whole net. It is recursion-safe, because (un)sets free flag to False, and, if it’s already False, returns immediately.
compute()
Cause computation of Node. Causes compute() ings of all Nodes that connected with direct arcs; so it is recursion-safe because of topological reasons.

Note

touch() and compute() will return immediately if calculated flag is set. Both methods also sets this flag after execution, so you need reset() ting of Node before second use.

prepare_calc()
fix_calc()
Preparing for/fixing calculations. Originally, both methods do nothing, so they may be overriden in subclass.
preprocess()
postprocess()
Preprocessing and postprocessing calculations. These methods are called just before and after calculate(). Originally, resets respectively output and input arrays. It is not necessary at all, but I am tired of stubs :)
get_values()
put_values()
mul_iweights()
mul_oweights()
These are internal methods called from touch() and compute(). Please don’t override they if you don’t know what are you doing.
calculate()
Calculation function. It is not function, it is operator in mathematical sense of these words, because it maps input array (vector) to output one. Actually, it must work with only these two arrays but there are no restrictions. Originally, it raises NotImplementedError so it should be overriden in subclasses.
teach()
Teaching function. Originally, it calls forth_propagation().
forth_propagation()
back_propagation(targets)

Two teaching methods in all meanings of this word. forth_propagation() is my own concept, consists of three parts: habituating; keyfactors search; merging. Habituating is getting used to similar values and ajusting an absolute value of weight. Keyfactors search uses an interesting “bell-like” keyness function, reaches maximal value around argument 1. Weights ajusts with keyness of value. Merging uses unstability of persistent weight: weight 0 is very stable, weight 0.5 is very unstable. It also uses force factor of temporary weight; it reaches maximal value with argument 0. With this two factors, new persistent weight is computed. back_propagation() is described in many articles. It uses targets argument to compute error and back-propagate it. It requires calc_drv() method that calculates derivative of function (ha! function that maps input[i] to output[i]). calc_drv() is called with output[i] argument.

Parameters:
  • targets (list/array) – targets of output values.
calc_drv(value)
Derivative calculation. See back_propagate(). :param value: value of f(x). :returns: value of f’(x). :type value: any numerical type
add_input(synaps)
add_output(synaps)
Dynamically adding inputs/outputs to Node. These methods simply modify respectively inputs and outputs and add new weights. Then they recall init_prepare() and, of course, check_valid() to finish work. :param synaps: synaps to be added. :type synaps: Synaps instance
reset()
Resets internal flags (free and calculated) to defaults.
__str__()
If sysname is not-null, returns it. Otherwise, returns unique name consists of __class__.__name__ and id().

Class Attributes

__itemtype__
Type of array items. It may be any type that NumPy accepts. By default, it is float32
__shape__ = iN, oN
Shape of Node. Should be a tuple of two values with below meanings: - If value is None, it means “any number of items”. - If value is greater than zero, it means “exactly N items”. - If value is less than zero, it means “abs(N) items or greater”. - If value equals to zero, it means “no items.”
Variable __itemtype__:
 type of array items.
Variable __shape__:
 shape of Node.

Instance attributes.

inputs
outputs
Input/output arcs(synapses) to other Nodes.
input_weights
output_weights
Input/output weights. These are NumPy arrays.
sysname
System name of Node. See constructor
iN
oN
Number of inputs/outputs. len() takes a time [1], so I decided to make these attributes.
ivalues
ovalues
NumPy arrays that contain input (raw) values and output values. These attributes are external; they are with what Synaps es and forth_propagation() work.
input
output
NumPy arrays that contain input and output values. These attributes are internal; they are with what calculate() works.
ilog
olog
NumPy arrays that contain “logs’ of values. These attributes are used in forth_propagate() to keep “old”, or “usual”, values.
N
Number of teachings. Used in forth_propagation() as stability (inertness).
free
calculated
Internal flags that indicates if Node is free and if it is already computed/touched. Used by touch() and compute().
layer
Read-only property means distance to closest input Node. If there are no inputs, returns -1.
Variable inputs, outputs:
 inputs/outputs of Node.
Variable input_weights, output_weights:
 input/output weights of Node.
Variable sysname:
 system name of Node.
Variable iN, oN:
 number of Node inputs/outputs.
Variable ivalues, ovalues:
 external input/output values.
Variable input, output:
 internal inut/output values.
Variable ilog, olog:
 input/output values logs.
Variable N:number of self-teachings.
Variable free:flag shows if Node is free.
Variable calculated:
 flag shows if Node is already calculated.
Variable layer:distance from closest input Node.

Synaps - basic Synaps interfaces.

class nodes.core.Synaps

Methods

bind(innode, inindex, outnode, outindex)
Binds Synaps to Nodes instances.
Parameters:
  • innode, outnode (Node instances.) – input and output Node.
  • inindex, outindex (integers.) – Indices to which bind self. if index==-1, it means “append”; in that case Synaps will use add_input()/add_output() method of Node.
pullin()
passin()
Pulls/passes value thru self without touching outnode.

Note

Pass means make value setup with possible call of compute() method (only if synaps/arc is direct) Pull means make value setup with possible call of touch() method, if it is necessary. Make value setup means assign outnode.ivalues[outindex]=innode.ovalues[inindex].

Note

passin() and pullin() are for use from outnode (its get_values() method).

pullout()
passout()
Pulls/passes value thru self without touching innode.

Note

passout() and pullout() are for use from innode (its put_values() method).

pullthru()
passthru()
Pulls/passes value thru self.

Note

pullthru() and passthru() are for external use (from Glob, by example).

Instance Attributes

innode
outnode
Input/output Node of Synaps. See bind().
inindex
outindex
Input/output indices. See bind().
bound
Flag shows if Synaps is already bound.
direction
Read-only property means direction of arc. if direction greater than zero, arc/synaps is direct; otherwise, it is indirect.
Variable innode, outnode:
 input and output Node.
Variable inindex, outindex:
 input/output indices.
Variable bound:flag shows if Synaps is already bound.
Variable direction:
 direction of Synaps (difference between Nodes’ layers).

Exceptions and other data

exception nodes.core.Stop
Internal exception that may be raised in calculate() and will be catched in touch() and compute() methods. It simply stops calculation and any propagation.
nodes.core.flotype
default floating point type of array items.
var flotype:=float32

Footnotes

[1]These attributes are/were used by forth_propagation(), the most slow method.