tfp.optimizer.convergence_criteria.ConvergenceCriterion
Stay organized with collections
Save and categorize content based on your preferences.
Base class for stopping rules.
tfp.optimizer.convergence_criteria.ConvergenceCriterion(
min_num_steps=None, name=None
)
A convergence criterion determines when an optimization has converged given
its history of losses, gradients, and parameter values. Each criterion is
responsible for propagating from step to step whatever state it needs to
represent the relevant aspects of that history (for example, a moving average
of previous loss values or gradients). In particular, subclasses must
implement:
_bootstrap(loss, grads, parameters)
: takes the
initial loss, gradients, and values of parameters, and returns a (structure
of) Tensor
(s) representing the initial values of any auxiliary quantities
tracked by the convergence criterion.
_one_step(step, loss, grads, window_size, auxiliary_state)
: At
integer step >= 1
,
takes the current loss, gradients, and values of parameters, along with
any auxiliary state carried over from the previous step, and returns
(has_converged, updated_auxiliary_state)
, where has_converged
is a
boolean Tensor
, and updated_auxiliary_state
is a (structure of)
Tensor(s) matching auxiliary_state
, containing whatever information must
be propagated to the next timestep.
Args |
min_num_steps
|
optional int Tensor minimum number of steps before
stopping. If set, subclass return values of has_converged=True will be
ignored until step >= min_num_steps .
Default value: None .
|
name
|
optional Python str name prefixed to ops created by this class.
|
Attributes |
min_num_steps
|
|
name
|
|
Methods
bootstrap
View source
bootstrap(
loss, grads, parameters
)
Returns a structure of Tensors
for the rule's state at step 0.
The shape of the Tensor
s specifying loss
, grads
, and parameters
may
optionally be prefixed by one or more batch dimension(s).
Args |
loss
|
float Tensor initial value of loss being optimized.
|
grads
|
list of float Tensor gradients of loss wrt parameters .
|
parameters
|
list of float Tensor initial values of parameters
being optimized.
|
Returns |
initial_auxiliary_state
|
(Structure of) Tensor (s) representing the
initial auxiliary state carried forward by this criterion.
|
one_step
View source
one_step(
step, loss, grads, parameters, auxiliary_state
)
Updates tracked quantities for a new step, and determines if converged.
The shape of the Tensor
s specifying loss
, grads
, and parameters
may
optionally be prefixed by one or more batch dimension(s). In this case,
the returned value has_converged
will have shape equal to the broadcast
batch shape of whichever of those quantities is used by this convergence
criterion, and the quantities defining the convergence criterion (
min_num_steps
, etc.).
Args |
step
|
integer Tensor index of the current step, where step >= 1 (on
step 0 , initial_state should be called instead).
|
loss
|
float Tensor value of loss at the current step.
|
grads
|
list of float Tensor gradients of loss wrt parameters .
|
parameters
|
list of float Tensor current values of parameters
being optimized.
|
auxiliary_state
|
the (structure of) Tensor (s) containing state carried
forward from the previous step.
|
Returns |
has_converged
|
boolean Tensor indicating whether the optimization has
converged.
|
updated_auxiliary_state
|
(Structure of) Tensor (s) representing
updated quantities tracked by the convergence criterion. This should
match the structure of the value returned by bootstrap .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-11-21 UTC.
[null,null,["Last updated 2023-11-21 UTC."],[],[],null,["# tfp.optimizer.convergence_criteria.ConvergenceCriterion\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/optimizer/convergence_criteria/convergence_criterion.py#L20-L131) |\n\nBase class for stopping rules. \n\n tfp.optimizer.convergence_criteria.ConvergenceCriterion(\n min_num_steps=None, name=None\n )\n\nA convergence criterion determines when an optimization has converged given\nits history of losses, gradients, and parameter values. Each criterion is\nresponsible for propagating from step to step whatever state it needs to\nrepresent the relevant aspects of that history (for example, a moving average\nof previous loss values or gradients). In particular, subclasses must\nimplement:\n\n- `_bootstrap(loss, grads, parameters)`: takes the initial loss, gradients, and values of parameters, and returns a (structure of) `Tensor`(s) representing the initial values of any auxiliary quantities tracked by the convergence criterion.\n- `_one_step(step, loss, grads, window_size, auxiliary_state)`: At integer `step \u003e= 1`, takes the current loss, gradients, and values of parameters, along with any auxiliary state carried over from the previous step, and returns `(has_converged, updated_auxiliary_state)`, where `has_converged` is a boolean `Tensor`, and `updated_auxiliary_state` is a (structure of) Tensor(s) matching `auxiliary_state`, containing whatever information must be propagated to the next timestep.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `min_num_steps` | optional int `Tensor` minimum number of steps before stopping. If set, subclass return values of `has_converged=True` will be ignored until `step \u003e= min_num_steps`. Default value: `None`. |\n| `name` | optional Python `str` name prefixed to ops created by this class. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------------|---------------|\n| `min_num_steps` | \u003cbr /\u003e \u003cbr /\u003e |\n| `name` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `bootstrap`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/optimizer/convergence_criteria/convergence_criterion.py#L67-L87) \n\n bootstrap(\n loss, grads, parameters\n )\n\nReturns a structure of `Tensors` for the rule's state at step 0.\n\nThe shape of the `Tensor`s specifying `loss`, `grads`, and `parameters` may\noptionally be prefixed by one or more batch dimension(s).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------|----------------------------------------------------------------------|\n| `loss` | float `Tensor` initial value of loss being optimized. |\n| `grads` | list of float `Tensor` gradients of `loss` wrt `parameters`. |\n| `parameters` | list of float `Tensor` initial values of parameters being optimized. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------------------|--------------------------------------------------------------------------------------------------------|\n| `initial_auxiliary_state` | (Structure of) `Tensor`(s) representing the initial auxiliary state carried forward by this criterion. |\n\n\u003cbr /\u003e\n\n### `one_step`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/optimizer/convergence_criteria/convergence_criterion.py#L89-L125) \n\n one_step(\n step, loss, grads, parameters, auxiliary_state\n )\n\nUpdates tracked quantities for a new step, and determines if converged.\n\nThe shape of the `Tensor`s specifying `loss`, `grads`, and `parameters` may\noptionally be prefixed by one or more batch dimension(s). In this case,\nthe returned value `has_converged` will have shape equal to the broadcast\nbatch shape of whichever of those quantities is used by this convergence\ncriterion, and the quantities defining the convergence criterion (\n`min_num_steps`, etc.).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|------------------------------------------------------------------------------------------------------------------------|\n| `step` | integer `Tensor` index of the current step, where `step \u003e= 1` (on step `0`, `initial_state` should be called instead). |\n| `loss` | float `Tensor` value of loss at the current step. |\n| `grads` | list of float `Tensor` gradients of `loss` wrt `parameters`. |\n| `parameters` | list of float `Tensor` current values of parameters being optimized. |\n| `auxiliary_state` | the (structure of) `Tensor`(s) containing state carried forward from the previous step. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `has_converged` | boolean `Tensor` indicating whether the optimization has converged. |\n| `updated_auxiliary_state` | (Structure of) `Tensor`(s) representing updated quantities tracked by the convergence criterion. This should match the structure of the value returned by `bootstrap`. |\n\n\u003cbr /\u003e"]]