# 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 feature_values, a control_allocation, and the net_outcome they produced, passed to it from an OptimizationControlMechanism.

The 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 feature_values are assigned to the 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(*args, **kwargs)

Specifies terms used to compute vector attribute of PredictionVector.

F

Main effect of feature_values.

C

Main effect of values of control_signals.

FF

Interaction among feature_values.

CC

Interaction among values of control_signals.

FC

Interaction between feature_values and values of control_signals.

FFC

Interaction between interactions of feature_values and values of control_signals.

FCC

Interaction between feature_values and interactions among values of control_signals.

FFCC

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

COST

Main effect of costs of control_signals.

_member_type_

alias of object

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 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

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

prediction_terms

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

prediction_vector

PredictionVector – 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.

regression_weights

1d array – result returned by update_weights method together with prediction_vector to generate predicted net_outcome.

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

see previous_state

Default value: None
regression_weights
Default value: None
update_weights
Default value: BayesGLM Function
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 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 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: feature_values (2d nparray) – arrays of features to assign as the PV.F term of terms. control_signals (List[ControlSignal]) – list containing the ControlSignals of an OptimizationControlMechanism; the variable of each is assigned as the PV.C term of terms. specified_terms (List[PV]) – terms to include in vector; entries must be members of the PV Enum.
specified_terms

List[PV] – terms included as predictors, specified using members of the PV Enum.

terms

List[ndarray] – 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.

num

List[int] – 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.

num_elems

List[int] – 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.

self.labels

List[str] – label of each item in terms. Only entries for terms in specified_terms are assigned values; others are assigned None.

vector

ndarray – 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.

idx

List[slice] – 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.

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 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.