creativity  v1.3.0
Agent-based model of creativity and piracy
Classes | Enumerations | Functions | Variables
creativity::data Namespace Reference

Namespace for classes related to generating and processing simulation data. More...

Classes

class  Addition
 Wrapper class around a addition of the elements of two Variables. More...
 
class  BinaryExpr
 Base class for composite variables with two Variable components. More...
 
class  ConstantVariable
 Special Variable subclass for representing a constant value. More...
 
class  CSVParser
 Primitive comma-separated-value file parser. More...
 
struct  datum
 Struct for holding a simulation data value calculator. More...
 
class  Division
 Class that returns the coefficient-wise division of elements in one Variable by corresponding elements in the other Variable. More...
 
class  Equation
 Class to store a equation. More...
 
class  Exponential
 Raises a base value to a Variable's value. More...
 
struct  initial_datum
 Struct for holding a simulator parameter. More...
 
class  Logarithm
 Takes a natural logarithm of a Variable's values. More...
 
class  Multiplication
 Wrapper class around a multiplication of the elements of two Variables. More...
 
class  OLS
 Class for running a basic OLS regression. More...
 
class  Power
 Raises a Variable's values to a power. More...
 
class  RankError
 Exception class for rank errors, for example when trying to do OLS with n < k, or an X matrix without full column rank. More...
 
class  SimpleVariable
 Wrapper class around a simple column, where values are exactly the value in the column. More...
 
class  SUR
 Class for running a seemingly-unrelated regressions model. More...
 
struct  tabulation_options
 Struct holding various options controlling tabulation output. More...
 
class  Treatment
 This class converts raw simulation data into multiple data rows, with piracy/policy, SR/LR as treatment effects on the base (pre-piracy, pre-policy) row. More...
 
class  TreatmentFilter
 Extension to Treatment that applies a filter to an existing Treatment variable, resulting in a new Treatment object that only contains the row sets for matched data observations. More...
 
class  UnaryExpr
 Base class for composite variables with a single variable. More...
 
class  Variable
 Abstract base class for model variables. More...
 

Enumerations

enum  TableFormat { TableFormat::Text, TableFormat::HTML, TableFormat::LaTeX }
 Enum for supported table output formats. More...
 
enum  OverlapReducer {
  OverlapReducer::None, OverlapReducer::Prefix, OverlapReducer::Suffix, OverlapReducer::Equalize,
  OverlapReducer::Disequalize
}
 enum of the different strategies for dealing with prefix/suffix overlap in common_ends(). More...
 

Functions

std::string quantile_field (double quantile)
 Takes a quantile and returns a CSV header representing that quantile. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
