OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
metrics.py
Go to the documentation of this file.
1 from tensorflow.python.ops import math_ops
2 import tensorflow as tf
3 
4 
5 class MSA(tf.keras.metrics.Mean):
6  ''' Mean Symmetric Accuracy '''
7 
8  def __init__(self, extract_estimate=lambda x:x, invert_scaling=lambda x:x):
9  super(MSA, self).__init__(name='MSA', dtype=float)
10  self._extract = extract_estimate
11  self._invert = invert_scaling
12 
13  def update_state(self, y_true, y_pred, *args, **kwargs):
14  y_true = self._invert(y_true)
15  y_pred = self._invert( self._extract(y_pred) )
16  value = tf.math.abs( tf.math.log(y_pred / y_true) )
17  return super().update_state(value, *args, **kwargs)
18 
19  def result(self):
20  return 100. * (tf.math.exp(math_ops.div_no_nan(self.total, self.count)) - 1.)
def update_state(self, y_true, y_pred, *args, **kwargs)
Definition: metrics.py:13
def result(self)
Definition: metrics.py:19
def __init__(self, extract_estimate=lambda x:x, invert_scaling=lambda x:x)
Definition: metrics.py:8