tf.contrib.metrics.streaming_covariance
Stay organized with collections
Save and categorize content based on your preferences.
Computes the unbiased sample covariance between predictions
and labels
.
tf.contrib.metrics.streaming_covariance(
predictions, labels, weights=None, metrics_collections=None,
updates_collections=None, name=None
)
The streaming_covariance
function creates four local variables,
comoment
, mean_prediction
, mean_label
, and count
, which are used to
compute the sample covariance between predictions and labels across multiple
batches of data. The covariance is ultimately returned as an idempotent
operation that simply divides comoment
by count
- 1. We use count
- 1
in order to get an unbiased estimate.
The algorithm used for this online computation is described in
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
Specifically, the formula used to combine two sample comoments is
C_AB = C_A + C_B + (E[x_A] - E[x_B]) * (E[y_A] - E[y_B]) * n_A * n_B / n_AB
The comoment for a single batch of data is simply
sum((x - E[x]) * (y - E[y]))
, optionally weighted.
If weights
is not None, then it is used to compute weighted comoments,
means, and count. NOTE: these weights are treated as "frequency weights", as
opposed to "reliability weights". See discussion of the difference on
https://wikipedia.org/wiki/Weighted_arithmetic_mean#Weighted_sample_variance
To facilitate the computation of covariance across multiple batches of data,
the function creates an update_op
operation, which updates underlying
variables and returns the updated covariance.
Args |
predictions
|
A Tensor of arbitrary size.
|
labels
|
A Tensor of the same size as predictions .
|
weights
|
Optional Tensor indicating the frequency with which an example is
sampled. Rank must be 0, or the same rank as labels , and must be
broadcastable to labels (i.e., all dimensions must be either 1 , or the
same as the corresponding labels dimension).
|
metrics_collections
|
An optional list of collections that the metric value
variable should be added to.
|
updates_collections
|
An optional list of collections that the metric update
ops should be added to.
|
name
|
An optional variable_scope name.
|
Returns |
covariance
|
A Tensor representing the current unbiased sample covariance,
comoment / (count - 1).
|
update_op
|
An operation that updates the local variables appropriately.
|
Raises |
ValueError
|
If labels and predictions are of different sizes or if either
metrics_collections or updates_collections are not a list or tuple.
|
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 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.metrics.streaming_covariance\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/metrics/python/ops/metric_ops.py#L3136-L3274) |\n\nComputes the unbiased sample covariance between `predictions` and `labels`. \n\n tf.contrib.metrics.streaming_covariance(\n predictions, labels, weights=None, metrics_collections=None,\n updates_collections=None, name=None\n )\n\nThe `streaming_covariance` function creates four local variables,\n`comoment`, `mean_prediction`, `mean_label`, and `count`, which are used to\ncompute the sample covariance between predictions and labels across multiple\nbatches of data. The covariance is ultimately returned as an idempotent\noperation that simply divides `comoment` by `count` - 1. We use `count` - 1\nin order to get an unbiased estimate.\n\nThe algorithm used for this online computation is described in\n\u003chttps://en.wikipedia.org/wiki/Algorithms_for_calculating_variance\u003e\nSpecifically, the formula used to combine two sample comoments is\n`C_AB = C_A + C_B + (E[x_A] - E[x_B]) * (E[y_A] - E[y_B]) * n_A * n_B / n_AB`\nThe comoment for a single batch of data is simply\n`sum((x - E[x]) * (y - E[y]))`, optionally weighted.\n\nIf `weights` is not None, then it is used to compute weighted comoments,\nmeans, and count. NOTE: these weights are treated as \"frequency weights\", as\nopposed to \"reliability weights\". See discussion of the difference on\n\u003chttps://wikipedia.org/wiki/Weighted_arithmetic_mean#Weighted_sample_variance\u003e\n\nTo facilitate the computation of covariance across multiple batches of data,\nthe function creates an `update_op` operation, which updates underlying\nvariables and returns the updated covariance.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `predictions` | A `Tensor` of arbitrary size. |\n| `labels` | A `Tensor` of the same size as `predictions`. |\n| `weights` | Optional `Tensor` indicating the frequency with which an example is sampled. Rank must be 0, or the same rank as `labels`, and must be broadcastable to `labels` (i.e., all dimensions must be either `1`, or the same as the corresponding `labels` dimension). |\n| `metrics_collections` | An optional list of collections that the metric value variable should be added to. |\n| `updates_collections` | An optional list of collections that the metric update ops should be added to. |\n| `name` | An optional variable_scope name. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|--------------|---------------------------------------------------------------------------------------------|\n| `covariance` | A `Tensor` representing the current unbiased sample covariance, `comoment` / (`count` - 1). |\n| `update_op` | An operation that updates the local variables appropriately. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If labels and predictions are of different sizes or if either `metrics_collections` or `updates_collections` are not a list or tuple. |\n\n\u003cbr /\u003e"]]