41 template <
class T>
class Matrix;
42 template <
class T>
class Tensor;
44 template <
class T> T calculate_random_uniform(
const T&,
const T&);
45 template <
class T> T calculate_random_normal(
const T&,
const T&);
62 explicit Vector(
const size_t &);
64 explicit Vector(
const size_t &,
const T&);
66 explicit Vector(
const string &);
68 explicit Vector(
const T&,
const double &,
const T&);
70 template <
class InputIterator>
explicit Vector(
const InputIterator&,
const InputIterator&);
76 Vector(
const initializer_list<T>&);
88 bool operator == (
const T&)
const;
90 bool operator != (
const T&)
const;
92 bool operator > (
const T&)
const;
94 bool operator < (
const T&)
const;
96 bool operator >= (
const T&)
const;
98 bool operator <= (
const T&)
const;
104 void set(
const size_t &);
106 void set(
const size_t &,
const T&);
108 void set(
const string &);
110 void set(
const T&,
const double &,
const T&);
116 const T& get_first()
const;
117 const T& get_last()
const;
118 const T& get_before_last()
const;
125 void initialize(
const T&);
126 void initialize_first(
const size_t&,
const T&);
128 void initialize_sequential();
130 void randomize_uniform(
const T&,
const T&);
133 void randomize_normal(
const double & = 0.0,
const double & = 1.0);
136 void randomize_binary(
const double & = 0.5,
const double & = 0.5);
150 bool contains(
const T&)
const;
153 bool contains_greater_than(
const T&)
const;
155 bool has_same_elements(
const Vector<T>&)
const;
157 bool is_in(
const T&,
const T&)
const;
159 bool is_constant(
const double & = 0.0)
const;
160 bool is_constant_string()
const;
162 bool is_crescent()
const;
163 bool is_decrescent()
const;
165 bool is_binary()
const;
166 bool is_binary_missing_values()
const;
167 bool is_binary_0_1()
const;
169 bool is_integer()
const;
170 bool is_integer_missing_values()
const;
172 bool is_positive()
const;
173 bool is_negative()
const;
175 bool check_period(
const double& period)
const;
177 bool has_nan()
const;
183 void replace_value(
const T&,
const T&);
187 size_t count_equal_to(
const T&)
const;
188 size_t count_equal_to(
const Vector<T>&)
const;
190 size_t count_NAN()
const;
191 size_t count_not_NAN()
const;
193 size_t count_not_equal_to(
const T&)
const;
194 size_t count_not_equal_to(
const Vector<T>&)
const;
196 size_t count_positive()
const;
197 size_t count_negative()
const;
199 size_t count_integers(
const size_t&)
const;
200 size_t count_integers_missing_values(
const size_t&)
const;
202 size_t count_greater_than(
const T&)
const;
203 size_t count_less_than(
const T&)
const;
204 size_t count_greater_equal_to(
const T&)
const;
206 size_t count_less_equal_to(
const T&)
const;
208 size_t count_between(
const T&,
const T&)
const;
210 size_t count_contains(
const string&)
const;
216 size_t get_first_index(
const T&)
const;
234 Vector<T> merge(
const string&,
const char&)
const;
236 Vector< Matrix<T> > to_vector_matrix(
const size_t&,
const size_t&,
const size_t&)
const;
240 Vector<T> filter_equal_to(
const T&)
const;
241 Vector<T> filter_not_equal_to(
const T&)
const;
249 Vector<T> filter_minimum_maximum(
const T&,
const T&)
const;
251 Vector<double> perform_Box_Cox_transformation(
const double& = 1)
const;
258 size_t calculate_cumulative_index(
const T&)
const;
260 T calculate_sum()
const;
264 T calculate_sum_missing_values()
const;
266 T calculate_product()
const;
274 Vector<T> calculate_lower_values(
const size_t&)
const;
277 Vector<T> sort_descending_values()
const;
286 inline Vector<T> operator = (
const initializer_list<T>&)
const;
288 inline Vector<T> operator + (
const T&)
const;
292 inline Vector<T> operator - (
const T&)
const;
296 inline Vector<T> operator * (
const T&)
const;
306 void operator += (
const T&);
310 void operator -= (
const T&);
314 void operator *= (
const T&);
318 void operator /= (
const T&);
327 Vector<T> get_subvector(
const size_t&,
const size_t&)
const;
333 Vector<T> get_subvector_random(
const size_t&)
const;
335 Vector<T> get_first(
const size_t &)
const;
337 Vector<T> get_last(
const size_t &)
const;
339 Vector<T> delete_first(
const size_t &)
const;
341 Vector<T> delete_last(
const size_t &)
const;
343 Vector<T> get_integer_elements(
const size_t&)
const;
344 Vector<T> get_integer_elements_missing_values(
const size_t&)
const;
348 void load(
const string &);
350 void save(
const string &,
const char& =
' ')
const;
352 void embed(
const size_t &,
const Vector<T>&);
356 Vector<T> insert_element(
const size_t &,
const T&)
const;
358 Vector<T> delete_index(
const size_t &)
const;
374 void print_unique_string()
const;
375 void print_unique_number()
const;
377 Vector<T> calculate_top_string(
const size_t&)
const;
378 Vector<T> calculate_top_number(
const size_t&)
const;
380 void print_top_string(
const size_t&)
const;
382 vector<T> to_std_vector()
const;
406 void parse(
const string &);
408 string to_text(
const char& =
',')
const;
409 string to_text(
const string& =
",")
const;
411 string vector_to_string(
const char&,
const char&)
const;
412 string vector_to_string(
const char&)
const;
413 string vector_to_string()
const;
415 string stack_vector_to_string()
const;
419 Matrix<T> to_matrix(
const size_t &,
const size_t &)
const;
438 : vector<T>(new_size) {}
449 : vector<T>(new_size, value) {}
474 set(first, step, last);
481 template <
class InputIterator>
482 Vector<T>::Vector(
const InputIterator& first,
const InputIterator& last): vector<T>(first, last) {}
516 const size_t vectors_size = vectors.size();
520 for(
size_t i = 0; i < vectors_size; i++)
522 new_size += vectors[i].size();
529 for(
size_t i = 0; i < vectors_size; i++)
531 for(
size_t j = 0; j < vectors[i].size(); j++)
533 (*this)[index] = vectors[i][j];
551 if(other_vector.size() != this->size())
553 this->resize(other_vector.size());
556 copy(other_vector.begin(), other_vector.end(), this->begin());
568 const size_t this_size = this->size();
570 for(
size_t i = 0; i < this_size; i++) {
571 if((*
this)[i] != value) {
586 const size_t this_size = this->size();
588 for(
size_t i = 0; i < this_size; i++) {
589 if((*
this)[i] != value) {
606 const size_t this_size = this->size();
608 for(
size_t i = 0; i < this_size; i++) {
609 if((*
this)[i] <= value) {
626 const size_t this_size = this->size();
628 for(
size_t i = 0; i < this_size; i++) {
629 if((*
this)[i] >= value) {
647 const size_t this_size = this->size();
649 for(
size_t i = 0; i < this_size; i++) {
650 if((*
this)[i] < value) {
668 const size_t this_size = this->size();
670 for(
size_t i = 0; i < this_size; i++) {
671 if((*
this)[i] > value) {
692 this->resize(new_size);
703 this->resize(new_size);
705 initialize(new_value);
728 if(first > last && step > 0) {
730 }
else if(first < last && step < 0) {
733 const size_t new_size = 1 + static_cast<size_t>((last - first) / step + 0.5);
735 this->resize(new_size);
737 for(
size_t i = 0; i < new_size; i++) {
738 (*this)[i] = first + static_cast<T>(i * step);
750 if(other_vector.size() != this->size())
752 this->resize(other_vector.size());
755 copy(other_vector.begin(), other_vector.end(), this->begin());
772 const size_t this_size = this->size();
774 return (*
this)[this_size-1];
782 const size_t this_size = this->size();
784 return (*
this)[this_size-2];
794 const size_t new_size = this->size() - elements_number;
796 return get_last(new_size);
806 const size_t new_size = this->size() - elements_number;
808 return get_first(new_size);
818 fill(this->begin(),this->end(), value);
828 for(
size_t i = 0; i < first; i++) (*
this)[i] = value;
835 for(
size_t i = 0; i < this->size(); i++) {
836 (*this)[i] = static_cast<T>(i);
852 #ifdef __OPENNN_DEBUG__
854 if(minimum > maximum) {
855 ostringstream buffer;
857 buffer <<
"OpenNN Exception: Vector Template.\n"
858 <<
"void randomize_uniform(const T&, const T&) method.\n"
859 <<
"Minimum value must be less or equal than maximum value.\n";
861 throw logic_error(buffer.str());
866 const size_t this_size = this->size();
868 for(
size_t i = 0; i < this_size; i++)
870 (*this)[i] = calculate_random_uniform(minimum, maximum);
885 const size_t this_size = this->size();
889 #ifdef __OPENNN_DEBUG__
891 const size_t minimums_size = minimums.size();
892 const size_t maximums_size = maximums.size();
894 if(minimums_size != this_size || maximums_size != this_size) {
895 ostringstream buffer;
897 buffer <<
"OpenNN Exception: Vector Template.\n"
898 <<
"void randomize_uniform(const Vector<T>&, const Vector<T>&) method.\n"
899 <<
"Minimum and maximum sizes must be equal to vector size.\n";
901 throw logic_error(buffer.str());
904 if(minimums > maximums) {
905 ostringstream buffer;
907 buffer <<
"OpenNN Exception: Vector Template.\n"
908 <<
"void randomize_uniform(const Vector<double>&, const "
909 "Vector<double>&) method.\n"
910 <<
"Minimum values must be less or equal than their corresponding "
913 throw logic_error(buffer.str());
918 for(
size_t i = 0; i < this_size; i++)
920 (*this)[i] = calculate_random_uniform(minimums[i], maximums[i]);
933 const double &standard_deviation)
936 #ifdef __OPENNN_DEBUG__
938 if(standard_deviation < 0.0) {
939 ostringstream buffer;
941 buffer <<
"OpenNN Exception: Vector Template.\n"
942 <<
"void randomize_normal(const double&, const double&) method.\n"
943 <<
"Standard deviation must be equal or greater than zero.\n";
945 throw logic_error(buffer.str());
950 const size_t this_size = this->size();
952 for(
size_t i = 0; i < this_size; i++)
954 (*this)[i] = calculate_random_normal(mean, standard_deviation);
968 const size_t this_size = this->size();
970 #ifdef __OPENNN_DEBUG__
972 const size_t mean_size = mean.size();
973 const size_t standard_deviation_size = standard_deviation.size();
975 if(mean_size != this_size || standard_deviation_size != this_size) {
976 ostringstream buffer;
979 <<
"OpenNN Exception: Vector Template.\n"
980 <<
"void randomize_normal(const Vector<double>&, const "
981 "Vector<double>&) method.\n"
982 <<
"Mean and standard deviation sizes must be equal to vector size.\n";
984 throw logic_error(buffer.str());
987 if(standard_deviation < 0.0) {
988 ostringstream buffer;
990 buffer <<
"OpenNN Exception: Vector Template.\n"
991 <<
"void randomize_normal(const Vector<double>&, const "
992 "Vector<double>&) method.\n"
993 <<
"Standard deviations must be equal or greater than zero.\n";
995 throw logic_error(buffer.str());
1000 for(
size_t i = 0; i < this_size; i++) {
1001 (*this)[i] = calculate_random_normal(mean[i], standard_deviation[i]);
1014 const size_t this_size = this->size();
1021 const double total_ratio = abs(negatives_ratio) + positives_ratio;
1025 const size_t positives_number = static_cast<size_t>(positives_ratio*this_size/total_ratio);
1026 const size_t negatives_number = this_size - positives_number;
1029 random_shuffle(indices.begin(), indices.end());
1036 size_t count_positives = 0;
1038 while(count_positives != positives_number)
1050 size_t count_negatives = 0;
1052 while(count_negatives != negatives_number)
1069 const size_t this_size = this->size();
1071 for(
size_t i = 0; i < this_size; i++)
1075 (*this)[i] = (*this)[i].erase(0,(*
this)[i].find_first_not_of(
' '));
1079 (*this)[i] = (*this)[i].erase((*
this)[i].find_last_not_of(
' ') + 1);
1108 for(
size_t i = from_index; i < from_index+fill_with.size(); i++)
1110 new_vector[i] = fill_with[counter];
1127 typename vector<T>::iterator it = find(copy.begin(), copy.end(), value);
1129 return(it != copy.end());
1141 for(
size_t i = 0; i < this->size(); i++)
1143 if((*
this)[i] > value)
return true;
1157 if(values.empty()) {
1163 const size_t values_size = values.size();
1165 for(
size_t j = 0; j < values_size; j++)
1167 typename vector<T>::iterator it = find(copy.begin(), copy.end(), values[j]);
1169 if(it != copy.end())
1186 const size_t this_size = this->size();
1188 if(this_size != other_vector.size())
1193 for(
size_t i = 0; i < this_size; i++)
1195 if(!other_vector.
contains((*
this)[i]))
1213 const size_t this_size = this->size();
1215 for(
size_t i = 0; i < this_size; i++) {
1216 if((*
this)[i] < minimum ||(*
this)[i] > maximum) {
1233 const size_t this_size = this->size();
1235 if(this_size == 0) {
1239 for(
size_t i = 0; i < this_size; i++)
1241 if(abs((*
this)[i] - (*
this)[0]) > tolerance)
return false;
1254 const size_t this_size = this->size();
1256 if(this_size == 0) {
1260 for(
size_t i = 1; i < this_size; i++)
1262 if((*
this)[i] != (*
this)[0])
1278 if(this->size() == 1)
return true;
1280 for(
size_t i = 0; i < this->size() - 1; i++)
1282 if((*
this)[i] > (*this)[i + 1])
return false;
1295 if(this->size() == 1)
return true;
1297 for(
size_t i = 0; i < this->size() - 1; i++)
1299 if((*
this)[i] < (*this)[i+1])
return false;
1311 for(
size_t i = 0; i < this->size(); i++)
1313 if((*
this)[i] < 0.0)
1327 for(
size_t i = 0; i < this->size(); i++)
1329 if((*
this)[i] > 0.0)
1345 for(
size_t i = 1; i < this->size(); i++)
1347 if((*
this)[i] != (*this)[i-1] + period)
1362 const size_t this_size = this->size();
1366 for(
size_t i = 1; i < this_size; i++)
1368 const bool contains_value = values.
contains((*
this)[i]);
1370 if(!contains_value && values.size() == 1)
1372 values.push_back((*
this)[i]);
1374 else if(!contains_value)
1389 if(this->get_unique_elements().size() != 2)
1393 const size_t this_size = this->size();
1395 for(
size_t i = 0; i < this_size; i++)
1397 if(!::isnan((*
this)[i]))
1399 if((*
this)[i] != 0 &&(*
this)[i] != 1)
1415 if(this->get_unique_elements().size() != 2)
1419 const size_t this_size = this->size();
1421 for(
size_t i = 0; i < this_size; i++)
1423 if((*
this)[i] != 0 &&(*
this)[i] != 1)
1439 const size_t this_size = this->size();
1441 for(
size_t i = 0; i < this_size; i++)
1443 if(floor((*
this)[i]) != (*
this)[i])
1458 const size_t this_size = this->size();
1460 for(
size_t i = 0; i < this_size; i++)
1462 if(!::isnan((*
this)[i]))
1464 if(floor((*
this)[i]) != (*
this)[i])
1481 const size_t this_size = this->size();
1485 for(
size_t i = 0; i < this_size; i++)
1487 reverse[i] = (*this)[this_size - 1 - i];
1500 return count(this->begin(), this->end(), value);
1512 const size_t this_size = this->size();
1513 const size_t values_size = values.size();
1515 for(
size_t i = 0; i < this_size; i++)
1517 for(
size_t j = 0; j < values_size; j++)
1519 if((*
this)[i] == values[j]) count++;
1534 const size_t this_size = this->size();
1536 for(
size_t i = 0; i < this_size; i++)
1538 if(::isnan((*
this)[i])) count++;
1552 const size_t this_size = this->size();
1554 for(
size_t i = 0; i < this_size; i++)
1556 if(!::isnan((*
this)[i])) count++;
1569 const size_t this_size = this->size();
1573 for(
size_t i = 0; i < this_size; i++)
1575 if((*
this)[i] != value)
1590 const size_t this_size = this->size();
1592 const size_t equal_to_count = count_equal_to(values);
1594 return(this_size - equal_to_count);
1603 const size_t this_size = this->size();
1607 for(
size_t i = 0; i < this_size; i++)
1623 const size_t this_size = this->size();
1627 for(
size_t i = 0; i < this_size; i++)
1645 const size_t this_size = this->size();
1647 const size_t new_size = count_equal_to(value);
1653 for(
size_t i = 0; i < this_size; i++)
1655 if((*
this)[i] == value)
1657 new_vector[index] = (*this)[i];
1673 return get_subvector(indices);
1683 const size_t this_size = this->size();
1685 const size_t new_size = count_not_equal_to(value);
1691 for(
size_t i = 0; i < this_size; i++)
1693 if((*
this)[i] != value)
1695 new_vector[index] = (*this)[i];
1712 return get_subvector(indices);
1721 const size_t this_size = this->size();
1722 const size_t new_size = count_positive();
1728 for(
size_t i = 0; i < this_size; i++)
1732 new_vector[count] = (*this)[i];
1747 const size_t this_size = this->size();
1748 const size_t new_size = count_negative();
1754 for(
size_t i = 0; i < this_size; i++)
1758 new_vector[count] = (*this)[i];
1771 const size_t this_size = this->size();
1773 for(
size_t i = 0; i < this_size; i++)
1775 if(::isnan((*
this)[i]))
return true;
1790 if(!this->is_integer())
1795 const size_t this_size = this->size();
1798 size_t integers_count = 0;
1800 for(
size_t i = 0; i < this_size; i++)
1804 integers.push_back((*
this)[i]);
1808 if(integers_count > maximum_integers)
1814 return integers_count;
1826 if(!this->is_integer_missing_values())
1831 const size_t this_size = this->size();
1834 size_t integers_count = 0;
1836 for(
size_t i = 0; i < this_size; i++)
1838 if(!::isnan((*
this)[i]))
1842 integers.push_back((*
this)[i]);
1846 if(integers_count > maximum_integers)
1853 return integers_count;
1864 const size_t this_size = this->size();
1866 const size_t new_size = count_between(minimum, maximum);
1872 for(
size_t i = 0; i < this_size; i++)
1874 if((*
this)[i] >= minimum &&(*
this)[i] <= maximum)
1892 const size_t this_size = this->size();
1894 const size_t occurrences_number = count_equal_to(values);
1896 if(occurrences_number == 0)
1900 return(occurrence_indices);
1907 for(
size_t i = 0; i < this_size; i++)
1911 occurrence_indices[index] = i;
1916 return(occurrence_indices);
1927 const size_t this_size = this->size();
1929 const size_t not_equal_to_count = count_not_equal_to(value);
1935 for(
size_t i = 0; i < this_size; i++) {
1936 if((*
this)[i] != value) {
1937 not_equal_to_indices[index] = i;
1942 return(not_equal_to_indices);
1952 const size_t this_size = this->size();
1954 const size_t occurrences_number = count_not_equal_to(values);
1962 for(
size_t i = 0; i < this_size; i++)
1966 occurrence_indices[index] = i;
1971 return(occurrence_indices);
1981 const size_t this_size = this->size();
1983 const size_t equal_to_count = count_equal_to(value);
1985 if(equal_to_count == 0)
1989 return(occurrence_indices);
1996 for(
size_t i = 0; i < this_size; i++)
1998 if((*
this)[i] == value)
2000 equal_to_indices[index] = i;
2005 return(equal_to_indices);
2016 const size_t this_size = this->size();
2018 const size_t less_than_count = count_less_than(value);
2024 for(
size_t i = 0; i < this_size; i++)
2026 if((*
this)[i] < value)
2028 less_than_indices[index] = i;
2033 return(less_than_indices);
2043 const size_t this_size = this->size();
2045 const size_t count = count_greater_than(value);
2051 for(
size_t i = 0; i < this_size; i++)
2053 if((*
this)[i] > value)
2070 const size_t this_size = this->size();
2074 for(
size_t i = 0; i < this_size; i++)
2076 if((*
this)[i] > value)
2092 const size_t this_size = this->size();
2096 for(
size_t i = 0; i < this_size; i++)
2098 if((*
this)[i] < value)
2114 const size_t this_size = this->size();
2118 for(
size_t i = 0; i < this_size; i++)
2120 if((*
this)[i] >= value)
2136 const size_t count = count_if(this->begin(), this->end(), [value](T elem){
return elem <= value; });
2150 const size_t this_size = this->size();
2154 for(
size_t i = 0; i < this_size; i++)
2156 if((*
this)[i] >= minimum &&(*
this)[i] <= maximum) count++;
2169 const size_t this_size = this->size();
2173 for(
size_t i = 0; i < this_size; i++)
2175 if((*
this)[i].find(find_what) != string::npos)
2192 const size_t this_size = this->size();
2196 for(
size_t i = 0; i < this_size; i++)
2198 merged[i] = (*this)[i] + separator + substring;
2213 const size_t this_size = this->size();
2214 const size_t new_size = count_between(minimum, maximum);
2220 for(
size_t i = 0; i < this_size; i++)
2222 if((*
this)[i] >= minimum && (*
this)[i] <= maximum)
2224 new_vector[count] = (*this)[i];
2239 const size_t this_size = this->size();
2243 for(
size_t i = 0; i < this_size; i++)
2245 if((*
this)[i].find(find_what) != string::npos)
2247 indices.push_back(i);
2261 const size_t this_size = this->size();
2265 for(
size_t i = 0; i < this_size; i++)
2267 if((*
this)[i] <= value)
2269 less_than_indices.push_back(i);
2273 return less_than_indices;
2284 const size_t this_size = this->size();
2288 for(
size_t i = 0; i < this_size; i++)
2290 if((*
this)[i] >= value)
2292 greater_than_indices.push_back(i);
2296 return greater_than_indices;
2305 const size_t size = this->size();
2309 for(
size_t i = 0; i < size; i++)
2311 if(abs(lambda - 0) < numeric_limits<double>::epsilon())
2313 vector_tranformation[i] = log(static_cast<double>((*
this)[i]));
2317 vector_tranformation[i] = (pow(static_cast<double>((*
this)[i]), lambda) - 1)/lambda;
2321 return vector_tranformation;
2331 const size_t this_size = this->size();
2335 for(
size_t i = 0; i < this_size; i++)
2337 percentage_vector[i] = static_cast<double>((*
this)[i])*100.0/static_cast<double>(total_sum);
2340 return percentage_vector;
2348 const size_t this_size = this->size();
2350 const size_t total_sum = this->calculate_sum();
2354 for(
size_t i = 0; i < this_size; i++)
2356 percentage_vector[i] = static_cast<double>((*
this)[i])*100.0/static_cast<double>(total_sum);
2359 return percentage_vector;
2369 const size_t this_size = this->size();
2371 for(
size_t i = 0; i < this_size; i++)
2373 if((*
this)[i] == value)
return i;
2376 ostringstream buffer;
2378 buffer <<
"OpenNN Exception: Vector Template.\n"
2379 <<
"size_t get_first_index(const T&) const.\n"
2380 <<
"Value not found in vector.\n";
2382 throw logic_error(buffer.str());
2393 const size_t this_size = this->size();
2396 #ifdef __OPENNN_DEBUG__
2398 if(this_size == 0) {
2399 ostringstream buffer;
2401 buffer <<
"OpenNN Exception: Vector Template.\n"
2402 <<
"size_t calculate_cumulative_index(const T&) const.\n"
2403 <<
"Size must be greater than zero.\n";
2405 throw logic_error(buffer.str());
2408 T cumulative_value = (*this)[this_size - 1];
2410 if(value > cumulative_value)
2412 ostringstream buffer;
2414 buffer <<
"OpenNN Exception: Vector Template.\n"
2415 <<
"size_t calculate_cumulative_index(const T&) const.\n"
2416 <<
"Value(" << value <<
") must be less than cumulative value("
2417 << cumulative_value <<
").\n";
2419 throw logic_error(buffer.str());
2422 for(
size_t i = 1; i < this_size; i++)
2424 if((*
this)[i] <(*this)[i - 1])
2426 ostringstream buffer;
2428 buffer <<
"OpenNN Exception: Vector Template.\n"
2429 <<
"int calculate_cumulative_index(const T&) const.\n"
2430 <<
"Vector elements must be crescent.\n";
2432 throw logic_error(buffer.str());
2438 if(value <= (*
this)[0])
2443 for(
size_t i = 1; i < this_size; i++)
2445 if(value >(*
this)[i - 1] && value <= (*this)[i])
2451 return(this_size - 1);
2460 const size_t this_size = this->size();
2464 for(
size_t i = 0; i < this_size; i++)
2479 const size_t this_size = this->size();
2483 for(
size_t i = 0; i < this_size; i++)
2500 const size_t this_size = this->size();
2504 for(
size_t i = 0; i < this_size; i++)
2506 if(!::isnan((*
this)[i]))
2521 const size_t this_size = this->size();
2525 for(
size_t i = 0; i < this_size; i++)
2527 product *= (*this)[i];
2545 for(
size_t i = 0; i < this->size(); i++)
2547 indices[less_rank[i]] = i;
2553 sort(indices.begin(), indices.end(), [
this](
size_t i1,
size_t i2) {
return (*
this)[i1] < (*this)[i2];});
2568 sort(sorted.begin(), sorted.end());
2581 return sort_ascending_indices().
get_subvector(0,indices_number-1);
2592 return sort_ascending_values().
get_subvector(0,indices_number-1);
2605 const Vector<size_t> greater_rank = this->calculate_greater_rank();
2607 for(
size_t i = 0; i < this->size(); i++)
2609 indices[greater_rank[i]] = i;
2616 sort(indices.begin(), indices.end(), [
this](
size_t i1,
size_t i2) {
return (*
this)[i1] > (*this)[i2];});
2631 sort(sorted.begin(), sorted.end());
2645 const size_t this_size = this->size();
2651 sort(sorted_vector.begin(), sorted_vector.end(), less<double>());
2654 previous_rank.
set(this_size);
2656 for(
size_t i = 0; i < this_size; i++)
2658 for(
size_t j = 0; j < this_size; j++)
2660 if(previous_rank.contains(static_cast<size_t>(j)))
continue;
2662 if((*
this)[i] == sorted_vector[j])
2664 rank[static_cast<size_t>(i)] = j;
2666 previous_rank[static_cast<size_t>(i)] = j;
2685 const size_t this_size = this->size();
2691 sort(sorted_vector.begin(), sorted_vector.end(), greater<T>());
2694 previous_rank.
set(this_size);
2696 for(
size_t i = 0; i < this_size; i++)
2698 for(
size_t j = 0; j < this_size; j++)
2700 if(previous_rank.contains(j))
continue;
2702 if(sorted_vector[i] == (*
this)[j])
2706 previous_rank[i] = j;
2723 const size_t this_size = this->size();
2725 #ifdef __OPENNN_DEBUG__
2726 const size_t rank_size = rank.size();
2728 if(this_size != rank_size) {
2729 ostringstream buffer;
2731 buffer <<
"OpenNN Exception: Vector Template.\n"
2732 <<
"Vector<T> sort_rank(const Vector<size_t>&) const.\n"
2733 <<
"Sizes of vectors are " << this_size <<
" and " << rank_size
2734 <<
" and they must be the same.\n";
2736 throw logic_error(buffer.str());
2743 for(
size_t i = 0; i < this_size; i++)
2745 sorted_vector[i] = (*this)[rank[i]];
2748 return sorted_vector;
2768 const size_t this_size = this->size();
2772 transform(this->begin(), this->end(), sum.begin(),
2773 bind2nd(plus<T>(), scalar));
2785 const size_t this_size = this->size();
2787 #ifdef __OPENNN_DEBUG__
2789 const size_t other_size = other_vector.size();
2791 if(other_size != this_size) {
2792 ostringstream buffer;
2794 buffer <<
"OpenNN Exception: Vector Template.\n"
2795 <<
"Vector<T> operator + (const Vector<T>) const.\n"
2796 <<
"Sizes of vectors are " << this_size <<
" and " << other_size
2797 <<
" and they must be the same.\n";
2799 throw logic_error(buffer.str());
2806 transform(this->begin(), this->end(), other_vector.begin(), sum.begin(),
2819 const size_t this_size = this->size();
2823 transform(this->begin(), this->end(), difference.begin(),
2824 bind2nd(minus<T>(), scalar));
2836 const size_t this_size = this->size();
2840 #ifdef __OPENNN_DEBUG__
2842 const size_t other_size = other_vector.size();
2844 if(other_size != this_size) {
2845 ostringstream buffer;
2847 buffer <<
"OpenNN Exception: Vector Template.\n"
2848 <<
"Vector<T> operator -(const Vector<T>&) const.\n"
2849 <<
"Sizes of vectors are " << this_size <<
" and " << other_size
2850 <<
" and they must be the same.\n";
2852 throw logic_error(buffer.str());
2859 transform(this->begin(), this->end(), other_vector.begin(),
2860 difference.begin(), minus<T>());
2871 const size_t this_size = this->size();
2875 transform(this->begin(), this->end(), product.begin(),
2876 bind2nd(multiplies<T>(), scalar));
2888 const size_t this_size = this->size();
2890 #ifdef __OPENNN_DEBUG__
2892 const size_t other_size = other_vector.size();
2894 if(other_size != this_size) {
2895 ostringstream buffer;
2897 buffer <<
"OpenNN Exception: Vector Template.\n"
2898 <<
"Vector<T> operator *(const Vector<T>&) const.\n"
2899 <<
"Size of other vector(" << other_size
2900 <<
") must be equal to size of this vector(" << this_size <<
").\n";
2902 throw logic_error(buffer.str());
2909 transform(this->begin(), this->end(), other_vector.begin(),
2910 product.begin(), multiplies<T>());
2925 #ifdef __OPENNN_DEBUG__
2927 const size_t this_size = this->size();
2929 if(rows_number != this_size) {
2930 ostringstream buffer;
2932 buffer <<
"OpenNN Exception: Vector Template.\n"
2933 <<
"Matrix<T> operator *(const Matrix<T>&) const.\n"
2934 <<
"Number of matrix rows(" << rows_number <<
") must be equal to vector size(" << this_size <<
").\n";
2936 throw logic_error(buffer.str());
2941 Matrix<T> product(rows_number, columns_number);
2943 for(
size_t i = 0; i < rows_number; i++) {
2944 for(
size_t j = 0; j < columns_number; j++) {
2945 product(i, j) = (*this)[i] * matrix(i, j);
2958 const size_t this_size = this->size();
2962 transform(this->begin(), this->end(), cocient.begin(),
2963 bind2nd(divides<T>(), scalar));
2975 const size_t this_size = this->size();
2979 #ifdef __OPENNN_DEBUG__
2981 const size_t other_size = other_vector.size();
2983 if(other_size != this_size) {
2984 ostringstream buffer;
2986 buffer <<
"OpenNN Exception: Vector Template.\n"
2987 <<
"Vector<T> operator /(const Vector<T>&) const.\n"
2988 <<
"Both vector sizes must be the same.\n";
2990 throw logic_error(buffer.str());
2997 transform(this->begin(), this->end(), other_vector.begin(),
2998 cocient.begin(), divides<T>());
3009 const size_t this_size = this->size();
3011 for(
size_t i = 0; i < this_size; i++) {
3012 (*this)[i] = (*this)[i] + value;
3022 const size_t this_size = this->size();
3026 #ifdef __OPENNN_DEBUG__
3028 const size_t other_size = other_vector.size();
3030 if(other_size != this_size) {
3031 ostringstream buffer;
3033 buffer <<
"OpenNN Exception: Vector Template.\n"
3034 <<
"void operator += (const Vector<T>&).\n"
3035 <<
"Both vector sizes must be the same.\n";
3037 throw logic_error(buffer.str());
3042 for(
size_t i = 0; i < this_size; i++) {
3043 (*this)[i] = (*this)[i] + other_vector[i];
3053 const size_t this_size = this->size();
3055 for(
size_t i = 0; i < this_size; i++) {
3056 (*this)[i] = (*this)[i] - value;
3066 const size_t this_size = this->size();
3070 #ifdef __OPENNN_DEBUG__
3072 const size_t other_size = other_vector.size();
3074 if(other_size != this_size) {
3075 ostringstream buffer;
3077 buffer <<
"OpenNN Exception: Vector Template.\n"
3078 <<
"void operator -= (const Vector<T>&).\n"
3079 <<
"Both vector sizes must be the same.\n";
3081 throw logic_error(buffer.str());
3086 for(
size_t i = 0; i < this_size; i++) {
3087 (*this)[i] = (*this)[i] - other_vector[i];
3097 const size_t this_size = this->size();
3099 for(
size_t i = 0; i < this_size; i++) {
3100 (*this)[i] = (*this)[i] * value;
3111 const size_t this_size = this->size();
3113 #ifdef __OPENNN_DEBUG__
3115 const size_t other_size = other_vector.size();
3117 if(other_size != this_size) {
3118 ostringstream buffer;
3120 buffer <<
"OpenNN Exception: Vector Template.\n"
3121 <<
"void operator *= (const Vector<T>&).\n"
3122 <<
"Both vector sizes must be the same.\n";
3124 throw logic_error(buffer.str());
3129 for(
size_t i = 0; i < this_size; i++) {
3130 (*this)[i] = (*this)[i] * other_vector[i];
3140 const size_t this_size = this->size();
3142 for(
size_t i = 0; i < this_size; i++)
3144 (*this)[i] = (*this)[i] / value;
3154 const size_t this_size = this->size();
3158 #ifdef __OPENNN_DEBUG__
3160 const size_t other_size = other_vector.size();
3162 if(other_size != this_size) {
3163 ostringstream buffer;
3165 buffer <<
"OpenNN Exception: Vector Template.\n"
3166 <<
"void operator /= (const Vector<T>&).\n"
3167 <<
"Both vector sizes must be the same.\n";
3169 throw logic_error(buffer.str());
3174 for(
size_t i = 0; i < this_size; i++)
3176 (*this)[i] = (*this)[i] / other_vector[i];
3188 for(
size_t i = 0; i < this->size(); i++)
3190 if(new_vector[i] < 0)
3206 for(
size_t i = 0; i < this->size(); i++)
3208 if(new_vector[i] > 0)
3224 const size_t this_size = this->size();
3226 Matrix<T> matrix(this_size, this_size, 0.0);
3242 #ifdef __OPENNN_DEBUG__
3244 const size_t this_size = this->size();
3246 if(first_index >= this_size) {
3247 ostringstream buffer;
3249 buffer <<
"OpenNN Exception: Vector Template.\n"
3250 <<
"Vector<T> get_subvector(const size_t&, const size_t&) const method.\n"
3251 <<
"First index (" << first_index <<
") is equal or greater than size (" << this_size <<
").\n";
3253 throw logic_error(buffer.str());
3256 if(last_index >= this_size) {
3257 ostringstream buffer;
3259 buffer <<
"OpenNN Exception: Vector Template.\n"
3260 <<
"Vector<T> get_subvector(const size_t&, const size_t&) const method.\n"
3261 <<
"Last index (" << last_index <<
") is equal or greater than size (" << this_size <<
").\n";
3263 throw logic_error(buffer.str());
3268 Vector<T> subvector(last_index-first_index + 1);
3270 for(
size_t i = first_index ; i < last_index+1 ; i++)
3272 subvector[i-first_index] = (*this)[i];
3287 const size_t new_size = indices.size();
3291 #ifdef __OPENNN_DEBUG__
3293 const size_t this_size = this->size();
3295 for(
size_t i = 0; i < new_size; i++) {
3296 if(indices[i] > this_size) {
3297 ostringstream buffer;
3299 buffer <<
"OpenNN Exception: Vector Template.\n"
3300 <<
"Vector<T> get_subvector(const Vector<T>&) const method.\n"
3301 <<
"Index (" << indices[i] <<
") is equal or greater than this size.\n";
3303 throw logic_error(buffer.str());
3311 for(
size_t i = 0; i < new_size; i++)
3313 subvector[i] = (*this)[indices[i]];
3328 return(get_subvector(indices));
3338 if(new_size == this->size())
return Vector<T>(*
this);
3342 random_shuffle(new_vector.begin(), new_vector.end());
3356 #ifdef __OPENNN_DEBUG__
3358 const size_t this_size = this->size();
3360 if(elements_number > this_size) {
3361 ostringstream buffer;
3363 buffer <<
"OpenNN Exception: Vector Template.\n"
3364 <<
"Vector<T> get_first(const size_t&) const method.\n"
3365 <<
"Number of elements must be equal or greater than this size.\n";
3367 throw logic_error(buffer.str());
3374 for(
size_t i = 0; i < elements_number; i++)
3376 subvector[i] = (*this)[i];
3389 const size_t this_size = this->size();
3392 #ifdef __OPENNN_DEBUG__
3394 if(elements_number > this_size) {
3395 ostringstream buffer;
3397 buffer <<
"OpenNN Exception: Vector Template.\n"
3398 <<
"Vector<T> get_last(const size_t&) const method.\n"
3399 <<
"Number of elements must be equal or greater than this size.\n";
3401 throw logic_error(buffer.str());
3408 for(
size_t i = 0; i < elements_number; i++)
3410 subvector[i] = (*this)[i + this_size - elements_number];
3425 const size_t this_size = this->size();
3427 const size_t integers_number = this->count_integers(maximum_integers);
3432 for(
size_t i = 0; i < this_size; i++)
3436 integers[index] = (*this)[i];
3439 if(index > integers_number)
3456 const size_t this_size = this->size();
3458 const size_t integers_number = this->count_integers_missing_values(maximum_integers);
3463 for(
size_t i = 0; i < this_size; i++)
3465 if(!::isnan((*
this)[i]))
3469 integers[index] = (*this)[i];
3472 if(index > integers_number)
break;
3488 ifstream file(file_name.c_str());
3490 stringstream buffer;
3496 getline(file, line);
3501 istream_iterator<string> it(buffer);
3502 istream_iterator<string> end;
3504 const vector<string> results(it, end);
3506 const size_t new_size = static_cast<size_t>(results.size());
3508 this->resize(new_size);
3511 file.seekg(0, ios::beg);
3515 for(
size_t i = 0; i < new_size; i++) {
3529 template <
class T>
void Vector<T>::save(
const string &file_name,
const char& separator)
const
3531 ofstream file(file_name.c_str());
3533 if(!file.is_open()) {
3534 ostringstream buffer;
3536 buffer <<
"OpenNN Exception: Vector template.\n"
3537 <<
"void save(const string&) const method.\n"
3538 <<
"Cannot open vector data file.\n";
3540 throw logic_error(buffer.str());
3545 const size_t this_size = this->size();
3550 for(
size_t i = 1; i < this_size; i++) {
3551 file << separator << (*this)[i];
3571 const size_t other_size = other_vector.size();
3573 #ifdef __OPENNN_DEBUG__
3575 const size_t this_size = this->size();
3577 if(position + other_size > this_size)
3579 ostringstream buffer;
3581 buffer <<
"OpenNN Exception: Vector Template.\n"
3582 <<
"void tuck_in(const size_t &, const Vector<T>&) method.\n"
3583 <<
"Cannot tuck in vector.\n";
3585 throw logic_error(buffer.str());
3590 for(
size_t i = 0; i < other_size; i++)
3592 (*this)[position + i] = other_vector[i];
3601 const size_t other_size =other_vector.size();
3602 const size_t new_size = this->size() + other_size;
3606 for(
size_t i = 0 ; i < position ; i++)
3608 new_vector[i] = (*this)[i];
3610 for(
size_t i = position ; i < position + other_size ; i++)
3612 new_vector[i] = other_vector[i-position];
3614 for(
size_t i = position + other_size ; i < new_size ; i++)
3616 new_vector[i] = (*this)[i-other_size];
3629 #ifdef __OPENNN_DEBUG__
3631 const size_t this_size = this->size();
3633 if(index > this_size) {
3634 ostringstream buffer;
3637 <<
"OpenNN Exception: Vector Template.\n"
3638 <<
"void insert_element(const size_t& index, const T& value) method.\n"
3639 <<
"Index is greater than vector size.\n";
3641 throw logic_error(buffer.str());
3648 const auto it = other_vector.begin();
3650 other_vector.insert(it+index, value);
3652 return other_vector;
3663 for(
size_t i = 0; i < this->size(); i++)
3665 if((*
this)[i] == find_value) (*
this)[i] = replace_value;
3678 const size_t this_size = this->size();
3680 #ifdef __OPENNN_DEBUG__
3682 if(index >= this_size) {
3683 ostringstream buffer;
3685 buffer <<
"OpenNN Exception: Vector Template.\n"
3686 <<
"Vector<T> remove_element(const size_t&) const method.\n"
3687 <<
"Index("<<index<<
") is equal or greater than vector size("<<this_size<<
").\n";
3689 throw logic_error(buffer.str());
3696 for(
size_t i = 0; i < this_size; i++) {
3699 other_vector[i] = (*this)[i];
3701 else if(i > index) {
3702 other_vector[i - 1] = (*this)[i];
3706 return other_vector;
3718 const size_t this_size = this->size();
3719 const size_t indices_size = indices.size();
3723 #ifdef __OPENNN_DEBUG__
3735 if(indices_size > this_size) {
3736 ostringstream buffer;
3738 buffer <<
"OpenNN Exception: Vector Template.\n"
3739 <<
"Vector<T> delete_indices(const Vector<size_t>&) const method.\n"
3740 <<
"Number of indices("<< indices_size <<
") to remove is greater than vector size(" << this_size <<
").\n";
3742 throw logic_error(buffer.str());
3747 Vector<T> other_vector(this_size - indices_size);
3751 for(
size_t i = 0; i < this_size; i++)
3755 other_vector[index] = (*this)[i];
3761 return other_vector;
3772 const size_t this_size = this->size();
3774 const size_t value_count = count_equal_to(value);
3776 if(value_count == 0)
return Vector<T>(*
this);
3778 const size_t other_size = this_size - value_count;
3782 size_t other_index = 0;
3784 for(
size_t i = 0; i < this_size; i++)
3786 if((*
this)[i] != value)
3788 other_vector[other_index] = (*this)[i];
3794 return other_vector;
3806 for(
size_t i = 0; i < values.size(); i++)
3821 const size_t this_size = this->size();
3822 const size_t other_size = other_vector.size();
3824 if(this_size == 0 && other_size == 0)
3830 else if(this_size == 0)
3832 return other_vector;
3834 else if(other_size == 0)
3840 Vector<T> assembly(this_size + other_size);
3842 for(
size_t i = 0; i < this_size; i++)
3844 assembly[i] = (*this)[i];
3847 for(
size_t i = 0; i < other_size; i++)
3849 assembly[this_size + i] = other_vector[i];
3863 const size_t vectors_size = vectors.size();
3865 size_t new_size = 0;
3867 for(
size_t i = 0; i < vectors_size; i++)
3869 new_size += vectors[i].size();
3876 for(
size_t i = 0; i < vectors_size; i++)
3878 for(
size_t j = 0; j < vectors[i].size(); j++)
3880 new_vector[index] = vectors[i][j];
3899 return other_vector;
3902 if(other_vector.empty())
3908 const size_t this_size = this->size();
3911 typename vector<T>::iterator iterator;
3914 Vector<T> copy_other_vector(other_vector);
3916 sort(copy_this.begin(), copy_this.end());
3917 sort(copy_other_vector.begin(), copy_other_vector.end());
3919 iterator = set_difference(copy_this.begin(),copy_this.end(), copy_other_vector.begin(), copy_other_vector.end(), difference.begin());
3921 difference.resize(iterator - difference.begin());
3936 sort(this_copy.begin(), this_copy.end());
3939 sort(other_copy.begin(), other_copy.end());
3943 set_union(this_copy.begin(), this_copy.end(), other_copy.begin(), other_copy.end(), back_inserter(union_vector));
3945 return union_vector;
3958 sort(this_copy.begin(), this_copy.end());
3961 sort(other_copy.begin(), other_copy.end());
3965 set_intersection(this_copy.begin(), this_copy.end(), other_copy.begin(), other_copy.end(), back_inserter(intersection));
3967 return intersection;
3979 sort(copy_vector.begin(), copy_vector.end());
3981 const auto last = unique(copy_vector.begin(), copy_vector.end());
3983 copy_vector.erase(last, copy_vector.end());
3995 const Vector<T> unique = get_unique_elements();
3997 const size_t unique_size = unique.size();
4001 #pragma omp parallel for
4002 for(
int i = 0; i < static_cast<int>(unique_size); i++)
4004 unique_count[i] = count_equal_to(unique[i]);
4007 return(unique_count);
4020 const size_t this_size = this->size();
4022 const Vector<T> unique = get_unique_elements();
4028 const size_t unique_size = unique.size();
4031 Matrix<T> unique_matrix(unique_size, 3);
4038 cout <<
"Total: " << this_size << endl;
4040 for(
size_t i = 0; i < unique_size; i++)
4042 cout << unique_matrix(i,0) <<
": " << unique_matrix(i,1) <<
" (" << unique_matrix(i,2) <<
"%)" << endl;
4056 const size_t this_size = this->size();
4058 const Vector<T> unique = get_unique_elements();
4064 const size_t unique_size = unique.size();
4067 Matrix<T> unique_matrix(unique_size, 3);
4074 cout <<
"Total: " << this_size << endl;
4076 for(
size_t i = 0; i < unique_size; i++)
4078 cout << unique_matrix(i,0) <<
": " << unique_matrix(i,1) <<
" (" << unique_matrix(i,2) <<
"%)" << endl;
4091 const Vector<T> unique = get_unique_elements();
4095 const size_t unique_size = unique.size();
4097 Matrix<T> unique_matrix(unique_size, 2);
4103 const size_t end = unique_size < rank ? unique_size : rank;
4119 const Vector<T> unique = get_unique_elements();
4125 const size_t unique_size = unique.size();
4127 Matrix<T> unique_matrix(unique_size, 2);
4133 const size_t end = unique_size < rank ? unique_size : rank;
4147 const Vector<T> unique = get_unique_elements();
4151 const size_t this_size = this->size();
4155 const size_t unique_size = unique.size();
4157 if(unique_size == 0)
return;
4159 Matrix<T> unique_matrix(unique_size, 3);
4166 const size_t end = unique_size < rank ? unique_size : rank;
4168 for(
size_t i = 0; i < end; i++)
4170 cout << i+1 <<
". " << unique_matrix(i,0) <<
": " << unique_matrix(i,1) <<
" (" << unique_matrix(i,2) <<
"%)" << endl;
4180 const size_t this_size = this->size();
4182 vector<T> std_vector(this_size);
4184 for(
size_t i = 0; i < this_size; i++)
4186 std_vector[i] = (*this)[i];
4198 const size_t this_size = this->size();
4202 for(
size_t i = 0; i < this_size; i++)
4204 float_vector[i] = static_cast<float>((*
this)[i]);
4207 return(float_vector);
4216 const size_t this_size = this->size();
4220 for(
size_t i = 0; i < this_size; i++)
4222 double_vector[i] = static_cast<double>((*
this)[i]);
4225 return(double_vector);
4234 const size_t this_size = this->size();
4238 for(
size_t i = 0; i < this_size; i++)
4240 int_vector[i] = static_cast<int>((*
this)[i]);
4252 const size_t this_size = this->size();
4256 for(
size_t i = 0; i < this_size; i++)
4258 size_t_vector[i] = static_cast<size_t>((*
this)[i]);
4261 return(size_t_vector);
4270 const size_t this_size = this->size();
4274 for(
size_t i = 0; i < this_size; i++)
4276 size_t_vector[i] = static_cast<time_t>((*
this)[i]);
4279 return(size_t_vector);
4289 const Vector<T> unique = get_unique_elements();
4302 const size_t this_size = this->size();
4306 for(
size_t i = 0; i < this_size; i++)
4308 if((*
this)[i] == unique[0])
4310 new_vector[i] =
true;
4314 new_vector[i] =
false;
4330 const Vector<T> unique = get_unique_elements();
4332 const size_t unique_number = unique.size();
4334 const size_t this_size = this->size();
4336 Matrix<T> new_matrix(this_size, unique_number, 0.0);
4338 for(
size_t i = 0; i < unique_number; i++)
4340 for(
size_t j = 0; j < this_size; j++)
4342 if((*
this)[j] == unique[j])
4344 new_matrix(j, i) = 1.0;
4359 const size_t this_size = this->size();
4362 ostringstream buffer;
4364 for(
size_t i = 0; i < this_size; i++)
4367 buffer << (*this)[i];
4369 string_vector[i] = buffer.str();
4372 return(string_vector);
4381 const size_t this_size = this->size();
4385 for(
size_t i = 0; i < this_size; i++)
4389 stringstream buffer;
4391 buffer << (*this)[i];
4393 double_vector[i] = stod(buffer.str());
4395 catch(
const logic_error&)
4397 double_vector[i] = nan(
"");
4401 return double_vector;
4410 const size_t this_size = this->size();
4414 for(
size_t i = 0; i < this_size; i++)
4418 int_vector[i] = stoi((*
this)[i]);
4420 catch(
const logic_error&)
4422 int_vector[i] = -999999999;
4435 const size_t this_size = this->size();
4439 for(
size_t i = 0; i < this_size; i++)
4443 size_t_vector[i] = static_cast<size_t>(stoi((*
this)[i]));
4445 catch(
const logic_error&)
4447 size_t_vector[i] = 999999;
4451 return size_t_vector;
4460 const size_t this_size = this->size();
4464 for(
size_t i = 0; i < this_size; i++)
4468 time_vector[i] = static_cast<time_t>(stoi((*
this)[i]));
4470 catch(
const logic_error&)
4472 time_vector[i] = -1;
4486 if(this->size() < n)
4494 const size_t batches_number = this->size() / n;
4503 for(
size_t k = 0; k < batches_number; ++k)
4507 auto start_itr = next(this->cbegin(), k*n);
4509 auto end_itr = k*n + n > this->size() ? this->cend() : next(this->cbegin(), k*n + n);
4513 batches[k].resize(n);
4525 copy(start_itr, end_itr, batches[k].begin());
4539 const size_t this_size = this->size();
4543 for(
size_t i = 0; i < this_size; i++)
4545 matrix(0, i) = (*this)[i];
4558 const size_t this_size = this->size();
4562 for(
size_t i = 0; i < this_size; i++) {
4563 matrix(i, 0) = (*this)[i];
4583 istringstream buffer(str);
4585 istream_iterator<string> first(buffer);
4586 istream_iterator<string> last;
4590 const size_t new_size = str_vector.size();
4594 this->resize(new_size);
4597 buffer.seekg(0, ios::beg);
4599 for(
size_t i = 0; i < new_size; i++)
4601 buffer >>(*this)[i];
4616 ostringstream buffer;
4618 const size_t this_size = this->size();
4623 buffer << quotation <<(*this)[0] << quotation;
4625 for(
size_t i = 1; i < this_size; i++)
4628 buffer << separator << quotation << (*this)[i] << quotation;
4632 return buffer.str();
4642 ostringstream buffer;
4644 const size_t this_size = this->size();
4648 buffer <<(*this)[0];
4650 for(
size_t i = 1; i < this_size; i++)
4652 buffer << separator << (*this)[i];
4656 return buffer.str();
4665 ostringstream buffer;
4667 const size_t this_size = this->size();
4671 buffer <<(*this)[0];
4673 for(
size_t i = 1; i < this_size; i++)
4675 buffer <<
' ' << (*this)[i];
4679 return buffer.str();
4688 ostringstream buffer;
4690 const size_t this_size = this->size();
4694 buffer <<(*this)[0];
4696 for(
size_t i = 1 ; i < this_size ; i++)
4698 buffer << (*this)[i];
4702 return buffer.str();
4711 ostringstream buffer;
4713 const size_t this_size = this->size();
4717 buffer <<(*this)[0];
4719 for(
size_t i = 1; i < this_size; i++)
4721 buffer << separator << (*this)[i];
4725 return buffer.str();
4733 ostringstream buffer;
4735 const size_t this_size = this->size();
4739 buffer <<(*this)[0];
4741 for(
size_t i = 1; i < this_size; i++)
4743 buffer << separator << (*this)[i];
4747 return buffer.str();
4758 const size_t this_size = this->size();
4762 ostringstream buffer;
4764 for(
size_t i = 0; i < this_size; i++)
4767 buffer << setprecision(precision) << (*this)[i];
4769 string_vector[i] = buffer.str();
4772 return(string_vector);
4785 const size_t &columns_number)
const
4789 #ifdef __OPENNN_DEBUG__
4791 const size_t this_size = this->size();
4793 if(rows_number * columns_number != this_size) {
4794 ostringstream buffer;
4796 buffer <<
"OpenNN Exception: Vector Template.\n"
4797 <<
"Matrix<T> to_matrix(const size_t&, const size_t&) method.\n"
4798 <<
"The number of rows(" << rows_number
4799 <<
") times the number of colums(" << columns_number
4800 <<
") must be equal to the size of the vector(" << this_size
4803 throw logic_error(buffer.str());
4808 Matrix<T> matrix(rows_number, columns_number);
4810 for(
size_t i = 0; i < this->size(); i++)
4812 matrix[i] = (*this)[i];
4828 for(
size_t i = 0; i < this->size(); i++)
4830 tensor[i] = (*this)[i];
4842 istream &operator>>(istream &is,
Vector<T>&v)
4844 const size_t size = v.size();
4846 for(
size_t i = 0; i < size; i++)
4860 ostream &operator<<(ostream &os,
const Vector<T>&v)
4862 const size_t this_size = v.size();
4868 const char space =
' ';
4870 for(
size_t i = 1; i < this_size; i++)
4872 os << space << v[i];
4885 ostream &operator<<(ostream &os,
const Vector<Vector<T>>&v)
4887 for(
size_t i = 0; i < v.size(); i++)
4889 os <<
"subvector_" << i <<
"\n" << v[i] << endl;
4901 ostream &operator<<(ostream &os,
const Vector< Matrix<T> >&v)
4903 for(
size_t i = 0; i < v.size(); i++)
4905 os <<
"submatrix_" << i <<
"\n" << v[i] << endl;
4917 T calculate_random_uniform(
const T&minimum,
const T&maximum)
4919 const T random = static_cast<T>(rand() /(RAND_MAX + 1.0));
4921 const T random_uniform = minimum + (maximum - minimum) * random;
4923 return(random_uniform);
4930 string number_to_string(
const T& value)
4945 T calculate_random_normal(
const T& mean,
const T& standard_deviation)
4947 const double pi = 4.0 * atan(1.0);
4953 random_uniform_1 = static_cast<T>(rand()) /(RAND_MAX + 1.0);
4956 while(random_uniform_1 == 0.0);
4958 const T random_uniform_2 = static_cast<T>(rand()) /(RAND_MAX + 1.0);
4962 const T random_normal = mean +
4963 sqrt(-2.0 * log(random_uniform_1)) *
4964 sin(2.0 * pi * random_uniform_2) *
4967 return(random_normal);
4976 string write_elapsed_time(
const T& elapsed_time)
4978 string elapsed_time_string;
4980 const size_t hours = static_cast<size_t>(elapsed_time/3600);
4982 size_t minutes = static_cast<size_t>(elapsed_time) - hours*3600;
4984 minutes = static_cast<size_t>(minutes/60);
4986 const size_t seconds = static_cast<size_t>(elapsed_time) - hours*3600 - minutes*60;
4990 elapsed_time_string = to_string(hours) +
":";
4995 elapsed_time_string +=
"0";
4998 elapsed_time_string += to_string(minutes) +
":";
5002 elapsed_time_string +=
"0";
5004 elapsed_time_string += to_string(seconds);
5006 return elapsed_time_string;
5014 Vector<T> to_vector(
const Vector< Matrix<T> >& array)
5017 Vector<T> new_vector;
5019 for(
size_t i = 0; i < array.size(); i++)
5021 const Vector<T> other_vector = array[i].to_vector();
5022 new_vector.insert(new_vector.end(), other_vector.begin(), other_vector.end());
5036 const size_t& columns_number,
5037 const size_t& channels_number)
const
5040 const size_t vector_size = this->size();
5041 Vector<Vector<T>> channels_vector = this->split(vector_size / channels_number);
5042 for(
size_t i = 0; i < channels_number; i++)
5044 new_vector_matrix[i] = channels_vector[i].
to_matrix(rows_number, columns_number);
5047 return new_vector_matrix;