How to use the tensorforce.core.parameter_modules function in Tensorforce

To help you get started, we’ve selected a few Tensorforce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tensorforce / tensorforce / tensorforce / core / policies / stochastic.py View on Github external
):
        super().__init__(
            name=name, states_spec=states_spec, actions_spec=actions_spec, device=device,
            summary_labels=summary_labels, l2_regularization=l2_regularization
        )

        # Sampling temperature
        if isinstance(temperature, dict) and \
                all(name in self.actions_spec for name in temperature):
            # Different temperature per action
            self.temperature = OrderedDict()
            for name in self.actions_spec:
                if name in temperature:
                    self.temperature[name] = self.add_module(
                        name=(name + '-temperature'), module=temperature[name],
                        modules=parameter_modules, is_trainable=False, dtype='float'
                    )
        else:
            # Same temperature for all actions
            self.temperature = self.add_module(
                name='temperature', module=temperature, modules=parameter_modules,
                is_trainable=False, dtype='float'
            )
github tensorforce / tensorforce / tensorforce / core / module.py View on Github external
elif summary_labels == 'all':
            self.summary_labels = summary_labels
        else:
            self.summary_labels = set(summary_labels)

        if not Module.is_add_module:
            Module.global_scope = list()
            Module.global_tensors_spec = OrderedDict()

        if Module.inherit_l2_regularization is None and l2_regularization is None:
            self.l2_regularization = None  # otherwise infinite recursion
        elif l2_regularization is not None:
            from tensorforce.core import parameter_modules
            self.l2_regularization = None  # for first module
            self.l2_regularization = self.add_module(
                name='l2-regularization', module=l2_regularization, modules=parameter_modules,
                is_trainable=False, dtype='float'
            )
        else:
            # Otherwise inherit arguments
            self.l2_regularization = Module.inherit_l2_regularization
