41 #include "../eigen/Eigen"
49 template<
class T>
class Matrix;
52 T calculate_random_uniform(
const T& = -1,
const T& = 1);
55 T calculate_random_normal(
const T& = 0.0,
const T& = 1.0);
78 explicit Vector(
const size_t&);
82 explicit Vector(
const size_t&,
const T&);
86 explicit Vector(
const std::string&);
90 explicit Vector(
const T&,
const double&,
const T&);
94 template<
class InputIterator>
95 explicit Vector(InputIterator, InputIterator);
127 void set(
const size_t&);
129 void set(
const size_t&,
const T&);
131 void set(
const std::string&);
133 void set(
const T&,
const double&,
const T&);
155 bool is_in(
const T&,
const T&)
const;
400 void load(
const std::string&);
402 void save(
const std::string&)
const;
421 void parse(
const std::string&);
425 std::string
to_string(
const std::string& =
" ")
const;
479 set(first, step, last);
486 template<
class InputIterator>
519 const size_t this_size = this->size();
521 for(
size_t i = 0; i < this_size; i++)
523 if((*
this)[i] != value)
542 const size_t this_size = this->size();
544 for(
size_t i = 0; i < this_size; i++)
546 if((*
this)[i] != value)
565 const size_t this_size = this->size();
567 for(
size_t i = 0; i < this_size; i++)
569 if((*
this)[i] <= value)
588 const size_t this_size = this->size();
590 for(
size_t i = 0; i < this_size; i++)
592 if((*
this)[i] >= value)
611 const size_t this_size = this->size();
613 for(
size_t i = 0; i < this_size; i++)
615 if((*
this)[i] < value)
634 const size_t this_size = this->size();
637 for(
size_t i = 0; i < this_size; i++)
639 if((*
this)[i] > value)
670 this->resize(new_size);
683 this->resize(new_size);
685 initialize(new_value);
713 if(first > last && step > 0 )
717 else if(first < last && step < 0)
723 const size_t new_size = 1 + (size_t)((last - first)/step + 0.5);
725 this->resize(new_size);
727 for(
size_t i = 0; i < new_size; i++)
729 (*this)[i] = first + (T)(i*step);
743 *
this = other_vector;
755 std::fill((*this).begin(), (*this).end(), value);
766 for(
size_t i = 0; i < this->size(); i++)
787 if(minimum > maximum)
789 std::ostringstream buffer;
791 buffer <<
"OpenNN Exception: Vector Template.\n"
792 <<
"void randomize_uniform(const double&, const double&) method.\n"
793 <<
"Minimum value must be less or equal than maximum value.\n";
795 throw std::logic_error(buffer.str());
800 const size_t this_size = this->size();
802 for(
size_t i = 0; i < this_size; i++)
804 (*this)[i] = (T)calculate_random_uniform(minimum, maximum);
819 const size_t this_size = this->size();
825 const size_t minimums_size = minimums.size();
826 const size_t maximums_size = maximums.size();
828 if(minimums_size != this_size || maximums_size != this_size)
830 std::ostringstream buffer;
832 buffer <<
"OpenNN Exception: Vector Template.\n"
833 <<
"void randomize_uniform(const Vector<double>&, const Vector<double>&) method.\n"
834 <<
"Minimum and maximum sizes must be equal to vector size.\n";
836 throw std::logic_error(buffer.str());
839 if(minimums > maximums)
841 std::ostringstream buffer;
843 buffer <<
"OpenNN Exception: Vector Template.\n"
844 <<
"void randomize_uniform(const Vector<double>&, const Vector<double>&) method.\n"
845 <<
"Minimum values must be less or equal than their corresponding maximum values.\n";
847 throw std::logic_error(buffer.str());
852 for(
size_t i = 0; i < this_size; i++)
854 (*this)[i] = calculate_random_uniform(minimums[i], maximums[i]);
873 if(standard_deviation < 0.0)
875 std::ostringstream buffer;
877 buffer <<
"OpenNN Exception: Vector Template.\n"
878 <<
"void randomize_normal(const double&, const double&) method.\n"
879 <<
"Standard deviation must be equal or greater than zero.\n";
881 throw std::logic_error(buffer.str());
886 const size_t this_size = this->size();
888 for(
size_t i = 0; i < this_size; i++)
890 (*this)[i] = calculate_random_normal(mean, standard_deviation);
905 const size_t this_size = this->size();
911 const size_t mean_size = mean.size();
912 const size_t standard_deviation_size = standard_deviation.size();
914 if(mean_size != this_size || standard_deviation_size != this_size)
916 std::ostringstream buffer;
918 buffer <<
"OpenNN Exception: Vector Template.\n"
919 <<
"void randomize_normal(const Vector<double>&, const Vector<double>&) method.\n"
920 <<
"Mean and standard deviation sizes must be equal to vector size.\n";
922 throw std::logic_error(buffer.str());
925 if(standard_deviation < 0.0)
927 std::ostringstream buffer;
929 buffer <<
"OpenNN Exception: Vector Template.\n"
930 <<
"void randomize_normal(const Vector<double>&, const Vector<double>&) method.\n"
931 <<
"Standard deviations must be equal or greater than zero.\n";
933 throw std::logic_error(buffer.str());
938 for(
size_t i = 0; i < this_size; i++)
940 (*this)[i] = calculate_random_normal(mean[i], standard_deviation[i]);
952 const size_t this_size = this->size();
954 for(
size_t i = 0; i < this_size; i++)
956 if((*
this)[i] == value)
978 const size_t this_size = this->size();
980 const size_t values_size = values.size();
982 for(
size_t i = 0; i < this_size; i++)
984 for(
size_t j = 0; j < values_size; j++)
986 if((*
this)[i] == values[j])
1007 const size_t this_size = this->size();
1009 for(
size_t i = 0; i < this_size; i++)
1011 if((*
this)[i] < minimum || (*
this)[i] > maximum)
1030 const size_t this_size = this->size();
1037 const T minimum = calculate_minimum();
1038 const T maximum = calculate_maximum();
1040 if(fabs(maximum-minimum) <= tolerance)
1058 for(
size_t i = 0; i < this->size()-1; i++)
1060 if((*
this)[i] > (*this)[i+1])
1077 for(
size_t i = 0; i < this->size()-1; i++)
1079 if((*
this)[i] < (*this)[i+1])
1096 const size_t this_size = this->size();
1100 for(
size_t i = 0; i < this_size; i++)
1102 if((*
this)[i] == value)
1120 const size_t this_size = this->size();
1122 const size_t occurrences_number = count_occurrences(value);
1128 for(
size_t i = 0; i < this_size; i++)
1130 if((*
this)[i] == value)
1132 occurrence_indices[index] = i;
1137 return(occurrence_indices);
1149 const size_t this_size = this->size();
1153 for(
size_t i = 0; i < this_size; i++)
1155 if((*
this)[i] > value)
1173 const size_t this_size = this->size();
1177 for(
size_t i = 0; i < this_size; i++)
1179 if((*
this)[i] < value)
1197 const size_t this_size = this->size();
1201 for(
size_t i = 0; i < this_size; i++)
1203 if((*
this)[i] < value)
1205 less_than_indices.push_back(i);
1209 return(less_than_indices);
1221 const size_t this_size = this->size();
1225 for(
size_t i = 0; i < this_size; i++)
1227 if((*
this)[i] > value)
1229 greater_than_indices.push_back(i);
1233 return(greater_than_indices);
1244 const size_t this_size = this->size();
1246 T minimum = std::numeric_limits<T>::max();
1248 for(
size_t i = 0; i < this_size; i++)
1250 if((*
this)[i] < minimum)
1252 minimum = (*this)[i];
1267 const size_t this_size = this->size();
1269 T maximum = std::numeric_limits<T>::max();
1271 if(std::numeric_limits<T>::is_signed)
1280 for(
size_t i = 0; i < this_size; i++)
1282 if((*
this)[i] > maximum)
1284 maximum = (*this)[i];
1299 size_t this_size = this->size();
1301 T minimum = std::numeric_limits<T>::max();
1305 if(std::numeric_limits<T>::is_signed)
1307 maximum = -std::numeric_limits<T>::max();
1314 for(
size_t i = 0; i < this_size; i++)
1316 if((*
this)[i] < minimum)
1318 minimum = (*this)[i];
1321 if((*
this)[i] > maximum)
1323 maximum = (*this)[i];
1328 minimum_maximum[0] = minimum;
1329 minimum_maximum[1] = maximum;
1331 return(minimum_maximum);
1342 const size_t this_size = this->size();
1344 T minimum = std::numeric_limits<T>::max();
1346 for(
size_t i = 0; i < this_size; i++)
1348 if((*
this)[i] < minimum && !missing_indices.
contains(i))
1350 minimum = (*this)[i];
1365 const size_t this_size = this->size();
1369 if(std::numeric_limits<T>::is_signed)
1371 maximum = -std::numeric_limits<T>::max();
1378 for(
size_t i = 0; i < this_size; i++)
1380 if((*
this)[i] > maximum && !missing_indices.
contains(i))
1382 maximum = (*this)[i];
1397 size_t this_size = this->size();
1399 T minimum = std::numeric_limits<T>::max();
1403 if(std::numeric_limits<T>::is_signed)
1405 maximum = -std::numeric_limits<T>::max();
1412 for(
size_t i = 0; i < this_size; i++)
1416 if((*
this)[i] < minimum)
1418 minimum = (*this)[i];
1421 if((*
this)[i] > maximum)
1423 maximum = (*this)[i];
1429 minimum_maximum[0] = minimum;
1430 minimum_maximum[1] = maximum;
1432 return(minimum_maximum);
1453 std::ostringstream buffer;
1455 buffer <<
"OpenNN Exception: Vector Template.\n"
1456 <<
"Histogram<T> calculate_histogram(const size_t&) const method.\n"
1457 <<
"Number of bins is less than one.\n";
1459 throw std::logic_error(buffer.str());
1470 const Vector<T> minimum_maximum = calculate_minimum_maximum();
1472 const T minimum = minimum_maximum[0];
1473 const T maximum = minimum_maximum[1];
1475 const double length = (maximum-minimum)/(
double)bins_number;
1477 minimums[0] = minimum;
1478 maximums[0] = minimum + length;
1479 centers[0] = (maximums[0] + minimums[0])/2.0;
1483 for(
size_t i = 1; i < bins_number; i++)
1485 minimums[i] = minimums[i-1] + length;
1486 maximums[i] = maximums[i-1] + length;
1488 centers[i] = (maximums[i] + minimums[i])/2.0;
1493 const size_t this_size = this->size();
1495 for(
size_t i = 0; i < this_size; i++)
1497 if((*
this)[i] < centers[0])
1502 for(
size_t j = 1; j < bins_number-1; j++)
1504 if((*
this)[i] >= minimums[j] && (*
this)[i] < maximums[j])
1510 if((*
this)[i] >= centers[bins_number-1])
1512 frequencies[bins_number-1]++;
1541 std::ostringstream buffer;
1543 buffer <<
"OpenNN Exception: Vector Template.\n"
1544 <<
"Histogram<T> calculate_histogram_missing_values(const Vector<size_t>&, const size_t&) const method.\n"
1545 <<
"Number of bins is less than one.\n";
1547 throw std::logic_error(buffer.str());
1558 const Vector<T> minimum_maximum = calculate_minimum_maximum_missing_values(missing_indices);
1560 const T minimum = minimum_maximum[0];
1561 const T maximum = minimum_maximum[1];
1563 const double length = (maximum-minimum)/(
double)bins_number;
1565 minimums[0] = minimum;
1566 maximums[0] = minimum + length;
1567 centers[0] = (maximums[0] + minimums[0])/2.0;
1571 for(
size_t i = 1; i < bins_number; i++)
1573 minimums[i] = minimums[i-1] + length;
1574 maximums[i] = maximums[i-1] + length;
1576 centers[i] = (maximums[i] + minimums[i])/2.0;
1581 const size_t this_size = this->size();
1583 for(
size_t i = 0; i < this_size; i++)
1587 if((*
this)[i] < centers[0])
1592 for(
size_t j = 1; j < bins_number-1; j++)
1594 if((*
this)[i] >= minimums[j] && (*this)[i] < maximums[j])
1600 if((*
this)[i] >= centers[bins_number-1])
1602 frequencies[bins_number-1]++;
1622 const size_t this_size = this->size();
1624 T minimum = (*this)[0];
1625 size_t minimal_index = 0;
1627 for(
size_t i = 1; i < this_size; i++)
1629 if((*
this)[i] < minimum)
1631 minimum = (*this)[i];
1636 return(minimal_index);
1647 const size_t this_size = this->size();
1649 T maximum = (*this)[0];
1650 size_t maximal_index = 0;
1652 for(
size_t i = 1; i < this_size; i++)
1654 if((*
this)[i] > maximum)
1656 maximum = (*this)[i];
1661 return(maximal_index);
1673 const size_t this_size = this->size();
1679 for(
size_t i = 0; i < this_size; i++)
1681 for(
size_t j = 0; j < number; j++)
1685 minimal_indices[j] = i;
1690 return(minimal_indices);
1702 const size_t this_size = this->size();
1708 for(
size_t i = 0; i < this_size; i++)
1710 for(
size_t j = 0; j < number; j++)
1714 maximal_indices[j] = i;
1719 return(maximal_indices);
1730 const size_t this_size = this->size();
1732 T minimum = (*this)[0];
1733 T maximum = (*this)[0];
1735 size_t minimal_index = 0;
1736 size_t maximal_index = 0;
1738 for(
size_t i = 1; i < this_size; i++)
1740 if((*
this)[i] < minimum)
1742 minimum = (*this)[i];
1745 if((*
this)[i] > maximum)
1747 maximum = (*this)[i];
1753 minimal_maximal_index[0] = minimal_index;
1754 minimal_maximal_index[1] = maximal_index;
1756 return(minimal_maximal_index);
1768 const size_t this_size = this->size();
1772 for(
size_t i = 0; i < this_size; i++)
1774 power[i] = pow((*
this)[i], exponent);
1789 const size_t this_size = this->size();
1793 const size_t maximal_index = calculate_maximal_index();
1795 competitive[maximal_index] = 1;
1797 return(competitive);
1809 const size_t this_size = this->size();
1815 for(
size_t i = 0; i < this_size; i++)
1817 sum += exp((*
this)[i]);
1820 for(
size_t i = 0; i < this_size; i++)
1822 softmax[i] = exp((*
this)[i])/sum;
1836 const size_t this_size = this->size();
1838 Matrix<T> softmax_Jacobian(this_size, this_size);
1840 for(
size_t i = 0; i < this_size; i++)
1842 for(
size_t j = 0; j < this_size; j++)
1846 softmax_Jacobian(i,i) = (*this)[i]*(1.0 - (*this)[i]);
1850 softmax_Jacobian(i,i) = (*this)[i]*(*this)[j];
1855 return(softmax_Jacobian);
1867 const size_t this_size = this->size();
1871 for(
size_t i = 0; i < this_size; i++)
1873 if((*
this)[i] < 0.5)
1895 const size_t this_size = this->size();
1901 cumulative[0] = (*this)[0];
1903 for(
size_t i = 1; i < this_size; i++)
1905 cumulative[i] = cumulative[i-1] + (*this)[i];
1922 const size_t this_size = this->size();
1930 std::ostringstream buffer;
1932 buffer <<
"OpenNN Exception: Vector Template.\n"
1933 <<
"size_t calculate_cumulative_index(const T&) const.\n"
1934 <<
"Size must be greater than zero.\n";
1936 throw std::logic_error(buffer.str());
1939 T cumulative_value = (*this)[this_size-1];
1941 if(value > cumulative_value)
1943 std::ostringstream buffer;
1945 buffer <<
"OpenNN Exception: Vector Template.\n"
1946 <<
"size_t calculate_cumulative_index(const T&) const.\n"
1947 <<
"Value (" << value <<
") must be less than cumulative value (" << cumulative_value <<
").\n";
1949 throw std::logic_error(buffer.str());
1952 for(
size_t i = 1; i < this_size; i++)
1954 if((*
this)[i] < (*this)[i-1])
1956 std::ostringstream buffer;
1958 buffer <<
"OpenNN Exception: Vector Template.\n"
1959 <<
"int calculate_cumulative_index(const T&) const.\n"
1960 <<
"Vector elements must be crescent.\n";
1962 throw std::logic_error(buffer.str());
1968 if(value <= (*
this)[0])
1973 for(
size_t i = 1; i < this_size; i++)
1975 if(value > (*
this)[i-1] && value <= (*this)[i])
1981 return(this_size-1);
1992 const Vector<T> difference = (*
this - value).calculate_absolute_value();
1996 return(closest_index);
2007 const size_t this_size = this->size();
2011 for(
size_t i = 0; i < this_size; i++)
2027 const size_t this_size = this->size();
2031 for(
size_t i = 0; i < this_size; i++)
2050 const size_t this_size = this->size();
2054 for(
size_t i = 0; i < this_size; i++)
2056 product *= (*this)[i];
2070 const size_t this_size = this->size();
2078 std::ostringstream buffer;
2080 buffer <<
"OpenNN Exception: Vector Template.\n"
2081 <<
"double calculate_mean(void) const method.\n"
2082 <<
"Size must be greater than zero.\n";
2084 throw std::logic_error(buffer.str());
2089 const T sum = calculate_sum();
2091 const double mean = sum/(double)this_size;
2104 const size_t this_size = this->size();
2112 std::ostringstream buffer;
2114 buffer <<
"OpenNN Exception: Vector Template.\n"
2115 <<
"double calculate_standard_deviation(void) const method.\n"
2116 <<
"Size must be greater than zero.\n";
2118 throw std::logic_error(buffer.str());
2129 double squared_sum = 0.0;
2131 for(
size_t i = 0; i < this_size; i++)
2134 squared_sum += (*this)[i]*(*this)[i];
2137 const double numerator = squared_sum - (sum*sum)/this_size;
2138 const double denominator = this_size - 1.0;
2140 return(sqrt(numerator/denominator));
2155 const size_t this_size = this->size();
2159 std::ostringstream buffer;
2161 buffer <<
"OpenNN Exception: Vector Template.\n"
2162 <<
"double calculate_mean_standard_deviation(void).\n"
2163 <<
"Size must be greater than zero.\n";
2165 throw std::logic_error(buffer.str());
2170 const double mean = calculate_mean();
2171 const double standard_deviation = calculate_standard_deviation();
2174 mean_standard_deviation[0] = mean;
2175 mean_standard_deviation[1] = standard_deviation;
2177 return(mean_standard_deviation);
2188 const size_t this_size = this->size();
2196 std::ostringstream buffer;
2198 buffer <<
"OpenNN Exception: Vector Template.\n"
2199 <<
"double calculate_mean_missing_values(const Vector<size_t>&) const method.\n"
2200 <<
"Size must be greater than zero.\n";
2202 throw std::logic_error(buffer.str());
2211 for(
size_t i = 0; i < this_size; i++)
2220 const double mean = sum/(double)count;
2233 const size_t this_size = this->size();
2241 std::ostringstream buffer;
2243 buffer <<
"OpenNN Exception: Vector Template.\n"
2244 <<
"double calculate_standard_deviation_missing_values(const Vector<size_t>&) const method.\n"
2245 <<
"Size must be greater than zero.\n";
2247 throw std::logic_error(buffer.str());
2253 double squared_sum = 0.0;
2257 for(
size_t i = 0; i < this_size; i++)
2262 squared_sum += (*this)[i]*(*this)[i];
2273 const double numerator = squared_sum - (sum*sum)/count;
2274 const double denominator = this_size - 1.0;
2276 return(sqrt(numerator/denominator));
2291 const size_t this_size = this->size();
2295 std::ostringstream buffer;
2297 buffer <<
"OpenNN Exception: Vector Template.\n"
2298 <<
"double calculate_statistics(void).\n"
2299 <<
"Size must be greater than zero.\n";
2301 throw std::logic_error(buffer.str());
2308 statistics.
minimum = calculate_minimum();
2309 statistics.
maximum = calculate_maximum();
2310 statistics.
mean = calculate_mean();
2328 const size_t this_size = this->size();
2332 std::ostringstream buffer;
2334 buffer <<
"OpenNN Exception: Vector Template.\n"
2335 <<
"double calculate_statistics_missing_values(const Vector<size_t>&).\n"
2336 <<
"Size must be greater than zero.\n";
2338 throw std::logic_error(buffer.str());
2344 statistics.
minimum = calculate_minimum_missing_values(missing_indices);
2345 statistics.
maximum = calculate_maximum_missing_values(missing_indices);
2346 statistics.
mean = calculate_mean_missing_values(missing_indices);
2347 statistics.
standard_deviation = calculate_standard_deviation_missing_values(missing_indices);
2360 const size_t this_size = this->size();
2366 for(
size_t i = 0; i < this_size; i++)
2368 norm += (*this)[i]*(*this)[i];
2384 const size_t this_size = this->size();
2390 const double norm = calculate_norm();
2398 gradient = (*this)/norm;
2412 const size_t this_size = this->size();
2416 Matrix<T> Hessian(this_size, this_size);
2418 const double norm = calculate_norm();
2427 Hessian = (*this).
direct(*
this)/(norm*norm*norm);
2445 std::ostringstream buffer;
2449 buffer <<
"OpenNN Exception: Vector Template.\n"
2450 <<
"double calculate_p_norm(const double&) const method.\n"
2451 <<
"p value must be greater than zero.\n";
2453 throw std::logic_error(buffer.str());
2458 const size_t this_size = this->size();
2464 for(
size_t i = 0; i < this_size; i++)
2466 norm += pow(fabs((*
this)[i]), p);
2469 norm = pow(norm, 1.0/p);
2486 std::ostringstream buffer;
2490 buffer <<
"OpenNN Exception: Vector Template.\n"
2491 <<
"Vector<double> calculate_p_norm_gradient(const double&) const method.\n"
2492 <<
"p value must be greater than zero.\n";
2494 throw std::logic_error(buffer.str());
2499 const size_t this_size = this->size();
2505 const double p_norm = calculate_p_norm(p);
2513 for(
size_t i = 0; i < this_size; i++)
2515 gradient[i] = (*this)[i]*pow(fabs((*
this)[i]),p-2.0)/pow(p_norm, p-1.0);
2532 const size_t this_size = (*this).size();
2536 const double norm = calculate_norm();
2544 normalized = (*this)/norm;
2559 return( sqrt(calculate_sum_squared_error(other_vector)) );
2571 const size_t this_size = this->size();
2577 const size_t other_size = other_vector.size();
2579 if(other_size != this_size)
2581 std::ostringstream buffer;
2583 buffer <<
"OpenNN Exception: Vector Template.\n"
2584 <<
"double calculate_sum_squared_error(const Vector<double>&) const method.\n"
2585 <<
"Size must be equal to this size.\n";
2587 throw std::logic_error(buffer.str());
2592 double sum_squared_error = 0.0;
2595 for(
size_t i = 0; i < this_size; i++)
2597 error = (*this)[i] - other_vector[i];
2599 sum_squared_error += error*error;
2602 return(sum_squared_error);
2615 const size_t this_size = this->size();
2621 std::ostringstream buffer;
2625 buffer <<
"OpenNN Exception: Vector Template.\n"
2626 <<
"double calculate_Minkowski_error(const Vector<double>&) const method.\n"
2627 <<
"Size must be greater than zero.\n";
2629 throw std::logic_error(buffer.str());
2632 const size_t other_size = other_vector.size();
2634 if(other_size != this_size)
2636 buffer <<
"OpenNN Exception: Vector Template.\n"
2637 <<
"double calculate_Minkowski_error(const Vector<double>&) const method.\n"
2638 <<
"Other size must be equal to this size.\n";
2640 throw std::logic_error(buffer.str());
2645 if(Minkowski_parameter < 1.0 || Minkowski_parameter > 2.0)
2647 buffer <<
"OpenNN Exception: Vector Template.\n"
2648 <<
"double calculate_Minkowski_error(const Vector<double>&) const method.\n"
2649 <<
"The Minkowski parameter must be comprised between 1 and 2\n";
2651 throw std::logic_error(buffer.str());
2656 double Minkowski_error = 0.0;
2658 for(
size_t i = 0; i < this_size; i++)
2660 Minkowski_error += pow(fabs((*
this)[i] - other_vector[i]), Minkowski_parameter);
2663 Minkowski_error = pow(Minkowski_error, 1.0/Minkowski_parameter);
2665 return(Minkowski_error);
2677 const size_t n = this->size();
2683 const size_t other_size = other.size();
2685 std::ostringstream buffer;
2689 buffer <<
"OpenNN Exception: Vector Template.\n"
2690 <<
"T calculate_linear_correlation(const Vector<T>&) const method.\n"
2691 <<
"Other size must be equal to this size.\n";
2693 throw std::logic_error(buffer.str());
2706 for(
size_t i = 0; i < n; i++)
2711 s_xx += other[i]*other[i];
2712 s_yy += (*this)[i]*(*this)[i];
2714 s_xy += other[i]*(*this)[i];
2717 T linear_correlation;
2719 if(s_x == 0 && s_y == 0 && s_xx == 0 && s_yy == 0 && s_xy == 0)
2721 linear_correlation = 1;
2725 const double numerator = (n*s_xy - s_x*s_y);
2726 const double denominator = sqrt((n*s_xx - s_x*s_x)*(n*s_yy - s_y*s_y));
2728 if(denominator < 1.0e-50)
2730 linear_correlation = 0;
2734 linear_correlation = numerator/denominator;
2738 return(linear_correlation);
2751 const size_t n = this->size();
2757 const size_t other_size = other.size();
2759 std::ostringstream buffer;
2763 buffer <<
"OpenNN Exception: Vector Template.\n"
2764 <<
"T calculate_linear_correlation(const Vector<T>&) const method.\n"
2765 <<
"Other size must be equal to this size.\n";
2767 throw std::logic_error(buffer.str());
2782 for(
size_t i = 0; i < n; i++)
2789 s_xx += other[i]*other[i];
2790 s_yy += (*this)[i]*(*this)[i];
2792 s_xy += other[i]*(*this)[i];
2798 T linear_correlation;
2800 if(s_x == 0 && s_y == 0 && s_xx == 0 && s_yy == 0 && s_xy == 0)
2802 linear_correlation = 1;
2806 const double numerator = (count*s_xy - s_x*s_y);
2807 const double denominator = sqrt((count*s_xx - s_x*s_x)*(count*s_yy - s_y*s_y));
2809 if(denominator < 1.0e-50)
2811 linear_correlation = 0;
2815 linear_correlation = numerator/denominator;
2819 return(linear_correlation);
2832 const size_t n = this->size();
2838 const size_t other_size = other.size();
2840 std::ostringstream buffer;
2844 buffer <<
"OpenNN Exception: Vector Template.\n"
2845 <<
"LinearRegressionParameters<T> calculate_linear_regression_parameters(const Vector<T>&) const method.\n"
2846 <<
"Other size must be equal to this size.\n";
2848 throw std::logic_error(buffer.str());
2861 for(
size_t i = 0; i < n; i++)
2866 s_xx += other[i]*other[i];
2867 s_yy += (*this)[i]*(*this)[i];
2869 s_xy += other[i]*(*this)[i];
2874 if(s_x == 0 && s_y == 0 && s_xx == 0 && s_yy == 0 && s_xy == 0)
2876 linear_regression_parameters.
intercept = 0;
2878 linear_regression_parameters.
slope = 0;
2884 linear_regression_parameters.
intercept = (s_y*s_xx - s_x*s_xy)
2885 /(n*s_xx - s_x*s_x);
2887 linear_regression_parameters.
slope = (n*s_xy - s_x*s_y)
2888 /(n*s_xx - s_x*s_x);
2890 linear_regression_parameters.
correlation = (n*s_xy - s_x*s_y)
2891 /sqrt((n*s_xx - s_x*s_x)*(n*s_yy - s_y*s_y));
2894 return(linear_regression_parameters);
2905 const size_t this_size = this->size();
2909 for(
size_t i = 0; i < this_size; i++)
2913 absolute_value[i] = (*this)[i];
2917 absolute_value[i] = -(*this)[i];
2921 return(absolute_value);
2932 const size_t this_size = this->size();
2934 for(
size_t i = 0; i < this_size; i++)
2938 (*this)[i] = -(*this)[i];
2952 const size_t this_size = this->size();
2956 for(
size_t i = 0; i < this_size; i++)
2958 if((*
this)[i] < lower_bound)
2960 bounded_vector[i] = lower_bound;
2964 bounded_vector[i] = (*this)[i];
2968 return(bounded_vector);
2980 const size_t this_size = this->size();
2986 const size_t lower_bound_size = lower_bound.size();
2988 if(lower_bound_size != this_size)
2990 std::ostringstream buffer;
2992 buffer <<
"OpenNN Exception: Vector Template.\n"
2993 <<
"Vector<T> calculate_lower_bounded(const Vector<T>&) const method.\n"
2994 <<
"Lower bound size must be equal to vector size.\n";
2996 throw std::logic_error(buffer.str());
3005 for(
size_t i = 0; i < this_size; i++)
3007 if((*
this)[i] < lower_bound[i])
3009 bounded_vector[i] = lower_bound[i];
3013 bounded_vector[i] = (*this)[i];
3017 return(bounded_vector);
3029 const size_t this_size = this->size();
3033 for(
size_t i = 0; i < this_size; i++)
3035 if((*
this)[i] > upper_bound)
3037 bounded_vector[i] = upper_bound;
3041 bounded_vector[i] = (*this)[i];
3045 return(bounded_vector);
3057 const size_t this_size = this->size();
3063 const size_t upper_bound_size = upper_bound.size();
3065 if(upper_bound_size != this_size)
3067 std::ostringstream buffer;
3069 buffer <<
"OpenNN Exception: Vector Template.\n"
3070 <<
"Vector<T> calculate_upper_bounded(const Vector<T>&) const method.\n"
3071 <<
"Upper bound size must be equal to vector size.\n";
3073 throw std::logic_error(buffer.str());
3082 for(
size_t i = 0; i < this_size; i++)
3084 if((*
this)[i] > upper_bound[i])
3086 bounded_vector[i] = upper_bound[i];
3090 bounded_vector[i] = (*this)[i];
3094 return(bounded_vector);
3108 const size_t this_size = this->size();
3112 for(
size_t i = 0; i < this_size; i++)
3114 if((*
this)[i] < lower_bound)
3116 bounded_vector[i] = lower_bound;
3118 else if((*
this)[i] > upper_bound)
3120 bounded_vector[i] = upper_bound;
3124 bounded_vector[i] = (*this)[i];
3128 return(bounded_vector);
3142 const size_t this_size = this->size();
3148 const size_t lower_bound_size = lower_bound.size();
3149 const size_t upper_bound_size = upper_bound.size();
3151 if(lower_bound_size != this_size || upper_bound_size != this_size)
3153 std::ostringstream buffer;
3155 buffer <<
"OpenNN Exception: Vector Template.\n"
3156 <<
"Vector<T> calculate_lower_upper_bounded(const Vector<T>&, const Vector<T>&) const method.\n"
3157 <<
"Lower and upper bound sizes must be equal to vector size.\n";
3159 throw std::logic_error(buffer.str());
3168 for(
size_t i = 0; i < this_size; i++)
3170 if((*
this)[i] < lower_bound[i])
3172 bounded_vector[i] = lower_bound[i];
3174 else if((*
this)[i] > upper_bound[i])
3176 bounded_vector[i] = upper_bound[i];
3180 bounded_vector[i] = (*this)[i];
3184 return(bounded_vector);
3196 const size_t this_size = this->size();
3198 for(
size_t i = 0; i < this_size; i++)
3200 if((*
this)[i] < lower_bound)
3202 (*this)[i] = lower_bound;
3216 const size_t this_size = this->size();
3218 for(
size_t i = 0; i < this_size; i++)
3220 if((*
this)[i] < lower_bound[i])
3222 (*this)[i] = lower_bound[i];
3236 const size_t this_size = this->size();
3238 for(
size_t i = 0; i < this_size; i++)
3240 if((*
this)[i] > upper_bound)
3242 (*this)[i] = upper_bound;
3256 const size_t this_size = this->size();
3258 for(
size_t i = 0; i < this_size; i++)
3260 if((*
this)[i] > upper_bound[i])
3262 (*this)[i] = upper_bound[i];
3278 const size_t this_size = this->size();
3280 for(
size_t i = 0; i < this_size; i++)
3282 if((*
this)[i] < lower_bound)
3284 (*this)[i] = lower_bound;
3286 else if((*
this)[i] > upper_bound)
3288 (*this)[i] = upper_bound;
3304 const size_t this_size = this->size();
3306 for(
size_t i = 0; i < this_size; i++)
3308 if((*
this)[i] < lower_bound[i])
3310 (*this)[i] = lower_bound[i];
3312 else if((*
this)[i] > upper_bound[i])
3314 (*this)[i] = upper_bound[i];
3330 const size_t this_size = this->size();
3336 std::sort(sorted_vector.begin(), sorted_vector.end(), std::less<double>());
3338 for(
size_t i = 0; i < this_size; i++)
3340 for(
size_t j = 0; j < this_size; j++)
3342 if((*
this)[i] == sorted_vector[j])
3362 const size_t this_size = this->size();
3368 std::sort(sorted_vector.begin(), sorted_vector.end(), std::greater<double>());
3370 for(
size_t i = 0; i < this_size; i++)
3372 for(
size_t j = 0; j < this_size; j++)
3374 if((*
this)[i] == sorted_vector[j])
3393 const size_t this_size = this->size();
3397 std::transform(this->begin(), this->end(),
3399 std::bind2nd(std::plus<T>(), scalar) );
3413 const size_t this_size = this->size();
3419 const size_t other_size = other_vector.size();
3421 if(other_size != this_size)
3423 std::ostringstream buffer;
3425 buffer <<
"OpenNN Exception: Vector Template.\n"
3426 <<
"Vector<T> operator + (const Vector<T>) const.\n"
3427 <<
"Size of vectors is " << this_size <<
" and " << other_size <<
" and they must be the same.\n";
3429 throw std::logic_error(buffer.str());
3436 std::transform(this->begin(), this->end(), other_vector.begin(), sum.begin(), std::plus<T>());
3450 const size_t this_size = this->size();
3454 std::transform(this->begin(), this->end(), difference.begin(), std::bind2nd(std::minus<T>(), scalar));
3468 const size_t this_size = this->size();
3474 const size_t other_size = other_vector.size();
3476 if(other_size != this_size)
3478 std::ostringstream buffer;
3480 buffer <<
"OpenNN Exception: Vector Template.\n"
3481 <<
"Vector<T> operator - (const Vector<T>&) const.\n"
3482 <<
"Size of vectors is " << this_size <<
" and " << other_size <<
" and they must be the same.\n";
3484 throw std::logic_error(buffer.str());
3491 std::transform( this->begin(), this->end(), other_vector.begin(), difference.begin(), std::minus<T>());
3505 const size_t this_size = this->size();
3509 std::transform( this->begin(), this->end(), product.begin(), std::bind2nd(std::multiplies<T>(), scalar));
3523 const size_t this_size = this->size();
3529 const size_t other_size = other_vector.size();
3531 if(other_size != this_size)
3533 std::ostringstream buffer;
3535 buffer <<
"OpenNN Exception: Vector Template.\n"
3536 <<
"Vector<T> operator * (const Vector<T>&) const.\n"
3537 <<
"Size of other vector (" << other_size <<
") must be equal to size of this vector (" << this_size <<
").\n";
3539 throw std::logic_error(buffer.str());
3546 std::transform(this->begin(), this->end(), other_vector.begin(), product.begin(), std::multiplies<T>());
3567 const size_t this_size = this->size();
3569 if(rows_number != this_size)
3571 std::ostringstream buffer;
3573 buffer <<
"OpenNN Exception: Vector Template.\n"
3574 <<
"Vector<T> operator * (const Matrix<T>&) const.\n"
3575 <<
"Number of matrix rows (" << rows_number <<
") must be equal to vector size (" << this_size <<
").\n";
3577 throw std::logic_error(buffer.str());
3582 Matrix<T> product(rows_number, columns_number);
3584 for(
size_t i = 0; i < rows_number; i++)
3586 for(
size_t j = 0; j < columns_number; j++)
3588 product(i,j) = (*this)[i]*matrix(i,j);
3607 const size_t this_size = this->size();
3613 if(rows_number != this_size)
3615 std::ostringstream buffer;
3617 buffer <<
"OpenNN Exception: Vector Template.\n"
3618 <<
"Vector<T> dot(const Matrix<T>&) const method.\n"
3619 <<
"Matrix number of rows must be equal to vector size.\n";
3621 throw std::logic_error(buffer.str());
3638 const Eigen::Map<Eigen::VectorXd> vector_eigen((
double*)this->data(), this_size);
3639 const Eigen::Map<Eigen::MatrixXd> matrix_eigen((
double*)matrix.data(), rows_number, columns_number);
3640 Eigen::Map<Eigen::VectorXd> product_eigen(product.data(), columns_number);
3642 product_eigen = vector_eigen.transpose()*matrix_eigen;
3656 const size_t this_size = this->size();
3662 const size_t other_size = other_vector.size();
3664 if(other_size != this_size)
3666 std::ostringstream buffer;
3668 buffer <<
"OpenNN Exception: Vector Template.\n"
3669 <<
"Type dot(const Vector<T>&) const method.\n"
3670 <<
"Both vector sizes must be the same.\n";
3672 throw std::logic_error(buffer.str());
3684 const Eigen::Map<Eigen::VectorXd> this_vector_eigen((
double*)this->data(), this_size);
3685 const Eigen::Map<Eigen::VectorXd> other_vector_eigen((
double*)other_vector.data(), this_size);
3687 return(this_vector_eigen.dot(other_vector_eigen));
3699 const size_t this_size = this->size();
3705 const size_t other_size = other_vector.size();
3707 if(other_size != this_size)
3709 std::ostringstream buffer;
3711 buffer <<
"OpenNN Exception: Vector Template.\n"
3712 <<
"Matrix<T> direct(const Vector<T>&) const method.\n"
3713 <<
"Both vector sizes must be the same.\n";
3715 throw std::logic_error(buffer.str());
3722 for(
size_t i = 0; i < this_size; i++)
3724 for(
size_t j = 0; j < this_size; j++)
3726 direct(i,j) = (*this)[i]*other_vector[j];
3742 const size_t this_size = this->size();
3746 std::transform(this->begin(), this->end(), cocient.begin(), std::bind2nd(std::divides<T>(), scalar));
3760 const size_t this_size = this->size();
3766 const size_t other_size = other_vector.size();
3768 if(other_size != this_size)
3770 std::ostringstream buffer;
3772 buffer <<
"OpenNN Exception: Vector Template.\n"
3773 <<
"Vector<T> operator / (const Vector<T>&) const.\n"
3774 <<
"Both vector sizes must be the same.\n";
3776 throw std::logic_error(buffer.str());
3783 std::transform(this->begin(), this->end(), other_vector.begin(), cocient.begin(), std::divides<T>());
3797 const size_t this_size = this->size();
3799 for(
size_t i = 0; i < this_size; i++)
3801 (*this)[i] = (*this)[i] + value;
3814 const size_t this_size = this->size();
3820 const size_t other_size = other_vector.size();
3822 if(other_size != this_size)
3824 std::ostringstream buffer;
3826 buffer <<
"OpenNN Exception: Vector Template.\n"
3827 <<
"void operator += (const Vector<T>&).\n"
3828 <<
"Both vector sizes must be the same.\n";
3830 throw std::logic_error(buffer.str());
3835 for(
size_t i = 0; i < this_size; i++)
3837 (*this)[i] = (*this)[i] + other_vector[i];
3850 const size_t this_size = this->size();
3852 for(
size_t i = 0; i < this_size; i++)
3854 (*this)[i] = (*this)[i] - value;
3867 const size_t this_size = this->size();
3873 const size_t other_size = other_vector.size();
3875 if(other_size != this_size)
3877 std::ostringstream buffer;
3879 buffer <<
"OpenNN Exception: Vector Template.\n"
3880 <<
"void operator -= (const Vector<T>&).\n"
3881 <<
"Both vector sizes must be the same.\n";
3883 throw std::logic_error(buffer.str());
3888 for(
size_t i = 0; i < this_size; i++)
3890 (*this)[i] = (*this)[i] - other_vector[i];
3903 const size_t this_size = this->size();
3905 for(
size_t i = 0; i < this_size; i++)
3907 (*this)[i] = (*this)[i]*value;
3920 const size_t this_size = this->size();
3926 const size_t other_size = other_vector.size();
3928 if(other_size != this_size)
3930 std::ostringstream buffer;
3932 buffer <<
"OpenNN Exception: Vector Template.\n"
3933 <<
"void operator *= (const Vector<T>&).\n"
3934 <<
"Both vector sizes must be the same.\n";
3936 throw std::logic_error(buffer.str());
3941 for(
size_t i = 0; i < this_size; i++)
3943 (*this)[i] = (*this)[i]*other_vector[i];
3956 const size_t this_size = this->size();
3958 for(
size_t i = 0; i < this_size; i++)
3960 (*this)[i] = (*this)[i]/value;
3973 const size_t this_size = this->size();
3979 const size_t other_size = other_vector.size();
3981 if(other_size != this_size)
3983 std::ostringstream buffer;
3985 buffer <<
"OpenNN Exception: Vector Template.\n"
3986 <<
"void operator /= (const Vector<T>&).\n"
3987 <<
"Both vector sizes must be the same.\n";
3989 throw std::logic_error(buffer.str());
3994 for(
size_t i = 0; i < this_size; i++)
3996 (*this)[i] = (*this)[i]/other_vector[i];
4008 for(
size_t i = 0; i < this->size(); i++)
4025 for(
size_t i = 0; i < this->size(); i++)
4043 if(maximum - minimum < 1.0e-99)
4048 const size_t this_size = this->size();
4050 for(
size_t i = 0; i < this_size; i++)
4052 (*this)[i] = 2.0*((*this)[i]-minimum)/(maximum-minimum)-1.0;
4080 scale_minimum_maximum(statistics);
4095 if(standard_deviation < 1.0e-99)
4100 const size_t this_size = this->size();
4102 for(
size_t i = 0; i < this_size; i++)
4104 (*this)[i] = ((*this)[i]-mean)/standard_deviation;
4133 scale_mean_standard_deviation(statistics);
4150 const size_t this_size = this->size();
4154 const size_t minimum_size = minimum.size();
4156 if(minimum_size != this_size)
4158 std::ostringstream buffer;
4160 buffer <<
"OpenNN Exception: Vector template."
4161 <<
"void scale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4162 <<
"Size of minimum vector must be equal to size.\n";
4164 throw std::logic_error(buffer.str());
4167 const size_t maximum_size = maximum.size();
4169 if(maximum_size != this_size)
4171 std::ostringstream buffer;
4173 buffer <<
"OpenNN Exception: Vector template."
4174 <<
"void scale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4175 <<
"Size of maximum vector must be equal to size.\n";
4177 throw std::logic_error(buffer.str());
4184 for(
size_t i = 0; i < this_size; i++)
4186 if(maximum[i] - minimum[i] < 1e-99)
4188 std::cout <<
"OpenNN Warning: Vector class.\n"
4189 <<
"void scale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4190 <<
"Minimum and maximum values of variable " << i <<
" are equal.\n"
4191 <<
"Those elements won't be scaled.\n";
4197 (*this)[i] = 2.0*((*this)[i] - minimum[i])/(maximum[i]-minimum[i])-1.0;
4214 const size_t this_size = this->size();
4218 const size_t mean_size = mean.size();
4220 if(mean_size != this_size)
4222 std::ostringstream buffer;
4224 buffer <<
"OpenNN Exception: Vector template."
4225 <<
"void scale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4226 <<
"Size of mean vector must be equal to size.\n";
4228 throw std::logic_error(buffer.str());
4231 const size_t standard_deviation_size = standard_deviation.size();
4233 if(standard_deviation_size != this_size)
4235 std::ostringstream buffer;
4237 buffer <<
"OpenNN Exception: Vector template."
4238 <<
"void scale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4239 <<
"Size of standard deviation vector must be equal to size.\n";
4241 throw std::logic_error(buffer.str());
4248 for(
size_t i = 0; i < this_size; i++)
4250 if(standard_deviation[i] < 1e-99)
4252 std::cout <<
"OpenNN Warning: Vector class.\n"
4253 <<
"void scale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4254 <<
"Standard deviation of variable " << i <<
" is zero.\n"
4255 <<
"Those elements won't be scaled.\n";
4261 (*this)[i] = ((*this)[i] - mean[i])/standard_deviation[i];
4277 const size_t this_size = this->size();
4281 const size_t minimum_size = minimum.size();
4283 if(minimum_size != this_size)
4285 std::ostringstream buffer;
4287 buffer <<
"OpenNN Exception: Vector template."
4288 <<
"Vector<T> calculate_scaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4289 <<
"Size of minimum vector must be equal to size.\n";
4291 throw std::logic_error(buffer.str());
4294 const size_t maximum_size = maximum.size();
4296 if(maximum_size != this_size)
4298 std::ostringstream buffer;
4300 buffer <<
"OpenNN Exception: Vector template."
4301 <<
"Vector<T> calculate_scaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4302 <<
"Size of maximum vector must be equal to size.\n";
4304 throw std::logic_error(buffer.str());
4309 Vector<T> scaled_minimum_maximum(this_size);
4313 for(
size_t i = 0; i < this_size; i++)
4315 if(maximum[i] - minimum[i] < 1e-99)
4317 std::cout <<
"OpenNN Warning: Vector class.\n"
4318 <<
"Vector<T> calculate_scaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4319 <<
"Minimum and maximum values of variable " << i <<
" are equal.\n"
4320 <<
"Those elements won't be scaled.\n";
4322 scaled_minimum_maximum[i] = (*this)[i];
4326 scaled_minimum_maximum[i] = 2.0*((*this)[i] - minimum[i])/(maximum[i]-minimum[i])-1.0;
4330 return(scaled_minimum_maximum);
4344 const size_t this_size = this->size();
4348 std::ostringstream buffer;
4350 const size_t mean_size = mean.size();
4352 if(mean_size != this_size)
4354 buffer <<
"OpenNN Exception: Vector template."
4355 <<
"Vector<T> calculate_scaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4356 <<
"Size of mean vector must be equal to size.\n";
4358 throw std::logic_error(buffer.str());
4361 const size_t standard_deviation_size = standard_deviation.size();
4363 if(standard_deviation_size != this_size)
4365 buffer <<
"OpenNN Exception: Vector template.\n"
4366 <<
"Vector<T> calculate_scaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4367 <<
"Size of standard deviation vector must be equal to size.\n";
4369 throw std::logic_error(buffer.str());
4374 Vector<T> scaled_mean_standard_deviation(this_size);
4376 for(
size_t i = 0; i < this_size; i++)
4378 if(standard_deviation[i] < 1e-99)
4380 std::cout <<
"OpenNN Warning: Vector template.\n"
4381 <<
"Vector<T> calculate_scaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4382 <<
"Standard deviation of variable " << i <<
" is zero.\n"
4383 <<
"Those elements won't be scaled.\n";
4385 scaled_mean_standard_deviation = (*this)[i];
4389 scaled_mean_standard_deviation[i] = (*this)[i]*standard_deviation[i] + mean[i];
4393 return(scaled_mean_standard_deviation);
4407 const size_t this_size = this->size();
4411 const size_t minimum_size = minimum.size();
4413 if(minimum_size != this_size)
4415 std::ostringstream buffer;
4417 buffer <<
"OpenNN Exception: Vector template."
4418 <<
"Vector<T> calculate_unscaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4419 <<
"Size of minimum vector must be equal to size.\n";
4421 throw std::logic_error(buffer.str());
4424 const size_t maximum_size = maximum.size();
4426 if(maximum_size != this_size)
4428 std::ostringstream buffer;
4430 buffer <<
"OpenNN Exception: Vector template."
4431 <<
"Vector<T> calculate_unscaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4432 <<
"Size of maximum vector must be equal to size.\n";
4434 throw std::logic_error(buffer.str());
4439 Vector<T> unscaled_minimum_maximum(this_size);
4441 for(
size_t i = 0; i < this_size; i++)
4443 if(maximum[i] - minimum[i] < 1e-99)
4445 std::cout <<
"OpenNN Warning: Vector template.\n"
4446 <<
"Vector<T> calculate_unscaled_minimum_maximum(const Vector<T>&, const Vector<T>&) const method.\n"
4447 <<
"Minimum and maximum values of variable " << i <<
" are equal.\n"
4448 <<
"Those elements won't be unscaled.\n";
4450 unscaled_minimum_maximum[i] = (*this)[i];
4454 unscaled_minimum_maximum[i] = 0.5*((*this)[i] + 1.0)*(maximum[i]-minimum[i]) + minimum[i];
4458 return(unscaled_minimum_maximum);
4472 const size_t this_size = this->size();
4476 const size_t mean_size = mean.size();
4478 if(mean_size != this_size)
4480 std::ostringstream buffer;
4482 buffer <<
"OpenNN Exception: Vector template."
4483 <<
"Vector<T> calculate_unscaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4484 <<
"Size of mean vector must be equal to size.\n";
4486 throw std::logic_error(buffer.str());
4489 const size_t standard_deviation_size = standard_deviation.size();
4491 if(standard_deviation_size != this_size)
4493 std::ostringstream buffer;
4495 buffer <<
"OpenNN Exception: Vector template.\n"
4496 <<
"Vector<T> calculate_unscaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4497 <<
"Size of standard deviation vector must be equal to size.\n";
4499 throw std::logic_error(buffer.str());
4504 Vector<T> unscaled_mean_standard_deviation(this_size);
4506 for(
size_t i = 0; i < this_size; i++)
4508 if(standard_deviation[i] < 1e-99)
4510 std::cout <<
"OpenNN Warning: Vector template.\n"
4511 <<
"Vector<T> calculate_unscaled_mean_standard_deviation(const Vector<T>&, const Vector<T>&) const method.\n"
4512 <<
"Standard deviation of variable " << i <<
" is zero.\n"
4513 <<
"Those elements won't be scaled.\n";
4515 unscaled_mean_standard_deviation[i] = (*this)[i];
4519 unscaled_mean_standard_deviation[i] = (*this)[i]*standard_deviation[i] + mean[i];
4523 return(unscaled_mean_standard_deviation);
4538 const size_t this_size = this->size();
4542 const size_t minimum_size = minimum.size();
4544 if(minimum_size != this_size)
4546 std::ostringstream buffer;
4548 buffer <<
"OpenNN Exception: Vector template."
4549 <<
"void unscale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4550 <<
"Size of minimum vector must be equal to size.\n";
4552 throw std::logic_error(buffer.str());
4555 const size_t maximum_size = maximum.size();
4557 if(maximum_size != this_size)
4559 std::ostringstream buffer;
4561 buffer <<
"OpenNN Exception: Vector template."
4562 <<
"void unscale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4563 <<
"Size of maximum vector must be equal to size.\n";
4565 throw std::logic_error(buffer.str());
4570 for(
size_t i = 0; i < this_size; i++)
4572 if(maximum[i] - minimum[i] < 1e-99)
4574 std::cout <<
"OpenNN Warning: Vector template.\n"
4575 <<
"void unscale_minimum_maximum(const Vector<T>&, const Vector<T>&) method.\n"
4576 <<
"Minimum and maximum values of variable " << i <<
" are equal.\n"
4577 <<
"Those elements won't be unscaled.\n";
4583 (*this)[i] = 0.5*((*this)[i] + 1.0)*(maximum[i]-minimum[i]) + minimum[i];
4600 const size_t this_size = this->size();
4604 const size_t mean_size = mean.size();
4606 if(mean_size != this_size)
4608 std::ostringstream buffer;
4610 buffer <<
"OpenNN Exception: Vector template."
4611 <<
"void unscale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4612 <<
"Size of mean vector must be equal to size.\n";
4614 throw std::logic_error(buffer.str());
4617 const size_t standard_deviation_size = standard_deviation.size();
4619 if(standard_deviation_size != this_size)
4621 std::ostringstream buffer;
4623 buffer <<
"OpenNN Exception: Vector template.\n"
4624 <<
"void unscale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4625 <<
"Size of standard deviation vector must be equal to size.\n";
4627 throw std::logic_error(buffer.str());
4632 for(
size_t i = 0; i < this_size; i++)
4634 if(standard_deviation[i] < 1e-99)
4636 std::cout <<
"OpenNN Warning: Vector template.\n"
4637 <<
"void unscale_mean_standard_deviation(const Vector<T>&, const Vector<T>&) method.\n"
4638 <<
"Standard deviation of variable " << i <<
" is zero.\n"
4639 <<
"Those elements won't be scaled.\n";
4645 (*this)[i] = (*this)[i]*standard_deviation[i] + mean[i];
4660 const size_t this_size = this->size();
4664 for(
size_t i = 0; i < this_size; i++)
4666 matrix(i,i) = (*this)[i];
4681 const size_t new_size = indices.size();
4687 const size_t this_size = this->size();
4689 for(
size_t i = 0; i < new_size; i++)
4691 if(indices[i] > this_size)
4693 std::ostringstream buffer;
4695 buffer <<
"OpenNN Exception: Vector Template.\n"
4696 <<
"Vector<T> arrange_subvector(const Vector<T>&) const method.\n"
4697 <<
"Index is equal or greater than this size.\n";
4699 throw std::logic_error(buffer.str());
4707 for(
size_t i = 0; i < new_size; i++)
4709 subvector[i] = (*this)[indices[i]];
4728 const size_t this_size = this->size();
4730 if(elements_number > this_size)
4732 std::ostringstream buffer;
4734 buffer <<
"OpenNN Exception: Vector Template.\n"
4735 <<
"Vector<T> arrange_subvector_first(const size_t&) const method.\n"
4736 <<
"Number of elements must be equal or greater than this size.\n";
4738 throw std::logic_error(buffer.str());
4745 for(
size_t i = 0; i < elements_number; i++)
4747 subvector[i] = (*this)[i];
4762 const size_t this_size = this->size();
4768 if(elements_number > this_size)
4770 std::ostringstream buffer;
4772 buffer <<
"OpenNN Exception: Vector Template.\n"
4773 <<
"Vector<T> arrange_subvector_last(const size_t&) const method.\n"
4774 <<
"Number of elements must be equal or greater than this size.\n";
4776 throw std::logic_error(buffer.str());
4783 for(
size_t i = 0; i < elements_number; i++)
4785 subvector[i] = (*this)[i+this_size-elements_number];
4801 std::ifstream file(file_name.c_str());
4803 std::stringstream buffer;
4809 getline(file, line);
4814 std::istream_iterator<std::string> it(buffer);
4815 std::istream_iterator<std::string> end;
4817 const std::vector<std::string> results(it, end);
4819 const size_t new_size = (size_t)results.size();
4821 this->resize(new_size);
4824 file.seekg(0, std::ios::beg);
4828 for(
size_t i = 0; i < new_size; i++)
4847 std::ofstream file(file_name.c_str());
4851 std::ostringstream buffer;
4853 buffer <<
"OpenNN Exception: Vector template.\n"
4854 <<
"void save(const std::string&) const method.\n"
4855 <<
"Cannot open vector data file.\n";
4857 throw std::logic_error(buffer.str());
4862 const size_t this_size = this->size();
4868 const char space =
' ';
4870 for(
size_t i = 1; i < this_size; i++)
4872 file << space << (*this)[i];
4893 const size_t other_size = other_vector.size();
4899 const size_t this_size = this->size();
4901 if(position + other_size > this_size)
4903 std::ostringstream buffer;
4905 buffer <<
"OpenNN Exception: Vector Template.\n"
4906 <<
"void tuck_in(const size_t&, const Vector<T>&) const method.\n"
4907 <<
"Cannot tuck in vector.\n";
4909 throw std::logic_error(buffer.str());
4914 for(
size_t i = 0; i < other_size; i++)
4916 (*this)[position + i] = other_vector[i];
4934 const size_t this_size = this->size();
4936 if(position + other_size > this_size)
4938 std::ostringstream buffer;
4940 buffer <<
"OpenNN Exception: Vector Template.\n"
4941 <<
"Vector<T> take_out(const size_t&, const size_t&) method.\n"
4942 <<
"Cannot take out vector.\n";
4944 throw std::logic_error(buffer.str());
4949 const Vector<T> other_vector((*this).begin() + position, (*this).begin() + position + other_size);
4956 return(other_vector);
4969 const size_t this_size = this->size();
4975 if(index > this_size)
4977 std::ostringstream buffer;
4979 buffer <<
"OpenNN Exception: Vector Template.\n"
4980 <<
"void insert_element(const size_t& index, const T& value) method.\n"
4981 <<
"Index is greater than vector size.\n";
4983 throw std::logic_error(buffer.str());
4990 for(
size_t i = 0; i <= this_size; i++)
4994 other_vector[i] = (*this)[i];
4998 other_vector[i] = value;
5002 other_vector[i] = (*this)[i-1];
5006 return(other_vector);
5019 const size_t this_size = this->size();
5025 if(index >= this_size)
5027 std::ostringstream buffer;
5029 buffer <<
"OpenNN Exception: Vector Template.\n"
5030 <<
"Vector<T> remove_element(const size_t&) const method.\n"
5031 <<
"Index is equal or greater than vector size.\n";
5033 throw std::logic_error(buffer.str());
5040 for(
size_t i = 0; i < this_size; i++)
5044 other_vector[i] = (*this)[i];
5048 other_vector[i-1] = (*this)[i];
5052 return(other_vector);
5065 const size_t this_size = this->size();
5067 size_t value_count = 0;
5069 for(
size_t i = 0; i < this_size; i++)
5071 if((*
this)[i] == value)
5077 if(value_count == 0)
5083 const size_t other_size = this_size - value_count;
5087 size_t other_index = 0;
5089 for(
size_t i = 0; i < this_size; i++)
5091 if((*
this)[i] != value)
5093 other_vector[other_index] = (*this)[i];
5099 return(other_vector);
5112 const size_t this_size = this->size();
5113 const size_t other_size = other_vector.size();
5115 if(this_size == 0 && other_size == 0)
5121 else if(this_size == 0)
5123 return(other_vector);
5125 else if(other_size == 0)
5131 Vector<T> assembly(this_size + other_size);
5133 for(
size_t i = 0; i < this_size; i++)
5135 assembly[i] = (*this)[i];
5138 for(
size_t i = 0; i < other_size; i++)
5140 assembly[this_size+i] = other_vector[i];
5155 const size_t this_size = this->size();
5157 std::vector<T> std_vector(this_size);
5159 for(
size_t i = 0; i < this_size; i++)
5161 std_vector[i] = (*this)[i];
5177 const size_t this_size = this->size();
5181 for(
size_t i = 0; i < this_size; i++)
5183 matrix(0,i) = (*this)[i];
5198 const size_t this_size = this->size();
5202 for(
size_t i = 0; i < this_size; i++)
5204 matrix(i,0) = (*this)[i];
5225 std::istringstream buffer(str);
5227 std::istream_iterator<std::string> first(buffer);
5228 std::istream_iterator<std::string> last;
5232 const size_t new_size = str_vector.size();
5236 this->resize(new_size);
5239 buffer.seekg(0, std::ios::beg);
5241 for(
size_t i = 0; i < new_size; i++)
5243 buffer >> (*this)[i];
5257 std::ostringstream buffer;
5259 const size_t this_size = this->size();
5263 buffer << (*this)[0];
5265 for(
size_t i = 1; i < this_size; i++)
5267 buffer << separator << (*this)[i];
5271 return(buffer.str());
5282 std::ostringstream buffer;
5284 const size_t this_size = this->size();
5288 buffer << (*this)[0];
5290 for(
size_t i = 1; i < this_size-1; i++)
5292 buffer <<
", " << (*this)[i];
5297 buffer <<
" and " << (*this)[this_size-1];
5301 return(buffer.str());
5312 const size_t this_size = this->size();
5316 std::ostringstream buffer;
5318 for(
size_t i = 0; i < this_size; i++)
5321 buffer << std::setprecision(precision) << (*this)[i];
5323 string_vector[i] = buffer.str();
5326 return(string_vector);
5344 const size_t this_size = this->size();
5346 if(rows_number*columns_number != this_size)
5348 std::ostringstream buffer;
5350 buffer <<
"OpenNN Exception: Vector Template.\n"
5351 <<
"Matrix<T> to_matrix(const size_t&, const size_t&) method.\n"
5352 <<
"The number of rows (" << rows_number <<
") times the number of colums (" << columns_number <<
") must be equal to the size of the vector (" << this_size <<
").\n";
5354 throw std::logic_error(buffer.str());
5359 Matrix<T> matrix(rows_number, columns_number);
5363 for(
size_t i = 0; i < rows_number; i++)
5365 for(
size_t j = 0; j < columns_number; j++)
5367 matrix(i,j) = (*this)[index];
5383 std::istream& operator >> (std::istream& is,
Vector<T>& v)
5385 const size_t size = v.size();
5387 for(
size_t i = 0; i < size; i++)
5403 std::ostream& operator << (std::ostream& os, const Vector<T>& v)
5405 const size_t this_size = v.size();
5411 const char space =
' ';
5413 for(
size_t i = 1; i < this_size; i++)
5415 os << space << v[i];
5430 std::ostream& operator << (std::ostream& os, const Vector< Vector<T> >& v)
5432 for(
size_t i = 0; i < v.size(); i++)
5434 os <<
"subvector_" << i <<
"\n"
5435 << v[i] << std::endl;
5449 std::ostream& operator << (std::ostream& os, const Vector< Matrix<T> >& v)
5451 for(
size_t i = 0; i < v.size(); i++)
5453 os <<
"submatrix_" << i <<
"\n"
5468 T calculate_random_uniform(
const T& minimum,
const T& maximum)
5470 const T random = (T)rand()/(RAND_MAX+1.0);
5472 const T random_uniform = minimum + (maximum-minimum)*random;
5474 return(random_uniform);
5485 T calculate_random_normal(
const T& mean,
const T& standard_deviation)
5487 const double pi = 4.0*atan(1.0);
5493 random_uniform_1 = (T)rand()/(RAND_MAX+1.0);
5495 }
while(random_uniform_1 == 0.0);
5497 const T random_uniform_2 = (T)rand()/(RAND_MAX+1.0);
5501 const T random_normal = mean + sqrt(-2.0*log(random_uniform_1))*sin(2.0*pi*random_uniform_2)*standard_deviation;
5503 return(random_normal);
5518 Statistics(
const T&,
const T&,
const T&,
const T&);
5541 void save(
const std::string& file_name)
const;
5569 standard_deviation = (T)1.0;
5577 minimum = new_minimum;
5578 maximum = new_maximum;
5580 standard_deviation = new_standard_deviation;
5596 minimum = new_minimum;
5605 maximum = new_maximum;
5623 standard_deviation = new_standard_deviation;
5634 statistics_vector[0] = minimum;
5635 statistics_vector[1] = maximum;
5636 statistics_vector[2] = mean;
5637 statistics_vector[3] = standard_deviation;
5639 return(statistics_vector);
5651 minimum = calculate_random_uniform(-1.0, 0.0);
5652 maximum = calculate_random_uniform(0.0, 1.0);
5653 mean = calculate_random_uniform(-1.0, 1.0);
5654 standard_deviation = calculate_random_uniform(0.0, 2.0);
5663 if(-1.000001 < minimum && minimum < -0.999999
5664 && 0.999999 < maximum && maximum < 1.000001)
5680 if(-0.000001 < mean && mean < 0.000001
5681 && 0.999999 < standard_deviation && standard_deviation < 1.000001)
5699 std::ofstream file(file_name.c_str());
5703 std::ostringstream buffer;
5705 buffer <<
"OpenNN Exception: Statistics template.\n"
5706 <<
"void save(const std::string&) const method.\n"
5707 <<
"Cannot open statistics data file.\n";
5709 throw std::logic_error(buffer.str());
5714 file <<
"Minimum: " << minimum << std::endl
5715 <<
"Maximum: " << maximum << std::endl
5716 <<
"Mean: " << mean << std::endl
5717 <<
"Standard deviation: " << standard_deviation << std::endl;
5732 std::ostream& operator << (std::ostream& os, const Statistics<T>& statistics)
5734 os <<
"Statistics structure\n"
5735 <<
" Minimum: " << statistics.minimum << std::endl
5736 <<
" Maximum: " << statistics.maximum << std::endl
5737 <<
" Mean: " << statistics.mean << std::endl
5738 <<
" Standard deviation: " << statistics.standard_deviation << std::endl;
5765 Histogram(
const Vector<T>&,
const Vector<size_t>&);
5809 centers.resize(bins_number);
5810 frequencies.resize(bins_number);
5821 centers = new_centers;
5822 frequencies = new_frequencies;
5831 return(centers.size());
5840 return(frequencies.count_occurrences(0));
5849 return(frequencies.calculate_minimum());
5858 return(frequencies.calculate_maximum());
5867 const size_t minimum_frequency = calculate_minimum_frequency();
5871 return(centers.arrange_subvector(minimal_indices));
5880 const size_t maximum_frequency = calculate_maximum_frequency();
5884 return(centers.arrange_subvector(maximal_indices));
5895 std::ostream& operator << (std::ostream& os, const Histogram<T>& histogram)
5897 os <<
"Histogram structure\n"
5898 <<
"Centers: " << histogram.centers << std::endl
5899 <<
"Frequencies: " << histogram.frequencies << std::endl;
5910 struct LinearRegressionParameters
5927 std::ostream& operator << (std::ostream& os, const LinearRegressionParameters<T>& linear_regression_parameters)
5929 os <<
"Linear regression parameters:\n"
5930 <<
"Intercept: " << linear_regression_parameters.intercept <<
"\n"
5931 <<
"Slope: " << linear_regression_parameters.slope <<
"\n"
5932 <<
"Correlation: " << linear_regression_parameters.correlation << std::endl;
5943 struct LogisticRegressionParameters
5960 std::ostream& operator << (std::ostream& os, const LogisticRegressionParameters<T>& logistic_regression_parameters)
5962 os <<
"Logistic regression parameters:\n"
5963 <<
"Position: " << logistic_regression_parameters.position <<
"\n"
5964 <<
"Slope: " << logistic_regression_parameters.slope <<
"\n"
5965 <<
"Correlation: " << logistic_regression_parameters.correlation << std::endl;
double calculate_Minkowski_error(const Vector< double > &, const double &) const
Vector< bool > calculate_binary(void) const
void parse(const std::string &)
size_t count_less_than(const T &) const
Statistics< T > scale_minimum_maximum(void)
bool has_minimum_minus_one_maximum_one(void)
virtual ~Statistics(void)
Destructor.
void randomize_uniform(const double &=-1.0, const double &=1.0)
bool is_in(const T &, const T &) const
void set_minimum(const double &)
size_t calculate_maximum_frequency(void) const
Returns the number of variates in the most populated bin.
Matrix< T > direct(const Matrix< T > &) const
Vector< T > calculate_minimum_maximum(void) const
Returns a vector containing the smallest and the largest elements in the vector.
Vector< T > calculate_lower_bounded(const T &) const
Vector< std::string > write_string_vector(const size_t &=3) const
This method retuns a vector of strings with size equal to the size of this vector and elements equal ...
bool is_crescent(void) const
Returns true if all the elements in the vector have values which increase with the index...
void initialize(const T &)
Vector< T > take_out(const size_t &, const size_t &) const
Vector< T > arrange_subvector_first(const size_t &) const
Vector< T > operator-(const T &) const
void operator+=(const T &)
bool is_constant(const double &=0.0) const
T calculate_linear_correlation_missing_values(const Vector< T > &, const Vector< size_t > &) const
void operator*=(const T &)
double correlation
Correlation coefficient (R-value) of the linear regression.
void unscale_minimum_maximum(const Vector< T > &, const Vector< T > &)
Statistics< T > calculate_statistics_missing_values(const Vector< size_t > &) const
Returns the minimum, maximum, mean and the standard deviation of the elements in the vector...
void operator-=(const T &)
void set(void)
Sets the size of a vector to zero.
Vector< size_t > calculate_maximal_indices(const size_t &) const
bool operator<(const T &) const
Vector< T > calculate_absolute_value(void) const
Returns a vector with the absolute values of the current vector.
void set_mean(const double &)
Vector< T > calculate_softmax(void) const
Vector< T > arrange_subvector(const Vector< size_t > &) const
Vector< T > remove_value(const T &) const
T calculate_maximum_missing_values(const Vector< size_t > &) const
Returns the largest element in the vector.
Matrix< T > calculate_norm_Hessian(void) const
Returns the Hessian of the vector norm.
T mean
Mean value of a set, function, etc.
Vector< T > centers
Positions of the bins in the histogram.
bool has_mean_zero_standard_deviation_one(void)
Vector< T > calculate_scaled_minimum_maximum(const Vector< T > &, const Vector< T > &) const
void unscale_mean_standard_deviation(const Vector< T > &, const Vector< T > &)
bool contains(const T &) const
Returns true if the vector contains a certain value, and false otherwise.
Vector(void)
Default constructor. It creates a vector of size zero.
LinearRegressionParameters< T > calculate_linear_regression_parameters(const Vector< T > &) const
Histogram< T > calculate_histogram(const size_t &=10) const
Vector< T > calculate_upper_bounded(const T &) const
T maximum
Biggest value of a set, function, etc.
void filter_positive(void)
Sets all the negative elements in the vector to zero.
size_t count_greater_than(const T &) const
T calculate_minimum(void) const
Returns the smallest element in the vector.
Vector< T > calculate_cumulative(void) const
Vector< T > assemble(const Vector< T > &) const
void apply_lower_bound(const T &)
Vector< T > calculate_lower_upper_bounded(const T &, const T &) const
void operator/=(const T &)
Matrix< T > arrange_diagonal_matrix(void) const
Vector< T > calculate_maximal_centers(void) const
Returns a vector with the centers of the most populated bins.
Matrix< T > direct(const Vector< T > &) const
const size_t & get_columns_number(void) const
Returns the number of columns in the matrix.
bool operator>=(const T &) const
size_t calculate_cumulative_index(const T &) const
void filter_negative(void)
Sets all the positive elements in the vector to zero.
double calculate_norm(void) const
Returns the vector norm.
size_t calculate_maximal_index(void) const
Returns the index of the largest element in the vector.
double intercept
Y-intercept of the linear regression.
size_t get_bins_number(void) const
Returns the number of bins in the histogram.
void initialize_sequential(void)
Initializes all the elements of the vector in a sequential order.
Vector< size_t > calculate_greater_rank(void) const
double calculate_mean_missing_values(const Vector< size_t > &) const
Returns the mean of the elements in the vector.
virtual ~Vector(void)
Destructor.
double calculate_standard_deviation(void) const
Returns the standard deviation of the elements in the vector.
double calculate_sum_squared_error(const Vector< double > &) const
Vector< T > operator*(const T &) const
double slope
Slope at the midpoint of the logistic regression.
std::string to_text() const
Returns a string representation of this vector which can be inserted in a text.
Vector< size_t > calculate_greater_than_indices(const T &) const
void initialize(const T &)
Vector< size_t > calculate_less_than_indices(const T &) const
size_t calculate_minimum_frequency(void) const
Returns the number of variates in the less populated bin.
Vector< T > operator/(const T &) const
Vector< double > calculate_mean_standard_deviation(void) const
Returns the mean and the standard deviation of the elements in the vector.
bool operator>(const T &) const
Vector< T > calculate_normalized(void) const
Returns this vector divided by its norm.
Vector< T > operator+(const T &) const
Matrix< T > to_row_matrix(void) const
void tuck_in(const size_t &, const Vector< T > &)
Vector< T > remove_element(const size_t &) const
Vector< T > calculate_unscaled_minimum_maximum(const Vector< T > &, const Vector< T > &) const
size_t calculate_minimal_index(void) const
Returns the index of the smallest element in the vector.
void save(const std::string &) const
Vector< T > calculate_competitive(void) const
Matrix< T > to_matrix(const size_t &, const size_t &) const
void randomize_normal(const double &=0.0, const double &=1.0)
double dot(const Vector< double > &) const
double slope
Slope of the linear regression.
const size_t & get_rows_number(void) const
Returns the number of rows in the matrix.
void save(const std::string &file_name) const
T calculate_maximum(void) const
Returns the largest element in the vector.
Matrix< T > calculate_softmax_Jacobian(void) const
Returns the softmax Jacobian of this vector.
T calculate_linear_correlation(const Vector< T > &) const
void apply_absolute_value(void)
Sets the elements of the vector to their absolute values.
double calculate_distance(const Vector< double > &) const
double position
Position of the midpoint of the logistic regression.
T calculate_minimum_missing_values(const Vector< size_t > &) const
Returns the smallest element in the vector.
bool operator<=(const T &) const
Histogram< T > calculate_histogram_missing_values(const Vector< size_t > &, const size_t &=10) const
void load(const std::string &)
bool operator!=(const T &) const
Vector< size_t > frequencies
Population of the bins in the histogram.
T minimum
Smallest value of a set, function, etc.
void apply_upper_bound(const T &)
double calculate_p_norm(const double &) const
Returns the vector p-norm.
Statistics< T > scale_mean_standard_deviation(void)
Vector< size_t > calculate_less_rank(void) const
Statistics< T > calculate_statistics(void) const
Returns the minimum, maximum, mean and the standard deviation of the elements in the vector...
T calculate_sum_missing_values(const Vector< size_t > &) const
Returns the sum of the elements in the vector.
Vector< T > insert_element(const size_t &, const T &) const
Vector< size_t > calculate_minimal_indices(const size_t &) const
Vector< double > calculate_p_norm_gradient(const double &) const
Returns the gradient of the vector norm.
Vector< T > calculate_norm_gradient(void) const
Returns the gradient of the vector norm.
Vector< T > calculate_pow(const T &) const
Matrix< T > to_column_matrix(void) const
Vector< T > to_vector(void) const
Vector< T > calculate_unscaled_mean_standard_deviation(const Vector< T > &, const Vector< T > &) const
void initialize_random(void)
double calculate_mean(void) const
Returns the mean of the elements in the vector.
Vector< T > calculate_scaled_mean_standard_deviation(const Vector< T > &, const Vector< T > &) const
size_t count_empty_bins(void) const
Returns the number of bins with zero variates.
void set_maximum(const double &)
T calculate_product(void) const
Returns the product of the elements in the vector.
double correlation
Correlation coefficient (R-value) of the logistic regression.
Vector< T > calculate_minimal_centers(void) const
Returns a vector with the centers of the less populated bins.
Vector< size_t > calculate_occurrence_indices(const T &) const
Vector< T > calculate_minimum_maximum_missing_values(const Vector< size_t > &) const
Returns a vector containing the smallest and the largest elements in the vector.
void set_standard_deviation(const double &)
T calculate_sum(void) const
Returns the sum of the elements in the vector.
void apply_lower_upper_bounds(const T &, const T &)
Histogram(void)
Default constructor.
std::string to_string(const std::string &=" ") const
Returns a string representation of this vector.
Vector< size_t > calculate_minimal_maximal_index(void) const
Returns a vector with the indexes of the smallest and the largest elements in the vector...
double calculate_standard_deviation_missing_values(const Vector< size_t > &) const
Returns the standard deviation of the elements in the vector.
virtual ~Histogram(void)
Destructor.
T standard_deviation
Standard deviation value of a set, function, etc.
size_t calculate_closest_index(const T &) const
Returns the index of the closest element in the vector to a given value.
bool operator==(const T &) const
bool is_decrescent(void) const
Returns true if all the elements in the vector have values which decrease with the index...
std::vector< T > to_std_vector(void) const
Returns a std vector with the size and elements of this OpenNN vector.
size_t count_occurrences(const T &) const
Returns the number of times that a certain value is contained in the vector.
Vector< T > arrange_subvector_last(const size_t &) const