{-# 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.ErrorMetric
-- 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.ErrorMetric where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides detailed error metrics to evaluate the performance of a
-- predictor. This object is part of the Metrics object.
--
-- /See:/ 'newErrorMetric' smart constructor.
data ErrorMetric = ErrorMetric'
  { -- | The Mean Absolute Scaled Error (MASE)
    ErrorMetric -> Maybe Double
mase :: Prelude.Maybe Prelude.Double,
    -- | The weighted absolute percentage error (WAPE).
    ErrorMetric -> Maybe Double
wape :: Prelude.Maybe Prelude.Double,
    -- | The Mean Absolute Percentage Error (MAPE)
    ErrorMetric -> Maybe Double
mape :: Prelude.Maybe Prelude.Double,
    -- | The root-mean-square error (RMSE).
    ErrorMetric -> Maybe Double
rmse :: Prelude.Maybe Prelude.Double,
    -- | The Forecast type used to compute WAPE, MAPE, MASE, and RMSE.
    ErrorMetric -> Maybe Text
forecastType :: Prelude.Maybe Prelude.Text
  }
  deriving (ErrorMetric -> ErrorMetric -> Bool
(ErrorMetric -> ErrorMetric -> Bool)
-> (ErrorMetric -> ErrorMetric -> Bool) -> Eq ErrorMetric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorMetric -> ErrorMetric -> Bool
$c/= :: ErrorMetric -> ErrorMetric -> Bool
== :: ErrorMetric -> ErrorMetric -> Bool
$c== :: ErrorMetric -> ErrorMetric -> Bool
Prelude.Eq, ReadPrec [ErrorMetric]
ReadPrec ErrorMetric
Int -> ReadS ErrorMetric
ReadS [ErrorMetric]
(Int -> ReadS ErrorMetric)
-> ReadS [ErrorMetric]
-> ReadPrec ErrorMetric
-> ReadPrec [ErrorMetric]
-> Read ErrorMetric
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ErrorMetric]
$creadListPrec :: ReadPrec [ErrorMetric]
readPrec :: ReadPrec ErrorMetric
$creadPrec :: ReadPrec ErrorMetric
readList :: ReadS [ErrorMetric]
$creadList :: ReadS [ErrorMetric]
readsPrec :: Int -> ReadS ErrorMetric
$creadsPrec :: Int -> ReadS ErrorMetric
Prelude.Read, Int -> ErrorMetric -> ShowS
[ErrorMetric] -> ShowS
ErrorMetric -> String
(Int -> ErrorMetric -> ShowS)
-> (ErrorMetric -> String)
-> ([ErrorMetric] -> ShowS)
-> Show ErrorMetric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorMetric] -> ShowS
$cshowList :: [ErrorMetric] -> ShowS
show :: ErrorMetric -> String
$cshow :: ErrorMetric -> String
showsPrec :: Int -> ErrorMetric -> ShowS
$cshowsPrec :: Int -> ErrorMetric -> ShowS
Prelude.Show, (forall x. ErrorMetric -> Rep ErrorMetric x)
-> (forall x. Rep ErrorMetric x -> ErrorMetric)
-> Generic ErrorMetric
forall x. Rep ErrorMetric x -> ErrorMetric
forall x. ErrorMetric -> Rep ErrorMetric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ErrorMetric x -> ErrorMetric
$cfrom :: forall x. ErrorMetric -> Rep ErrorMetric x
Prelude.Generic)

-- |
-- Create a value of 'ErrorMetric' 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:
--
-- 'mase', 'errorMetric_mase' - The Mean Absolute Scaled Error (MASE)
--
-- 'wape', 'errorMetric_wape' - The weighted absolute percentage error (WAPE).
--
-- 'mape', 'errorMetric_mape' - The Mean Absolute Percentage Error (MAPE)
--
-- 'rmse', 'errorMetric_rmse' - The root-mean-square error (RMSE).
--
-- 'forecastType', 'errorMetric_forecastType' - The Forecast type used to compute WAPE, MAPE, MASE, and RMSE.
newErrorMetric ::
  ErrorMetric
newErrorMetric :: ErrorMetric
newErrorMetric =
  ErrorMetric' :: Maybe Double
-> Maybe Double
-> Maybe Double
-> Maybe Double
-> Maybe Text
-> ErrorMetric
ErrorMetric'
    { $sel:mase:ErrorMetric' :: Maybe Double
mase = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:wape:ErrorMetric' :: Maybe Double
wape = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:mape:ErrorMetric' :: Maybe Double
mape = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:rmse:ErrorMetric' :: Maybe Double
rmse = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:forecastType:ErrorMetric' :: Maybe Text
forecastType = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The Mean Absolute Scaled Error (MASE)
errorMetric_mase :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_mase :: (Maybe Double -> f (Maybe Double)) -> ErrorMetric -> f ErrorMetric
errorMetric_mase = (ErrorMetric -> Maybe Double)
-> (ErrorMetric -> Maybe Double -> ErrorMetric)
-> Lens ErrorMetric ErrorMetric (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorMetric' {Maybe Double
mase :: Maybe Double
$sel:mase:ErrorMetric' :: ErrorMetric -> Maybe Double
mase} -> Maybe Double
mase) (\s :: ErrorMetric
s@ErrorMetric' {} Maybe Double
a -> ErrorMetric
s {$sel:mase:ErrorMetric' :: Maybe Double
mase = Maybe Double
a} :: ErrorMetric)

