1. Introduction

GNA provides a way to build a numerical model as lazy evaluated computational graph. The nodes of a graph represent functions and are called transformations. The transformations produce few return arrays, called outputs, and may have arguments, called inputs. Outputs of transformations may be connected to inputs of other transformations. They all are represented by the graph edges.

The data is allocated on the transformations’ outputs while inputs are simple views on the relevant data.

Transformations may depend on a number of variables.

The main object in GNA is GNAObject which holds the following information:
  1. A list of transformations, accessible by name or by index.

  2. A list of variables the transformations depend on.

The typical syntax includes:

 1# Create GNAObject holding some transformations
 2obj = SomeGNAObject()
 3
 4# There are several ways to access the transformation 'tname' from obj
 5# 1. By keyword from a dictionary
 6trans = obj.transformations['tname']
 7# 2. By attribute (syntactic sugar for 1.)
 8trans = obj.transformations.tname
 9# 3. By index from a dictionary
10trans = obj.transformations[0]
11# 4. Or even more shorter versions or 2.
12trans = obj['tname']
13trans = obj.tname
14
15# Similar ways are available for accessing transfromations' outputs
16out = trans.outputs['oname']
17out = trans.outputs.oname
18out = trans.outputs[0]
19# The short ways are only valid in case there are no inputs with name 'oname'
20out = trans['oname']
21out = trans.oname
22
23# Similar ways are available for accessing transfromations' inputs
24inp = trans.inputs['iname']
25inp = trans.inputs.iname
26inp = trans.inputs[0]
27# The short ways are only valid in case there are no outputs with name 'iname'
28inp = trans['iname']
29inp = trans.iname

Note

Any ambiguity will trigger the exception. For example, if transformation has input and output with similar name thename, shortcut trans.thename is forbidden.

Each input and output has methods data() and datatype():
  • data() returns numpy view on the relevant data with proper shape.

  • datatype() returns DataType object with information on data shape and bin edges (for histogram).

Each output’s data may be accessed via function call: trans.output() works the same way as trans.output.data().

Let us now see the actual code examples.