{-# LANGUAGE BangPatterns              #-}
{-# LANGUAGE DeriveAnyClass            #-}
{-# LANGUAGE DeriveGeneric             #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE OverloadedStrings         #-}
{-# LANGUAGE TemplateHaskell           #-}

module Experimenter.Eval.Type where

import           Control.DeepSeq
import           Control.Lens              hiding (Over)
import           Data.ByteString           (ByteString)
import           Data.Serialize
import qualified Data.Text                 as T
import qualified Data.Text.Encoding        as E
import           GHC.Generics
import           Prelude                   hiding (sum)


import           Experimenter.Availability
import           Experimenter.Result.Type  hiding (Experiments)
import qualified Experimenter.Result.Type  as R

-- | Over datatype to reduce data vectors.
data Over a
  = OverPeriods
  | OverReplications
  | OverExperimentRepetitions
  -- implement this by sorting and taking/dropping results
  --  | OverBestXExperimentRepetitions Int (ExperimentResult a -> ExperimentResult a -> Ordering)
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Over a) x -> Over a
forall a x. Over a -> Rep (Over a) x
$cto :: forall a x. Rep (Over a) x -> Over a
$cfrom :: forall a x. Over a -> Rep (Over a) x
Generic, forall a. Get (Over a)
forall a. Putter (Over a)
forall t. Putter t -> Get t -> Serialize t
get :: Get (Over a)
$cget :: forall a. Get (Over a)
put :: Putter (Over a)
$cput :: forall a. Putter (Over a)
Serialize, forall a. Over a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Over a -> ()
$crnf :: forall a. Over a -> ()
NFData)

instance Eq (Over a) where
  Over a
OverReplications == :: Over a -> Over a -> Bool
== Over a
OverReplications = Bool
True
  Over a
OverPeriods == Over a
OverPeriods = Bool
True
  Over a
OverExperimentRepetitions == Over a
OverExperimentRepetitions = Bool
True
  -- OverBestXExperimentRepetitions _ _ == OverBestXExperimentRepetitions _ _ = True
  Over a
_ == Over a
_ = Bool
False

instance Show (Over a) where
  show :: Over a -> String
show Over a
OverReplications          = String
"Replications"
  show Over a
OverPeriods               = String
"Periods"
  show Over a
OverExperimentRepetitions = String
"Experiments"
  -- show (OverBestXExperimentRepetitions nr _) = "(BestXExperimentEvaluations " <> show nr <> ")"

instance Ord (Over a) where
  compare :: Over a -> Over a -> Ordering
compare Over a
OverExperimentRepetitions Over a
OverExperimentRepetitions = Ordering
EQ
  compare Over a
OverExperimentRepetitions Over a
_                         = Ordering
GT
  compare Over a
OverReplications Over a
OverReplications                   = Ordering
EQ
  compare Over a
OverReplications Over a
_                                  = Ordering
GT
  compare Over a
OverPeriods Over a
OverPeriods                             = Ordering
EQ
  compare Over a
OverPeriods Over a
_                                       = Ordering
LT

  -- compare OverExperimentRepetitions OverReplications          = GT
  -- compare OverExperimentRepetitions OverPeriods               = GT

  -- compare OverReplications _                                  = LT
  -- compare OverReplications OverPeriods                        = GT
  -- compare OverPeriods OverPeriods                             = EQ
  -- compare OverPeriods _                                       = LT
  -- compare OverBestXExperimentRepetitions{} OverBestXExperimentRepetitions{} = EQ
  -- compare OverBestXExperimentRepetitions{} _                                = GT


-- | Definition of statisics. Is used to define the desired output.


data StatsDef a
  = Mean !(Over a) !(Of a)
  | StdDev !(Over a) !(Of a)
  | Sum !(Over a) !(Of a)
  --  | TakeBest Int (StatsDef a) (Of a)
  | Id !(Of a)
  | Named !(StatsDef a) !ByteString
  | Name !ByteString !(StatsDef a)
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (StatsDef a) x -> StatsDef a
forall a x. StatsDef a -> Rep (StatsDef a) x
$cto :: forall a x. Rep (StatsDef a) x -> StatsDef a
$cfrom :: forall a x. StatsDef a -> Rep (StatsDef a) x
Generic, forall a. Get (StatsDef a)
forall a. Putter (StatsDef a)
forall t. Putter t -> Get t -> Serialize t
get :: Get (StatsDef a)
$cget :: forall a. Get (StatsDef a)
put :: Putter (StatsDef a)
$cput :: forall a. Putter (StatsDef a)
Serialize, Int -> StatsDef a -> ShowS
forall a. Int -> StatsDef a -> ShowS
forall a. [StatsDef a] -> ShowS
forall a. StatsDef a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatsDef a] -> ShowS
$cshowList :: forall a. [StatsDef a] -> ShowS
show :: StatsDef a -> String
$cshow :: forall a. StatsDef a -> String
showsPrec :: Int -> StatsDef a -> ShowS
$cshowsPrec :: forall a. Int -> StatsDef a -> ShowS
Show, StatsDef a -> StatsDef a -> Bool
forall a. StatsDef a -> StatsDef a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatsDef a -> StatsDef a -> Bool
$c/= :: forall a. StatsDef a -> StatsDef a -> Bool
== :: StatsDef a -> StatsDef a -> Bool
$c== :: forall a. StatsDef a -> StatsDef a -> Bool
Eq, StatsDef a -> StatsDef a -> Ordering
forall a. Eq (StatsDef a)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. StatsDef a -> StatsDef a -> Bool
forall a. StatsDef a -> StatsDef a -> Ordering
forall a. StatsDef a -> StatsDef a -> StatsDef a
min :: StatsDef a -> StatsDef a -> StatsDef a
$cmin :: forall a. StatsDef a -> StatsDef a -> StatsDef a
max :: StatsDef a -> StatsDef a -> StatsDef a
$cmax :: forall a. StatsDef a -> StatsDef a -> StatsDef a
>= :: StatsDef a -> StatsDef a -> Bool
$c>= :: forall a. StatsDef a -> StatsDef a -> Bool
> :: StatsDef a -> StatsDef a -> Bool
$c> :: forall a. StatsDef a -> StatsDef a -> Bool
<= :: StatsDef a -> StatsDef a -> Bool
$c<= :: forall a. StatsDef a -> StatsDef a -> Bool
< :: StatsDef a -> StatsDef a -> Bool
$c< :: forall a. StatsDef a -> StatsDef a -> Bool
compare :: StatsDef a -> StatsDef a -> Ordering
$ccompare :: forall a. StatsDef a -> StatsDef a -> Ordering
Ord, forall a. StatsDef a -> ()
forall a. (a -> ()) -> NFData a
rnf :: StatsDef a -> ()
$crnf :: forall a. StatsDef a -> ()
NFData)