github tensorforce / tensorforce / tensorforce / core / optimizers / tf_optimizer.py View on Github external
def __init__(
        self, name, optimizer, learning_rate=3e-4, gradient_norm_clipping=1.0, summary_labels=None,
        **kwargs
    ):
        super().__init__(name=name, summary_labels=summary_labels)

        assert optimizer in tensorflow_optimizers
        self.optimizer = tensorflow_optimizers[optimizer]
        self.learning_rate = self.add_module(
            name='learning-rate', module=learning_rate, modules=parameter_modules, dtype='float'
        )
        self.gradient_norm_clipping = self.add_module(
            name='gradient-norm-clipping', module=gradient_norm_clipping,
            modules=parameter_modules, dtype='float'
        )
        self.optimizer_kwargs = kwargs

        if 'decoupled_weight_decay' in self.optimizer_kwargs:
            decoupled_weight_decay = self.optimizer_kwargs.pop('decoupled_weight_decay')
            self.optimizer = partial(
                tfa.optimizers.extend_with_decoupled_weight_decay(base_optimizer=self.optimizer),
                weight_decay=decoupled_weight_decay
            )
        if 'lookahead' in self.optimizer_kwargs:
            lookahead = self.optimizer_kwargs.pop('lookahead')
            if isinstance(lookahead, dict) or lookahead is True:
                if lookahead is True:
                    lookahead = dict()
                self.optimizer = util.compose(
                    function1=partial(tfa.optimizers.Lookahead, name=self.name, **lookahead),
github tensorforce / tensorforce / tensorforce / core / optimizers / clipping_step.py View on Github external
def __init__(self, name, optimizer, threshold, mode='global_norm', summary_labels=None):
        super().__init__(name=name, optimizer=optimizer, summary_labels=summary_labels)

        self.threshold = self.add_module(
            name='threshold', module=threshold, modules=parameter_modules, dtype='float'
        )

        assert mode in ('global_norm', 'norm', 'value')
        self.mode = mode
github tensorforce / tensorforce / tensorforce / core / models / model.py View on Github external
# Exploration
        exploration = 0.0 if exploration is None else exploration
        if isinstance(exploration, dict) and \
                all(name in self.actions_spec for name in exploration):
            # Different exploration per action
            self.exploration = OrderedDict()
            for name in self.actions_spec:
                if name in exploration:
                    self.exploration[name] = self.add_module(
                        name=(name + '-exploration'), module=exploration[name],
                        modules=parameter_modules, is_trainable=False, dtype='float'
                    )
        else:
            # Same exploration for all actions
            self.exploration = self.add_module(
                name='exploration', module=exploration, modules=parameter_modules,
                is_trainable=False, dtype='float'
            )

        # Variable noise
        assert variable_noise is None or isinstance(variable_noise, dict) or variable_noise >= 0.0
        variable_noise = 0.0 if variable_noise is None else variable_noise
        self.variable_noise = self.add_module(
            name='variable-noise', module=variable_noise, modules=parameter_modules,
            is_trainable=False, dtype='float'
        )

        # Execution
        self.execution_spec = None
        if self.execution_spec is not None:
            self.execution_type = self.execution_spec['type']
            self.session_config = self.execution_spec['session_config']
github tensorforce / tensorforce / tensorforce / core / objectives / policy_gradient.py View on Github external
def __init__(
        self, name, ratio_based=False, clipping_value=0.0, early_reduce=False,
        summary_labels=None
    ):
        super().__init__(name=name, summary_labels=summary_labels)

        self.ratio_based = ratio_based

        clipping_value = 0.0 if clipping_value is None else clipping_value
        self.clipping_value = self.add_module(
            name='clipping-value', module=clipping_value, modules=parameter_modules, dtype='float'
        )

        self.early_reduce = early_reduce
github tensorforce / tensorforce / tensorforce / core / optimizers / solvers / line_search.py View on Github external
super().__init__(name=name, max_iterations=max_iterations, unroll_loop=unroll_loop)

        assert accept_ratio >= 0.0
        self.accept_ratio = self.add_module(
            name='accept-ratio', module=accept_ratio, modules=parameter_modules
        )

        # TODO: Implement such sequences more generally, also useful for learning rate decay or so.
        if mode not in ('linear', 'exponential'):
            raise TensorforceError(
                "Invalid line search mode: {}, please choose one of 'linear' or 'exponential'".format(mode)
            )
        self.mode = mode

        self.parameter = self.add_module(
            name='parameter', module=parameter, modules=parameter_modules
        )
github tensorforce / tensorforce / tensorforce / core / layers / misc.py View on Github external
def __init__(self, name, rate, input_spec=None, summary_labels=None):
        super().__init__(
            name=name, input_spec=input_spec, summary_labels=summary_labels, l2_regularization=0.0
        )

        # Rate
        self.rate = self.add_module(
            name='rate', module=rate, modules=parameter_modules, dtype='float'
        )
github tensorforce / tensorforce / tensorforce / core / layers / preprocessing.py View on Github external
def __init__(self, name, upper, lower=None, input_spec=None, summary_labels=None):
        super().__init__(
            name=name, input_spec=input_spec, summary_labels=summary_labels, l2_regularization=0.0
        )

        self.upper = self.add_module(
            name='upper', module=lower, modules=parameter_modules, dtype='float'
        )

        if lower is None:
            self.lower = None
        else:
            self.lower = self.add_module(
                name='lower', module=lower, modules=parameter_modules, dtype='float'
            )
github tensorforce / tensorforce / tensorforce / core / layers / normalization.py View on Github external
def __init__(self, name, decay=0.999, axes=None, input_spec=None, summary_labels=None):
        super().__init__(
            name=name, input_spec=input_spec, summary_labels=summary_labels, l2_regularization=0.0
        )

        self.decay = self.add_module(
            name='decay', module=decay, modules=parameter_modules, dtype='float'
        )

        self.axes = axes if axes is None else tuple(axes)