{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Forecast.Types.Metrics
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Forecast.Types.Metrics where

import qualified Amazonka.Core as Core
import Amazonka.Forecast.Types.ErrorMetric
import Amazonka.Forecast.Types.WeightedQuantileLoss
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides metrics that are used to evaluate the performance of a
-- predictor. This object is part of the WindowSummary object.
--
-- /See:/ 'newMetrics' smart constructor.
data Metrics = Metrics'
  { -- | Provides detailed error metrics for each forecast type. Metrics include
    -- root-mean square-error (RMSE), mean absolute percentage error (MAPE),
    -- mean absolute scaled error (MASE), and weighted average percentage error
    -- (WAPE).
    Metrics -> Maybe [ErrorMetric]
errorMetrics :: Prelude.Maybe [ErrorMetric],
    -- | The root-mean-square error (RMSE).
    Metrics -> Maybe Double
rmse :: Prelude.Maybe Prelude.Double,
    -- | An array of weighted quantile losses. Quantiles divide a probability
    -- distribution into regions of equal probability. The distribution in this
    -- case is the loss function.
    Metrics -> Maybe [WeightedQuantileLoss]
weightedQuantileLosses :: Prelude.Maybe [WeightedQuantileLoss],
    -- | The average value of all weighted quantile losses.
    Metrics -> Maybe Double
averageWeightedQuantileLoss :: Prelude.Maybe Prelude.Double
  }
  deriving (Metrics -> Metrics -> Bool
(Metrics -> Metrics -> Bool)
-> (Metrics -> Metrics -> Bool) -> Eq Metrics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metrics -> Metrics -> Bool
$c/= :: Metrics -> Metrics -> Bool
== :: Metrics -> Metrics -> Bool
$c== :: Metrics -> Metrics -> Bool
Prelude.Eq, ReadPrec [Metrics]
ReadPrec Metrics
Int -> ReadS Metrics
ReadS [Metrics]
(Int -> ReadS Metrics)
-> ReadS [Metrics]
-> ReadPrec Metrics
-> ReadPrec [Metrics]
-> Read Metrics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metrics]
$creadListPrec :: ReadPrec [Metrics]
readPrec :: ReadPrec Metrics
$creadPrec :: ReadPrec Metrics
readList :: ReadS [Metrics]
$creadList :: ReadS [Metrics]
readsPrec :: Int -> ReadS Metrics
$creadsPrec :: Int -> ReadS Metrics
Prelude.Read, Int -> Metrics -> ShowS
[Metrics] -> ShowS
Metrics -> String
(Int -> Metrics -> ShowS)
-> (Metrics -> String) -> ([Metrics] -> ShowS) -> Show Metrics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metrics] -> ShowS
$cshowList :: [Metrics] -> ShowS
show :: Metrics -> String
$cshow :: Metrics -> String
showsPrec :: Int -> Metrics -> ShowS
$cshowsPrec :: Int -> Metrics -> ShowS
Prelude.Show, (forall x. Metrics -> Rep Metrics x)
-> (forall x. Rep Metrics x -> Metrics) -> Generic Metrics
forall x. Rep Metrics x -> Metrics
forall x. Metrics -> Rep Metrics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metrics x -> Metrics
$cfrom :: forall x. Metrics -> Rep Metrics x
Prelude.Generic)

-- |
-- Create a value of 'Metrics' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'errorMetrics', 'metrics_errorMetrics' - Provides detailed error metrics for each forecast type. Metrics include
-- root-mean square-error (RMSE), mean absolute percentage error (MAPE),
-- mean absolute scaled error (MASE), and weighted average percentage error
-- (WAPE).
--
-- 'rmse', 'metrics_rmse' - The root-mean-square error (RMSE).
--
-- 'weightedQuantileLosses', 'metrics_weightedQuantileLosses' - An array of weighted quantile losses. Quantiles divide a probability
-- distribution into regions of equal probability. The distribution in this
-- case is the loss function.
--
-- 'averageWeightedQuantileLoss', 'metrics_averageWeightedQuantileLoss' - The average value of all weighted quantile losses.
newMetrics ::
  Metrics
newMetrics :: Metrics
newMetrics =
  Metrics' :: Maybe [ErrorMetric]