-- type Name =

getOver :: StatsDef a -> Maybe (Over a)
getOver :: forall a. StatsDef a -> Maybe (Over a)
getOver (Mean Over a
o Of a
_)   = forall a. a -> Maybe a
Just Over a
o
getOver (StdDev Over a
o Of a
_) = forall a. a -> Maybe a
Just Over a
o
getOver (Sum Over a
o Of a
_)    = forall a. a -> Maybe a
Just Over a
o
getOver (Id Of a
_)       = forall a. Maybe a
Nothing
getOver (Named StatsDef a
_ ByteString
_)  = forall a. Maybe a
Nothing
getOver (Name ByteString
_ StatsDef a
_)   = forall a. Maybe a
Nothing


data Of a
  = Of !ByteString
  | Stats !(StatsDef a)
  | Div !(Of a) !(Of a)
  | Add !(Of a) !(Of a)
  | Sub !(Of a) !(Of a)
  | Mult !(Of a) !(Of a)
  | Last !(Of a)
  | First !(Of a)
  | EveryXthElem !Int !(Of a)
  | Length !(Of a)
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Of a) x -> Of a
forall a x. Of a -> Rep (Of a) x
$cto :: forall a x. Rep (Of a) x -> Of a
$cfrom :: forall a x. Of a -> Rep (Of a) x
Generic, forall a. Get (Of a)
forall a. Putter (Of a)
forall t. Putter t -> Get t -> Serialize t
get :: Get (Of a)
$cget :: forall a. Get (Of a)
put :: Putter (Of a)
$cput :: forall a. Putter (Of a)
Serialize, Int -> Of a -> ShowS
forall a. Int -> Of a -> ShowS
forall a. [Of a] -> ShowS
forall a. Of a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Of a] -> ShowS
$cshowList :: forall a. [Of a] -> ShowS
show :: Of a -> String
$cshow :: forall a. Of a -> String
showsPrec :: Int -> Of a -> ShowS
$cshowsPrec :: forall a. Int -> Of a -> ShowS
Show, Of a -> Of a -> Bool
forall a. Of a -> Of a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Of a -> Of a -> Bool
$c/= :: forall a. Of a -> Of a -> Bool
== :: Of a -> Of a -> Bool
$c== :: forall a. Of a -> Of a -> Bool
Eq, Of a -> Of a -> Ordering
forall a. Eq (Of a)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Of a -> Of a -> Bool
forall a. Of a -> Of a -> Ordering
forall a. Of a -> Of a -> Of a
min :: Of a -> Of a -> Of a
$cmin :: forall a. Of a -> Of a -> Of a
max :: Of a -> Of a -> Of a
$cmax :: forall a. Of a -> Of a -> Of a
>= :: Of a -> Of a -> Bool
$c>= :: forall a. Of a -> Of a -> Bool
> :: Of a -> Of a -> Bool
$c> :: forall a. Of a -> Of a -> Bool
<= :: Of a -> Of a -> Bool
$c<= :: forall a. Of a -> Of a -> Bool
< :: Of a -> Of a -> Bool
$c< :: forall a. Of a -> Of a -> Bool
compare :: Of a -> Of a -> Ordering
$ccompare :: forall a. Of a -> Of a -> Ordering
Ord, forall a. Of a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Of a -> ()
$crnf :: forall a. Of a -> ()
NFData)

