{-# 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.Personalize.Types.HPOConfig
-- 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.Personalize.Types.HPOConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Personalize.Types.HPOObjective
import Amazonka.Personalize.Types.HPOResourceConfig
import Amazonka.Personalize.Types.HyperParameterRanges
import qualified Amazonka.Prelude as Prelude

-- | Describes the properties for hyperparameter optimization (HPO).
--
-- /See:/ 'newHPOConfig' smart constructor.
data HPOConfig = HPOConfig'
  { -- | The hyperparameters and their allowable ranges.
    HPOConfig -> Maybe HyperParameterRanges
algorithmHyperParameterRanges :: Prelude.Maybe HyperParameterRanges,
    -- | Describes the resource configuration for HPO.
    HPOConfig -> Maybe HPOResourceConfig
hpoResourceConfig :: Prelude.Maybe HPOResourceConfig,
    -- | The metric to optimize during HPO.
    --
    -- Amazon Personalize doesn\'t support configuring the @hpoObjective@ at
    -- this time.
    HPOConfig -> Maybe HPOObjective
hpoObjective :: Prelude.Maybe HPOObjective
  }
  deriving (HPOConfig -> HPOConfig -> Bool
(HPOConfig -> HPOConfig -> Bool)
-> (HPOConfig -> HPOConfig -> Bool) -> Eq HPOConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HPOConfig -> HPOConfig -> Bool
$c/= :: HPOConfig -> HPOConfig -> Bool
== :: HPOConfig -> HPOConfig -> Bool
$c== :: HPOConfig -> HPOConfig -> Bool
Prelude.Eq, ReadPrec [HPOConfig]
ReadPrec HPOConfig
Int -> ReadS HPOConfig
ReadS [HPOConfig]
(Int -> ReadS HPOConfig)
-> ReadS [HPOConfig]
-> ReadPrec HPOConfig
-> ReadPrec [HPOConfig]
-> Read HPOConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HPOConfig]
$creadListPrec :: ReadPrec [HPOConfig]
readPrec :: ReadPrec HPOConfig
$creadPrec :: ReadPrec HPOConfig
readList :: ReadS [HPOConfig]
$creadList :: ReadS [HPOConfig]
readsPrec :: Int -> ReadS HPOConfig
$creadsPrec :: Int -> ReadS HPOConfig
Prelude.Read, Int -> HPOConfig -> ShowS
[HPOConfig] -> ShowS
HPOConfig -> String
(Int -> HPOConfig -> ShowS)
-> (HPOConfig -> String)
-> ([HPOConfig] -> ShowS)
-> Show HPOConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HPOConfig] -> ShowS
$cshowList :: [HPOConfig] -> ShowS
show :: HPOConfig -> String
$cshow :: HPOConfig -> String
showsPrec :: Int -> HPOConfig -> ShowS
$cshowsPrec :: Int -> HPOConfig -> ShowS
Prelude.Show, (forall x. HPOConfig -> Rep HPOConfig x)
-> (forall x. Rep HPOConfig x -> HPOConfig) -> Generic HPOConfig
forall x. Rep HPOConfig x -> HPOConfig
forall x. HPOConfig -> Rep HPOConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HPOConfig x -> HPOConfig
$cfrom :: forall x. HPOConfig -> Rep HPOConfig x
Prelude.Generic)

-- |
-- Create a value of 'HPOConfig' 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:
--
-- 'algorithmHyperParameterRanges', 'hPOConfig_algorithmHyperParameterRanges' - The hyperparameters and their allowable ranges.
--
-- 'hpoResourceConfig', 'hPOConfig_hpoResourceConfig' - Describes the resource configuration for HPO.
--
-- 'hpoObjective', 'hPOConfig_hpoObjective' - The metric to optimize during HPO.
--
-- Amazon Personalize doesn\'t support configuring the @hpoObjective@ at
-- this time.
newHPOConfig ::
  HPOConfig
newHPOConfig :: HPOConfig
newHPOConfig =
  HPOConfig' :: Maybe HyperParameterRanges
-> Maybe HPOResourceConfig -> Maybe HPOObjective -> HPOConfig
HPOConfig'
    { $sel:algorithmHyperParameterRanges:HPOConfig' :: Maybe HyperParameterRanges
algorithmHyperParameterRanges =
        Maybe HyperParameterRanges
forall a. Maybe a
Prelude.Nothing,
      $sel:hpoResourceConfig:HPOConfig' :: Maybe HPOResourceConfig
hpoResourceConfig = Maybe HPOResourceConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:hpoObjective:HPOConfig' :: Maybe HPOObjective
hpoObjective = Maybe HPOObjective
forall a. Maybe a
Prelude.Nothing
    }

-- | The hyperparameters and their allowable ranges.
hPOConfig_algorithmHyperParameterRanges :: Lens.Lens' HPOConfig (Prelude.Maybe HyperParameterRanges)
hPOConfig_algorithmHyperParameterRanges :: (Maybe HyperParameterRanges -> f (Maybe HyperParameterRanges))
-> HPOConfig -> f HPOConfig
hPOConfig_algorithmHyperParameterRanges = (HPOConfig -> Maybe HyperParameterRanges)
-> (HPOConfig -> Maybe HyperParameterRanges -> HPOConfig)
-> Lens
     HPOConfig
     HPOConfig
     (Maybe HyperParameterRanges)
     (Maybe HyperParameterRanges)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOConfig' {Maybe HyperParameterRanges
