creativity  v1.3.0
Agent-based model of creativity and piracy
Profit.hpp
1 #pragma once
2 #include <eris/learning/BayesianLinear.hpp>
3 #include <eris/learning/BayesianLinearRestricted.hpp>
4 #include <Eigen/Core>
5 #include <algorithm>
6 #include <functional>
7 #include <string>
8 
9 namespace creativity { namespace belief {
10 
33 class Profit : public eris::learning::BayesianLinearRestricted {
34  public:
40 
47  template <typename ...Args>
48  explicit Profit(Args &&...args) : BayesianLinearRestricted(std::forward<Args>(args)...)
49  {
50  // Add restrictions:
51  //restrict(1) >= 0; // beta_q >= 0 (higher quality <-> higher profits, at least for low quality)
52  //restrict(2) <= 0; // beta_{q^2} <= 0 (quality effect is concave)
53  //restrict(3) <= 0; // beta_{marketbooks} <= 0 (more competition <-> lower profit)
54 
55  // Set beta names for nicer output
56  names({"const", "quality", u8"quality²", "marketBooks"});
57  }
58 
60  static unsigned int parameters() { return 4; }
61 
63  virtual unsigned int fixedModelSize() const override;
64 
74  double predict(unsigned int draws, double q, unsigned long previousBooks, unsigned long marketBooks);
75 
76  using BayesianLinearRestricted::predict;
77 
103  std::pair<double, double> argmaxL(
104  unsigned int draws,
105  const std::function<double(const double &)> q,
106  unsigned long previousBooks, unsigned long marketBooks,
107  double l_min,
108  double l_max
109  );
110 
126  static Eigen::RowVectorXd profitRow(double quality, int previous_books, int avg_market_books);
127 
129  virtual std::string display_name() const override { return "Profit"; }
130 };
131 
132 }}
double predict(unsigned int draws, double q, unsigned long previousBooks, unsigned long marketBooks)
Given a set of model parameters, this returns an expected value , the lifetime profit of the book...
std::pair< double, double > argmaxL(unsigned int draws, const std::function< double(const double &)> q, unsigned long previousBooks, unsigned long marketBooks, double l_min, double l_max)
Given previousBooks and marketBooks parameters, a function that returns expected quality for a given...
Primary namespace for all Creativity library code.
Definition: config.hpp:4
virtual unsigned int fixedModelSize() const override
Returns parameters()
Definition: Variable.hpp:389
virtual std::string display_name() const override
Returns "Profit", the name of this model.
Definition: Profit.hpp:129
Profit()
Construct a noninformative profit model.
Definition: Profit.hpp:39
static Eigen::RowVectorXd profitRow(double quality, int previous_books, int avg_market_books)
Builds an X matrix row of profit data for a book.
This class represents an author&#39;s belief about the lifetime profitability of a work.
Definition: Profit.hpp:33
Profit(Args &&...args)
Constructs a profit model with the given parameter information.
Definition: Profit.hpp:48
static unsigned int parameters()
Returns the number of parameters of this model (4)
Definition: Profit.hpp:60