Functions

Function
Example function:

Overview

A Function is a Component that “packages” a function for use by other Components. Every Component in PsyNeuLink is assigned a Function; when that Component is executed, its Function’s function is executed. The function can be any callable operation, although most commonly it is a mathematical operation (and, for those, almost always uses a call to one or more numpy functions). There are two reasons PsyNeuLink packages functions in a Function Component:

  • Manage parameters – parameters are attributes of a Function that either remain stable over multiple calls to the function (e.g., the gain or bias of a Logistic function, or the learning rate of a learning function); or, if they change, they do so less frequently or under the control of different factors than the function’s variable (i.e., its input). As a consequence, it is useful to manage these separately from the function’s variable, and not have to provide them every time the function is called. To address this, every PsyNeuLink Function has a set of attributes corresponding to the parameters of the function, that can be specified at the time the Function is created (in arguments to its constructor), and can be modified independently of a call to its function. Modifications can be directly (e.g., in a script), or by the operation of other PsyNeuLink Components (e.g., Adaptive Mechanisms) by way of ControlProjections.
  • Modularity – by providing a standard interface, any Function assigned to a Components in PsyNeuLink can be replaced with other PsyNeuLink Functions, or with user-written custom functions so long as they adhere to certain standards (the PsyNeuLink Function API).

Creating a Function

A Function can be created directly by calling its constructor. Functions are also created automatically whenever any other type of PsyNeuLink Component is created (and its function is not otherwise specified). The constructor for a Function has an argument for its variable and each of the parameters of its function. The variable argument is used both to format the input to the function, and assign its default value. The arguments for each parameter can be used to specify the default value for that parameter; the values can later be modified in various ways as described below.

Structure

Core Attributes

Every Function has the following core attributes:

  • function – determines the computation carried out by the Function; it must be a callable object (that is, a python function or method of some kind). Unlike other PsyNeuLink Components, it cannot be (another) Function object (it can’t be “turtles” all the way down!).

A Function also has an attribute for each of the parameters of its function.

Owner

If a Function has been assigned to another Component, then it also has an owner attribute that refers to that Component. The Function itself is assigned as the Component’s function attribute. Each of the Function’s attributes is also assigned as an attribute of the owner, and those are each associated with with a parameterState of the owner. Projections to those parameterStates can be used by ControlProjections to modify the Function’s parameters.

Modulatory Parameters

Some classes of Functions also implement a pair of modulatory parameters: multiplicative_param and additive_param. Each of these is assigned the name of one of the function’s parameters. These are used by ModulatorySignals to modulate the output of the function (see figure). For example, they are used by GatingSignals to modulate the function of an InputState or OutputState, and thereby its value; and by the ControlSignal(s) of an LCControlMechanism to modulate the multiplicative_param of the function of a TransferMechanism.

Execution

Functions are executable objects that can be called directly. More commonly, however, they are called when their owner is executed. The parameters of the function can be modified when it is executed, by assigning a parameter specification dictionary to the params argument in the call to the function.

For Mechanisms, this can also be done by specifying runtime_params in the Run method of their Composition.

Class Reference

class psyneulink.core.components.functions.function.Function_Base(default_variable, params=None, owner=None, name=None, prefs=None)

Implement abstract class for Function category of Component class

Parameters:
  • variable (value : default class_defaults.variable) – specifies the format and a default value for the input to function.
  • params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the function. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor.
  • owner (Component) – component to which to assign the Function.
  • name (str : default see name) – specifies the name of the Function.
  • prefs (PreferenceSet or specification dict : default Function.classPreferences) – specifies the PreferenceSet for the Function (see prefs for details).
variable

value – format and default value can be specified by the variable argument of the constructor; otherwise, they are specified by the Function’s class_defaults.variable.

function

function – called by the Function’s owner when it is executed.

owner

Componentcomponent to which the Function has been assigned.

name

str – the name of the Function; if it is not specified in the name argument of the constructor, a default is assigned by FunctionRegistry (see Naming for conventions used for default and duplicate names).

prefs

PreferenceSet or specification dict : Function.classPreferences – the PreferenceSet for function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).

class psyneulink.core.components.functions.function.ArgumentTherapy(variable, propensity=Manner.CONTRARIAN, pertinacity=10.0 params=None, owner=None, name=None, prefs=None)

Return True or False according to the manner of the therapist.

Parameters:
  • variable (boolean or statement that resolves to one : default class_defaults.variable) – assertion for which a therapeutic response will be offered.
  • propensity (Manner value : default Manner.CONTRARIAN) – specifies preferred therapeutic manner
  • pertinacity (float : default 10.0) – specifies therapeutic consistency
  • params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the function. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor.
  • owner (Component) – component to which to assign the Function.
  • name (str : default see name) – specifies the name of the Function.
  • prefs (PreferenceSet or specification dict : default Function.classPreferences) – specifies the PreferenceSet for the Function (see prefs for details).
variable

boolean – assertion to which a therapeutic response is made.

propensity

Manner value : default Manner.CONTRARIAN – determines therapeutic manner: tendency to agree or disagree.

pertinacity

float : default 10.0 – determines consistency with which the manner complies with the propensity.

owner

Componentcomponent to which the Function has been assigned.

name

str – the name of the Function; if it is not specified in the name argument of the constructor, a default is assigned by FunctionRegistry (see Naming for conventions used for default and duplicate names).

prefs

PreferenceSet or specification dict : Function.classPreferences – the PreferenceSet for function; if it is not specified in the prefs argument of the Function’s constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).

class Manner

An enumeration.

function(variable=None, execution_id=None, params=None, context=None)

Returns a boolean that is (or tends to be) the same as or opposite the one passed in.

Parameters:
  • variable (boolean : default class_defaults.variable) – an assertion to which a therapeutic response is made.
  • params (Dict[param keyword: param value] : default None) – a parameter dictionary that specifies the parameters for the function. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor.
Returns:

therapeutic response

Return type:

boolean