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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ShuffleConfig -> ShuffleConfig -> Bool)
-> (ShuffleConfig -> ShuffleConfig -> Bool) -> Eq ShuffleConfig
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]
(Int -> ReadS ShuffleConfig)
-> ReadS [ShuffleConfig]
-> ReadPrec ShuffleConfig
-> ReadPrec [ShuffleConfig]
-> Read 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
(Int -> ShuffleConfig -> ShowS)
-> (ShuffleConfig -> String)
-> ([ShuffleConfig] -> ShowS)
-> Show ShuffleConfig
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. ShuffleConfig -> Rep ShuffleConfig x)
-> (forall x. Rep ShuffleConfig x -> ShuffleConfig)
-> Generic ShuffleConfig
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' :: Integer -> ShuffleConfig
ShuffleConfig' {$sel:seed:ShuffleConfig' :: Integer
seed = Integer
pSeed_}

-- | Determines the shuffling order in @ShuffleConfig@ value.
shuffleConfig_seed :: Lens.Lens' ShuffleConfig Prelude.Integer
shuffleConfig_seed :: (Integer -> f Integer) -> ShuffleConfig -> f ShuffleConfig
shuffleConfig_seed = (ShuffleConfig -> Integer)
-> (ShuffleConfig -> Integer -> ShuffleConfig)
-> Lens ShuffleConfig ShuffleConfig Integer Integer
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 Core.FromJSON ShuffleConfig where
  parseJSON :: Value -> Parser ShuffleConfig
parseJSON =
    String
-> (Object -> Parser ShuffleConfig)
-> Value
-> Parser ShuffleConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ShuffleConfig"
      ( \Object
x ->
          Integer -> ShuffleConfig
ShuffleConfig' (Integer -> ShuffleConfig)
-> Parser Integer -> Parser ShuffleConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Integer
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Seed")
      )

instance Prelude.Hashable ShuffleConfig

instance Prelude.NFData ShuffleConfig

instance Core.ToJSON ShuffleConfig where
  toJSON :: ShuffleConfig -> Value
toJSON ShuffleConfig' {Integer
seed :: Integer
$sel:seed:ShuffleConfig' :: ShuffleConfig -> Integer
..} =
    [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
"Seed" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Integer
seed)]
      )