aivika-experiment 0.2.1 → 0.2.2
raw patch · 9 files changed
+784/−17 lines, 9 filesdep +splitdep −MissingHdep ~aivikaPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: split
Dependencies removed: MissingH
Dependency ranges changed: aivika
API changes (from Hackage documentation)
+ Simulation.Aivika.Experiment: data SeriesArrayWithSubscript i s
+ Simulation.Aivika.Experiment: data SeriesListWithSubscript s
+ Simulation.Aivika.Experiment: instance (Ix i, Series s) => Series (SeriesArrayWithSubscript i s)
+ Simulation.Aivika.Experiment: instance Ix i => Series (Dynamics (Array i Double))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Dynamics (Array i Int))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Ref (Array i Double))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Ref (Array i Int))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Simulation (Array i Double))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Simulation (Array i Int))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Var (Array i Double))
+ Simulation.Aivika.Experiment: instance Ix i => Series (Var (Array i Int))
+ Simulation.Aivika.Experiment: instance Series (Dynamics (SamplingStats Double))
+ Simulation.Aivika.Experiment: instance Series (Dynamics (SamplingStats Int))
+ Simulation.Aivika.Experiment: instance Series (Dynamics [Double])
+ Simulation.Aivika.Experiment: instance Series (Dynamics [Int])
+ Simulation.Aivika.Experiment: instance Series (Ref (SamplingStats Double))
+ Simulation.Aivika.Experiment: instance Series (Ref (SamplingStats Int))
+ Simulation.Aivika.Experiment: instance Series (Ref [Double])
+ Simulation.Aivika.Experiment: instance Series (Ref [Int])
+ Simulation.Aivika.Experiment: instance Series (Simulation (SamplingStats Double))
+ Simulation.Aivika.Experiment: instance Series (Simulation (SamplingStats Int))
+ Simulation.Aivika.Experiment: instance Series (Simulation [Double])
+ Simulation.Aivika.Experiment: instance Series (Simulation [Int])
+ Simulation.Aivika.Experiment: instance Series (Var (SamplingStats Double))
+ Simulation.Aivika.Experiment: instance Series (Var (SamplingStats Int))
+ Simulation.Aivika.Experiment: instance Series (Var [Double])
+ Simulation.Aivika.Experiment: instance Series (Var [Int])
+ Simulation.Aivika.Experiment: instance Series s => Series (SeriesListWithSubscript s)
+ Simulation.Aivika.Experiment: providerToDoubleList :: SeriesProvider -> Maybe (Dynamics [Double])
+ Simulation.Aivika.Experiment: providerToDoubleStats :: SeriesProvider -> Maybe (Dynamics (SamplingStats Double))
+ Simulation.Aivika.Experiment: providerToIntList :: SeriesProvider -> Maybe (Dynamics [Int])
+ Simulation.Aivika.Experiment: providerToIntStats :: SeriesProvider -> Maybe (Dynamics (SamplingStats Int))
+ Simulation.Aivika.Experiment: seriesArrayWithSubscript :: (Ix i, Series s) => Array i s -> Array i String -> SeriesArrayWithSubscript i s
+ Simulation.Aivika.Experiment: seriesListWithSubscript :: Series s => [s] -> [String] -> SeriesListWithSubscript s
+ Simulation.Aivika.Experiment.ListSource: addDataToListRef :: ListRef a -> ListData a -> IO ()
+ Simulation.Aivika.Experiment.ListSource: data ListData a
+ Simulation.Aivika.Experiment.ListSource: data ListRef a
+ Simulation.Aivika.Experiment.ListSource: data ListSource a
+ Simulation.Aivika.Experiment.ListSource: listDataList :: ListData a -> [a]
+ Simulation.Aivika.Experiment.ListSource: listSourceData :: ListSource a -> Dynamics (ListData a)
+ Simulation.Aivika.Experiment.ListSource: newListRef :: IO (ListRef a)
+ Simulation.Aivika.Experiment.ListSource: providerToDoubleListSource :: SeriesProvider -> Maybe (ListSource Double)
+ Simulation.Aivika.Experiment.ListSource: providerToIntListSource :: SeriesProvider -> Maybe (ListSource Int)
+ Simulation.Aivika.Experiment.ListSource: readListRef :: ListRef a -> IO [a]
+ Simulation.Aivika.Experiment.SamplingStatsSource: addDataToSamplingStats :: SamplingData a => SamplingStatsData a -> SamplingStats a -> SamplingStats a
+ Simulation.Aivika.Experiment.SamplingStatsSource: data SamplingStatsData a
+ Simulation.Aivika.Experiment.SamplingStatsSource: data SamplingStatsSource a
+ Simulation.Aivika.Experiment.SamplingStatsSource: providerToDoubleStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Double)
+ Simulation.Aivika.Experiment.SamplingStatsSource: providerToIntStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Int)
+ Simulation.Aivika.Experiment.SamplingStatsSource: samplingStatsSourceData :: SamplingStatsSource a -> Dynamics (SamplingStatsData a)
+ Simulation.Aivika.Experiment.Utils: replace :: String -> String -> String -> String
- Simulation.Aivika.Experiment: SeriesProvider :: String -> Maybe (Dynamics Double) -> Maybe (Dynamics Int) -> Maybe (Dynamics String) -> Maybe (Signal ()) -> SeriesProvider
+ Simulation.Aivika.Experiment: SeriesProvider :: String -> Maybe (Dynamics Double) -> Maybe (Dynamics (SamplingStats Double)) -> Maybe (Dynamics [Double]) -> Maybe (Dynamics Int) -> Maybe (Dynamics (SamplingStats Int)) -> Maybe (Dynamics [Int]) -> Maybe (Dynamics String) -> Maybe (Signal ()) -> SeriesProvider
Files
- Simulation/Aivika/Experiment.hs +605/−1
- Simulation/Aivika/Experiment/FinalStatsView.hs +5/−4
- Simulation/Aivika/Experiment/LastValueView.hs +1/−2
- Simulation/Aivika/Experiment/ListSource.hs +88/−0
- Simulation/Aivika/Experiment/SamplingStatsSource.hs +68/−0
- Simulation/Aivika/Experiment/TableView.hs +1/−2
- Simulation/Aivika/Experiment/TimingStatsView.hs +1/−2
- Simulation/Aivika/Experiment/Utils.hs +8/−1
- aivika-experiment.cabal +7/−5
Simulation/Aivika/Experiment.hs view
@@ -31,6 +31,10 @@ Series(..), SeriesEntity(..), SeriesProvider(..),+ SeriesListWithSubscript,+ SeriesArrayWithSubscript,+ seriesListWithSubscript,+ seriesArrayWithSubscript, View(..), Generator(..), Reporter(..),@@ -47,7 +51,6 @@ import Data.Array import Data.Maybe import Data.Monoid-import Data.String.Utils (replace) import qualified System.IO.UTF8 as UTF8 import System.Directory@@ -63,8 +66,10 @@ import Simulation.Aivika.Dynamics.UVar import Simulation.Aivika.Dynamics.EventQueue import Simulation.Aivika.Dynamics.Parameter+import Simulation.Aivika.Statistics import Simulation.Aivika.Experiment.HtmlWriter+import Simulation.Aivika.Experiment.Utils (replace) -- | It defines the simulation experiment. data Experiment = @@ -118,6 +123,21 @@ -- | Represents the series. It is usually something, or -- an array of something, or a list of such values which -- can be simulated.+--+-- The array and list of series are treated as a sequence of+-- separate sub-series that have a subscript which can be+-- optionally specified explicitly. By default, the subscript+-- is numeric but it may be any string.+-- +-- At the same time, if the array or list of numeric values+-- is wrapped in monad 'Simulation' or 'Dynamics' then the+-- underlying numeric array and list are already treated as+-- a sampling statistics or list of numbers in time point.+--+-- Moreover, if the array or list of numbers is contained in+-- reference 'Ref' or variable 'Var' then the array and list+-- of such values are also treated as a sampling statistics+-- or list of numbers in time point. class Series s where -- | Return the simulatable entity with the specified name@@ -136,8 +156,16 @@ -- ^ Return the name. providerToDouble :: Maybe (Dynamics Double), -- ^ Try to return the data as double values.+ providerToDoubleStats :: Maybe (Dynamics (SamplingStats Double)),+ -- ^ Try to return the statistics data in time points.+ providerToDoubleList :: Maybe (Dynamics [Double]),+ -- ^ Try to return the list of double values. providerToInt :: Maybe (Dynamics Int), -- ^ Try to return the data as integers.+ providerToIntStats :: Maybe (Dynamics (SamplingStats Int)),+ -- ^ Try to return the statistics data in time points.+ providerToIntList :: Maybe (Dynamics [Int]),+ -- ^ Try to return the list of integer values. providerToString :: Maybe (Dynamics String), -- ^ Try to return the data as strings. providerSignal :: Maybe (Signal ())@@ -388,7 +416,13 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ liftSimulation s,+ providerToDoubleStats =+ Just $ liftSimulation $ fmap returnSamplingStats s,+ providerToDoubleList =+ Just $ liftSimulation $ fmap return s, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ liftSimulation $ fmap show s, providerSignal = Nothing }] } @@ -398,7 +432,19 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ liftSimulation $ fmap fromIntegral s,+ providerToDoubleStats =+ Just $ liftSimulation $+ fmap returnSamplingStats $+ fmap fromIntegral s,+ providerToDoubleList =+ Just $ liftSimulation $+ fmap return $+ fmap fromIntegral s, providerToInt = Just $ liftSimulation s,+ providerToIntStats =+ Just $ liftSimulation $ fmap returnSamplingStats s,+ providerToIntList =+ Just $ liftSimulation $ fmap return s, providerToString = Just $ liftSimulation $ fmap show s, providerSignal = Nothing }] } @@ -408,7 +454,11 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Nothing,+ providerToDoubleStats = Nothing,+ providerToDoubleList = Nothing, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ liftSimulation s, providerSignal = Nothing }] } @@ -418,7 +468,11 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just s,+ providerToDoubleStats = Just $ fmap returnSamplingStats s,+ providerToDoubleList = Just $ fmap return s, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ fmap show s, providerSignal = Nothing }] } @@ -428,7 +482,13 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ fmap fromIntegral s,+ providerToDoubleStats =+ Just $ fmap returnSamplingStats $ fmap fromIntegral s,+ providerToDoubleList =+ Just $ fmap return $ fmap fromIntegral s, providerToInt = Just s,+ providerToIntStats = Just $ fmap returnSamplingStats s,+ providerToIntList = Just $ fmap return s, providerToString = Just $ fmap show s, providerSignal = Nothing }] } @@ -438,7 +498,11 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Nothing,+ providerToDoubleStats = Nothing,+ providerToDoubleList = Nothing, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just s, providerSignal = Nothing }] } @@ -448,7 +512,13 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ readRef s,+ providerToDoubleStats =+ Just $ fmap returnSamplingStats $ readRef s,+ providerToDoubleList =+ Just $ fmap return $ readRef s, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ fmap show (readRef s), providerSignal = Just $ refChanged_ s }] } @@ -458,7 +528,19 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ fmap fromIntegral (readRef s),+ providerToDoubleStats =+ Just $+ fmap returnSamplingStats $+ fmap fromIntegral (readRef s),+ providerToDoubleList =+ Just $+ fmap return $+ fmap fromIntegral (readRef s), providerToInt = Just $ readRef s,+ providerToIntStats =+ Just $ fmap returnSamplingStats (readRef s),+ providerToIntList =+ Just $ fmap return (readRef s), providerToString = Just $ fmap show (readRef s), providerSignal = Just $ refChanged_ s }] } @@ -468,7 +550,11 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Nothing,+ providerToDoubleStats = Nothing,+ providerToDoubleList = Nothing, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ readRef s, providerSignal = Just $ refChanged_ s }] } @@ -478,7 +564,13 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ readVar s,+ providerToDoubleStats =+ Just $ fmap returnSamplingStats $ readVar s,+ providerToDoubleList =+ Just $ fmap return $ readVar s, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ fmap show (readVar s), providerSignal = Just $ varChanged_ s }] } @@ -488,7 +580,19 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ fmap fromIntegral (readVar s),+ providerToDoubleStats =+ Just $+ fmap returnSamplingStats $+ fmap fromIntegral (readVar s),+ providerToDoubleList =+ Just $+ fmap return $+ fmap fromIntegral (readVar s), providerToInt = Just $ readVar s,+ providerToIntStats =+ Just $ fmap returnSamplingStats (readVar s),+ providerToIntList =+ Just $ fmap return (readVar s), providerToString = Just $ fmap show (readVar s), providerSignal = Just $ varChanged_ s }] } @@ -498,7 +602,11 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Nothing,+ providerToDoubleStats = Nothing,+ providerToDoubleList = Nothing, providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ readVar s, providerSignal = Just $ varChanged_ s }] } @@ -508,7 +616,13 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ readUVar s,+ providerToDoubleStats =+ Just $ fmap returnSamplingStats (readUVar s),+ providerToDoubleList =+ Just $ fmap return (readUVar s), providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing, providerToString = Just $ fmap show (readUVar s), providerSignal = Just $ uvarChanged_ s }] } @@ -518,7 +632,19 @@ SeriesEntity { seriesProviders = [SeriesProvider { providerName = name, providerToDouble = Just $ fmap fromIntegral (readUVar s),+ providerToDoubleStats =+ Just $+ fmap returnSamplingStats $+ fmap fromIntegral (readUVar s),+ providerToDoubleList =+ Just $+ fmap return $+ fmap fromIntegral (readUVar s), providerToInt = Just $ readUVar s,+ providerToIntStats =+ Just $ fmap returnSamplingStats (readUVar s),+ providerToIntList =+ Just $ fmap return (readUVar s), providerToString = Just $ fmap show (readUVar s), providerSignal = Just $ uvarChanged_ s }] } @@ -537,3 +663,481 @@ join $ forM (assocs s) $ \(i, s) -> let name' = name ++ "[" ++ show i ++ "]" in seriesProviders $ seriesEntity name' s }++-- | Represents a list with the specified subscript.+data SeriesListWithSubscript s =+ SeriesListWithSubscript { seriesList :: [s],+ seriesListSubscript :: [String] }++-- | Represents an array with the specified subscript.+data SeriesArrayWithSubscript i s =+ SeriesArrayWithSubscript { seriesArray :: Array i s,+ seriesArraySubscript :: Array i String }++-- | Add the specified subscript to the list.+seriesListWithSubscript :: Series s => [s] -> [String] -> SeriesListWithSubscript s+seriesListWithSubscript = SeriesListWithSubscript++-- | Add the specified subscript to the array.+seriesArrayWithSubscript :: (Ix i, Series s) => Array i s -> Array i String+ -> SeriesArrayWithSubscript i s+seriesArrayWithSubscript = SeriesArrayWithSubscript++instance Series s => Series (SeriesListWithSubscript s) where+ + seriesEntity name s = + SeriesEntity { seriesProviders = do+ let xs = seriesList s+ ns = seriesListSubscript s+ join $ forM (zip3 [1..] xs ns) $ \(i, s, n) ->+ let name' = name ++ n+ in seriesProviders $ seriesEntity name' s }+ +instance (Ix i, Series s) => Series (SeriesArrayWithSubscript i s) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders = do+ let xs = seriesArray s+ ns = seriesArraySubscript s+ join $ forM (zip (assocs xs) (elems ns)) $ \((i, s), n) ->+ let name' = name ++ n+ in seriesProviders $ seriesEntity name' s }++instance Series (Simulation (SamplingStats Double)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats = Just $ liftSimulation s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Simulation (SamplingStats Int)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ liftSimulation $ fmap fromIntSamplingStats s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Just $ liftSimulation s,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Dynamics (SamplingStats Double)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats = Just s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Dynamics (SamplingStats Int)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats = Just $ fmap fromIntSamplingStats s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Just $ s,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Ref (SamplingStats Double)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats = Just $ readRef s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Ref (SamplingStats Int)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ fmap fromIntSamplingStats $ readRef s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Just $ readRef s,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Var (SamplingStats Double)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats = Just $ readVar s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Var (SamplingStats Int)) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ fmap fromIntSamplingStats $ readVar s,+ providerToDoubleList = Nothing,+ providerToInt = Nothing,+ providerToIntStats = Just $ readVar s,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Simulation [Double]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ liftSimulation $ fmap listSamplingStats s,+ providerToDoubleList =+ Just $ liftSimulation s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Simulation [Int]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ liftSimulation $+ fmap fromIntSamplingStats $+ fmap listSamplingStats s,+ providerToDoubleList =+ Just $ liftSimulation $+ fmap (map fromIntegral) s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $ liftSimulation $ fmap listSamplingStats s,+ providerToIntList =+ Just $ liftSimulation s,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Dynamics [Double]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ fmap listSamplingStats s,+ providerToDoubleList =+ Just s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Dynamics [Int]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats s,+ providerToDoubleList =+ Just $ fmap (map fromIntegral) s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $ fmap listSamplingStats s,+ providerToIntList =+ Just s,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Ref [Double]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ fmap listSamplingStats $ readRef s,+ providerToDoubleList =+ Just $ readRef s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Ref [Int]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $ readRef s,+ providerToDoubleList =+ Just $ fmap (map fromIntegral) $ readRef s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $ fmap listSamplingStats $ readRef s,+ providerToIntList =+ Just $ readRef s,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Var [Double]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ fmap listSamplingStats $ readVar s,+ providerToDoubleList =+ Just $ readVar s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Series (Var [Int]) where+ + seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $ readVar s,+ providerToDoubleList =+ Just $ fmap (map fromIntegral) $ readVar s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $ fmap listSamplingStats $ readVar s,+ providerToIntList =+ Just $ readVar s,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Simulation (Array i Double)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ liftSimulation $+ fmap listSamplingStats $+ fmap elems s,+ providerToDoubleList =+ Just $ liftSimulation $+ fmap elems s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Simulation (Array i Int)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $ liftSimulation $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $+ fmap elems s,+ providerToDoubleList =+ Just $ liftSimulation $+ fmap (map fromIntegral) $+ fmap elems s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $ liftSimulation $+ fmap listSamplingStats $+ fmap elems s,+ providerToIntList =+ Just $ liftSimulation $+ fmap elems s,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Dynamics (Array i Double)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap listSamplingStats $+ fmap elems s,+ providerToDoubleList =+ Just $ fmap elems s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Dynamics (Array i Int)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $+ fmap elems s,+ providerToDoubleList =+ Just $+ fmap (map fromIntegral) $+ fmap elems s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $+ fmap listSamplingStats $+ fmap elems s,+ providerToIntList =+ Just $ fmap elems s,+ providerToString = Nothing,+ providerSignal = Nothing }] }+++instance Ix i => Series (Ref (Array i Double)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap listSamplingStats $+ fmap elems $ readRef s,+ providerToDoubleList =+ Just $ fmap elems $ readRef s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Ref (Array i Int)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $+ fmap elems $ readRef s,+ providerToDoubleList =+ Just $+ fmap (map fromIntegral) $+ fmap elems $ readRef s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $+ fmap listSamplingStats $+ fmap elems $ readRef s,+ providerToIntList =+ Just $+ fmap elems $ readRef s,+ providerToString = Nothing,+ providerSignal = Nothing }] }+++instance Ix i => Series (Var (Array i Double)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap listSamplingStats $+ fmap elems $ readVar s,+ providerToDoubleList =+ Just $+ fmap elems $ readVar s,+ providerToInt = Nothing,+ providerToIntStats = Nothing,+ providerToIntList = Nothing,+ providerToString = Nothing,+ providerSignal = Nothing }] }++instance Ix i => Series (Var (Array i Int)) where++ seriesEntity name s =+ SeriesEntity { seriesProviders =+ [SeriesProvider { providerName = name,+ providerToDouble = Nothing,+ providerToDoubleStats =+ Just $+ fmap fromIntSamplingStats $+ fmap listSamplingStats $+ fmap elems $ readVar s,+ providerToDoubleList =+ Just $+ fmap (map fromIntegral) $+ fmap elems $ readVar s,+ providerToInt = Nothing,+ providerToIntStats =+ Just $+ fmap listSamplingStats $+ fmap elems $ readVar s,+ providerToIntList =+ Just $+ fmap elems $ readVar s,+ providerToString = Nothing,+ providerSignal = Nothing }] }
Simulation/Aivika/Experiment/FinalStatsView.hs view
@@ -25,6 +25,7 @@ import Simulation.Aivika.Experiment import Simulation.Aivika.Experiment.HtmlWriter import Simulation.Aivika.Experiment.SamplingStatsWriter+import Simulation.Aivika.Experiment.SamplingStatsSource import Simulation.Aivika.Dynamics import Simulation.Aivika.Dynamics.Simulation@@ -109,12 +110,12 @@ providers = concat protoproviders input = flip map providers $ \provider ->- case providerToDouble provider of+ case providerToDoubleStatsSource provider of Nothing -> error $ "Cannot represent series " ++ providerName provider ++ - " as double values: simulateFinalStats"- Just input -> input+ " as a source of double values: simulateFinalStats"+ Just input -> samplingStatsSourceData input names = map providerName providers predicate = finalStatsPredicate $ finalStatsView st exp = finalStatsExperiment st@@ -142,7 +143,7 @@ liftIO $ withMVar lock $ \() -> forM_ (zip xs values) $ \(x, values) -> do y <- readIORef values- let y' = addSamplingStats x y+ let y' = addDataToSamplingStats x y y' `seq` writeIORef values y' return $ return ()
Simulation/Aivika/Experiment/LastValueView.hs view
@@ -22,10 +22,9 @@ import Data.IORef import Data.Maybe -import Data.String.Utils (replace)- import Simulation.Aivika.Experiment import Simulation.Aivika.Experiment.HtmlWriter+import Simulation.Aivika.Experiment.Utils (replace) import Simulation.Aivika.Dynamics import Simulation.Aivika.Dynamics.Simulation
+ Simulation/Aivika/Experiment/ListSource.hs view
@@ -0,0 +1,88 @@++-- |+-- Module : Simulation.Aivika.Experiment.ListSource+-- Copyright : Copyright (c) 2013, David Sorokin <david.sorokin@gmail.com>+-- License : BSD3+-- Maintainer : David Sorokin <david.sorokin@gmail.com>+-- Stability : experimental+-- Tested with: GHC 7.6.3+--+-- It represents an optimized source of data to construct the list.+--++module Simulation.Aivika.Experiment.ListSource+ (ListSource,+ providerToDoubleListSource,+ providerToIntListSource,+ ListData,+ listSourceData,+ listDataList,+ ListRef,+ newListRef,+ addDataToListRef,+ readListRef) where++import Data.IORef+import Control.Monad++import Simulation.Aivika.Dynamics+import Simulation.Aivika.Statistics+import Simulation.Aivika.Experiment++-- | Represents the optimized source of data for constructing the list.+data ListSource a = SingleValueSource (Dynamics a)+ | MultipleValueSource (Dynamics [a])++-- | Represents the optimized data by which the list will be created.+data ListData a = SingleValueData !a+ | MultipleValueData [a]++-- | Try to return the source of list data by the specified provider.+providerToDoubleListSource :: SeriesProvider -> Maybe (ListSource Double)+providerToDoubleListSource provider =+ case providerToDouble provider of+ Just x -> Just $ SingleValueSource x+ Nothing ->+ case providerToDoubleList provider of+ Just x -> Just $ MultipleValueSource x+ Nothing -> Nothing+ +-- | Try to return the source of list data by the specified provider.+providerToIntListSource :: SeriesProvider -> Maybe (ListSource Int)+providerToIntListSource provider =+ case providerToInt provider of+ Just x -> Just $ SingleValueSource x+ Nothing ->+ case providerToIntList provider of+ Just x -> Just $ MultipleValueSource x+ Nothing -> Nothing++-- | Get data from the source in the current time point.+listSourceData :: ListSource a -> Dynamics (ListData a)+listSourceData (SingleValueSource x) = x >>= return . SingleValueData+listSourceData (MultipleValueSource xs) =+ do ys <- xs+ zs <- forM ys $ \y -> return $ y `seq` y+ return $ MultipleValueData ys -- it contains strict data, which is important for big models ++-- | Return the list of values contained in the specified data.+listDataList :: ListData a -> [a]+listDataList (SingleValueData x) = [x]+listDataList (MultipleValueData xs) = xs++-- | Represents a reference to the list, optimized to work with the source of data.+newtype ListRef a = ListRef { listRef :: IORef [ListData a] } ++-- | Create a new list reference.+newListRef :: IO (ListRef a)+newListRef = fmap ListRef $ newIORef []++-- | Add data to the list reference.+addDataToListRef :: ListRef a -> ListData a -> IO ()+addDataToListRef (ListRef r) a = modifyIORef r (a :)++-- | Read the list contained in the reference.+readListRef :: ListRef a -> IO [a]+readListRef (ListRef r) =+ do x <- readIORef r+ return $ concat $ map listDataList x
+ Simulation/Aivika/Experiment/SamplingStatsSource.hs view
@@ -0,0 +1,68 @@++-- |+-- Module : Simulation.Aivika.Experiment.SamplingStatsSource+-- Copyright : Copyright (c) 2013, David Sorokin <david.sorokin@gmail.com>+-- License : BSD3+-- Maintainer : David Sorokin <david.sorokin@gmail.com>+-- Stability : experimental+-- Tested with: GHC 7.6.3+--+-- It represents an optimized source of statistical data.+--++module Simulation.Aivika.Experiment.SamplingStatsSource+ (SamplingStatsSource,+ providerToDoubleStatsSource,+ providerToIntStatsSource,+ SamplingStatsData,+ samplingStatsSourceData,+ addDataToSamplingStats) where++import Simulation.Aivika.Dynamics+import Simulation.Aivika.Statistics+import Simulation.Aivika.Experiment++-- | Represents the optimized source of data for the statistics.+data SamplingStatsSource a = SingleValueSource (Dynamics a)+ | MultipleValueSource (Dynamics (SamplingStats a))++-- | Represents the optimized data to be included in the statistics.+data SamplingStatsData a = SingleValueData !a+ | MultipleValueData (SamplingStats a)++-- | Try to return the source of statistical data by the specified provider.+providerToDoubleStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Double)+providerToDoubleStatsSource provider =+ case providerToDouble provider of+ Just x -> Just $ SingleValueSource x+ Nothing ->+ case providerToDoubleStats provider of+ Just x -> Just $ MultipleValueSource x+ Nothing -> Nothing+ +-- | Try to return the source of statistical data.+providerToIntStatsSource :: SeriesProvider -> Maybe (SamplingStatsSource Int)+providerToIntStatsSource provider =+ case providerToInt provider of+ Just x -> Just $ SingleValueSource x+ Nothing ->+ case providerToIntStats provider of+ Just x -> Just $ MultipleValueSource x+ Nothing -> Nothing++-- | Get data from the source in the current time point.+samplingStatsSourceData :: SamplingStatsSource a -> Dynamics (SamplingStatsData a)+samplingStatsSourceData source =+ case source of+ SingleValueSource x -> x >>= return . SingleValueData+ MultipleValueSource x -> x >>= return . MultipleValueData++-- | Add data from the source to the statistics.+addDataToSamplingStats :: SamplingData a+ => SamplingStatsData a+ -> SamplingStats a+ -> SamplingStats a+addDataToSamplingStats d stats =+ case d of+ SingleValueData x -> addSamplingStats x stats+ MultipleValueData x -> combineSamplingStats x stats
Simulation/Aivika/Experiment/TableView.hs view
@@ -25,10 +25,9 @@ import System.IO import System.FilePath -import Data.String.Utils (replace)- import Simulation.Aivika.Experiment import Simulation.Aivika.Experiment.HtmlWriter+import Simulation.Aivika.Experiment.Utils (replace) import Simulation.Aivika.Dynamics import Simulation.Aivika.Dynamics.Simulation
Simulation/Aivika/Experiment/TimingStatsView.hs view
@@ -22,11 +22,10 @@ import Data.IORef import Data.Maybe -import Data.String.Utils (replace)- import Simulation.Aivika.Experiment import Simulation.Aivika.Experiment.HtmlWriter import Simulation.Aivika.Experiment.TimingStatsWriter+import Simulation.Aivika.Experiment.Utils (replace) import Simulation.Aivika.Dynamics import Simulation.Aivika.Dynamics.Simulation
Simulation/Aivika/Experiment/Utils.hs view
@@ -11,8 +11,11 @@ -- module Simulation.Aivika.Experiment.Utils- (divideBy) where+ (divideBy, replace) where +import Data.List+import Data.List.Split+ -- | Divide into the groups removing those elements -- that satisfy the predicate. divideBy :: (a -> Bool) -> [a] -> [[a]]@@ -21,3 +24,7 @@ [] -> [] xs' -> ys : divideBy p xs'' where (ys, xs'') = break p xs'++-- | Replace the string.+replace :: String -> String -> String -> String+replace old new = intercalate new . splitOn old
aivika-experiment.cabal view
@@ -1,5 +1,5 @@ name: aivika-experiment-version: 0.2.1+version: 0.2.2 synopsis: Simulation experiments for the Aivika library description: This package allows defining simulation experiments for the Aivika@@ -12,13 +12,13 @@ category: Simulation license: BSD3 license-file: LICENSE-copyright: (c) 2012. David Sorokin <david.sorokin@gmail.com>+copyright: (c) 2012-2013. David Sorokin <david.sorokin@gmail.com> author: David Sorokin maintainer: David Sorokin <david.sorokin@gmail.com> homepage: http://github.com/dsorokin/aivika-experiment cabal-version: >= 1.2.0 build-type: Simple-tested-with: GHC == 7.4.1+tested-with: GHC == 7.6.3 extra-source-files: examples/MachRep3.hs @@ -31,11 +31,13 @@ Simulation.Aivika.Experiment.TimingStatsView Simulation.Aivika.Experiment.TimingStatsWriter Simulation.Aivika.Experiment.SamplingStatsWriter+ Simulation.Aivika.Experiment.SamplingStatsSource Simulation.Aivika.Experiment.FinalStatsView Simulation.Aivika.Experiment.Histogram Simulation.Aivika.Experiment.ExperimentSpecsView Simulation.Aivika.Experiment.ExperimentSpecsWriter Simulation.Aivika.Experiment.FinalTableView+ Simulation.Aivika.Experiment.ListSource Simulation.Aivika.Experiment.Utils build-depends: base >= 3 && < 6,@@ -45,10 +47,10 @@ directory >= 1.1.0.2, filepath >= 1.3.0.0, utf8-string >= 0.3.7,- MissingH >= 1.2.0.0,+ split >= 0.2.2, network >= 2.3.0.13, parallel-io >= 0.3.2.1,- aivika >= 0.5.1+ aivika >= 0.5.4 extensions: FlexibleInstances