creativity  v1.3.0
Agent-based model of creativity and piracy
simdata.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <functional>
4 #include <vector>
5 #include <algorithm>
6 #include <type_traits>
7 #include <eris/types.hpp>
8 #include <Eigen/Core>
9 
14 namespace creativity { struct CreativitySettings; }
15 namespace creativity { namespace state { class Storage; } }
16 
17 namespace creativity {
19 namespace data {
20 
22 struct initial_datum {
24  const std::string name;
26  const std::function<long(const CreativitySettings&)> calc_int;
28  const std::function<double(const CreativitySettings&)> calc_double;
29 
31  initial_datum() = delete;
33  template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
34  initial_datum(std::string name, std::function<IntType(const CreativitySettings&)> &&calc_int)
35  : name(std::move(name)), calc_int(std::move(calc_int)) {}
37  initial_datum(std::string name, std::function<double(const CreativitySettings&)> &&calc_double)
38  : name(std::move(name)), calc_double(std::move(calc_double)) {}
39 };
40 
42 struct datum {
44  const std::string name;
50  const std::function<double(const state::Storage&, eris::eris_time_t, eris::eris_time_t)> calculate;
52  struct {
53  bool pre;
54  bool piracy;
55  bool policy;
56  } applies_to;
57 
59  datum() = delete;
70  datum(std::string &&name, decltype(calculate) calc, bool pre = true, bool piracy = true, bool policy = true)
71  : name(std::move(name)), calculate(std::move(calc)), applies_to{pre, piracy, policy} {}
72 };
73 
78 double book_market_periods(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
79 
83 double book_p0(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
84 
92 double book_p1(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
93 
101 double book_p2(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
102 
106 double book_sales(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
107 
118 double book_revenue(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
119 
127 double book_gross_margin(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
128 
139 double book_profit(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
140 
142 #define DIST_FNS(variable) \
143 double variable(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
144 double variable##_sd(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
145 double variable##_min(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
146 double variable##_5th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
147 double variable##_10th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
148 double variable##_25th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
149 double variable##_median(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
150 double variable##_75th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
151 double variable##_90th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
152 double variable##_95th(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to); \
153 double variable##_max(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
154 
160 
162 
167 
169 
174 
176 
182 
183 #undef DIST_FNS
184 
187 double books_written_pc(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
188 
191 double books_bought(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
192 
197 double books_pirated(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
198 
201 double books_public_copies(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
202 
207 double reader_market_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
208 
212 double reader_piracy_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
213 
220 double reader_public_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
221 
229 double reader_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
230 
236 double reader_taxes(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
237 
243 double reader_spending_total(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
244 
245 // FIXME: don't have this info stored yet
246 
248 //double readers_caught_pc(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
249 
251 //double reader_fines(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to);
252 
254 std::vector<initial_datum> initial_data_fields();
255 
257 std::vector<datum> data_fields();
258 
262 std::string csv_fix(std::string val);
263 
264 }}
std::string csv_fix(std::string val)
Takes a string, manipulates it into our simplified CSV-suitable value by replacing any special charac...
double books_bought(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average number of books purchased per reader per period.
double book_p1(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Returns the average second-period price of books written in the given period range.
double book_p0(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Returns the average first-sale-period price of books written in the given period range.
double book_market_periods(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Calculates the average market life of books written between from and to, in simulation periods...
double book_profit(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average profit (i.e.
Primary namespace for all Creativity library code.
Definition: config.hpp:4
double book_author_level(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Distribution values (mean, standard deviation, min, max, quantiles) for author creation scale of the ...
double book_p2(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Returns the average third-period price of books.
bool piracy
True if this field applies to piracy periods.
Definition: simdata.hpp:54
const std::string name
The name of this parameter (to be included in the output header).
Definition: simdata.hpp:24
Definition: Variable.hpp:389
double book_author_effort(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Distribution values (mean, standard deviation, min, max, quantiles) for author effort level of each b...
std::vector< initial_datum > initial_data_fields()
Average number of readers caught per 100 readers per period for piracy.
double books_written_pc(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average number of books written per 100 agents per period.
double reader_piracy_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-reader piracy cost expenditure for obtaining pirated copies of books, averaged over the g...
double books_public_copies(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average number of books obtained from the public provider per reader per period.
double net_u(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Distribution of reader net utility values over the period range.
bool pre
True if this field applies to pre-piracy periods.
Definition: simdata.hpp:53
double book_gross_margin(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average gross margin (i.e.
double reader_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-reader expenditure for obtaining books from any source.
double book_sales(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average copies sold per book.
Class for state storage access which accesses State values.
Definition: Storage.hpp:27
Struct for holding a simulation data value calculator.
Definition: simdata.hpp:42
double reader_spending_total(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-reader expenditure on books, including lump-sum taxes (e.g.
initial_datum(std::string name, std::function< IntType(const CreativitySettings &)> &&calc_int)
Constructs a simulation parameter datum that returns an integral value.
Definition: simdata.hpp:34
initial_datum(std::string name, std::function< double(const CreativitySettings &)> &&calc_double)
Constructs a simulation parameter datum that returns a double value.
Definition: simdata.hpp:37
double reader_market_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-reader private market spending on books, averaged over the given period.
#define DIST_FNS(variable)
Macro to generate mean, sd, and quantile functions for a given variable.
Definition: simdata.hpp:142
datum(std::string &&name, decltype(calculate) calc, bool pre=true, bool piracy=true, bool policy=true)
Constructor.
Definition: simdata.hpp:70
const std::function< long(const CreativitySettings &)> calc_int
Returns an integer value for this parameter, if callable.
Definition: simdata.hpp:26
const std::function< double(const state::Storage &, eris::eris_time_t, eris::eris_time_t)> calculate
Callable object called to calculate the value of the parameter.
Definition: simdata.hpp:50
double books_pirated(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average number of books pirated per reader per period.
const std::string name
The name of this parameter (will be prefixed with pre_, new_, or post_)
Definition: simdata.hpp:44
double book_revenue(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-book revenue over the given period.
bool policy
True if this field applies to policy periods.
Definition: simdata.hpp:55
Struct for holding a simulator parameter.
Definition: simdata.hpp:22
Simulation parameters that are used to configure the simulation when calling setup().
Definition: CreativitySettings.hpp:10
std::vector< datum > data_fields()
Returns a vector of all supported calculated datum values.
double reader_public_spending(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Average per-reader public sharing expenditure for obtaining public provider copies of books...
const std::function< double(const CreativitySettings &)> calc_double
Returns a double value for this parameter, if callable.
Definition: simdata.hpp:28
double book_quality(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Distribution values (mean, standard deviation, min, max, quantiles) for quality of books written duri...
double reader_taxes(const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
Returns the average per-reader lump-sum taxes collected, averaged over the given period.