Esempio n. 1
0
    def __init__(self,
                 default_variable=None,
                 mode: tc.optional(
                     tc.enum(MAX_VAL, MAX_ABS_VAL, MAX_INDICATOR,
                             MAX_ABS_INDICATOR, MIN_VAL, MIN_ABS_VAL,
                             MIN_INDICATOR, MIN_ABS_INDICATOR, PROB,
                             PROB_INDICATOR)) = None,
                 seed=None,
                 params=None,
                 owner=None,
                 prefs: tc.optional(is_pref_set) = None):

        if seed is None:
            seed = get_global_seed()

        random_state = np.random.RandomState([seed])

        reset_variable_shape_flexibility = False
        if mode in {PROB, PROB_INDICATOR} and default_variable is None:
            default_variable = [[0], [0]]
            reset_variable_shape_flexibility = True

        super().__init__(
            default_variable=default_variable,
            mode=mode,
            random_state=random_state,
            params=params,
            owner=owner,
            prefs=prefs,
        )

        if reset_variable_shape_flexibility:
            self._variable_shape_flexibility = DefaultsFlexibility.FLEXIBLE
Esempio n. 2
0
    def __init__(self,
                 default_variable=None,
                 mode: tc.enum(MAX_VAL, MAX_ABS_VAL, MAX_INDICATOR,
                               MAX_ABS_INDICATOR, MIN_VAL, MIN_ABS_VAL,
                               MIN_INDICATOR, MIN_ABS_INDICATOR, PROB,
                               PROB_INDICATOR) = MAX_VAL,
                 seed=None,
                 params=None,
                 owner=None,
                 prefs: is_pref_set = None):

        if seed is None:
            seed = get_global_seed()

        random_state = np.random.RandomState([seed])
        if not hasattr(self, "stateful_attributes"):
            self.stateful_attributes = ["random_state"]

        reset_default_variable_flexibility = False
        if mode in {PROB, PROB_INDICATOR} and default_variable is None:
            default_variable = [[0], [0]]
            reset_default_variable_flexibility = True

        super().__init__(
            default_variable=default_variable,
            mode=mode,
            random_state=random_state,
            params=params,
            owner=owner,
            prefs=prefs,
        )

        if reset_default_variable_flexibility:
            self._default_variable_flexibility = DefaultsFlexibility.FLEXIBLE
Esempio n. 3
0
 def __deepcopy__(self, memo):
     new = super().__deepcopy__(memo)
     # ensure copy does not have identical name
     register_category(new, Function_Base, new.name, FunctionRegistry)
     try:
         # HACK: Make sure any copies are re-seeded to avoid dependent RNG.
         new.random_state.seed([get_global_seed()])
     except:
         pass
     return new
Esempio n. 4
0
def _seed_setter(value, owning_component, context):
    if value in {None, DEFAULT_SEED}:
        value = get_global_seed()

    value = int(value)

    owning_component.parameters.random_state._set(
        np.random.RandomState([value]),
        context
    )

    return value