prettyStatsDef :: StatsDef a -> T.Text
prettyStatsDef :: forall a. StatsDef a -> Text
prettyStatsDef StatsDef a
statsDef =
  case StatsDef a
statsDef of
    Named StatsDef a
_ ByteString
txt     -> ByteString -> Text
E.decodeUtf8 ByteString
txt
    Name ByteString
txt StatsDef a
_      -> ByteString -> Text
E.decodeUtf8 ByteString
txt
    Mean Over a
over Of a
of'   -> Text
"Mean " forall a. Semigroup a => a -> a -> a
<> forall a. Over a -> Text
prettyOver Over a
over forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> forall a. Of a -> Text
prettyOf Of a
of'
    StdDev Over a
over Of a
of' -> Text
"StdDev " forall a. Semigroup a => a -> a -> a
<> forall a. Over a -> Text
prettyOver Over a
over forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> forall a. Of a -> Text
prettyOf Of a
of'
    Sum Over a
over Of a
of'    -> Text
"Sum " forall a. Semigroup a => a -> a -> a
<> forall a. Over a -> Text
prettyOver Over a
over forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> forall a. Of a -> Text
prettyOf Of a
of'
    Id (Of ByteString
name)    -> ByteString -> Text
E.decodeUtf8 ByteString
name forall a. Semigroup a => a -> a -> a
<> Text
"s"
    Id Of a
of'          -> forall a. Of a -> Text
prettyOf Of a
of'

prettyOf :: Of a -> T.Text
prettyOf :: forall a. Of a -> Text
prettyOf = Text -> Text
dropDoublePars forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Of a -> Text
prettyOf'
  where
    prettyOf' :: Of a -> Text
prettyOf' Of a
of' =
      case Of a
of' of
        Of ByteString
name -> Text
"of " forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
E.decodeUtf8 ByteString
name
        Stats StatsDef a
statsDef -> Text
"(" forall a. Semigroup a => a -> a -> a
<> forall a. StatsDef a -> Text
prettyStatsDef StatsDef a
statsDef forall a. Semigroup a => a -> a -> a
<> Text
")"
        Div Of a
x Of a
y -> Text
"( " forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
") / (" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
y forall a. Semigroup a => a -> a -> a
<> Text
")"
        Add Of a
x Of a
y -> Text
"( " forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
") + (" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
y forall a. Semigroup a => a -> a -> a
<> Text
")"
        Sub Of a
x Of a
y -> Text
"( " forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
") - (" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
y forall a. Semigroup a => a -> a -> a
<> Text
")"
        Mult Of a
x Of a
y -> Text
"( " forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
") * (" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
y forall a. Semigroup a => a -> a -> a
<> Text
")"
        Last Of a
x -> Text
"Last(" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
")"
        First Of a
x -> Text
"First(" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
")"
        Length Of a
x -> Text
"Length(" forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
")"
        EveryXthElem Int
