Elementary Example
The below example has three parts:
- an input type schema,
- an output type schema,
- and a list of expressions to compute, returning the last one (or in this case, the only one).
These are the only required top-level fields.
In [1]:
from titus.genpy import PFAEngine
Simple PFA Document from YAML string¶
In [2]:
pfaYAMLDocument = """
input: double
output: double
action:
- {+: [input, 100]}"""
The action routine is called once for every input datum, and a symbol(variable) named input references that datum.
The above action calls the + function and passes input and 100 as arguments: {"+": ["input", 100]}
.
Much like Lisp, PFA has no infix operators — everything is laid out as a syntax tree in Polish notation.
You can write the PFA document in JSON or YAML or PrettyPFA.
Initializing the Scoring Engine¶
In [3]:
engine, = PFAEngine.fromYaml(pfaYAMLDocument)
Viewing Engine Configuration¶
In [4]:
engine.config
Out[4]:
Simple PFA Document from JSON¶
The PFA Document can also be provided as a stringified JSON.
In [5]:
pfaJSONDocument = """
{
"input": "double",
"output": "double",
"action": [
{"+": ["input", 100]}
]
}
"""
engine2, = PFAEngine.fromJson(pfaJSONDocument)
In [6]:
engine2.config
Out[6]:
Scoring Engine in Action¶
In [7]:
l = [1.0, 2.0, 3.0, 4.0, 5.0]
for n in l:
print(n, engine.action(n), engine2.action(n))