{-# 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.SageMaker.Types.MetricDefinition
-- 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.SageMaker.Types.MetricDefinition where

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

-- | Specifies a metric that the training algorithm writes to @stderr@ or
-- @stdout@. Amazon SageMakerhyperparameter tuning captures all defined
-- metrics. You specify one metric that a hyperparameter tuning job uses as
-- its objective metric to choose the best training job.
--
-- /See:/ 'newMetricDefinition' smart constructor.
data MetricDefinition = MetricDefinition'
  { -- | The name of the metric.
    MetricDefinition -> Text
name :: Prelude.Text,
    -- | A regular expression that searches the output of a training job and gets
    -- the value of the metric. For more information about using regular
    -- expressions to define metrics, see
    -- <https://docs.aws.amazon.com/sagemaker/latest/dg/automatic-model-tuning-define-metrics.html Defining Objective Metrics>.
    MetricDefinition -> Text
regex :: Prelude.Text
  }
  deriving (MetricDefinition -> MetricDefinition -> Bool
(MetricDefinition -> MetricDefinition -> Bool)
-> (MetricDefinition -> MetricDefinition -> Bool)
-> Eq MetricDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDefinition -> MetricDefinition -> Bool
$c/= :: MetricDefinition -> MetricDefinition -> Bool
== :: MetricDefinition -> MetricDefinition -> Bool
$c== :: MetricDefinition -> MetricDefinition -> Bool
Prelude.Eq, ReadPrec [MetricDefinition]
ReadPrec MetricDefinition
Int -> ReadS MetricDefinition
ReadS [MetricDefinition]
(Int -> ReadS MetricDefinition)
-> ReadS [MetricDefinition]
-> ReadPrec MetricDefinition
-> ReadPrec [MetricDefinition]
-> Read MetricDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDefinition]
$creadListPrec :: ReadPrec [MetricDefinition]
readPrec :: ReadPrec MetricDefinition
$creadPrec :: ReadPrec MetricDefinition
readList :: ReadS [MetricDefinition]
$creadList :: ReadS [MetricDefinition]
readsPrec :: Int -> ReadS MetricDefinition
$creadsPrec :: Int -> ReadS MetricDefinition
Prelude.Read, Int -> MetricDefinition -> ShowS
[MetricDefinition] -> ShowS
MetricDefinition -> String
(Int -> MetricDefinition -> ShowS)
-> (MetricDefinition -> String)
-> ([MetricDefinition] -> ShowS)
-> Show MetricDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDefinition] -> ShowS
$cshowList :: [MetricDefinition] -> ShowS
show :: MetricDefinition -> String
$cshow :: MetricDefinition -> String
showsPrec :: Int -> MetricDefinition -> ShowS
$cshowsPrec :: Int -> MetricDefinition -> ShowS
Prelude.Show, (forall x. MetricDefinition -> Rep MetricDefinition x)
-> (forall x. Rep MetricDefinition x -> MetricDefinition)
-> Generic MetricDefinition
forall x. Rep MetricDefinition x -> MetricDefinition
forall x. MetricDefinition -> Rep MetricDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDefinition x -> MetricDefinition
$cfrom :: forall x. MetricDefinition -> Rep MetricDefinition x
Prelude.Generic)

-- |
-- Create a value of 'MetricDefinition' 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:
--
-- 'name', 'metricDefinition_name' - The name of the metric.
--
-- 'regex', 'metricDefinition_regex' - A regular expression that searches the output of a training job and gets
-- the value of the metric. For more information about using regular
-- expressions to define metrics, see
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/automatic-model-tuning-define-metrics.html Defining Objective Metrics>.
newMetricDefinition ::
  -- | 'name'
  Prelude.Text ->
  -- | 'regex'
  Prelude.Text ->
  MetricDefinition
newMetricDefinition :: Text -> Text -> MetricDefinition
newMetricDefinition Text
pName_ Text
pRegex_ =
  MetricDefinition' :: Text -> Text -> MetricDefinition
MetricDefinition' {$sel:name:MetricDefinition' :: Text
name = Text
pName_, $sel:regex:MetricDefinition' :: Text
regex = Text
pRegex_}

-- | The name of the metric.
metricDefinition_name :: Lens.Lens' MetricDefinition Prelude.Text
metricDefinition_name :: (Text -> f Text) -> MetricDefinition -> f MetricDefinition
metricDefinition_name = (MetricDefinition -> Text)
-> (MetricDefinition -> Text -> MetricDefinition)
-> Lens MetricDefinition MetricDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Text
name :: Text
$sel:name:MetricDefinition' :: MetricDefinition -> Text
name} -> Text
name) (\s :: MetricDefinition
s@MetricDefinition' {} Text
a -> MetricDefinition
s {$sel:name:MetricDefinition' :: Text
name = Text
a} :: MetricDefinition)

-- | A regular expression that searches the output of a training job and gets
-- the value of the metric. For more information about using regular
-- expressions to define metrics, see
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/automatic-model-tuning-define-metrics.html Defining Objective Metrics>.
metricDefinition_regex :: Lens.Lens' MetricDefinition Prelude.Text
metricDefinition_regex :: (Text -> f Text) -> MetricDefinition -> f MetricDefinition
metricDefinition_regex = (MetricDefinition -> Text)
-> (MetricDefinition -> Text -> MetricDefinition)
-> Lens MetricDefinition MetricDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDefinition' {Text
regex :: Text
$sel:regex:MetricDefinition' :: MetricDefinition -> Text
regex} -> Text
regex) (\s :: MetricDefinition
s@MetricDefinition' {} Text
a -> MetricDefinition
s {$sel:regex:MetricDefinition' :: Text
regex = Text
a} :: MetricDefinition)

instance Core.FromJSON MetricDefinition where
  parseJSON :: Value -> Parser MetricDefinition
parseJSON =
    String
-> (Object -> Parser MetricDefinition)
-> Value
-> Parser MetricDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MetricDefinition"
      ( \Object
x ->
          Text -> Text -> MetricDefinition
MetricDefinition'
            (Text -> Text -> MetricDefinition)
-> Parser Text -> Parser (Text -> MetricDefinition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name") Parser (Text -> MetricDefinition)
-> Parser Text -> Parser MetricDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Regex")
      )

instance Prelude.Hashable MetricDefinition

instance Prelude.NFData MetricDefinition

instance Core.ToJSON MetricDefinition where
  toJSON :: MetricDefinition -> Value
toJSON MetricDefinition' {Text
regex :: Text
name :: Text
$sel:regex:MetricDefinition' :: MetricDefinition -> Text
$sel:name:MetricDefinition' :: MetricDefinition -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Regex" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
regex)
          ]
      )