24 readCSV(inputStream, instanceVectors);
28 void readCSV(istream &inputStream, vector< vector<double> > &instanceVectors) {
30 while (getline(inputStream, strLine))
31 instanceVectors.push_back(readCSVLine(strLine));
32 if (!allRowsEqualLength(instanceVectors))
33 throw invalid_argument(
string(
typeid(*this).name()) +
string(
": rows are not of equal length."));
38 stringstream strLineStream(strLine);
40 vector<double> lineVector;
42 while (getline(strLineStream, doubleString,
',')) {
50 if (instanceVectors.size() == 0)
52 const unsigned int numParametersPerInstance = instanceVectors[0].size();
53 for (
unsigned int i = 1; i < instanceVectors.size(); i++)
54 if (instanceVectors[i].size() != numParametersPerInstance)
59 vector<double>
getInstance(
const unsigned int instance)
const {
60 assert(instance < getNumInstances());
61 return instanceVectors[instance];
64 double getParameter(
const unsigned int instance,
const unsigned int parameter)
const {
65 assert(instance < getNumInstances());
66 assert(parameter < getNumParameters());
67 return instanceVectors[instance][parameter];
71 return instanceVectors.size();
75 if (0 == getNumInstances())
77 return instanceVectors[0].size();
81 return allRowsEqualLength(instanceVectors);
vector< double > readCSVLine(const string &strLine)
void readCSV(istream &inputStream, vector< vector< double > > &instanceVectors)
ParameterInstancesImpl(istream &inputStream)
std::vector< double > getInstance(const unsigned int instance) const
unsigned int getNumInstances() const
double getParameter(const unsigned int instance, const unsigned int parameter) const
vector< double > getInstance(const unsigned int instance) const
static bool allRowsEqualLength(const vector< vector< double > > &instanceVectors)
unsigned int getNumParameters() const
ParameterInstances(std::istream &inputStream)
double stringToDouble(const string &str)
double getParameter(const unsigned int instance, const unsigned int parameter) const
unsigned int getNumInstances() const
unsigned int getNumParameters() const
vector< vector< double > > instanceVectors