40 const double brange =
max -
min;
41 const double srange = to.
max - to.
min;
43 if(brange < FSMALL || srange < FSMALL)
45 return (to.
max + to.
min) * 2;
49 const double x = (value -
min) / brange;
50 return x * srange + to.
min;
64 for(
unsigned n = 0, e = size(); n < e; ++n)
67 const SInfo &i2 = other.at(n);
76 out << size() << std::endl;
79 for(
unsigned b = 0, e = size(); b < e; ++b)
80 out << at(b).min <<
"\t" << at(b).max << std::endl;
90 for(
unsigned i = 0; i < n; ++i)
91 inp >> at(i).min >> at(i).max;
97 inp.open(path.c_str());
102 inp.imbue(std::locale(
"C"));
125 :
std::vector<
Row>(rows,
Row(cols)), n_total(cols)
130 for(
unsigned r = 0; r < rows; ++r)
134 for(
unsigned c = 0; c < cols; ++c)
135 a[c] = st[r * cols + c];
140 :
std::vector<
Row>(rows,
Row(cols)), n_total(cols)
145 for(
unsigned r = 0; r < rows; ++r)
149 for(
unsigned c = 0; c < cols; ++c)
150 a[c] = row[r * cols + c];
160 new_data.reserve(size());
164 for(
unsigned i = 0; i <
n_total; ++i)
169 new_data.
to.push_back(
to[i]);
174 for(
unsigned i = 0, e = size(); i < e; ++i)
178 for(
unsigned j = 0; j <
n_total; ++j)
181 r.push_back(at(i)[j]);
183 new_data.push_back(r);
191 random_shuffle(begin(), end());
196 const int n_rows = last - first;
203 for(
int i = 0; i < n_rows; ++i)
204 new_data[i] = at(first + i);
221 inp.open(path.c_str());
226 inp.imbue(std::locale(
"C"));
231 from.resize(n_total);
234 if(n_rows < 1 || n_total < 2)
240 reserve(size() + n_rows);
242 for(
unsigned r = 0; r < n_rows; ++r)
246 for(
unsigned i = 0; i <
n_total; ++i)
259 out.open(path.c_str());
264 out.imbue(std::locale(
"C"));
266 out << size() <<
" " <<
n_total << std::endl;
269 for(
unsigned r = 0, e = size(); r < e; ++r)
271 for(
unsigned i = 0; i <
n_total; ++i)
272 out << at(r)[i] <<
" ";
283 out.open(path.c_str());
288 out.imbue(std::locale(
"C"));
301 for(
unsigned n = 0; n <
n_total; ++n)
303 double min = at(0)[n], max = at(0)[n];
305 for(
unsigned p = 1, e = size(); p < e; ++p)
307 const double v = at(p)[n];
323 for(
unsigned p = 0, e = size(); p < e; ++p)
324 at(p)[n] = curv.
scale(newv, at(p)[n]);
329 for(
unsigned c = 0; c <
n_total; ++c)
335 for(
unsigned c = 0; c <
n_total; ++c)
344 for(
unsigned c = 0; c <
n_total; ++c)
350 for(
unsigned r = 0, e = size(); r < e; ++r)
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.