double book_sales (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Average copies sold per book. More...
 
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. More...
 
double book_gross_margin (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Average gross margin (i.e. More...
 
double book_profit (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Average profit (i.e. More...
 
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 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 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. More...
 
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 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. More...
 
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 given period.
 
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, averaged over the given period. More...
 
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. More...
 
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. More...
 
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. More...
 
std::vector< initial_datuminitial_data_fields ()
 Average number of readers caught per 100 readers per period for piracy. More...
 
std::vector< datumdata_fields ()
 Returns a vector of all supported calculated datum values. More...
 
std::string csv_fix (std::string val)
 Takes a string, manipulates it into our simplified CSV-suitable value by replacing any special characters (such as commas, newline, etc.) with underscores.
 
std::string tabulate (const Eigen::Ref< const Eigen::MatrixXd > &matrix, const tabulation_options &options=tabulation_options{}, const std::vector< std::string > &rownames={}, const std::vector< std::string > &colnames={}, const std::vector< std::string > &extracol={})
 Function that takes an Eigen matrix and optional row and column names and displays the results. More...
 
std::string tabulate_preamble (const tabulation_options &options)
 Returns the preamble (if any) for the format contain within the given tabulation_options. More...
 
std::string tabulate_postamble (const tabulation_options &options)
 Returns the postamble (if any) for the format contain within the given tabulation_options. More...
 
std::string tabulate_escape (const std::string &in, const tabulation_options &options)
 Escapes a value according to the given tabulation options format. More...
 
std::string tabulate (const Equation &equation, const tabulation_options &options=tabulation_options{}, const std::vector< std::string > &rownames={})
 Function that takes an Equation object and optional row names and displays the values of the variables of the equation. More...
 
std::string tabulate (const SUR &sur, const tabulation_options &options=tabulation_options{}, const std::vector< std::string > &rownames={})
 Function that takes an SUR object (i.e. More...
 
std::string double_str (double d, unsigned precision=std::numeric_limits< double >::max_digits10)
 Converts a double value to a string, use as much precision is required (but no more). More...
 
template<typename RAIter , typename = typename std::enable_if< std::is_same< std::random_access_iterator_tag, typename std::iterator_traits<RAIter>::iterator_category >::value and std::is_arithmetic<typename std::iterator_traits<RAIter>::value_type>::value>::type>
double quantile (RAIter begin, RAIter end, double prob)
 Returns a sample quantile from a pair of random access iterators over the range of sorted values [begin, end). More...
 
double quantile (const std::vector< double > &vals, double prob)
 Shortcut for quantile(vals.begin(), vals.end(), prob)
 
double quantile (const Eigen::Ref< const Eigen::VectorXd > &vals, double prob)
 Works like quantile(begin,end,prob), but but operates on an Eigen vector-like object. More...
 
double variance (const std::vector< double > &vals, double mean=std::numeric_limits< double >::quiet_NaN())
 Calculates and returns the sample variance of the given vector of values. More...
 
template<typename InputIt >
std::enable_if< std::is_base_of< std::input_iterator_tag, typename std::iterator_traits< InputIt >::iterator_category >::value and std::is_base_of< std::bidirectional_iterator_tag, typename std::iterator_traits< typename InputIt::value_type::iterator >::iterator_category >::value, std::pair< size_t, size_t >>::type common_ends (InputIt it, InputIt last, bool prefix=true, bool suffix=true, OverlapReducer reducer=OverlapReducer::Disequalize)
 Determines the number of equal (by ==) front and/or back elements in a range of random-access iterable objects. More...
 
std::string to_string (double d)
 Helper wrapper around std::to_string that removes insignificant 0s and a .
 
std::shared_ptr< Multiplicationoperator* (const std::shared_ptr< const Variable > &left, const std::shared_ptr< const Variable > &right)
 Multiplies two Variable objects together, returning a new Multiplication object. More...
 
std::shared_ptr< Multiplicationoperator* (const std::shared_ptr< const Variable > &v, double c)
 Multiplies a Variable by a constant.
 
std::shared_ptr< Multiplicationoperator* (double c, const std::shared_ptr< const Variable > &v)
 Multiplies a constant by a Variable.
 
std::shared_ptr< Multiplicationoperator- (const std::shared_ptr< const Variable > &v)
 Unary negation of a Variable is converted to a multiplication by -1.
 
std::shared_ptr< Additionoperator+ (const std::shared_ptr< const Variable > &left, const std::shared_ptr< const Variable > &right)
 Adds two Variable objects together, returning a new Addition object. More...
 
std::shared_ptr< Additionoperator+ (const std::shared_ptr< const Variable > &v, double c)
 Adds a constant to a Variable; the constant is converted to a ConstantVariable.
 
std::shared_ptr< Additionoperator+ (double c, const std::shared_ptr< const Variable > &v)
 Adds a Variable to a constant; the constant is converted to a ConstantVariable.
 
std::shared_ptr< Additionoperator- (const std::shared_ptr< const Variable > &left, const std::shared_ptr< const Variable > &right)
 Subtracts one Variable from another; the subtracted value is multiplied by -1.
 
std::shared_ptr< Additionoperator- (const std::shared_ptr< const Variable > &v, double c)
 Subtracts a constant from a Variable; the constant is converted to a ConstantVariable.
 
std::shared_ptr< Additionoperator- (double c, const std::shared_ptr< const Variable > &v)
 Subtracts a Variable from a constant; the constant is converted to a ConstantVariable, and the Variable is multiplied by -1.
 
std::shared_ptr< Divisionoperator/ (const std::shared_ptr< const Variable > &numerator, const std::shared_ptr< const Variable > &denominator)
 Divides one Variable by another, returning a new Division object. More...
 
std::shared_ptr< Divisionoperator/ (const std::shared_ptr< const Variable > &v, double c)
 Divides a Variable by a constant.
 
std::shared_ptr< Divisionoperator/ (double c, const std::shared_ptr< const Variable > &v)
 Divides a constant by a Variable.
 
std::shared_ptr< Poweroperator^ (const std::shared_ptr< const Variable > &val, double pow)
 Variable ^ power returns a Power object. More...
 
std::shared_ptr< Exponentialoperator^ (double base, const std::shared_ptr< const Variable > &val)
 base ^ Variable returns an Exponential object. More...
 
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 during the period range.
 
double book_quality_sd (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 during the period range.
 
double book_quality_min (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 during the period range.
 
double book_quality_5th (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 during the period range.
 
double book_quality_10th (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 during the period range.
 
double book_quality_25th (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 during the period range.
 
double book_quality_median (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 during the period range.
 
double book_quality_75th (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 during the period range.
 
double book_quality_90th (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 during the period range.
 
double book_quality_95th (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 during the period range.
 
double book_quality_max (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 during the period range.
 
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 author of each book created during the period range.
 
double book_author_level_sd (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 author of each book created during the period range.
 
double book_author_level_min (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 author of each book created during the period range.
 
double book_author_level_5th (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 author of each book created during the period range.
 
double book_author_level_10th (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 author of each book created during the period range.
 
double book_author_level_25th (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 author of each book created during the period range.
 
double book_author_level_median (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 author of each book created during the period range.
 
double book_author_level_75th (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 author of each book created during the period range.
 
double book_author_level_90th (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 author of each book created during the period range.
 
double book_author_level_95th (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 author of each book created during the period range.
 
double book_author_level_max (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 author of each book created during the period range.
 
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 book created during the period range.
 
double book_author_effort_sd (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 book created during the period range.
 
double book_author_effort_min (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 book created during the period range.
 
double book_author_effort_5th (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 book created during the period range.
 
double book_author_effort_10th (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 book created during the period range.
 
double book_author_effort_25th (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 book created during the period range.
 
double book_author_effort_median (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 book created during the period range.
 
double book_author_effort_75th (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 book created during the period range.
 
double book_author_effort_90th (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 book created during the period range.
 
double book_author_effort_95th (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 book created during the period range.
 
double book_author_effort_max (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 book created during the period range.
 
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. More...
 
double net_u_sd (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_min (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_5th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_10th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_25th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_median (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_75th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_90th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_95th (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 
double net_u_max (const state::Storage &cs, eris::eris_time_t from, eris::eris_time_t to)
 Distribution of reader net utility values over the period range. More...
 

Variables

const std::regex quantile_field_regex
 A std::regex object that matches all values returned by quantile_field(). More...
 

Detailed Description

Namespace for classes related to generating and processing simulation data.

Enumeration Type Documentation

§ OverlapReducer

enum of the different strategies for dealing with prefix/suffix overlap in common_ends().

Enumerator
None 

Don't reduce the prefix/suffix: the returned prefix and suffix may overlap.

Prefix 

Reduce the prefix by the minimum amount needed to eliminate the overlap.

Suffix 

Reduce the suffix by the minimum amount needed to eliminate the overlap.

Equalize 

Apply reductions to the prefix/suffix values that make the values closer to equal.

Disequalize 

Apply reductions to whichever of the prefix/suffix is smaller.

§ TableFormat

Enum for supported table output formats.

Enumerator
Text 

Plain-text format.

HTML 

HTML table format.

LaTeX 

LaTeX output.

Function Documentation

§ book_gross_margin()

double creativity::data::book_gross_margin ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Average gross margin (i.e.

P-MC) of book over the given period. Books written before from are included (if revenue in incurred in [from,to]; for books who continue selling after to, only the revenue up to to is included. All books on the market (even if sales are 0) are included.

The average is calculated based on the number of books seen, not the number of simulation periods.

§ book_market_periods()

double creativity::data::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.

Books still on the market in period to aren't included (because they might stay on the market).

§ book_p0()

double creativity::data::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.

(This is absolute price, not price less marginal cost).

§ book_p1()

double creativity::data::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.

(This is absolute price, not price less marginal cost). Note that books written in period to are not considered (because their 2nd-period price occurs in to+1), but books written in period from-1 are.

If there are no suitable books that were on the market for 2+ periods at all, NaN is returned.

§ book_p2()

double creativity::data::book_p2 ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Returns the average third-period price of books.

(This is absolute price, not price less marginal cost). Note that books written in period to and to-1 are not included, since their third-period occurs later than to, but books written in periods from-1 and from-2 are considered.

If there are no suitable books that were on the market for 3+ periods at all, NaN is returned.

§ book_profit()

double creativity::data::book_profit ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Average profit (i.e.

profit minus writing cost and keep-on-market costs) of a book. Only costs incurred during the period are included. In particular, this means profits from pre-from-written books are included but (some) fixed costs are not, and some near-to books will have fixed costs but may omit some earned profits.

Prize revenue (i.e. public market payours) are included.

The average is calculated based on the number of books seen, not the number of simulation periods.

§ book_revenue()

double creativity::data::book_revenue ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Average per-book revenue over the given period.

Books written before from are included (if revenue is received in [from,to]; for books who continue selling after to, only the revenue up to to is included. All books created in the given period range (even if revenue is 0) are included.

Prize revenue (i.e. public market payouts) is counted as revenue.

The average is calculated based on the number of books included, not the number of simulation periods.

§ book_sales()

double creativity::data::book_sales ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Average copies sold per book.

All books on the market in the given range are included. The average is per book seen in the period, not per simulation period.

§ books_pirated()

double creativity::data::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.

Note that pirated copies of books that left the market before from are still included, i.e. this counts all piracy activity in the given period, not just piracy activity for books written in the given period.

§ common_ends()

template<typename InputIt >
std::enable_if< std::is_base_of<std::input_iterator_tag, typename std::iterator_traits<InputIt>::iterator_category>::value and std::is_base_of< std::bidirectional_iterator_tag, typename std::iterator_traits<typename InputIt::value_type::iterator>::iterator_category >::value, std::pair<size_t, size_t>>::type creativity::data::common_ends ( InputIt  it,
InputIt  last,
bool  prefix = true,
bool  suffix = true,
OverlapReducer  reducer = OverlapReducer::Disequalize 
)

Determines the number of equal (by ==) front and/or back elements in a range of random-access iterable objects.

Returns a pair where .first is the number of common elements from the beginning of each given container, and .second is the number of common elements from the end of each given container.

For example:

std::list<std::string> strings({"abcdxyz", "abcxyz", "abcsomethingyz"});
common_ends(strings); // Returns std::pair<size_t,size_t>(3,2)

In the case of overlaps, for example with the strings "aabbc" and "aabbbaabbc" (which each have a common prefix of length 4 ("aabb") and common suffix of length 5 ("aabbc")), the optional overlap_reduce parameter controls how to reduce the overlap.

Parameters
itan iterator to the first element to consider
lastthe past-the-end iterator at which to stop
prefixwhether to look for a common prefix (defaults to true). If false, the returned prefix length will be 0.
suffixwhether to look for a common suffix (defaults to true). If false, the returned suffix length will be 0.
reduceran OverlapReducer value controlling what happens when the prefix and suffix overlaps for one or more elements. The default, OverlapReducer::Disequalize, reduces reduces whichever is smaller (leaving the larger match unadjuated). by approximately equal values to eliminate the overlap.
Returns
a pair of size_t values where .first is the common prefix length and .second is the common suffix length.

§ data_fields()

std::vector<datum> creativity::data::data_fields ( )

Returns a vector of all supported calculated datum values.

§ double_str()

std::string creativity::data::double_str ( double  d,
unsigned  precision = std::numeric_limits< double >::max_digits10 
)

Converts a double value to a string, use as much precision is required (but no more).

When outputting values, we want maximum precision, but don't necessarily need the full max_digits10 digits to get there. For example, 0.1 with max_digits10 significant digits becomes 0.10000000000000001 but 0.1 also converts to the (numerically) identical value. 0.10000000000000002, on the other hand, is a numerically distinct value and thus needs every decimal digit.

This function first tries to convert the value at the requested precision, then at the requested precision less one, then less two; if the subsequent values are numerically identical to the given double value when reconverted to a double, the shortest is returned.

Parameters
dthe double to convert to a string
precisionthe requested precision, defaulting to std::numeric_limits<double>::max_digits10

§ initial_data_fields()

std::vector<initial_datum> creativity::data::initial_data_fields ( )

Average number of readers caught per 100 readers per period for piracy.

Average fines paid (e.g. for being caught pirating) per reader. Returns a vector of all supported initial datum values.

§ net_u()

double creativity::data::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.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_10th()

double creativity::data::net_u_10th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_25th()

double creativity::data::net_u_25th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_5th()

double creativity::data::net_u_5th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_75th()

double creativity::data::net_u_75th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_90th()

double creativity::data::net_u_90th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_95th()

double creativity::data::net_u_95th ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_max()

double creativity::data::net_u_max ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_median()

double creativity::data::net_u_median ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_min()

double creativity::data::net_u_min ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ net_u_sd()

double creativity::data::net_u_sd ( const state::Storage cs,
eris::eris_time_t  from,
eris::eris_time_t  to 
)

Distribution of reader net utility values over the period range.

This is net of the utility readers would have if there were no book activity at all, which is simply the reader's exogenous income level.

§ operator*()

std::shared_ptr<Multiplication> creativity::data::operator* ( const std::shared_ptr< const Variable > &  left,
const std::shared_ptr< const Variable > &  right 
)

Multiplies two Variable objects together, returning a new Multiplication object.

§ operator+()

std::shared_ptr<Addition> creativity::data::operator+ ( const std::shared_ptr< const Variable > &  left,
const std::shared_ptr< const Variable > &  right 
)

Adds two Variable objects together, returning a new Addition object.

§ operator/()

std::shared_ptr<Division> creativity::data::operator/ ( const std::shared_ptr< const Variable > &  numerator,
const std::shared_ptr< const Variable > &  denominator 
)

Divides one Variable by another, returning a new Division object.

§ operator^() [1/2]

std::shared_ptr<Power> creativity::data::operator^ ( const std::shared_ptr< const Variable > &  val,
double  pow 
)

Variable ^ power returns a Power object.

§ operator^() [2/2]

std::shared_ptr<Exponential> creativity::data::operator^ ( double  base,
const std::shared_ptr< const Variable > &  val 
)

base ^ Variable returns an Exponential object.

§ quantile() [1/2]

template<typename RAIter , typename = typename std::enable_if< std::is_same< std::random_access_iterator_tag, typename std::iterator_traits<RAIter>::iterator_category >::value and std::is_arithmetic<typename std::iterator_traits<RAIter>::value_type>::value>::type>
double creativity::data::quantile ( RAIter  begin,
RAIter  end,
double  prob 
)

Returns a sample quantile from a pair of random access iterators over the range of sorted values [begin, end).

Linear interpolation is used for quantiles that lie between elements. The interpolation is such that the quantile for 0 returns the smallest value and the quantile for 1 returns the largest value.

The range of values must be sorted in order for this function to work correctly–but this is not checked.

Parameters
beginthe random access iterator to the first value
endthe past-the-end random access iterator
probthe probability for which the quantile should be calculated; must be between 0 and 1.
Returns
NaN if begin == end, otherwise returns the requested quantile.

§ quantile() [2/2]

double creativity::data::quantile ( const Eigen::Ref< const Eigen::VectorXd > &  vals,
double  prob 
)

Works like quantile(begin,end,prob), but but operates on an Eigen vector-like object.

§ quantile_field()

std::string creativity::data::quantile_field ( double  quantile)

Takes a quantile and returns a CSV header representing that quantile.

The special quantiles 0, 0.5, and 1 become "min", "median", and "max", respectively. All other values take the form qXXX where XXX is formed by converting the quantile to a string (via creativity::data::double_str) have the leading "0." and any trailing 0s removed. Thus 0.052 becomes q052, 0.52 becomes q52, and 0.999 becomes q999.

Parameters
quantilethe quantile to convert to header form
Returns
the header string version of the quantile
See also
quantile_field_regex
Exceptions
std::invalid_argumentif given a quantile not in [0,1]

§ reader_market_spending()

double creativity::data::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.

Only spending on books bought from the author is included, specifically piracy cost and public sharing costs are not included.

§ reader_public_spending()

double creativity::data::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, averaged over the given period.

This does not include the lump-sum tax paid by all readers, only the per-copy price (= marginal cost) of a book.

§ reader_spending()

double creativity::data::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.

This is the sum of book_market_spending plus book_piracy_spending (when piracy is available) plus book_public_spending (when public sharing is available).

This does not include spending incurred by authors to create books or sell copies of books, nor does it include lump sum tax amounts.

§ reader_spending_total()

double creativity::data::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.

policing or public sharing prize costs).

This is simply a shortcut for reader_spending(...) + reader_taxes(...).

§ reader_taxes()

double creativity::data::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.

If the period doesn't overlap the beginning of the policy period, this will simply be 0 (if before the policy period begins) or the per-period tax value (if during the policy period).

§ tabulate() [1/3]

std::string creativity::data::tabulate ( const Eigen::Ref< const Eigen::MatrixXd > &  matrix,
const tabulation_options options = tabulation_options{},
const std::vector< std::string > &  rownames = {},
const std::vector< std::string > &  colnames = {},
const std::vector< std::string > &  extracol = {} 
)

Function that takes an Eigen matrix and optional row and column names and displays the results.

Parameters
matrixthe matrix (or matrix-like Eigen object) to display
optionsthe tabulation_options controlling display output
rownamesthe row names to use. The first value is the header for the rows; subsequent values are the row names. If this vector exactly equals the number of rows of the matrix, an empty row name header (and so this is equivalent to passing a vector with an empty string prepended to the beginning). If the vector is smaller than the number of rows, the first value is used as the row header, and unspecified rows will be named [r,] where r is the row index beginning at 0. If entirely empty, the row header will an the empty string.
colnamesthe column names to use. If too short (including empty, the default), unprovided columns will be named [,c], where c is the column index beginning at 0.
extracolis an extra column of string values to display to the right of the last matrix column. If empty (the default), no extra column is added. If the length of the vector exactly equals the number of rows of the matrix, the extra column receives no header name; otherwise the first value of the vector is used as the extra column header name. If the vector is too short, blank values will be used for any missing row values. Values will be left-aligned in the column.

§ tabulate() [2/3]

std::string creativity::data::tabulate ( const Equation equation,
const tabulation_options options = tabulation_options{},
const std::vector< std::string > &  rownames = {} 
)

Function that takes an Equation object and optional row names and displays the values of the variables of the equation.

Column names come from the equation.

Parameters
equationthe equation object of values to display
optionsthe tabulation_options controlling display output
rownamesthe row names to use. If too short (including empty, the default), unspecified rows will be named [r,] where r is the row index beginning at 0.

§ tabulate() [3/3]

std::string creativity::data::tabulate ( const SUR sur,
const tabulation_options options = tabulation_options{},
const std::vector< std::string > &  rownames = {} 
)

Function that takes an SUR object (i.e.

of multiple equations) and returns a string of its data, side-by-side in a table. Each y variable heading is prefixed with "Eq. n: ", with n starting from 1, then followed by the RHS variables of the equation, then the next y variable, etc.

Parameters
surthe SUR data to display
optionsthe tabulation_options controlling display output
rownamesthe row names to use. If too short (including empty, the default), unspecified rows will be named [r,] where r is the row index beginning at 0.

§ tabulate_escape()

std::string creativity::data::tabulate_escape ( const std::string &  in,
const tabulation_options options 
)

Escapes a value according to the given tabulation options format.

This is primarily intended for use when passing raw column or row values with the escape option set to false.

The options.escape value is ignored for this method (that is, the method escapes even if the escape value is set to false).

Parameters
inthe input string to be escaped
optionsthe tabulation options containing the format value specifying which type of escaping is to be performed. Can also be passed as simple a TableFormat value (using the implicit tabulation_options constructor).
Returns
a string with characters that need to be escaped replaced with suitable replacements for the given options.format value.

§ tabulate_postamble()

std::string creativity::data::tabulate_postamble ( const tabulation_options options)

Returns the postamble (if any) for the format contain within the given tabulation_options.

This is called internally if tabulate() is called with the postamble option set to true, but can also be called explicitly.

See also
tabulation_options.postamble

§ tabulate_preamble()

std::string creativity::data::tabulate_preamble ( const tabulation_options options)

Returns the preamble (if any) for the format contain within the given tabulation_options.

This is called internally if tabulate() is called with the preamble option set to true, but can also be called explicitly.

See also
tabulation_options.preamble

§ variance()

double creativity::data::variance ( const std::vector< double > &  vals,
double  mean = std::numeric_limits< double >::quiet_NaN() 
)

Calculates and returns the sample variance of the given vector of values.

If the mean of the vector is already known it can be passed in as mean, otherwise the default, NaN, calculates the mean from the vector.

Variable Documentation

§ quantile_field_regex

const std::regex creativity::data::quantile_field_regex

A std::regex object that matches all values returned by quantile_field().

See also
quantile_field()