creativity
v1.3.0
Agent-based model of creativity and piracy
|
Central class for a creativity simulation; this class handles setting up the simulation according to configured parameters and running the simulation. More...
#include <creativity/Creativity.hpp>
Public Member Functions | |
Creativity ()=default | |
Default constructor. More... | |
CreativitySettings & | set () |
Provides writeable access to the parameters used to configure the simulation. More... | |
template<class T , typename... Args> | |
void | write (Args &&... args) |
Creates a new Storage object with any type of StorageBackend class. More... | |
template<class T , typename... Args> | |
void | read (Args &&... args) |
Opens a creativity simulation storage source for reading via storage(). More... | |
void | checkParameters () |
Checks .parameters to make sure that all configured values are valid, throwing an exception if any invalid values are found. More... | |
void | setup () |
Creates the Simulation object and adds the configured number of readers plus some base members (such as the common money good). More... | |
void | run () |
Runs one iteration of the simulation. More... | |
double | densityFromBoundary () const |
Returns the value of densityFromBoundary called with the current readers, dimensions, and boundary settings. | |
bool | piracy () const |
Returns true if piracy exists yet in the simulation. More... | |
bool | policyActive () const |
Returns true if a policy response exists yet in the simulation. More... | |
bool | publicSharingActive () const |
Returns true if public sharing is an enabled policy response and it is active in the simulation (i.e. More... | |
bool | publicVotingActive () const |
Returns true if public sharing with voting is an enabled policy response and it is active in the simulation (i.e. More... | |
bool | catchPiratesActive () const |
Returns true if getting caught for piracy is a configured policy response and it is active in the simulation (i.e. More... | |
double | policyTaxes () const |
Returns the per-user policies taxes currently in effect. More... | |
double | disposableIncome () const |
Returns the level of exogenous, disposable income, i.e. More... | |
double | priorWeight () const |
Returns the prior multiplier currently in effect. More... | |
double | meanInitialQuality () const |
Returns the mean quality of books created with initial parameter distributions. More... | |
std::pair< std::vector< eris::SharedMember< Book > > &, std::unique_lock< std::mutex > > | newBooks () |
Establishes a lock on the new books storage and returns a pair consisting of the new books reference and a unique lock on the books. More... | |
std::pair< std::shared_ptr< state::Storage > &, std::unique_lock< std::mutex > > | storage () |
Establishes a lock on the storage object and returns a pair consisting of the storage object and the unique lock on the object. More... | |
Static Public Member Functions | |
static double | boundaryFromDensity (uint32_t readers, uint32_t dimensions, double density) |
Static method that calculates a boundary given a number of readers, dimensions, and a desired density. More... | |
static double | densityFromBoundary (uint32_t readers, uint32_t dimensions, double boundary) |
Static method that calculates a density given a number of readers, dimensions, and a desired boundary location. More... | |
static double | policyTaxes (const CreativitySettings &s) |
Returns the policy taxes that will be in effect in a simulation using the given CreativitySettings during the policy period. | |
template<typename Iter , typename = typename std::enable_if<std::is_arithmetic< typename std::iterator_traits<Iter>::value_type>::value>::type> | |
static double | evalPolynomial (double x, Iter it, Iter end) |
Evaluates a polynomial at the value x . More... | |
template<typename Container , typename = typename std::enable_if<std::is_arithmetic< typename Container::value_type>::value>::type> | |
static double | evalPolynomial (double x, const Container &cont) |
Evaluates a polynomial at the value x . More... | |
Public Attributes | |
std::shared_ptr< eris::Simulation > | sim |
The simulation object. More... | |
eris::SharedMember< eris::Good > | money |
The money good. Will be empty until setup() is called. | |
const CreativitySettings & | parameters {set_} |
Simulation parameters that are used to configure the simulation when calling setup(). More... | |
unsigned long | market_books {0} |
Stores the number of on-market books. More... | |
double | market_books_avg {0.0} |
Stores the average number of on-market books over the past creation_time + 1 periods. More... | |
Protected Member Functions | |
void | createPiracyNetwork () |
Sets up the piracy network. More... | |
Central class for a creativity simulation; this class handles setting up the simulation according to configured parameters and running the simulation.
This class is the central code used by both the command line and GUI interfaces.
|
default |
Default constructor.
|
static |
Static method that calculates a boundary given a number of readers, dimensions, and a desired density.
std::logic_error | if any of the parameters are <= 0. |
bool creativity::Creativity::catchPiratesActive | ( | ) | const |
Returns true if getting caught for piracy is a configured policy response and it is active in the simulation (i.e.
the simulation has reached the policy response stage). Attempting to call this on a Creativity object that is not a live simulation, or is a live simulation but has not been set up yet, will raise an exception.
void creativity::Creativity::checkParameters | ( | ) |
Checks .parameters
to make sure that all configured values are valid, throwing an exception if any invalid values are found.
This doesn't check that parameters are useful, it merely checks whether the parameters can be used. (For example, readers=1 is a useless setting, but is still permitted because such a simulation can technically be created).
This method is called automatically by setup(), but can be called otherwise as well.
std::domain_error | if any of the values in .parameters are invalid. |
|
protected |
Sets up the piracy network.
Called automatically by run() just before the piracy_begins
period.
|
static |
Static method that calculates a density given a number of readers, dimensions, and a desired boundary location.
std::logic_error | if any of the parameters are <= 0. |
double creativity::Creativity::disposableIncome | ( | ) | const |
Returns the level of exogenous, disposable income, i.e.
income minus policy taxes. This is simply a shortcut for creativity.parameters.income - creativity.policyTaxes()
. Note that this does not include any income or costs associated with authorship.
|
inlinestatic |
Evaluates a polynomial at the value x
.
x | the value at which to evaluate the polynomial. |
it | an iterator to the first coefficient of the polynomial. The first value is the constant, the second is the linear term, the \(i\)th term applies to the \(x^i\) term. The order of the polynomial is implicitly determined by the distance between begin and end . Typically container.begin() . |
end | the past-the-end iterator at which to stop evaluating the polynomial. Typically container.end() . |
|
inlinestatic |
Evaluates a polynomial at the value x
.
This is simply a shortcut for calling evalPolynomial(x, cont.begin(), cont.end())
for containers with an stl-like container interface.
double creativity::Creativity::meanInitialQuality | ( | ) | const |
Returns the mean quality of books created with initial parameter distributions.
With effort levels distributed \(\ell \sim U[l,L]\), and creation_scale distributed \(\alpha \sim U[a,A]\), the expected value of the mean quality will be, since the two distributions are independent, \(E[\alpha]E[Q(\ell)] = \frac{A-a}{2} E[Q(\ell)]\), where \(Q(\ell)\) is the quality function not including the creation_scale multiplier.
Integrating the quality function \(q(\ell) = \alpha \frac{(\ell+1)^\beta - 1}{\beta}\) over the uniform range \([l,L]\) yields:
\[ E[Q(\ell)] = \frac{1}{L-l} \frac{1}{\beta} \left[\frac{(x+1)^{\beta+1}}{\beta+1} - x\right]_{x=l}^{L} \]
for \(\beta \neq 0\) and
\[ E[Q(\ell)] = \frac{1}{L-l} \left[x \log(x+1) - x + \log(x+1)\right]_{x=l}^{L} \]
for the log version when \(\beta = 0\). Multiplying these expressions by \(\frac{1}{2}(A-a)\) gives the expected quality value of a book.
Note that this function implicitly assumes that all readers' creation_scale and creation_shape parameters remain set to the values as dictated by the current parameters
values.
std::pair<std::vector<eris::SharedMember<Book> >&, std::unique_lock<std::mutex> > creativity::Creativity::newBooks | ( | ) |
Establishes a lock on the new books storage and returns a pair consisting of the new books reference and a unique lock on the books.
For optimal performance, store the returned value in the smallest scope practical.
.first
set to a reference to the new book vector and .second
set to the established lock. bool creativity::Creativity::piracy | ( | ) | const |
Returns true if piracy exists yet in the simulation.
Attempting to call this on a Creativity object that is not a live simulation, or is a live simulation but has not been set up yet, will raise an exception.
bool creativity::Creativity::policyActive | ( | ) | const |
Returns true if a policy response exists yet in the simulation.
This must only be called on a live, setup simulation.
This returns false if the policy_begins
period has not yet been reached, or if there is no policy response configured at all.
double creativity::Creativity::policyTaxes | ( | ) | const |
Returns the per-user policies taxes currently in effect.
Before the policy comes into effect, this is 0; afterwards, it is whatever is the sum of the taxes of whichever policies are enabled.
double creativity::Creativity::priorWeight | ( | ) | const |
Returns the prior multiplier currently in effect.
This is CreativitySettings.prior_scale except in the first piracy period, during which it is CreativitySettings.prior_scale_piracy, and in the initial burnin periods, during which it is CreativitySettings.prior_scale_burnin.
bool creativity::Creativity::publicSharingActive | ( | ) | const |
Returns true if public sharing is an enabled policy response and it is active in the simulation (i.e.
the simulation has reached the period in which the policy response begins). Attempting to call this on a Creativity object that is not a live simulation, or is a live simulation but has not been set up yet, will raise an exception.
bool creativity::Creativity::publicVotingActive | ( | ) | const |
Returns true if public sharing with voting is an enabled policy response and it is active in the simulation (i.e.
the simulation has reached the period in which the policy response begins). Attempting to call this on a Creativity object that is not a live simulation, or is a live simulation but has not been set up yet, will raise an exception.
|
inline |
Opens a creativity simulation storage source for reading via storage().
Typically called instead of setup() when loading an existing creativity simulation record from a stored location.
This method cannot be combined with a call to setup(): while that method is used to create a live simulation, this one reads a prior one.
void creativity::Creativity::run | ( | ) |
Runs one iteration of the simulation.
This calls simulation()->run(), but also takes care of other details (such as setting up the piracy network at the right time, creating a public tracker agent when appropriate, and updating stored simulation state data).
CreativitySettings& creativity::Creativity::set | ( | ) |
Provides writeable access to the parameters used to configure the simulation.
This method may only be called before setup() or fileRead(); attempting to call it afterwards will raise an exception.
void creativity::Creativity::setup | ( | ) |
Creates the Simulation object and adds the configured number of readers plus some base members (such as the common money good).
After calling this method, the simulation will be available in .sim
.
std::domain_error | (via checkParameters()) if any parameters are invalid. |
std::pair<std::shared_ptr<state::Storage>&, std::unique_lock<std::mutex> > creativity::Creativity::storage | ( | ) |
Establishes a lock on the storage object and returns a pair consisting of the storage object and the unique lock on the object.
For optimal performance, store the returned value in the smallest scope practical.
.first
set to a reference to the storage shared_ptr and .second
set to the established lock.
|
inline |
Creates a new Storage object with any type of StorageBackend class.
Writes any existing and any new data to the new Storage object.
Any existing simulation states are copied from the current Storage object, then the existing Storage object is released (and destroyed, unless something else has copied its shared_ptr). After calling this method, .storage
will be set to the new FileStorage object.
unsigned long creativity::Creativity::market_books {0} |
Stores the number of on-market books.
This is updated at the beginning of every new simulation stage (in inter-begin) with the number of on-market books in the just-ended period.
double creativity::Creativity::market_books_avg {0.0} |
Stores the average number of on-market books over the past creation_time + 1
periods.
This is updated at the same time as market_books.
const CreativitySettings& creativity::Creativity::parameters {set_} |
std::shared_ptr<eris::Simulation> creativity::Creativity::sim |
The simulation object.
Will be emtpy until setup() is called.