-> Maybe Double
-> Maybe [WeightedQuantileLoss]
-> Maybe Double
-> Metrics
Metrics'
    { $sel:errorMetrics:Metrics' :: Maybe [ErrorMetric]
errorMetrics = Maybe [ErrorMetric]
forall a. Maybe a
Prelude.Nothing,
      $sel:rmse:Metrics' :: Maybe Double
rmse = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:weightedQuantileLosses:Metrics' :: Maybe [WeightedQuantileLoss]
weightedQuantileLosses = Maybe [WeightedQuantileLoss]
forall a. Maybe a
Prelude.Nothing,
      $sel:averageWeightedQuantileLoss:Metrics' :: Maybe Double
averageWeightedQuantileLoss = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | Provides detailed error metrics for each forecast type. Metrics include
-- root-mean square-error (RMSE), mean absolute percentage error (MAPE),
-- mean absolute scaled error (MASE), and weighted average percentage error
-- (WAPE).
metrics_errorMetrics :: Lens.Lens' Metrics (Prelude.Maybe [ErrorMetric])
metrics_errorMetrics :: (Maybe [ErrorMetric] -> f (Maybe [ErrorMetric]))
-> Metrics -> f Metrics
metrics_errorMetrics = (Metrics -> Maybe [ErrorMetric])
-> (Metrics -> Maybe [ErrorMetric] -> Metrics)
-> Lens Metrics Metrics (Maybe [ErrorMetric]) (Maybe [ErrorMetric])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metrics' {Maybe [ErrorMetric]
errorMetrics :: Maybe [ErrorMetric]
$sel:errorMetrics:Metrics' :: Metrics -> Maybe [ErrorMetric]
errorMetrics} -> Maybe [ErrorMetric]
errorMetrics) (\s :: Metrics
s@Metrics' {} Maybe [ErrorMetric]
a -> Metrics
s {$sel:errorMetrics:Metrics' :: Maybe [ErrorMetric]
errorMetrics = Maybe [ErrorMetric]
a} :: Metrics) ((Maybe [ErrorMetric] -> f (Maybe [ErrorMetric]))
 -> Metrics -> f Metrics)
-> ((Maybe [ErrorMetric] -> f (Maybe [ErrorMetric]))
    -> Maybe [ErrorMetric] -> f (Maybe [ErrorMetric]))
-> (Maybe [ErrorMetric] -> f (Maybe [ErrorMetric]))
-> Metrics
-> f Metrics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [ErrorMetric] [ErrorMetric] [ErrorMetric] [ErrorMetric]
-> Iso
     (Maybe [ErrorMetric])
     (Maybe [ErrorMetric])
     (Maybe [ErrorMetric])
     (Maybe [ErrorMetric])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [ErrorMetric] [ErrorMetric] [ErrorMetric] [ErrorMetric]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The root-mean-square error (RMSE).
metrics_rmse :: Lens.Lens' Metrics (Prelude.Maybe Prelude.Double)
metrics_rmse :: (Maybe Double -> f (Maybe Double)) -> Metrics -> f Metrics
metrics_rmse = (Metrics -> Maybe Double)
-> (Metrics -> Maybe Double -> Metrics)
-> Lens Metrics Metrics (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metrics' {Maybe Double
rmse :: Maybe Double
$sel:rmse:Metrics' :: Metrics -> Maybe Double
rmse} -> Maybe Double
rmse) (\s :: Metrics
s@Metrics' {} Maybe Double
a -> Metrics
s {$sel:rmse:Metrics' :: Maybe Double
rmse = Maybe Double
a} :: Metrics)

-- | An array of weighted quantile losses. Quantiles divide a probability
-- distribution into regions of equal probability. The distribution in this
-- case is the loss function.
metrics_weightedQuantileLosses :: Lens.Lens' Metrics (Prelude.Maybe [WeightedQuantileLoss])
metrics_weightedQuantileLosses :: (Maybe [WeightedQuantileLoss] -> f (Maybe [WeightedQuantileLoss]))
-> Metrics -> f Metrics
metrics_weightedQuantileLosses = (Metrics -> Maybe [WeightedQuantileLoss])
-> (Metrics -> Maybe [WeightedQuantileLoss] -> Metrics)
-> Lens
     Metrics
     Metrics
     (Maybe [WeightedQuantileLoss])
     (Maybe [WeightedQuantileLoss])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metrics' {Maybe [WeightedQuantileLoss]