-- | The weighted absolute percentage error (WAPE).
errorMetric_wape :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_wape :: (Maybe Double -> f (Maybe Double)) -> ErrorMetric -> f ErrorMetric
errorMetric_wape = (ErrorMetric -> Maybe Double)
-> (ErrorMetric -> Maybe Double -> ErrorMetric)
-> Lens ErrorMetric ErrorMetric (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorMetric' {Maybe Double
wape :: Maybe Double
$sel:wape:ErrorMetric' :: ErrorMetric -> Maybe Double
wape} -> Maybe Double
wape) (\s :: ErrorMetric
s@ErrorMetric' {} Maybe Double
a -> ErrorMetric
s {$sel:wape:ErrorMetric' :: Maybe Double
wape = Maybe Double
a} :: ErrorMetric)

-- | The Mean Absolute Percentage Error (MAPE)
errorMetric_mape :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_mape :: (Maybe Double -> f (Maybe Double)) -> ErrorMetric -> f ErrorMetric
errorMetric_mape = (ErrorMetric -> Maybe Double)
-> (ErrorMetric -> Maybe Double -> ErrorMetric)
-> Lens ErrorMetric ErrorMetric (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorMetric' {Maybe Double
mape :: Maybe Double
$sel:mape:ErrorMetric' :: ErrorMetric -> Maybe Double
mape} -> Maybe Double
mape) (\s :: ErrorMetric
s@ErrorMetric' {} Maybe Double
a -> ErrorMetric
s {$sel:mape:ErrorMetric' :: Maybe Double
mape = Maybe Double
a} :: ErrorMetric)

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

-- | The Forecast type used to compute WAPE, MAPE, MASE, and RMSE.
errorMetric_forecastType :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Text)
errorMetric_forecastType :: (Maybe Text -> f (Maybe Text)) -> ErrorMetric -> f ErrorMetric
errorMetric_forecastType = (ErrorMetric -> Maybe Text)
-> (ErrorMetric -> Maybe Text -> ErrorMetric)
-> Lens ErrorMetric ErrorMetric (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorMetric' {Maybe Text
forecastType :: Maybe Text
$sel:forecastType:ErrorMetric' :: ErrorMetric -> Maybe Text
forecastType} -> Maybe Text
forecastType) (\s :: ErrorMetric
s@ErrorMetric' {} Maybe Text
a -> ErrorMetric
s {$sel:forecastType:ErrorMetric' :: Maybe Text
forecastType = Maybe Text
a} :: ErrorMetric)

instance Core.FromJSON ErrorMetric where
  parseJSON :: Value -> Parser ErrorMetric
parseJSON =
    String
-> (Object -> Parser ErrorMetric) -> Value -> Parser ErrorMetric
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ErrorMetric"
      ( \Object
x ->
          Maybe Double
-> Maybe Double
-> Maybe Double
-> Maybe Double
-> Maybe Text
-> ErrorMetric
ErrorMetric'
            (Maybe Double
 -> Maybe Double
 -> Maybe Double
 -> Maybe Double
 -> Maybe Text
 -> ErrorMetric)
-> Parser (Maybe Double)
-> Parser
     (Maybe Double
      -> Maybe Double -> Maybe Double -> Maybe Text -> ErrorMetric)
forall (f :: * -> *) a b. Functor 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
"MASE")
            Parser
  (Maybe Double
   -> Maybe Double -> Maybe Double -> Maybe Text -> ErrorMetric)
-> Parser (Maybe Double)
-> Parser
     (Maybe Double -> Maybe Double -> Maybe Text -> ErrorMetric)
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
"WAPE")
            Parser (Maybe Double -> Maybe Double -> Maybe Text -> ErrorMetric)
-> Parser (Maybe Double)
-> Parser (Maybe Double -> Maybe Text -> ErrorMetric)
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
"MAPE")
            Parser (Maybe Double -> Maybe Text -> ErrorMetric)
-> Parser (Maybe Double) -> Parser (Maybe Text -> ErrorMetric)
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 Text -> ErrorMetric)
-> Parser (Maybe Text) -> Parser ErrorMetric
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ForecastType")
      )

instance Prelude.Hashable ErrorMetric

instance Prelude.NFData ErrorMetric