• Github
Table of Contents
0.16.1.0
  • Welcome to PsyNeuLink
  • Basics and Primer
  • Quick Reference
  • Core
  • Library
  • Contributors Guide
  • Docs >
  • SelectionFunctions
Shortcuts

SelectionFunctions¶

  • OneHot

Functions that selects a subset of elements to maintain or transform, while nulling the others.

class psyneulink.core.components.functions.selectionfunctions.SelectionFunction(default_variable, params, owner=None, name=None, prefs=None, context=None, **kwargs)¶

Functions that selects a particular value to maintain or transform, while nulling the others.

class psyneulink.core.components.functions.selectionfunctions.OneHot(default_variable=None, mode=None, direction=None, abs_val=None, indicator=None, tie=None, seed=None, params=None, owner=None, prefs=None)¶

Return an array with one non-zero value.

function returns an array the same length as the first item in variable, with all of its values zeroed except one (unless there is a tie, which is handled as specified by tie); the following options can be used in any combination:

  • mode: determines how the non-zero value(s) in the array is (are) selected

    • STANDARD: value (or 1) for the element(s) with the maximum or minimum value(s) in the array, as specified by the options below; all other elements are zeroed; this is the default.

    • PROB: value of probabilistically chosen element based on probabilities passed in second item of variable; if there is a tie, a single element is chosen probabilistically.

    • PROB_INDICATOR: same as PROB but chosen item is assigned a value of 1; if there is a tie, a single element is chosen probabilistically.

  • direction: MAX (default) or MIN determines whether the maximum or minimum value(s) in the array are selected.

  • abs_val: False (default) or True determines whether the absolute values of the elements in the array are used to select the maximum or minimum value(s).

  • indicator: False (default) or True determines whether the selected values(s) is (are) replace with a value of 1.

  • tie: ALL (default), FIRST, LAST or RANDOM determines how a tie is handled when there is more than one element with the maximum or minimum value;

    ALL: selects all elements in the tie;

    FIRST: selects the value of the element with the lowest index;

    LAST: selects the value of the element with the lowest index;

    RANDOM: randomly selects one of the tied elements;

The following convenience keywords can be used to specify particular combinations of options for the mode argument together with the tie argument (these are included mainly for backward compatibility):

  • ARG_MAX: signed value of a single element with the maximum signed value, or the one with lowest index if there is a tie.

  • ARG_MAX_ABS: absolute value of a single element with the maximum absolute value, or the one with lowest index if there is a tie.

  • ARG_MAX_INDICATOR: 1 in place of single element with maximum signed value, or the one with lowest index if there is a tie.

  • ARG_MAX_ABS_INDICATOR: 1 in place of single element with maximum absolute value, or the one with lowest index if there is a tie.

  • MAX_VAL: signed value of the element with the maximum signed value; if there is a tie, which elements are returned is determined by tie_index.

  • MAX_ABS_VAL: absolute value of the element with the maximum absolute value; if there is a tie, which elements are returned is determined by tie_index.

  • MAX_INDICATOR: 1 in place of the element with the maximum signed value; if there is a tie, which elements are returned is determined by tie_index.

  • MAX_ABS_INDICATOR: 1 in place of the element(s) with the maximum absolute value; if there is a tie, which elements are returned is determined by tie_index.

  • ARG_MIN: signed value of a single element with the minium signed value, or the one with lowest index if there is a tie.

  • ARG_MIN_ABS: absolute value of a single element with the minium absolute value, or the one with lowest index if there is a tie.

  • ARG_MIN_INDICATOR: 1 in place of single element with minimum signed value, or the one with lowest index if there is a tie.

  • MIN_VAL: signed value of the element with the minimum signed value, or all elements with the minimum value if there is a tie.

  • MIN_ABS_VAL: absolute value of element with the minimum absolute value; if there is a tie, which elements are returned is determined by tie_index.

  • MIN_INDICATOR: 1 in place of the element with the minimum signed value; if there is a tie, which elements are returned is determined by tie_index.

  • MIN_ABS_INDICATOR: 1 in place of the element with the minimum absolute value; if there is a tie, which elements are returned is determined by tie_index.