algorithmHyperParameterRanges :: Maybe HyperParameterRanges
$sel:algorithmHyperParameterRanges:HPOConfig' :: HPOConfig -> Maybe HyperParameterRanges
algorithmHyperParameterRanges} -> Maybe HyperParameterRanges
algorithmHyperParameterRanges) (\s :: HPOConfig
s@HPOConfig' {} Maybe HyperParameterRanges
a -> HPOConfig
s {$sel:algorithmHyperParameterRanges:HPOConfig' :: Maybe HyperParameterRanges
algorithmHyperParameterRanges = Maybe HyperParameterRanges
a} :: HPOConfig)

-- | Describes the resource configuration for HPO.
hPOConfig_hpoResourceConfig :: Lens.Lens' HPOConfig (Prelude.Maybe HPOResourceConfig)
hPOConfig_hpoResourceConfig :: (Maybe HPOResourceConfig -> f (Maybe HPOResourceConfig))
-> HPOConfig -> f HPOConfig
hPOConfig_hpoResourceConfig = (HPOConfig -> Maybe HPOResourceConfig)
-> (HPOConfig -> Maybe HPOResourceConfig -> HPOConfig)
-> Lens
     HPOConfig
     HPOConfig
     (Maybe HPOResourceConfig)
     (Maybe HPOResourceConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOConfig' {Maybe HPOResourceConfig
hpoResourceConfig :: Maybe HPOResourceConfig
$sel:hpoResourceConfig:HPOConfig' :: HPOConfig -> Maybe HPOResourceConfig
hpoResourceConfig} -> Maybe HPOResourceConfig
hpoResourceConfig) (\s :: HPOConfig
s@HPOConfig' {} Maybe HPOResourceConfig
a -> HPOConfig
s {$sel:hpoResourceConfig:HPOConfig' :: Maybe HPOResourceConfig
hpoResourceConfig = Maybe HPOResourceConfig
a} :: HPOConfig)

-- | The metric to optimize during HPO.
--
-- Amazon Personalize doesn\'t support configuring the @hpoObjective@ at
-- this time.
hPOConfig_hpoObjective :: Lens.Lens' HPOConfig (Prelude.Maybe HPOObjective)
hPOConfig_hpoObjective :: (Maybe HPOObjective -> f (Maybe HPOObjective))
-> HPOConfig -> f HPOConfig
hPOConfig_hpoObjective = (HPOConfig -> Maybe HPOObjective)
-> (HPOConfig -> Maybe HPOObjective -> HPOConfig)
-> Lens
     HPOConfig HPOConfig (Maybe HPOObjective) (Maybe HPOObjective)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOConfig' {Maybe HPOObjective
hpoObjective :: Maybe HPOObjective
$sel:hpoObjective:HPOConfig' :: HPOConfig -> Maybe HPOObjective
hpoObjective} -> Maybe HPOObjective
hpoObjective) (\s :: HPOConfig
s@HPOConfig' {} Maybe HPOObjective
a -> HPOConfig
s {$sel:hpoObjective:HPOConfig' :: Maybe HPOObjective
hpoObjective = Maybe HPOObjective
a} :: HPOConfig)

instance Core.FromJSON HPOConfig where
  parseJSON :: Value -> Parser HPOConfig
parseJSON =
    String -> (Object -> Parser HPOConfig) -> Value -> Parser HPOConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HPOConfig"
      ( \Object
x ->
          Maybe HyperParameterRanges
-> Maybe HPOResourceConfig -> Maybe HPOObjective -> HPOConfig
HPOConfig'
            (Maybe HyperParameterRanges
 -> Maybe HPOResourceConfig -> Maybe HPOObjective -> HPOConfig)
-> Parser (Maybe HyperParameterRanges)
-> Parser
     (Maybe HPOResourceConfig -> Maybe HPOObjective -> HPOConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe HyperParameterRanges)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"algorithmHyperParameterRanges")
            Parser (Maybe HPOResourceConfig -> Maybe HPOObjective -> HPOConfig)
-> Parser (Maybe HPOResourceConfig)
-> Parser (Maybe HPOObjective -> HPOConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HPOResourceConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"hpoResourceConfig")
            Parser (Maybe HPOObjective -> HPOConfig)
-> Parser (Maybe HPOObjective) -> Parser HPOConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HPOObjective)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"hpoObjective")
      )

instance Prelude.Hashable HPOConfig

instance Prelude.NFData HPOConfig

instance Core.ToJSON HPOConfig where
  toJSON :: HPOConfig -> Value
toJSON HPOConfig' {Maybe HPOObjective
Maybe HPOResourceConfig
Maybe HyperParameterRanges
hpoObjective :: Maybe HPOObjective
hpoResourceConfig :: Maybe HPOResourceConfig
algorithmHyperParameterRanges :: Maybe HyperParameterRanges
$sel:hpoObjective:HPOConfig' :: HPOConfig -> Maybe HPOObjective
$sel:hpoResourceConfig:HPOConfig' :: HPOConfig -> Maybe HPOResourceConfig
$sel:algorithmHyperParameterRanges:HPOConfig' :: HPOConfig -> Maybe HyperParameterRanges
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"algorithmHyperParameterRanges" Text -> HyperParameterRanges -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HyperParameterRanges -> Pair)
-> Maybe HyperParameterRanges -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HyperParameterRanges
algorithmHyperParameterRanges,
            (Text
"hpoResourceConfig" Text -> HPOResourceConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HPOResourceConfig -> Pair)
-> Maybe HPOResourceConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HPOResourceConfig
hpoResourceConfig,
            (Text
"hpoObjective" Text -> HPOObjective -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HPOObjective -> Pair) -> Maybe HPOObjective -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HPOObjective
hpoObjective
          ]
      )