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

-- | A configuration for a shuffle option for input data in a channel. If you
-- use @S3Prefix@ for @S3DataType@, the results of the S3 key prefix
-- matches are shuffled. If you use @ManifestFile@, the order of the S3
-- object references in the @ManifestFile@ is shuffled. If you use
-- @AugmentedManifestFile@, the order of the JSON lines in the
-- @AugmentedManifestFile@ is shuffled. The shuffling order is determined
-- using the @Seed@ value.
--
-- For Pipe input mode, when @ShuffleConfig@ is specified shuffling is done
-- at the start of every epoch. With large datasets, this ensures that the
-- order of the training data is different for each epoch, and it helps
-- reduce bias and possible overfitting. In a multi-node training job when
-- @ShuffleConfig@ is combined with @S3DataDistributionType@ of
-- @ShardedByS3Key@, the data is shuffled across nodes so that the content
-- sent to a particular node on the first epoch might be sent to a
-- different node on the second epoch.
--
-- /See:/ 'newShuffleConfig' smart constructor.
data ShuffleConfig = ShuffleConfig'
  { -- | Determines the shuffling order in @ShuffleConfig@ value.
    ShuffleConfig -> Integer
seed :: Prelude.Integer
  }
  deriving (ShuffleConfig -> ShuffleConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShuffleConfig -> ShuffleConfig -> Bool
$c/= :: ShuffleConfig -> ShuffleConfig -> Bool
== :: ShuffleConfig -> ShuffleConfig -> Bool
$c== :: ShuffleConfig -> ShuffleConfig -> Bool
Prelude.Eq, ReadPrec [ShuffleConfig]
ReadPrec ShuffleConfig
Int -> ReadS ShuffleConfig
ReadS [ShuffleConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShuffleConfig]
$creadListPrec :: ReadPrec [ShuffleConfig]
readPrec :: ReadPrec ShuffleConfig
$creadPrec :: ReadPrec ShuffleConfig
readList :: ReadS [ShuffleConfig]
$creadList :: ReadS [ShuffleConfig]
readsPrec :: Int -> ReadS ShuffleConfig
$creadsPrec :: Int -> ReadS ShuffleConfig
Prelude.Read, Int -> ShuffleConfig -> ShowS
[ShuffleConfig] -> ShowS
ShuffleConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShuffleConfig] -> ShowS
$cshowList :: [ShuffleConfig] -> ShowS
show :: ShuffleConfig -> String
$cshow :: ShuffleConfig -> String
showsPrec :: Int -> ShuffleConfig -> ShowS
$cshowsPrec :: Int -> ShuffleConfig -> ShowS
Prelude.Show, forall x. Rep ShuffleConfig x -> ShuffleConfig
forall x. ShuffleConfig -> Rep ShuffleConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShuffleConfig x -> ShuffleConfig
$cfrom :: forall x. ShuffleConfig -> Rep ShuffleConfig x
Prelude.Generic)

-- |
-- Create a value of 'ShuffleConfig' 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:
--
-- 'seed', 'shuffleConfig_seed' - Determines the shuffling order in @ShuffleConfig@ value.
newShuffleConfig ::
  -- | 'seed'
  Prelude.Integer ->
  ShuffleConfig
newShuffleConfig :: Integer -> ShuffleConfig
newShuffleConfig Integer
pSeed_ =
  ShuffleConfig' {$sel:seed:ShuffleConfig' :: Integer
seed = Integer
pSeed_}

-- | Determines the shuffling order in @ShuffleConfig@ value.
shuffleConfig_seed :: Lens.Lens' ShuffleConfig Prelude.Integer
shuffleConfig_seed :: Lens' ShuffleConfig Integer
shuffleConfig_seed = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShuffleConfig' {Integer
seed :: Integer
$sel:seed:ShuffleConfig' :: ShuffleConfig -> Integer
seed} -> Integer
seed) (\s :: ShuffleConfig
s@ShuffleConfig' {} Integer
a -> ShuffleConfig
s {$sel:seed:ShuffleConfig' :: Integer
seed = Integer
a} :: ShuffleConfig)

instance Data.FromJSON ShuffleConfig where
  parseJSON :: Value -> Parser ShuffleConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ShuffleConfig"
      ( \Object
x ->
          Integer -> ShuffleConfig
ShuffleConfig' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Seed")
      )

instance Prelude.Hashable ShuffleConfig where
  hashWithSalt :: Int -> ShuffleConfig -> Int
hashWithSalt Int
_salt ShuffleConfig' {Integer
seed :: Integer
$sel:seed:ShuffleConfig' :: ShuffleConfig -> Integer
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Integer
seed

instance Prelude.NFData ShuffleConfig where
  rnf :: ShuffleConfig -> ()
rnf ShuffleConfig' {Integer
seed :: Integer
$sel:seed:ShuffleConfig' :: ShuffleConfig -> Integer
..} = forall a. NFData a => a -> ()
Prelude.rnf Integer
seed

instance Data.ToJSON ShuffleConfig where
  toJSON :: ShuffleConfig -> Value
toJSON ShuffleConfig' {Integer
seed :: Integer
$sel:seed:ShuffleConfig' :: ShuffleConfig -> Integer
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Seed" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Integer
seed)]
      )