Observation.jl
MiniObserve.Observation
— ModuleThis module implements the observation logic itself.
MiniObserve.Observation.add_to_dataframe!
— Functionadd_to_dataframe!(df, stats)
add_to_dataframe!(df, stats, pre)
add_to_dataframe!(df, stats, pre, post)
Store results from observation type stats_t
in dataframe df
. With pre
and post
additional data that is not contained in the stats object can be added.
MiniObserve.Observation.create_dataframe!
— Methodcreate_dataframe!(stats_t, df)
Add columns to a dataframe df
, so that it can record the data from an observation type stats_t
.
MiniObserve.Observation.joined_named_tuple_T
— Methodconcatenate named tuple and/or struct types into one single named tuple
MiniObserve.Observation.log_results
— Methodlog_results(out, stats; FS, LS)
Print results stored in stats
to output
using field separator FS
and line separator LS
.
MiniObserve.Observation.print_header
— Methodprint_header(output, stats_t; FS, NS, LS)
Print a header for an observation type stats_t
to output
using field separator FS
, name separator NS
and line separator LS
.
MiniObserve.Observation.stat_names
— Methodtranslate accumulator types into prefixes for the header (e.g. min, max, etc.)
MiniObserve.Observation.to_named_tuple
— Methodconstruct a named tuple from x
MiniObserve.Observation.tuple_type
— Methodobtain a named tuple type with the same field types and names as struct_T
MiniObserve.Observation.@observe
— Macro@observe(statstype, user_arg1 [, user_arg2...], declarations)
Generate a full analysis and logging suite for a set of data structures.
Observe expects a (new) type name, a number of user arguments and a block of declarations. It will generate a function observe
that takes the user arguments and returns an instance of the data type. The declaration block will be copied verbatim to the body of the observe
function, but all occurences of the "pseudo-macros" @record
and @stat
will be replaced with corresponding analysis code.
The newly defined result data type will contain properties for all calculated results.
So, given a declaration
@observe Data model stat1 stat2 begin
@record "time" model.time
@record "N" Int length(model.population)
for ind in model.population
@stat("capital", MaxMinAcc{Float64}, MeanVarAcc{FloatT}) <| ind.capital
@stat("n_alone", CountAcc) <| has_neighbours(ind)
end
@record s1 stat1
@record s2 stat1 * stat2
end
a type Data will be generated that provides (at least) the following members:
struct Data
time :: Float64
N :: Int
capital :: @NamedTuple{max :: Float64, min :: Float64, mean :: Float64, var :: Float64}
n_alone :: @NamedTuple{N :: Int}
s1 :: Float64
s2 :: Float64
end
The macro will also create a method observe(::Type{Data), model, stat1, stat2)
that will perform the required calculations and returns a Data
object.
Use print_header
to print a header for the generated type to an output and log_results
to print the content of a data object.
Index
MiniObserve.Observation
MiniObserve.StatsAccumulatorBase
MiniObserve.StatsAccumulator.CountAcc
MiniObserve.StatsAccumulator.HistAcc
MiniObserve.StatsAccumulator.HistAcc
MiniObserve.StatsAccumulator.MaxMinAcc
MiniObserve.StatsAccumulator.MeanVarAcc
MiniObserve.StatsAccumulator.SumAcc
MiniObserve.Observation.add_to_dataframe!
MiniObserve.Observation.create_dataframe!
MiniObserve.Observation.joined_named_tuple_T
MiniObserve.Observation.log_results
MiniObserve.Observation.print_header
MiniObserve.Observation.stat_names
MiniObserve.Observation.to_named_tuple
MiniObserve.Observation.tuple_type
MiniObserve.StatsAccumulatorBase.add!
MiniObserve.StatsAccumulatorBase.result_type
MiniObserve.StatsAccumulatorBase.results
MiniObserve.Observation.@observe