RegressionCFA¶

Overview¶

A RegressionCFA is a subclass of CompositionFunctionApproximator that parameterizes a set of regression_weights over trials to predict the net_outcome for a Composition (or part of one) controlled by an OptimizationControlMechanism. The regression_weights are updated by its update_weights LearningFunction assigned as its adapt method, which is called by the evaluate method to predict the net_outcome for a Composition (or part of one) controlled by an OptimiziationControlMechanism, based on a set of state_feature_values, a control_allocation, and the net_outcome they produced, passed to it from an OptimizationControlMechanism.

The state_feature_values and control_allocation passed to the RegressorCFA’s adapt method, and provided as the input to its update_weights, are represented in the vector attribute of a PredictionVector assigned to the RegressorCFAs prediction_vector attribute. The state_feature_values are assigned to the state_features field of the prediction_vector, and the control_allocation is assigned to the control_allocation field of the prediction_vector. The prediction_vector may also contain fields for the costs ControlMechanism.costs associated with the control_allocation and for interactions among those terms.

The regression_weights returned by the update_weights are used by the RegressorCFA’s evaluate method to predict the net_outcome from the prediction_vector.

Class Reference¶

class psyneulink.library.compositions.regressioncfa.PV

Specifies terms used to compute vector attribute of PredictionVector.

F

Main effect of state_feature_values.

C

Main effect of values of control_signals.

FF

Interaction among state_feature_values.

CC

Interaction among values of control_signals.

FC

Interaction between state_feature_values and values of control_signals.

FFC

Interaction between interactions of state_feature_values and values of control_signals.

FCC

Interaction between state_feature_values and interactions among values of control_signals.

FFCC

Interaction between interactions of state_feature_values and interactions among values of control_signals.

COST

Main effect of costs of control_signals.

class psyneulink.library.compositions.regressioncfa.RegressionCFA(name=None, update_weights=None, prediction_terms=None)
RegressionCFA(

update_weights=BayesGLM, prediction_terms=[PV.F, PV.C, PV.COST])

Subclass of CompositionFunctionApproximator that implements a CompositionFunctionApproximator as the agent_rep of an OptimizationControlmechanism.

See CompositionFunctionApproximator for additional arguments and attributes.

Parameters
• update_weights (LearningFunction, function or method : default BayesGLM) – parameterizes the regression_weights used by the evaluate method to improve its prediction of net_outcome from a given set of state_feature_values and a control_allocation provided by an OptimiziationControlMechanism. It must take a 2d array as its first argument, the first item of which is an array the same length of the vector attribute of its prediction_vector, and the second item a 1d array containing a scalar value that it tries predict.

• prediction_terms (List[PV] : default [PV.F, PV.C, PV.COST]) – terms to be included in (and thereby determines the length of) the vector attribute of the prediction_vector; items are members of the PV enum; the default is [F, C FC, COST]. If None is specified, the default values will automatically be assigned.

update_weights

parameterizes the regression_weights used by the evaluate method to improve prediction of net_outcome from a given set of state_feature_values and a control_allocation provided by an OptimiziationControlMechanism; its result is assigned as the value of the regression_weights attribute.

Type

LearningFunction, function or method

prediction_terms

terms included in vector attribute of the prediction_vector; items are members of the PV enum; the default is [F, C FC, COST].

Type

List[PV]

prediction_vector

represents and manages values in its vector attribute that are used by evaluate, along with regression_weights to make its prediction. The values contained in the vector attribute are determined by prediction_terms.

Type

PredictionVector

regression_weights

result returned by update_weights method together with prediction_vector to generate predicted net_outcome.

Type

1d array

class Parameters(owner, parent=None)
prediction_vector
Default value

None

Type

previous_state

see previous_state

Default value

None

Type

regression_weights
Default value

None

Type

update_weights
Default value

BayesGLM

Type

Function

prediction_vector = None
previous_state = None
regression_weights = None
initialize(features_array, control_signals, context)

Assign owner and instantiate prediction_vector

Must be called before RegressorCFA’s methods can be used.

adapt(feature_values, control_allocation, net_outcome, context=None)

Update regression_weights so as to improve prediction of net_outcome from state_feature_values and control_allocation.

evaluate(feature_values, control_allocation, num_estimates, context)

Update prediction_vector <RegressorCFA.prediction_vector>, then multiply by regression_weights.

Uses the current values of regression_weights together with values of control_allocation and state_feature_values arguments to generate predicted net_outcome.

Note

If this method is assigned as the objective_funtion of a GradientOptimization Function, it is differentiated using autograd.grad().

class PredictionVector(feature_values, control_signals, specified_terms)

Maintain a vector of terms for a regression model specified by a list of specified_terms.

Terms are maintained in lists indexed by the PV Enum and, in “flattened” form within fields of a 1d array in vector indexed by slices listed in the idx attribute.

Parameters
specified_terms

terms included as predictors, specified using members of the PV Enum.

Type

List[PV]

terms

current value of ndarray terms, some of which are used to compute other terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

Type

List[ndarray]

num

number of arrays in outer dimension (axis 0) of each ndarray in terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

Type

List[int]

num_elems

number of elements in flattened array for each ndarray in terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

Type

List[int]

self.labels

label of each item in terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

Type

List[str]

vector

contains the flattened array for all ndarrays in terms. Contains only the terms specified in specified_terms. Indices for the fields corresponding to each term are listed in idx.

Type

ndarray

idx

indices of vector for the flattened version of each nd term in terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

Type

List[slice]

update_vector(variable, feature_values=None, context=None)

Update vector with flattened versions of values returned from the compute_terms method of the prediction_vector.

Updates vector with current values of variable and, optionally, and state_feature_values.

compute_terms(control_allocation, context=None)

Calculate interaction terms.

Results are returned in a dict; entries are keyed using names of terms listed in the PV` Enum. Values of entries are nd arrays.