2 #include <creativity/data/CSVParser.hpp> 3 #include <creativity/data/Variable.hpp> 23 explicit Treatment(
const std::string &filename);
90 const Eigen::MatrixXd&
data()
const {
return data_; }
106 const std::unordered_map<std::string, unsigned>&
columns()
const;
116 std::shared_ptr<const SimpleVariable>
variable(
const std::string &name)
const;
119 std::shared_ptr<const SimpleVariable>
operator[](
const std::string &name)
const {
return variable(name); }
142 mutable std::unordered_map<std::string, std::shared_ptr<SimpleVariable>>
var_cache_;
152 Eigen::Ref<Eigen::RowVectorXd, 0, Eigen::InnerStride<>> newrow,
153 const std::string &prefix)
const;
const Eigen::MatrixXd & data() const
The full set of data.
Definition: Treatment.hpp:90
std::shared_ptr< const SimpleVariable > variable(const std::string &name) const
Returns a shared_ptr to a SimpleVariable containing a copy of the requested column.
bool require_piracy_
True if piracy data is required.
Definition: Treatment.hpp:132
Primary namespace for all Creativity library code.
Definition: config.hpp:4
unsigned int rows_per_sim_
The number of treatment row observations per source data rows (i.e. per simulation) ...
Definition: Treatment.hpp:136
const bool & hasPiracySR() const
True if the source data has short-run piracy data.
Definition: Treatment.hpp:67
const bool & hasPolicySR() const
True if the source data has short-run policy data.
Definition: Treatment.hpp:70
const bool & hasPre() const
True if this treatment data pre-piracy observations.
Definition: Treatment.hpp:58
const std::unordered_map< std::string, unsigned > & columns() const
Accesses the map of field name to column indices.
bool have_data_
True once we've parsed a data file.
Definition: Treatment.hpp:125
bool has_pre_
True if the data contains pre-piracy, non-treatment rows.
Definition: Treatment.hpp:126
void requireSR(bool require=true)
Requires short-run data for long-run piracy/policy data that exists in the source data...
void generateRow(const CSVParser &csv, Eigen::Ref< Eigen::RowVectorXd, 0, Eigen::InnerStride<>> newrow, const std::string &prefix) const
Generates a row of data from the CSVParser at its current position.
Treatment()=default
Default constructor.
void requirePolicy(bool require=true)
Like requirePiracy(), but for policy data.
bool require_policy_
True if policy data is required.
Definition: Treatment.hpp:133
std::shared_ptr< const SimpleVariable > operator[](const std::string &name) const
Alias for variable()
Definition: Treatment.hpp:119
bool has_policy_sr_
True if the data contains SR policy treatment rows.
Definition: Treatment.hpp:130
bool has_piracy_sr_
True if the data contains SR piracy treatment rows.
Definition: Treatment.hpp:128
void readCSV(CSVParser &&csv)
Reads the data from the given CSVParser.
const std::vector< std::string > & sourceFiles() const
The simulation source values.
Definition: Treatment.hpp:95
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.
Definition: Treatment.hpp:14
Eigen::MatrixXd data_
The data matrix.
Definition: Treatment.hpp:122
const bool & hasPolicy() const
True if the source data has policy data.
Definition: Treatment.hpp:64
unsigned int simulations() const
The number of simulation files contributing to this data: this is simply an alias for obj...
Definition: Treatment.hpp:84
bool require_sr_
True if short-run data is required for each type of long-run data.
Definition: Treatment.hpp:134
const unsigned int & rowsPerSimulation() const
The number of data rows per simulation input. This equals 1 plus the number of treatments.
Definition: Treatment.hpp:79
const std::string & sourceFile(unsigned r) const
Return the source file associated with row r.
Definition: Treatment.hpp:100
std::unordered_map< std::string, std::shared_ptr< SimpleVariable > > var_cache_
Cache of weak pointers to returned SimpleVariables.
Definition: Treatment.hpp:142
void requirePre(bool require=true)
Like requirePiracy(), but for pre-piracy data.
std::vector< std::string > source_
In-order source values for data.
Definition: Treatment.hpp:123
const bool & hasPiracy() const
True if the source data has piracy data.
Definition: Treatment.hpp:61
bool has_policy_
True if the data contains LR policy treatment rows.
Definition: Treatment.hpp:129
bool has_piracy_
True if the data contains LR piracy treatment rows.
Definition: Treatment.hpp:127
bool hasShortrun() const
True if the source data has short-run data for each type of associated long-run data.
Definition: Treatment.hpp:76
Primitive comma-separated-value file parser.
Definition: CSVParser.hpp:32
std::unordered_map< std::string, unsigned > data_column_
Field name to column map.
Definition: Treatment.hpp:139
bool require_pre_
True if pre data is required.
Definition: Treatment.hpp:131
void requirePiracy(bool require=true)
Requires that the parsed data contain piracy observations.