creativity  v1.3.0
Agent-based model of creativity and piracy
Demand.hpp
1 #pragma once
2 #include <eris/learning/BayesianLinearRestricted.hpp>
3 #include <eris/SharedMember.hpp>
4 #include <Eigen/Core>
5 #include <string>
6 #include <utility>
7 
8 namespace creativity { class Book; }
9 
10 namespace creativity { namespace belief {
11 
36 class Demand : public eris::learning::BayesianLinearRestricted {
37  public:
44 
52  template <typename ...Args>
53  explicit Demand(Args &&...args) : BayesianLinearRestricted(std::forward<Args>(args)...)
54  {
55  // Add restrictions:
56  restrict(1) <= -0.05; // beta_price <= 0 (higher price <-> lower quantity)
57  restrict(2) >= 0.0; // beta_q >= 0
58  restrict(4) <= -1.0; // beta_{nosales_periods} <= 0
59 // restrict(7) <= 0.0; // beta_{age} <= 0
60 // restrict(9) <= 0.0; // beta_{market_size} <= 0
61 
62  // Set beta names for nicer output
63  names({"const", "price", "quality", /*u8"quality²",*/ "prevSales", "noSales"});//, "I(new)", "age", "otherBooks", "marketBooks"});
64  }
65 
67  static unsigned int parameters() { return 5; }
68 
70  virtual unsigned int fixedModelSize() const override;
71 
87  double predict(unsigned int draws, double P, double q, unsigned int S, unsigned int nosales, unsigned int age, unsigned int otherBooks, unsigned int lag_marketBooks);
88 
89  using BayesianLinearRestricted::predict;
90 
104  static Eigen::RowVectorXd row(double P, double q, unsigned S, unsigned nosales, unsigned age, unsigned otherBooks, unsigned lag_marketBooks);
105 
146  std::pair<double, double> argmaxP(unsigned int draws, double q, unsigned int s, unsigned int z, unsigned int n, unsigned int nosales, unsigned int age, unsigned int otherBooks, unsigned int marketBooks, double c, double max_price);
147 
156  static Eigen::RowVectorXd bookRow(eris::SharedMember<Book> book, double quality, unsigned int lag_market_books);
157 
159  virtual std::string display_name() const override { return "Demand"; }
160 };
161 
162 }}
Primary namespace for all Creativity library code.
Definition: config.hpp:4
std::pair< double, double > argmaxP(unsigned int draws, double q, unsigned int s, unsigned int z, unsigned int n, unsigned int nosales, unsigned int age, unsigned int otherBooks, unsigned int marketBooks, double c, double max_price)
Given a set of model parameters (other than ) and a per-unit cost this returns the value that maximi...
This class represents an author&#39;s belief about the per-period demand for books.
Definition: Demand.hpp:36
Definition: Variable.hpp:389
Demand(Args &&...args)
Constructs a demand model with the given prior information.
Definition: Demand.hpp:53
static Eigen::RowVectorXd row(double P, double q, unsigned S, unsigned nosales, unsigned age, unsigned otherBooks, unsigned lag_marketBooks)
Given various information about a book, returns an X matrix row of data representing that information...
static Eigen::RowVectorXd bookRow(eris::SharedMember< Book > book, double quality, unsigned int lag_market_books)
Given a book and perceived quality, this builds an X matrix row of data representing that book...
Demand()
Default constructor: note that unlike a default-constructed BayesianLinear model, this default constr...
Definition: Demand.hpp:43
virtual unsigned int fixedModelSize() const override
This model always has exactly parameters() parameters.
double predict(unsigned int draws, double P, double q, unsigned int S, unsigned int nosales, unsigned int age, unsigned int otherBooks, unsigned int lag_marketBooks)
Given a set of model parameters, this returns an expected value , the number of sales.
virtual std::string display_name() const override
Returns "Demand", the name of this model.
Definition: Demand.hpp:159
static unsigned int parameters()
Returns the number of parameters of this model (5)
Definition: Demand.hpp:67