opto-0.1.0.0: General-purpose performant numeric optimization library

Safe HaskellNone
LanguageHaskell2010

Numeric.Opto.Run.Simple

Contents

Synopsis

Simple conduit runners

sampleCollect Source #

Arguments

:: (PrimMonad m, MonadIO m, MonoFoldable t) 
=> TBQueue (Element t)

Queue to deposit samples

-> Maybe Int

Number of epochs (Nothing for forever)

-> (Int -> m ())

Report each new epoch. See dispEpoch for a simple one.

-> t

Collection to source

-> Gen (PrimState m)

Random shuffling generator

-> ConduitT i (Element t) m () 

A sample conduit Source that yields shuffled items in a collection repeatedly. Deposits the yielded items in a TBQueue, and takes a callback for reporting each new epoch (cycle of items in the collection).

trainReport Source #

Arguments

:: (MonadIO m, NFData a) 
=> TBQueue i

Queue to acquire used training samples

-> (Int -> m ())

Report each new batch. See dispBatch for a simple one.

-> Int

Number of samples to go through before running reporting function

-> (NominalDiffTime -> [i] -> a -> m ())

Reporting function. See simpleReport for a simple one.

-> ConduitT a a m () 

A conduit that processes "trained" items and outputs a report every report batch, based on samples accumulated in a TBQueue. Meant to be used alongside sampleCollect. It passes through all of its input.

    sampleCollect sampleQueue epochs dispEpoch samples
 .| optoConduit ro model0 optimizer
 .| trainReport sampleQueue dispBatch 2500 (simpleReport (Just valSet) runTest)
 .| sink -- (other stuff you would want to do with trained models)

Simple callbacks for runners

dispEpoch :: MonadIO m => Int -> m () Source #

Simple reporter to give to sampleCollect:

[Epoch 1]
[Epoch 2]
[Epoch 3]

dispBatch :: MonadIO m => Int -> m () Source #

Simple reporter to give to trainReport:

(Batch 1)
(Batch 2)
(Batch 3)

simpleReport Source #

Arguments

:: MonadIO m 
=> Maybe [i]

A "validation set" that's consistent across all batches.

-> ([i] -> a -> String)

A function to run to evaluate a set.

-> NominalDiffTime

Time it took to train

-> [i]

Set of batch points

-> a

New predictor

-> m () 

Simple reporting callback to provide trainReport.

Integrated runners

simpleRunner Source #

Arguments

:: (MonadIO m, PrimMonad m, NFData a, MonoFoldable t) 
=> SimpleOpts m (Element t) a b

Options

-> t

Collection of samples

-> SOOptimizer m n (Element t) a

Choice of optimizer concurrency strategy

-> RunOpts m a

Runner options

-> a

Initial value

-> Opto n (Element t) a

Optimizer

-> Gen (PrimState m)

Random generator

-> m b 

Integrate sampleCollect and trainReport together, automatically generating the sample queue and supplying all callbacks based on the SimpleOpts.

data SimpleOpts m i a b Source #

Options for simpleRunner. def gives sensible defaults.

Constructors

SO 

Fields

  • soEpochs :: Maybe Int

    How many epochs (default: Nothing, forever)

  • soDispEpoch :: Int -> m ()

    Display a new epoch to the screen (default: "[Epoch %d]")

  • soDispBatch :: Int -> m ()

    Display a new report batch to the screen (defualt: "(Batch %d)")

  • soTestSet :: Maybe [i]

    Test set to validate results (default: Nothing)

  • soSkipSamps :: Int

    Number of samples to skip per report batch (default: 1000)

  • soEvaluate :: [i] -> a -> String

    Evaluate a model against samples and report accuracy. (default: do nothing)

  • soSink :: ConduitT a Void m b

    Collect the optimized values (default: sinkNull, ignore them)

Instances
(MonadIO m, Default b) => Default (SimpleOpts m i a b) Source # 
Instance details

Defined in Numeric.Opto.Run.Simple

Methods

def :: SimpleOpts m i a b #

data SOOptimizer :: (Type -> Type) -> (Type -> Type) -> Type -> Type -> Type where Source #

Choose a concurrency strategy for your runner.

Constructors

SOSingle :: SOOptimizer m (ConduitT i a m) i a

Single-threaded

SOParallel :: MonadUnliftIO m => ParallelOpts m a -> SOOptimizer m m i a

Parallel

SOParChunked :: MonadUnliftIO m => ParallelOpts m a -> SOOptimizer m (StateT [i] m) i a

Parallel chunked