creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
creativity::Creativity Class Reference

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...
 
CreativitySettingsset ()
 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 CreativitySettingsparameters {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...
 

Detailed Description

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.

Constructor & Destructor Documentation

§ Creativity()

creativity::Creativity::Creativity ( )
default

Default constructor.

Member Function Documentation

§ boundaryFromDensity()

static double creativity::Creativity::boundaryFromDensity ( uint32_t  readers,
uint32_t  dimensions,
double  density 
)
static

Static method that calculates a boundary given a number of readers, dimensions, and a desired density.

Exceptions
std::logic_errorif any of the parameters are <= 0.

§ catchPiratesActive()

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.

§ checkParameters()

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.

Exceptions
std::domain_errorif any of the values in .parameters are invalid.

§ createPiracyNetwork()

void creativity::Creativity::createPiracyNetwork ( )
protected

Sets up the piracy network.

Called automatically by run() just before the piracy_begins period.

§ densityFromBoundary()

static double creativity::Creativity::densityFromBoundary ( uint32_t  readers,
uint32_t  dimensions,
double  boundary 
)
static

Static method that calculates a density given a number of readers, dimensions, and a desired boundary location.

Exceptions
std::logic_errorif any of the parameters are <= 0.

§ disposableIncome()

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.

§ evalPolynomial() [1/2]

template<typename Iter , typename = typename std::enable_if<std::is_arithmetic< typename std::iterator_traits<Iter>::value_type>::value>::type>
static double creativity::Creativity::evalPolynomial ( double  x,
Iter  it,
Iter  end 
)
inlinestatic

Evaluates a polynomial at the value x.

Parameters
xthe value at which to evaluate the polynomial.
itan 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().
endthe past-the-end iterator at which to stop evaluating the polynomial. Typically container.end().

§ evalPolynomial() [2/2]

template<typename Container , typename = typename std::enable_if<std::is_arithmetic< typename Container::value_type>::value>::type>
static double creativity::Creativity::evalPolynomial ( double  x,
const Container &  cont 
)
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.

§ meanInitialQuality()

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.

§ newBooks()

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.

Returns
a pair with .first set to a reference to the new book vector and .second set to the established lock.

§ piracy()

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.

§ policyActive()

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.

§ policyTaxes()

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.

Returns
the quantity of the money good that must be surrended.

§ priorWeight()

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.

§ publicSharingActive()

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.

§ publicVotingActive()

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.

§ read()

template<class T , typename... Args>
void creativity::Creativity::read ( Args &&...  args)
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.

§ run()

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).

§ set()

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.

§ setup()

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.

Exceptions
std::domain_error(via checkParameters()) if any parameters are invalid.

§ storage()

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.

Returns
a pair with .first set to a reference to the storage shared_ptr and .second set to the established lock.

§ write()

template<class T , typename... Args>
void creativity::Creativity::write ( Args &&...  args)
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.

Member Data Documentation

§ market_books

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.

§ market_books_avg

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.

§ parameters

const CreativitySettings& creativity::Creativity::parameters {set_}

Simulation parameters that are used to configure the simulation when calling setup().

To adjust these parameters, call set().

§ sim

std::shared_ptr<eris::Simulation> creativity::Creativity::sim

The simulation object.

Will be emtpy until setup() is called.

Inheritance diagram for creativity::Creativity:
[legend]
Collaboration diagram for creativity::Creativity:
[legend]

The documentation for this class was generated from the following file: