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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.HyperParameterTuningJobObjectiveType

-- | Defines the objective metric for a hyperparameter tuning job.
-- Hyperparameter tuning uses the value of this metric to evaluate the
-- training jobs it launches, and returns the training job that results in
-- either the highest or lowest value for this metric, depending on the
-- value you specify for the @Type@ parameter.
--
-- /See:/ 'newHyperParameterTuningJobObjective' smart constructor.
data HyperParameterTuningJobObjective = HyperParameterTuningJobObjective'
  { -- | Whether to minimize or maximize the objective metric.
    HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjectiveType
type' :: HyperParameterTuningJobObjectiveType,
    -- | The name of the metric to use for the objective metric.
    HyperParameterTuningJobObjective -> Text
metricName :: Prelude.Text
  }
  deriving (HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjective -> Bool
(HyperParameterTuningJobObjective
 -> HyperParameterTuningJobObjective -> Bool)
-> (HyperParameterTuningJobObjective
    -> HyperParameterTuningJobObjective -> Bool)
-> Eq HyperParameterTuningJobObjective
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjective -> Bool
$c/= :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjective -> Bool
== :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjective -> Bool
$c== :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjective -> Bool
Prelude.Eq, ReadPrec [HyperParameterTuningJobObjective]
ReadPrec HyperParameterTuningJobObjective
Int -> ReadS HyperParameterTuningJobObjective
ReadS [HyperParameterTuningJobObjective]
(Int -> ReadS HyperParameterTuningJobObjective)
-> ReadS [HyperParameterTuningJobObjective]
-> ReadPrec HyperParameterTuningJobObjective
-> ReadPrec [HyperParameterTuningJobObjective]
-> Read HyperParameterTuningJobObjective
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HyperParameterTuningJobObjective]
$creadListPrec :: ReadPrec [HyperParameterTuningJobObjective]
readPrec :: ReadPrec HyperParameterTuningJobObjective
$creadPrec :: ReadPrec HyperParameterTuningJobObjective
readList :: ReadS [HyperParameterTuningJobObjective]
$creadList :: ReadS [HyperParameterTuningJobObjective]
readsPrec :: Int -> ReadS HyperParameterTuningJobObjective
$creadsPrec :: Int -> ReadS HyperParameterTuningJobObjective
Prelude.Read, Int -> HyperParameterTuningJobObjective -> ShowS
[HyperParameterTuningJobObjective] -> ShowS
HyperParameterTuningJobObjective -> String
(Int -> HyperParameterTuningJobObjective -> ShowS)
-> (HyperParameterTuningJobObjective -> String)
-> ([HyperParameterTuningJobObjective] -> ShowS)
-> Show HyperParameterTuningJobObjective
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperParameterTuningJobObjective] -> ShowS
$cshowList :: [HyperParameterTuningJobObjective] -> ShowS
show :: HyperParameterTuningJobObjective -> String
$cshow :: HyperParameterTuningJobObjective -> String
showsPrec :: Int -> HyperParameterTuningJobObjective -> ShowS
$cshowsPrec :: Int -> HyperParameterTuningJobObjective -> ShowS
Prelude.Show, (forall x.
 HyperParameterTuningJobObjective
 -> Rep HyperParameterTuningJobObjective x)
-> (forall x.
    Rep HyperParameterTuningJobObjective x
    -> HyperParameterTuningJobObjective)
-> Generic HyperParameterTuningJobObjective
forall x.
Rep HyperParameterTuningJobObjective x
-> HyperParameterTuningJobObjective
forall x.
HyperParameterTuningJobObjective
-> Rep HyperParameterTuningJobObjective x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep HyperParameterTuningJobObjective x
-> HyperParameterTuningJobObjective
$cfrom :: forall x.
HyperParameterTuningJobObjective
-> Rep HyperParameterTuningJobObjective x
Prelude.Generic)

-- |
-- Create a value of 'HyperParameterTuningJobObjective' 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:
--
-- 'type'', 'hyperParameterTuningJobObjective_type' - Whether to minimize or maximize the objective metric.
--
-- 'metricName', 'hyperParameterTuningJobObjective_metricName' - The name of the metric to use for the objective metric.
newHyperParameterTuningJobObjective ::
  -- | 'type''
  HyperParameterTuningJobObjectiveType ->
  -- | 'metricName'
  Prelude.Text ->
  HyperParameterTuningJobObjective
newHyperParameterTuningJobObjective :: HyperParameterTuningJobObjectiveType
-> Text -> HyperParameterTuningJobObjective
newHyperParameterTuningJobObjective
  HyperParameterTuningJobObjectiveType
pType_
  Text
pMetricName_ =
    HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjectiveType
-> Text -> HyperParameterTuningJobObjective
HyperParameterTuningJobObjective'
      { $sel:type':HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjectiveType
type' = HyperParameterTuningJobObjectiveType
pType_,
        $sel:metricName:HyperParameterTuningJobObjective' :: Text
metricName = Text
pMetricName_
      }

-- | Whether to minimize or maximize the objective metric.
hyperParameterTuningJobObjective_type :: Lens.Lens' HyperParameterTuningJobObjective HyperParameterTuningJobObjectiveType
hyperParameterTuningJobObjective_type :: (HyperParameterTuningJobObjectiveType
 -> f HyperParameterTuningJobObjectiveType)
-> HyperParameterTuningJobObjective
-> f HyperParameterTuningJobObjective
hyperParameterTuningJobObjective_type = (HyperParameterTuningJobObjective
 -> HyperParameterTuningJobObjectiveType)
-> (HyperParameterTuningJobObjective
    -> HyperParameterTuningJobObjectiveType
    -> HyperParameterTuningJobObjective)
-> Lens
     HyperParameterTuningJobObjective
     HyperParameterTuningJobObjective
     HyperParameterTuningJobObjectiveType
     HyperParameterTuningJobObjectiveType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HyperParameterTuningJobObjective' {HyperParameterTuningJobObjectiveType
type' :: HyperParameterTuningJobObjectiveType
$sel:type':HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjectiveType
type'} -> HyperParameterTuningJobObjectiveType
type') (\s :: HyperParameterTuningJobObjective
s@HyperParameterTuningJobObjective' {} HyperParameterTuningJobObjectiveType
a -> HyperParameterTuningJobObjective
s {$sel:type':HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjectiveType
type' = HyperParameterTuningJobObjectiveType
a} :: HyperParameterTuningJobObjective)

-- | The name of the metric to use for the objective metric.
hyperParameterTuningJobObjective_metricName :: Lens.Lens' HyperParameterTuningJobObjective Prelude.Text
hyperParameterTuningJobObjective_metricName :: (Text -> f Text)
-> HyperParameterTuningJobObjective
-> f HyperParameterTuningJobObjective
hyperParameterTuningJobObjective_metricName = (HyperParameterTuningJobObjective -> Text)
-> (HyperParameterTuningJobObjective
    -> Text -> HyperParameterTuningJobObjective)
-> Lens
     HyperParameterTuningJobObjective
     HyperParameterTuningJobObjective
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HyperParameterTuningJobObjective' {Text
metricName :: Text
$sel:metricName:HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjective -> Text
metricName} -> Text
metricName) (\s :: HyperParameterTuningJobObjective
s@HyperParameterTuningJobObjective' {} Text
a -> HyperParameterTuningJobObjective
s {$sel:metricName:HyperParameterTuningJobObjective' :: Text
metricName = Text
a} :: HyperParameterTuningJobObjective)

instance
  Core.FromJSON
    HyperParameterTuningJobObjective
  where
  parseJSON :: Value -> Parser HyperParameterTuningJobObjective
parseJSON =
    String
-> (Object -> Parser HyperParameterTuningJobObjective)
-> Value
-> Parser HyperParameterTuningJobObjective
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HyperParameterTuningJobObjective"
      ( \Object
x ->
          HyperParameterTuningJobObjectiveType
-> Text -> HyperParameterTuningJobObjective
HyperParameterTuningJobObjective'
            (HyperParameterTuningJobObjectiveType
 -> Text -> HyperParameterTuningJobObjective)
-> Parser HyperParameterTuningJobObjectiveType
-> Parser (Text -> HyperParameterTuningJobObjective)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser HyperParameterTuningJobObjectiveType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
            Parser (Text -> HyperParameterTuningJobObjective)
-> Parser Text -> Parser HyperParameterTuningJobObjective
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
"MetricName")
      )

instance
  Prelude.Hashable
    HyperParameterTuningJobObjective

instance
  Prelude.NFData
    HyperParameterTuningJobObjective

instance Core.ToJSON HyperParameterTuningJobObjective where
  toJSON :: HyperParameterTuningJobObjective -> Value
toJSON HyperParameterTuningJobObjective' {Text
HyperParameterTuningJobObjectiveType
metricName :: Text
type' :: HyperParameterTuningJobObjectiveType
$sel:metricName:HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjective -> Text
$sel:type':HyperParameterTuningJobObjective' :: HyperParameterTuningJobObjective
-> HyperParameterTuningJobObjectiveType
..} =
    [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
"Type" Text -> HyperParameterTuningJobObjectiveType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HyperParameterTuningJobObjectiveType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MetricName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
metricName)
          ]
      )