weightedQuantileLosses :: Maybe [WeightedQuantileLoss]
$sel:weightedQuantileLosses:Metrics' :: Metrics -> Maybe [WeightedQuantileLoss]
weightedQuantileLosses} -> Maybe [WeightedQuantileLoss]
weightedQuantileLosses) (\s :: Metrics
s@Metrics' {} Maybe [WeightedQuantileLoss]
a -> Metrics
s {$sel:weightedQuantileLosses:Metrics' :: Maybe [WeightedQuantileLoss]
weightedQuantileLosses = Maybe [WeightedQuantileLoss]
a} :: Metrics) ((Maybe [WeightedQuantileLoss] -> f (Maybe [WeightedQuantileLoss]))
 -> Metrics -> f Metrics)
-> ((Maybe [WeightedQuantileLoss]
     -> f (Maybe [WeightedQuantileLoss]))
    -> Maybe [WeightedQuantileLoss]
    -> f (Maybe [WeightedQuantileLoss]))
-> (Maybe [WeightedQuantileLoss]
    -> f (Maybe [WeightedQuantileLoss]))
-> Metrics
-> f Metrics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
-> Iso
     (Maybe [WeightedQuantileLoss])
     (Maybe [WeightedQuantileLoss])
     (Maybe [WeightedQuantileLoss])
     (Maybe [WeightedQuantileLoss])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
  [WeightedQuantileLoss]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The average value of all weighted quantile losses.
metrics_averageWeightedQuantileLoss :: Lens.Lens' Metrics (Prelude.Maybe Prelude.Double)
metrics_averageWeightedQuantileLoss :: (Maybe Double -> f (Maybe Double)) -> Metrics -> f Metrics
metrics_averageWeightedQuantileLoss = (Metrics -> Maybe Double)
-> (Metrics -> Maybe Double -> Metrics)
-> Lens Metrics Metrics (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metrics' {Maybe Double
averageWeightedQuantileLoss :: Maybe Double
$sel:averageWeightedQuantileLoss:Metrics' :: Metrics -> Maybe Double
averageWeightedQuantileLoss} -> Maybe Double
averageWeightedQuantileLoss) (\s :: Metrics
s@Metrics' {} Maybe Double
a -> Metrics
s {$sel:averageWeightedQuantileLoss:Metrics' :: Maybe Double
averageWeightedQuantileLoss = Maybe Double
a} :: Metrics)

instance Core.FromJSON Metrics where
  parseJSON :: Value -> Parser Metrics
parseJSON =
    String -> (Object -> Parser Metrics) -> Value -> Parser Metrics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Metrics"
      ( \Object
x ->
          Maybe [ErrorMetric]
-> Maybe Double
-> Maybe [WeightedQuantileLoss]
-> Maybe Double
-> Metrics
Metrics'
            (Maybe [ErrorMetric]
 -> Maybe Double
 -> Maybe [WeightedQuantileLoss]
 -> Maybe Double
 -> Metrics)
-> Parser (Maybe [ErrorMetric])
-> Parser
     (Maybe Double
      -> Maybe [WeightedQuantileLoss] -> Maybe Double -> Metrics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [ErrorMetric]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ErrorMetrics" Parser (Maybe (Maybe [ErrorMetric]))
-> Maybe [ErrorMetric] -> Parser (Maybe [ErrorMetric])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ErrorMetric]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Double
   -> Maybe [WeightedQuantileLoss] -> Maybe Double -> Metrics)
-> Parser (Maybe Double)
-> Parser (Maybe [WeightedQuantileLoss] -> Maybe Double -> Metrics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RMSE")
            Parser (Maybe [WeightedQuantileLoss] -> Maybe Double -> Metrics)
-> Parser (Maybe [WeightedQuantileLoss])
-> Parser (Maybe Double -> Metrics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [WeightedQuantileLoss]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"WeightedQuantileLosses"
                            Parser (Maybe (Maybe [WeightedQuantileLoss]))
-> Maybe [WeightedQuantileLoss]
-> Parser (Maybe [WeightedQuantileLoss])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [WeightedQuantileLoss]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Double -> Metrics)
-> Parser (Maybe Double) -> Parser Metrics
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AverageWeightedQuantileLoss")
      )

instance Prelude.Hashable Metrics

instance Prelude.NFData Metrics