Skip to contents

For example, if values is [1, 3, 5, 7] then their sum is 16. If sample_weight was specified as [1, 1, 0, 0] then the sum would be 4.

This metric creates one variable, total. This is ultimately returned as the sum value.

Usage

metric_sum(..., name = "sum", dtype = NULL)

Arguments

...

For forward/backward compatability.

name

(Optional) string name of the metric instance.

dtype

(Optional) data type of the metric result.

Value

a Metric instance is returned. The Metric instance can be passed directly to compile(metrics = ), or used as a standalone object. See ?Metric for example usage.

Examples

m <- metric_sum()
m$update_state(c(1, 3, 5, 7))
m$result()

## tf.Tensor(16.0, shape=(), dtype=float32)

m <- metric_sum()
m$update_state(c(1, 3, 5, 7), sample_weight = c(1, 1, 0, 0))
m$result()

## tf.Tensor(4.0, shape=(), dtype=float32)