Callable
new to Analytica 7.0
Callable class
A Callable Object is a Variable subclass. Like a Variable, it has a mid-value and a sample-value that are computed by evaluating its Definition.
The result of a Callable is expected to be a value that is itself callable with parameters. For example, its value might be a local function, a handle to an Analytica function, a python function, a python class, or even an array of these.
In other words, the Callable instance is a type of Variable, but its value is a function-like instance.
Comparison to a Variable class
The Callable class provides two advantages over a Variable class. First, it displays with a function-like shape on an influence diagram, which may better reflect the logical purpose of the node, and second, it allows you to use a X(a,b,c) syntax to call it instead of the X->(a,b,c) syntax that would be required with a normal Variable. This is most useful when intermixing Python code. For example, when a Callable object's definition is set to be a Python expression that contains a function def or a class declaration.
A callable behaves as if it were a type of Variable. It has a definition, which gets evaluated when the callable itself is evaluated. It caches its computed value, and it contains dependencies to and from other variables. The primary distinction is that a Variable is generally used when you expect the result to be a final (non-callable) value, whereas the result for the Callable is expected to be a callable value. But neither is a hard requirement.
If you define a Variable, X, such that its computed result is a function, you could call that function using the syntax:
X->(a,b,c)
The arrow operator performs the operation at the atomic cell level (whereas the dot operator, e.g., A.I, is an array-level operation). You can also use this arrow syntax when using a Callable, but because it is a callable you can also use the more natural calling syntax,
X(a,b,c)
Comparison to a Function class
Unlike a Function node, which is a single fixed-function, the specific function (or array of functions) is computed when the Callable itself is evaluated. Thus, a callable can be used to select which underlying function to use based on other computed criteria, or can actually define the function on the fly (when the Callable itself is evaluated).
Using with Python functions
A Callable is a natural class to use for a Python function. Select Python Expression from the Definition-type pulldown. For an existing python function in a library, you can set the Definition (python expression) to, e.g.,
from scipy.signal import bilinear
For a function already in the global python namespace, you can set the Definition (python expression) to its name, or use the python dot notation (Python's equivalent to Analyticas -> operator) to extract a function from a library or class that is in scope.
From an Analytica expression view, you can set the Definition to
py::fn
or
py::someModule->fn
When you wish to define a Python function inside your model, the Callable is the natural place to do this. In this case, select Python expression from the Definition-type pulldown, and enter the python "def", e.g.,
(insert object window screenshot here with a def)
Enable comment auto-refresher