Assume we have created an inference script (Factor algebra expression), for example with:
>>> import symfer as s
>>> model = s.loadhugin('extended-student.net')
>>> query = ['H']
>>> obs = {'S':'s1'}
>>> ve = s.ve_minweight(model,query)
>>> ve_obs = s.indextree(obs,ve)
The most straightforward option is to evaluate it using Python:
>>> s.evaluate(ve_obs)
Multinom(dom=[{'H': ['h0', 'h1']}],par=[0.0677442825, 0.20725571750000002])
However, the ve_obs script can also be executed on a separate platform. For this, serialize it to YAML:
>>> s.dumpyaml(ve_obs, 've_obs.yaml')
The resulting file ve_obs.yaml can be evaluated, for example, from a shell command line:
$ evaluate.py ve_obs.yaml
[0.0677442825, 0.2072557175]
Of course, it can also be loaded by a separate Python interpreter again:
>>> import symfer as s
>>> ve_obs = s.loadyaml('ve_obs.yaml')
The file can also be evaluated by the Java evaluator jsymfer (also usable as a Java library):
$ java -jar jsymfer.jar ve_obs.yaml
# YAML parsed in 67 ms
# Inference in 3 ms
!multinom
par: [0.067744285, 0.20725572]
dom:
- H: [h0, h1]
Instead of serializing to YAML, ve_obs can also be compiled to C source:
>>> s.dumpc(ve_obs, 've_obs.c')
From the shell:
$ gcc ve_obs.c -o ve_obs
$ ./ve_obs
[0.067744, 0.207256]
Evaluating an inference script as a generated C file is somewhat faster, and more reliable because of explicit garbage collection. It can also be done from Python using one function call:
>>> s.evalc(ve_obs)
Multinom(dom=[{'H': ['h0', 'h1']}],par=[0.067744, 0.207256])