nr Of a
x -> Text
"EveryXthElem(" forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (forall a. Show a => a -> String
show Int
nr) forall a. Semigroup a => a -> a -> a
<> Text
", " forall a. Semigroup a => a -> a -> a
<> Of a -> Text
prettyOf' Of a
x forall a. Semigroup a => a -> a -> a
<> Text
")"
    dropDoublePars :: Text -> Text
dropDoublePars = Text -> Text -> Text -> Text
T.replace Text
"((" Text
"(" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text -> Text
T.replace Text
"))" Text
")"


prettyOver :: Over a -> T.Text
prettyOver :: forall a. Over a -> Text
prettyOver Over a
ov = Text
"over " forall a. Semigroup a => a -> a -> a
<> case Over a
ov of
  Over a
OverPeriods               -> Text
"periods"
  Over a
OverReplications          -> Text
"replications"
  Over a
OverExperimentRepetitions -> Text
"experiment repetitions"
  -- OverBestXExperimentRepetitions nr _ -> "best " <> T.pack (show nr) <> " experiment repetitions"


-- Helper functions for demoting StatsDefs to Ofs.

sum :: Over a -> Of a -> Of a
sum :: forall a. Over a -> Of a -> Of a
sum Over a
over Of a
of' = forall a. StatsDef a -> Of a
Stats (forall a. Over a -> Of a -> StatsDef a
Sum Over a
over Of a
of')

stdDev :: Over a -> Of a -> Of a
stdDev :: forall a. Over a -> Of a -> Of a
stdDev Over a
over Of a
of' = forall a. StatsDef a -> Of a
Stats (forall a. Over a -> Of a -> StatsDef a
StdDev Over a
over Of a
of')

mean :: Over a -> Of a -> Of a
mean :: forall a. Over a -> Of a -> Of a
mean Over a
over Of a
of' = forall a. StatsDef a -> Of a
Stats (forall a. Over a -> Of a -> StatsDef a
Mean Over a
over Of a
of')


-- | Simple examples on how to use the types

example :: StatsDef a
example :: forall a. StatsDef a
example = forall a. Over a -> Of a -> StatsDef a
Mean forall a. Over a
OverReplications (forall a. Over a -> Of a -> Of a
sum forall a. Over a
OverPeriods (forall a. ByteString -> Of a
Of ByteString
"NrEarly") forall a. Of a -> Of a -> Of a
`Div` forall a. Over a -> Of a -> Of a
sum forall a. Over a
OverPeriods (forall a. ByteString -> Of a
Of ByteString
"NrOrders"))

example2 :: StatsDef a
example2 :: forall a. StatsDef a
example2 = forall a. Over a -> Of a -> StatsDef a
Mean forall a. Over a
OverReplications (forall a. ByteString -> Of a
Of ByteString
"NrEarly" forall a. Of a -> Of a -> Of a
`Div` forall a. ByteString -> Of a
Of ByteString
"NrOrders")


example3 :: StatsDef a
example3 :: forall a. StatsDef a
example3 = forall a. Over a -> Of a -> StatsDef a
Mean forall a. Over a
OverReplications (forall a. ByteString -> Of a
Of ByteString
"X")


-- | Datatypes for the evaluation result.
data Unit
  = UnitPeriods
  | UnitReplications
  | UnitExperimentRepetition
  | UnitScalar
  deriving (forall x. Rep Unit x -> Unit
forall x. Unit -> Rep Unit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Unit x -> Unit
$cfrom :: forall x. Unit -> Rep Unit x
Generic, Get Unit
Putter Unit
forall t. Putter t -> Get t -> Serialize t
get :: Get Unit
$cget :: Get Unit
put :: Putter Unit
$cput :: Putter Unit
Serialize, ReadPrec [Unit]
ReadPrec Unit
Int -> ReadS Unit
ReadS [Unit]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Unit]
$creadListPrec :: ReadPrec [Unit]
readPrec :: ReadPrec Unit
$creadPrec :: ReadPrec Unit
readList :: ReadS [Unit]
$creadList :: ReadS [Unit]
readsPrec :: Int -> ReadS Unit
$creadsPrec :: Int -> ReadS Unit
Read, Unit -> Unit -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Unit -> Unit -> Bool
$c/= :: Unit -> Unit -> Bool
== :: Unit -> Unit -> Bool
$c== :: Unit -> Unit -> Bool
Eq, Eq Unit
Unit -> Unit -> Bool
Unit -> Unit -> Ordering
Unit -> Unit -> Unit
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Unit -> Unit -> Unit
$cmin :: Unit -> Unit -> Unit
max :: Unit -> Unit -> Unit
$cmax :: Unit -> Unit -> Unit
>= :: Unit -> Unit -> Bool
$c>= :: Unit -> Unit -> Bool
> :: Unit -> Unit -> Bool
$c> :: Unit -> Unit -> Bool
<= :: Unit -> Unit -> Bool
$c<= :: Unit -> Unit -> Bool
< :: Unit -> Unit -> Bool
$c< :: Unit -> Unit -> Bool
compare :: Unit -> Unit -> Ordering
$ccompare :: Unit -> Unit -> Ordering
Ord, Int -> Unit -> ShowS
[Unit] -> ShowS
Unit -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Unit] -> ShowS
$cshowList :: [Unit] -> ShowS
show :: Unit -> String
$cshow :: Unit -> String
showsPrec :: Int -> Unit -> ShowS
$cshowsPrec :: Int -> Unit -> ShowS
Show, Unit -> ()
forall a. (a -> ()) -> NFData a
rnf :: Unit -> ()
$crnf :: Unit -> ()
NFData)
  --  UnitBestExperimentRepetitions Int

data EvalResults a
  = EvalVector { forall a. EvalResults a -> StatsDef a
_evalType   :: !(StatsDef a)
               , forall a. EvalResults a -> Unit
_evalUnit   :: !Unit -- ^ Over which the vector runs.
               , forall a. EvalResults a -> [EvalResults a]
_evalValues :: ![EvalResults a]
               }
  | EvalValue { _evalType         :: !(StatsDef a)
              , _evalUnit         :: !Unit -- ^ Is always periods.
              , forall a. EvalResults a -> ByteString
_evalVariableName :: !ByteString
              , forall a. EvalResults a -> Either Int Double
_evalX            :: !(Either Int Double) -- ^ Either period or xValue.
              , forall a. EvalResults a -> Double
_evalY            :: !Double }
  | EvalReducedValue { _evalType  :: !(StatsDef a)
                     , _evalUnit  :: !Unit -- ^ Over which was reduced.
                     , forall a. EvalResults a -> Double
_evalValue :: !Double }
  deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (EvalResults a) x -> EvalResults a
forall a x. EvalResults a -> Rep (EvalResults a) x
$cto :: forall a x. Rep (EvalResults a) x -> EvalResults a
$cfrom :: forall a x. EvalResults a -> Rep (EvalResults a) x
Generic, forall a. Get (EvalResults a)
forall a. Putter (EvalResults a)
forall t. Putter t -> Get t -> Serialize t
get :: Get (EvalResults a)
$cget :: forall a. Get (EvalResults a)
put :: Putter (EvalResults a)
$cput :: forall a. Putter (EvalResults a)
Serialize, Int -> EvalResults a -> ShowS
forall a. Int -> EvalResults a -> ShowS
forall a. [EvalResults a] -> ShowS
forall a. EvalResults a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvalResults a] -> ShowS
$cshowList :: forall a. [EvalResults a] -> ShowS
show :: EvalResults a -> String
$cshow :: forall a. EvalResults a -> String
showsPrec :: Int -> EvalResults a -> ShowS
$cshowsPrec :: forall a. Int -> EvalResults a -> ShowS
Show, forall a. EvalResults a -> ()
forall a. (a -> ()) -> NFData a
rnf :: EvalResults a -> ()
$crnf :: forall a. EvalResults a -> ()
NFData)
makeLenses ''EvalResults

