diff --git a/src/DataSet/DataSet.cpp.orig b/src/DataSet/DataSet.cpp.orig deleted file mode 100644 index 374d13ff3477becb0303e230efad2873e787073d..0000000000000000000000000000000000000000 --- a/src/DataSet/DataSet.cpp.orig +++ /dev/null @@ -1,205 +0,0 @@ -// -// Created by martin on 7/13/18. -// - - -#include "DataSetSerialization.h" - -namespace lib4neuro { - - DataSet::DataSet(std::string file_path) { - std::ifstream ifs(file_path); - boost::archive::text_iarchive ia(ifs); - ia >> *this; - ifs.close(); - } -<<<<<<< HEAD -======= - - DataSet::DataSet() { - - } ->>>>>>> 5fd0f3dcf535edfc3e3f4dd7b4cb256f2e95e8fe - - DataSet::DataSet(std::vector<std::pair<std::vector<double>, std::vector<double>>> *data_ptr) { - this->n_elements = data_ptr->size(); - this->data = *data_ptr; - - this->input_dim = this->data[0].first.size(); - this->output_dim = this->data[0].second.size(); - - //TODO check the complete data set for input/output dimensions - } - - DataSet::DataSet(double lower_bound, double upper_bound, unsigned int size, double output) { - std::vector<std::pair<std::vector<double>, std::vector<double>>> new_data_vec; - this->data = new_data_vec; - this->n_elements = 0; - this->input_dim = 1; - this->output_dim = 1; - - this->add_isotropic_data(lower_bound, upper_bound, size, output); - } - - DataSet::DataSet(std::vector<double> &bounds, unsigned int no_elems_in_one_dim, - std::vector<double> (*output_func)(std::vector<double> &), unsigned int output_dim) { - std::vector<std::pair<std::vector<double>, std::vector<double>>> new_data_vec; - this->data = new_data_vec; - this->input_dim = bounds.size() / 2; - this->output_dim = output_dim; - this->n_elements = 0; - - this->add_isotropic_data(bounds, no_elems_in_one_dim, output_func); - } - - - void DataSet::add_data_pair(std::vector<double> &inputs, std::vector<double> &outputs) { - if (inputs.size() != this->input_dim) { - throw InvalidDimension("Bad input dimension."); - } else if (outputs.size() != this->output_dim) { - throw InvalidDimension("Bad output dimension."); - } - - this->n_elements++; - this->data.emplace_back(std::make_pair(inputs, outputs)); - } - - void DataSet::add_isotropic_data(double lower_bound, double upper_bound, unsigned int size, double output) { - if (this->input_dim != 1 || this->output_dim != 1) { - throw InvalidDimension("Cannot add data with dimensionality 1:1 when the data set " - "is of different dimensionality!"); - } - - double frac = (upper_bound - lower_bound) / (size - 1); - std::vector<double> inp, out; - - out = {output}; - - for (unsigned int i = 0; i < size; ++i) { - inp = {frac * i}; - this->data.emplace_back(std::make_pair(inp, out)); - } - - this->n_elements += size; - } - - void DataSet::add_isotropic_data(std::vector<double> &bounds, unsigned int no_elems_in_one_dim, - std::vector<double> (*output_func)(std::vector<double> &)) { - // TODO add check of dataset dimensions - - std::vector<std::vector<double>> grid; - std::vector<double> tmp; - double frac; - - for (unsigned int i = 0; i < bounds.size(); i += 2) { - frac = (bounds[i] + bounds[i + 1]) / (no_elems_in_one_dim - 1); - tmp.clear(); - for (double j = bounds[i]; j <= bounds[i + 1]; j += frac) { - tmp.emplace_back(j); - } - - grid.emplace_back(tmp); - } - - grid = this->cartesian_product(&grid); - - for (auto vec : grid) { - this->n_elements++; - this->data.emplace_back(std::make_pair(vec, output_func(vec))); - } - } - - std::vector<std::pair<std::vector<double>, std::vector<double>>> *DataSet::get_data() { - return &(this->data); - } - - size_t DataSet::get_n_elements() { - return this->n_elements; - } - - size_t DataSet::get_input_dim() { - return this->input_dim; - } - - size_t DataSet::get_output_dim() { - return this->output_dim; - } -<<<<<<< HEAD - - void DataSet::print_data() { - if (n_elements) { - for (auto p : this->data) { - /* INPUT */ - for (auto v : std::get<0>(p)) { - std::cout << v << " "; - } - - std::cout << "-> "; - - /* OUTPUT */ - for (auto v : std::get<1>(p)) { - std::cout << v << " "; - } - -======= - - void DataSet::print_data() { - if (n_elements) { - for (auto p : this->data) { - /* INPUT */ - for (auto v : std::get<0>(p)) { - std::cout << v << " "; - } - - std::cout << "-> "; - - /* OUTPUT */ - for (auto v : std::get<1>(p)) { - std::cout << v << " "; - } - ->>>>>>> 5fd0f3dcf535edfc3e3f4dd7b4cb256f2e95e8fe - std::cout << std::endl; - } - } - } - - void DataSet::store_text(std::string &file_path) { - //TODO check if stream was successfully opened - std::ofstream ofs(file_path); - boost::archive::text_oarchive oa(ofs); - oa << *this; - ofs.close(); - } - - template<class T> - std::vector<std::vector<T>> DataSet::cartesian_product(const std::vector<std::vector<T>> *v) { - std::vector<std::vector<double>> v_combined_old, v_combined, v_tmp; - std::vector<double> tmp; - - for (const auto &e : v->at(0)) { - tmp = {e}; - v_combined.emplace_back(tmp); - } - - for (unsigned int i = 1; i < v->size(); i++) { // Iterate through remaining vectors of 'v' - v_combined_old = v_combined; - v_combined.clear(); - - for (const auto &e : v->at(i)) { - for (const auto &vec : v_combined_old) { - tmp = vec; - tmp.emplace_back(e); - - /* Add only unique elements */ - if (std::find(v_combined.begin(), v_combined.end(), tmp) == v_combined.end()) { - v_combined.emplace_back(tmp); - } - } - } - } - - return v_combined; - } - -} \ No newline at end of file diff --git a/src/DataSet/DataSet.h.orig b/src/DataSet/DataSet.h.orig deleted file mode 100644 index 94eb3ae8bf33729c664259e7ef1af3d682c926c3..0000000000000000000000000000000000000000 --- a/src/DataSet/DataSet.h.orig +++ /dev/null @@ -1,177 +0,0 @@ -// -// Created by martin on 7/13/18. -// - -#ifndef INC_4NEURO_DATASET_H -#define INC_4NEURO_DATASET_H - -#include <iostream> -#include <fstream> -#include <utility> -#include <vector> -#include <string> -#include <functional> - -#include "../settings.h" -#include "../Exception/Exceptions.h" - -namespace lib4neuro { - /** - * Class representing data, which can be used for training - * and testing purposes. - */ - class DataSet { - - private: - - /** - * Number of elements in the data set - */ - size_t n_elements; - - /** - * Dimension of the input - */ - size_t input_dim = 0; - - /** - * Dimension of the output - */ - size_t output_dim = 0; - - /** - * Stored data in the format of pairs of corresponding - * input and output vectors - */ - std::vector<std::pair<std::vector<double>, std::vector<double>>> data; - - template<class T> - std::vector<std::vector<T>> cartesian_product(const std::vector<std::vector<T>> *v); - - public: - - /** - * Struct used to access private properties from - * the serialization function - */ - struct access; - - /** - * Constructor reading data from the file - * @param file_path Path to the file with stored data set - */ - LIB4NEURO_API DataSet(std::string file_path); - -<<<<<<< HEAD -======= - LIB4NEURO_API DataSet(); - ->>>>>>> 5fd0f3dcf535edfc3e3f4dd7b4cb256f2e95e8fe - /** - * Constructor accepting data vector - * @param data_ptr Pointer to the vector containing data - */ - LIB4NEURO_API DataSet(std::vector<std::pair<std::vector<double>, std::vector<double>>> *data_ptr); - - /** - * Creates a new data set with input values equidistantly positioned - * over the certain interval and the output value - * being constant - * - * Both input and output are 1-dimensional - * - * @todo add bounds as vectors for multi-dimensional data-sets - * - * @param lower_bound Lower bound of the input data interval - * @param upper_bound Upper bound of the input data interval - * @param size Number of input-output pairs generated - * @param output Constant output value - */ - LIB4NEURO_API DataSet(double lower_bound, double upper_bound, unsigned int size, double output); - - /** - * - * @param bounds - * @param no_elems_in_one_dim - * @param output_func - * @param output_dim - */ - LIB4NEURO_API DataSet(std::vector<double> &bounds, unsigned int no_elems_in_one_dim, - std::vector<double> (*output_func)(std::vector<double> &), unsigned int output_dim); - - /** - * Getter for number of elements - * @return Number of elements in the data set - */ - LIB4NEURO_API size_t get_n_elements(); - - /** - * Returns the input dimension - * @return Input dimension - */ - LIB4NEURO_API size_t get_input_dim(); - - - /** - * Return the output dimension - * @return Output dimension - */ - LIB4NEURO_API size_t get_output_dim(); - - /** - * Getter for the data structure - * @return Vector of data - */ - LIB4NEURO_API std::vector<std::pair<std::vector<double>, std::vector<double>>> *get_data(); - - /** - * Adds a new pair of data to the data set - * @param inputs Vector of input data - * @param outputs Vector of output data corresponding to the input data - */ - LIB4NEURO_API void add_data_pair(std::vector<double> &inputs, std::vector<double> &outputs); - - //TODO expand method to generate multiple data types - chebyshev etc. - /** - * Adds a new data with input values equidistantly positioned - * over the certain interval and the output value - * being constant - * - * Both input and output are 1-dimensional - * - * @param lower_bound Lower bound of the input data interval - * @param upper_bound Upper bound of the input data interval - * @param size Number of input-output pairs generated - * @param output Constant output value - */ - LIB4NEURO_API void add_isotropic_data(double lower_bound, double upper_bound, unsigned int size, double output); - - /** - * Adds a new data with input values equidistantly positioned - * over the certain interval and the output value - * being constant - * - * Input can have arbitrary many dimensions, - * output can be an arbitrary function - * - * @param bounds Odd values are lower bounds and even values are corresponding upper bounds - * @param size Number of input-output pairs generated - * @param output_func Function determining output value - */ - LIB4NEURO_API void add_isotropic_data(std::vector<double> &bounds, unsigned int no_elems_in_one_dim, - std::vector<double> (*output_func)(std::vector<double> &)); - - //TODO Chebyshev - ch. interpolation points, i-th point = cos(i*alpha) from 0 to pi - - /** - * Prints the data set - */ - LIB4NEURO_API void print_data(); - - /** - * Stores the DataSet object to the binary file - */ - LIB4NEURO_API void store_text(std::string &file_path); - }; -} -#endif //INC_4NEURO_DATASET_H