Parameters
  • variable (2d np.array : default class_defaults.variable) – First (possibly only) item specifies a template for the array to be transformed; if mode is PROB then a 2nd item must be included that is a probability distribution with same length as 1st item.

  • mode (DETERMINISTiC, PROB, PROB_INDICATOR,) –

  • ARG_MAX –

  • ARG_MAX_ABS –

  • ARG_MAX_INDICATOR –

  • ARG_MAX_ABS_INDICATOR –

:param : :param ARG_MIN: :param ARG_MIN_ABS: :param ARG_MIN_INDICATOR: :param ARG_MIN_ABS_INDICATOR: :param : :param MAX_VAL: :param MAX_ABS_VAL: :param MAX_INDICATOR: :param MAX_ABS_INDICATOR: :param : :param MIN_VAL: :param MIN_ABS_VAL: :param MIN_INDICATOR: :param MIN_ABS_INDICATOR: :param : :param : specifies how non-zero value(s) in the array returned by function are determined

(see above for details).

:type : default ARG_MAX :type direction: Optional[Literal[‘max’, ‘min’]] :param direction: specifies whether the maximum or minimum value(s) in the array are selected.

(see above for details).

Parameters
  • abs_val (bool : default False) – specifies whether the absolute values of the elements in the array are used to select the maximum or minimum value(s). (see above for details).

  • indicator (bool : default False) – specifies whether the selected values(s) is (are) replace with a value of 1. (see above for details).

  • tie (ALL, FIRST, LAST, RANDOM : default ALL) – specifies how a tie is handled when there is more than one element with the maximum or minimum value; (see above for details).

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

1st item contains value to be transformed; if mode is PROB, 2nd item is a probability distribution, each element of which specifies the probability for selecting the corresponding element of the 1st item.

Type

number or np.array

mode¶
Type

DETERMINISTIC, PROB, PROB_INDICATOR,

ARG_MAX, ARG_MAX_ABS, ARG_MAX_INDICATOR, ARG_MAX_ABS_INDICATOR,
ARG_MIN, ARG_MIN_ABS, ARG_MIN_INDICATOR, ARG_MIN_ABS_INDICATOR,
MAX_VAL, MAX_ABS_VAL, MAX_INDICATOR, MAX_ABS_INDICATOR,
MIN_VAL, MIN_ABS_VAL, MIN_INDICATOR,  MIN_ABS_INDICATOR,
direction¶

determines whether the maximum or minimum value(s) in the array are selected. (see above for details).

Type

MAX or MIN

abs_val¶

determines whether the absolute values of the elements in the array are used to select the maximum or minimum value(s). (see above for details).

Type

bool

indicator¶

determines whether the selected values(s) is (are) replace with a value of 1. (see above for details).

Type

bool

tie¶

determines how a tie is handled when there is more than one element with the maximum or minimum value; (see above for details).

Type

ALL, FIRST, LAST, RANDOM

random_state¶

private pseudorandom number generator

Type

numpy.RandomState

owner¶

component to which the Function has been assigned.

Type

Component

name¶

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

Type

str

prefs¶

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 Preferences for details).

Type

PreferenceSet or specification dict : Function.classPreferences

_validate_params(request_set, target_set=None, context=None)¶

Validate params and assign validated values to targets,

This performs top-level type validation of params

This can be overridden by a subclass to perform more detailed checking (e.g., range, recursive, etc.) It is called only if the parameter_validation attribute is True (which it is by default)

IMPLEMENTATION NOTES:
  • future versions should add recursive and content (e.g., range) checking

  • should method return validated param set?

Parameters
  • validated (dict (target_set) - repository of params that have been) –

  • validated –

Return none

_parse_mode(mode)¶

Convert mode spec to corresponding options. Here for convenience, but mostly for backward compatibility with old mode spec.

_function(variable=None, context=None, params=None)¶
Parameters
  • variable (2d np.array : default class_defaults.variable) – 1st item is an array to be transformed; if mode is PROB, 2nd item must be an array of probabilities (i.e., elements between 0 and 1) of equal length as the 1st item.

  • 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

array with selected elements having non-zero values and all others having zeroes – specified by mode, direction, abs_val, indicator, and tie.

Return type

np.array


© Copyright 2016, Jonathan D. Cohen.

Built with Sphinx using a theme provided by Read the Docs.
  • SelectionFunctions
  • Github