23 #include "foreach.hpp"
41 const double brange =
max -
min;
42 const double srange = to.
max - to.
min;
44 if(brange < FSMALL || srange < FSMALL)
46 return (to.
max + to.
min) * 2;
50 const double x = (value -
min) / brange;
51 return x * srange + to.
min;
68 const SInfo &i2 = other.at(n);
77 out << size() << std::endl;
81 out << at(b).min <<
"\t" << at(b).max << std::endl;
92 inp >> at(i).min >> at(i).max;
98 inp.open(path.c_str());
103 inp.imbue(std::locale(
"C"));
126 :
std::vector<
Row>(rows,
Row(cols)), n_total(cols)
135 a[c] = st[r * cols + c];
140 :
std::vector<
Row>(rows,
Row(cols)), n_total(cols)
149 a[c] = row[r * cols + c];
159 new_data.reserve(size());
168 new_data.
to.push_back(
to[i]);
173 foreach(i, 0, size())
179 r.push_back(at(i)[j]);
181 new_data.push_back(r);
189 random_shuffle(begin(), end());
194 const int n_rows = last - first;
201 for(
int i = 0; i < n_rows; ++i)
202 new_data[i] = at(first + i);
219 inp.open(path.c_str());
224 inp.imbue(std::locale(
"C"));
229 from.resize(n_total);
232 if(n_rows < 1 || n_total < 2)
238 reserve(size() + n_rows);
240 foreach(r, 0, n_rows)
244 foreach(i, 0, n_total)
257 out.open(path.c_str());
262 out.imbue(std::locale(
"C"));
264 out << size() <<
" " <<
n_total << std::endl;
267 foreach(r, 0, size())
270 out << at(r)[i] <<
" ";
280 out.open(path.c_str());
285 out.imbue(std::locale(
"C"));
300 double min = at(0)[n], max = at(0)[n];
302 foreach(p, 1, size())
320 foreach(p, 0, size())
321 at(p)[n] = curv.
scale(newv, at(p)[n]);
347 foreach(r, 0, size())
void k_fold(unsigned n, unsigned k, Data &p, Data &l) const
Fills two Data objects with complementary information, useful for cross-validation.
void scale_column(unsigned n, const SInfo &curv, const SInfo &newv)
Scales a single data column.
Bounds from
Original data bounds.
thrown when a file couldn't be opened
Bounds & calc_bounds()
Calculates and sets the data bounds using the minimum and maximum values of each neuron.
Data sample(unsigned first, unsigned last) const
Samples the data.
void merge_with(const Bounds &other)
Merges the values from another Bounds with the current, retaining the limits.
void load_file(std::ifstream &inp)
Reads the scaling information from a file stream.
const unsigned file_precision
Precision used when writting floating point number to files.
Minimum / maximum scaling information.
void save_file(const std::string &path) const
Erases the contents of a file and saves the Data values into it.
void scale()
Scales the data, neuron per neuron, using the current from and to bounds.
size_t n_total
Number of inputs + outputs per row.
thrown when calling a function with invalid parameters
Bounds to
Scaled data bounds.
Data scaling information, for all input and output neurons.
double scale(const SInfo &to, double value) const
void save_file(std::ofstream &out) const
Appends the data bounds values into a file stream.
The exception can be identified by the type() method.
void save_info_file(const std::string &path) const
Erases the contents of a file and saves the Data bounds info into it.
std::vector< double > Row
Data row.
Data used in training, validation and testing.
thrown when a file has invalid contents
void descale()
Descales the data.
unsigned load_file(const std::string &path)
Reads values from a file and appends then into the data.
void shuffle()
Randomizes the positions of the rows.
Data drop_column(unsigned col) const
Returns a copy of the current object, without a column.
Row & add()
Adds a row to the data, returning a reference to it.