{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Forecast.Types.ErrorMetric where

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

-- | The Forecast type used to compute WAPE, MAPE, MASE, and RMSE.
errorMetric_forecastType :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Text)
errorMetric_forecastType :: Lens' ErrorMetric (Maybe Text)
errorMetric_forecastType = 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)

-- | The Mean Absolute Percentage Error (MAPE)
errorMetric_mape :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_mape :: Lens' ErrorMetric (Maybe Double)
errorMetric_mape = 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 Mean Absolute Scaled Error (MASE)
errorMetric_mase :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_mase :: Lens' ErrorMetric (Maybe Double)
errorMetric_mase = 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 root-mean-square error (RMSE).
errorMetric_rmse :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_rmse :: Lens' ErrorMetric (Maybe Double)
errorMetric_rmse = 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 weighted absolute percentage error (WAPE).
errorMetric_wape :: Lens.Lens' ErrorMetric (Prelude.Maybe Prelude.Double)
errorMetric_wape :: Lens' ErrorMetric (Maybe Double)
errorMetric_wape = 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)

instance Data.FromJSON ErrorMetric where
  parseJSON :: Value -> Parser ErrorMetric
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ErrorMetric"
      ( \Object
x ->
          Maybe Text
-> Maybe Double
-> Maybe Double
-> Maybe Double
-> Maybe Double
-> ErrorMetric
ErrorMetric'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ForecastType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MAPE")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MASE")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RMSE")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"WAPE")
      )

instance Prelude.Hashable ErrorMetric where
  hashWithSalt :: Int -> ErrorMetric -> Int
hashWithSalt Int
_salt ErrorMetric' {Maybe Double
Maybe Text
wape :: Maybe Double
rmse :: Maybe Double
mase :: Maybe Double
mape :: Maybe Double
forecastType :: Maybe Text
$sel:wape:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:rmse:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:mase:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:mape:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:forecastType:ErrorMetric' :: ErrorMetric -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
forecastType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
mape
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
mase
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
rmse
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
wape

instance Prelude.NFData ErrorMetric where
  rnf :: ErrorMetric -> ()
rnf ErrorMetric' {Maybe Double
Maybe Text
wape :: Maybe Double
rmse :: Maybe Double
mase :: Maybe Double
mape :: Maybe Double
forecastType :: Maybe Text
$sel:wape:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:rmse:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:mase:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:mape:ErrorMetric' :: ErrorMetric -> Maybe Double
$sel:forecastType:ErrorMetric' :: ErrorMetric -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
forecastType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
mape
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
mase
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
rmse
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
wape