data ExperimentEval a = ExperimentEval
  { forall a. ExperimentEval a -> Int
_evalExperimentNumber  :: !Int
  , forall a. ExperimentEval a -> [Availability IO (EvalResults a)]
_evalExperimentResults :: ![Availability IO (EvalResults a)]
  , forall a. ExperimentEval a -> Experiment a
_evalExperiment        :: !(Experiment a)
  } deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (ExperimentEval a) x -> ExperimentEval a
forall a x. ExperimentEval a -> Rep (ExperimentEval a) x
$cto :: forall a x. Rep (ExperimentEval a) x -> ExperimentEval a
$cfrom :: forall a x. ExperimentEval a -> Rep (ExperimentEval a) x
Generic, forall a. ExperimentDef a => ExperimentEval a -> ()
forall a. (a -> ()) -> NFData a
rnf :: ExperimentEval a -> ()
$crnf :: forall a. ExperimentDef a => ExperimentEval a -> ()
NFData)
makeLenses ''ExperimentEval

instance Show (ExperimentEval a) where
  show :: ExperimentEval a -> String
show ExperimentEval a
x = forall a. Show a => a -> String
show (ExperimentEval a
x forall s a. s -> Getting a s a -> a
^. forall a.
Lens' (ExperimentEval a) [Availability IO (EvalResults a)]
evalExperimentResults)

data Evals a = Evals
  { forall a. Evals a -> Experiments a
_evalsExperiments :: !(R.Experiments a)
  , forall a. Evals a -> [ExperimentEval a]
_evalsResults     :: ![ExperimentEval a]
  } deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Evals a) x -> Evals a
forall a x. Evals a -> Rep (Evals a) x
$cto :: forall a x. Rep (Evals a) x -> Evals a
$cfrom :: forall a x. Evals a -> Rep (Evals a) x
Generic, forall a. ExperimentDef a => Evals a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Evals a -> ()
$crnf :: forall a. ExperimentDef a => Evals a -> ()
NFData)
makeLenses ''Evals


-- Helper Functions

getEvalValue :: EvalResults a -> [Double]
getEvalValue :: forall a. EvalResults a -> [Double]
getEvalValue (EvalVector StatsDef a
_ Unit
_ [EvalResults a]
xs)      = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. EvalResults a -> [Double]
getEvalValue [EvalResults a]
xs
getEvalValue (EvalValue StatsDef a
_ Unit
_ ByteString
_ Either Int Double
_ Double
y)    = [Double
y]
getEvalValue (EvalReducedValue StatsDef a
_ Unit
_ Double
y) = [Double
y]

getEvalType :: (Over a -> Of a -> StatsDef a) -> EvalResults a -> StatsDef a
getEvalType :: forall a.
(Over a -> Of a -> StatsDef a) -> EvalResults a -> StatsDef a
getEvalType Over a -> Of a -> StatsDef a
f (EvalVector StatsDef a
tp Unit
unit [EvalResults a]
_)     = Over a -> Of a -> StatsDef a
f (forall {a}. Unit -> Over a
fromUnit Unit
unit) (forall a. StatsDef a -> Of a
Stats StatsDef a
tp)
  where fromUnit :: Unit -> Over a
fromUnit Unit
UnitPeriods              = forall a. Over a
OverPeriods
        fromUnit Unit
UnitReplications         = forall a. Over a
OverReplications
        fromUnit Unit
UnitExperimentRepetition = forall a. Over a
OverExperimentRepetitions
        -- fromUnit (UnitBestExperimentRepetitions nr) = OverBestXExperimentRepetitions nr (error "compare function in BestXExperimentEvaluations may not be used")
        fromUnit Unit
UnitScalar               = forall a. Over a
OverExperimentRepetitions -- TODO really?
getEvalType Over a -> Of a -> StatsDef a
_ (EvalValue StatsDef a
t Unit
_ ByteString
_ Either Int Double
_ Double
_)      = StatsDef a
t
getEvalType Over a -> Of a -> StatsDef a
_ (EvalReducedValue StatsDef a
t Unit
_ Double
_) = StatsDef a
t

fromOver :: Over a -> Unit
fromOver :: forall a. Over a -> Unit
fromOver Over a
OverPeriods               = Unit
UnitPeriods
fromOver Over a
OverReplications          = Unit
UnitReplications
fromOver Over a
OverExperimentRepetitions = Unit
UnitExperimentRepetition
-- fromOver (OverBestXExperimentRepetitions nr _) = UnitBestExperimentRepetitions nr


-- | Demotes the unit by 1 degree. Thus this calculates the unit of a vector over which it was reduced.
demoteUnit :: Unit -> Maybe Unit
demoteUnit :: Unit -> Maybe Unit
demoteUnit Unit
UnitPeriods              = forall a. Maybe a
Nothing
demoteUnit Unit
UnitReplications         = forall a. a -> Maybe a
Just Unit
UnitPeriods
demoteUnit Unit
UnitExperimentRepetition = forall a. a -> Maybe a
Just Unit
UnitReplications
-- demoteUnit UnitBestExperimentRepetitions{} = Just UnitReplications
demoteUnit Unit
UnitScalar               = forall a. a -> Maybe a
Just Unit
UnitExperimentRepetition