41 #ifndef BPP_NUMERIC_VECTORTOOLS_H
42 #define BPP_NUMERIC_VECTORTOOLS_H
45 #include "../App/ApplicationTools.h"
46 #include "../Io/OutputStream.h"
62 typedef std::vector<std::complex<double> >
Vcomplex;
66 typedef std::vector<std::complex<long double> >
Vlcomplex;
80 typedef std::vector<int>
Vint;
81 typedef std::vector<Vint>
VVint;
85 typedef std::vector<unsigned int>
Vuint;
96 std::vector<T>
operator+(
const std::vector<T>& v1,
const std::vector<T>& v2)
99 if (v1.size() != v2.size())
107 std::vector<T> result(size);
108 for (
size_t i = 0; i < size; i++)
110 result[i] = v1[i] + v2[i];
116 std::vector<T>
operator-(
const std::vector<T>& v1,
const std::vector<T>& v2)
119 if (v1.size() != v2.size())
127 std::vector<T> result(size);
128 for (
size_t i = 0; i < size; i++)
130 result[i] = v1[i] - v2[i];
136 std::vector<T>
operator*(
const std::vector<T>& v1,
const std::vector<T>& v2)
139 if (v1.size() != v2.size())
147 std::vector<T> result(size);
148 for (
size_t i = 0; i < size; i++)
150 result[i] = v1[i] * v2[i];
156 std::vector<T>
operator/(
const std::vector<T>& v1,
const std::vector<T>& v2)
159 if (v1.size() != v2.size())
167 std::vector<T> result(size);
168 for (
size_t i = 0; i < size; i++)
170 result[i] = v1[i] / v2[i];
176 template<
class T,
class C>
177 std::vector<T>
operator+(
const std::vector<T>& v1,
const C& c)
179 std::vector<T> result(v1.size());
180 for (
size_t i = 0; i < result.size(); i++)
182 result[i] = v1[i] + T(c);
186 template<
class T,
class C>
187 std::vector<T>
operator+(
const C& c,
const std::vector<T>& v1)
189 std::vector<T> result(v1.size());
190 for (
size_t i = 0; i < result.size(); i++)
192 result[i] = T(c) + v1[i];
197 template<
class T,
class C>
198 std::vector<T>
operator-(
const std::vector<T>& v1,
const C& c)
200 std::vector<T> result(v1.size());
201 for (
size_t i = 0; i < result.size(); i++)
203 result[i] = v1[i] - T(c);
207 template<
class T,
class C>
208 std::vector<T>
operator-(
const C& c,
const std::vector<T>& v1)
210 std::vector<T> result(v1.size());
211 for (
size_t i = 0; i < result.size(); i++)
213 result[i] = T(c) - v1[i];
218 template<
class T,
class C>
219 std::vector<T>
operator*(
const std::vector<T>& v1,
const C& c)
221 std::vector<T> result(v1.size());
222 for (
size_t i = 0; i < result.size(); i++)
224 result[i] = v1[i] * c;
228 template<
class T,
class C>
229 std::vector<T>
operator*(
const C& c,
const std::vector<T>& v1)
231 std::vector<T> result(v1.size());
232 for (
size_t i = 0; i < result.size(); i++)
234 result[i] = c * v1[i];
239 template<
class T,
class C>
240 std::vector<T>
operator/(
const std::vector<T>& v1,
const C& c)
242 std::vector<T> result(v1.size());
243 for (
size_t i = 0; i < result.size(); i++)
245 result[i] = v1[i] / c;
249 template<
class T,
class C>
250 std::vector<T>
operator/(
const C& c,
const std::vector<T>& v1)
252 std::vector<T> result(v1.size());
253 for (
size_t i = 0; i < result.size(); i++)
255 result[i] = c / v1[i];
261 void operator+=(std::vector<T>& v1,
const std::vector<T>& v2)
263 for (
size_t i = 0; i < v1.size(); i++)
270 void operator-=(std::vector<T>& v1,
const std::vector<T>& v2)
272 for (
size_t i = 0; i < v1.size(); i++)
279 void operator*=(std::vector<T>& v1,
const std::vector<T>& v2)
281 for (
size_t i = 0; i < v1.size(); i++)
288 void operator/=(std::vector<T>& v1,
const std::vector<T>& v2)
290 for (
size_t i = 0; i < v1.size(); i++)
296 template<
class T,
class C>
305 template<
class T,
class C>
314 template<
class T,
class C>
323 template<
class T,
class C>
332 template<
class T,
class C>
360 for (
auto& x : vv) { x.resize(n2); }
379 for (
auto& vvv : vvvv)
396 static void fill(std::vector<T>& v, T value)
398 std::fill(v.begin(), v.end(), value);
414 static std::vector<T>
seq(T from, T
to, T by)
416 std::vector<T> v((
size_t)((std::abs(from -
to) + by / 100) / by) + 1);
417 T step = from <
to ? by : -by;
418 T val(from <
to ? from :
to);
441 for (
size_t i = 0; i < v.size(); i++)
443 if (v[i] ==
which)
return i;
459 static std::vector<size_t>
whichAll(
const std::vector<T>& v,
const T&
which)
461 std::vector<size_t> w;
462 for (
size_t i = 0; i < v.size(); i++)
464 if (v[i] ==
which) w.push_back(i);
483 static std::vector<T>
unique(
const std::vector<T>& v)
485 if (v.size() == 0)
return v;
486 std::vector<T> sortedV(v.begin(), v.end());
487 sort(sortedV.begin(), sortedV.end());
489 uniq.push_back(sortedV[0]);
490 for (
size_t i = 1; i < sortedV.size(); i++)
492 if (sortedV[i] != sortedV[i - 1]) uniq.push_back(sortedV[i]);
510 if (v.size() == 0)
return true;
511 std::vector<T> sortedV(v.begin(), v.end());
512 sort(sortedV.begin(), sortedV.end());
513 for (
size_t i = 1; i < sortedV.size(); i++)
515 if (sortedV[i] == sortedV[i - 1])
return false;
530 static std::vector<T>
extract(
const std::vector<T>& v1,
const std::vector<int>& v2)
532 std::vector<T> v(v2.size());
533 for (
size_t i = 0; i < v2.size(); i++)
549 std::map<T, size_t> c;
567 static std::vector<double>
breaks(
const std::vector<double>& v,
unsigned int n);
585 double h = 3.5 * VectorTools::sd<T, double>(v) * std::pow(n, -1. / 3);
586 return (
size_t) ceil(r / h);
594 static T
prod(
const std::vector<T>& v1)
610 static std::vector<T>
cumProd(
const std::vector<T>& v1)
612 std::vector<T> p(v1.size());
613 if (v1.size() == 0)
return p;
615 for (
size_t i = 1; i < v1.size(); i++) { p[i] = v1[i] * p[i - 1]; }
624 static T
sum(
const std::vector<T>& v1)
627 for (
const auto& x : v1) { s += x; }
639 static T
sumProd(
const std::vector<T>& v1,
const std::vector<T>& v2)
642 if (v1.size() != v2.size())
648 for (
size_t i = 1; i < size; i++)
662 static std::vector<T>
cumSum(
const std::vector<T>& v1)
665 std::partial_sum(s.begin(), s.end(), s.begin());
696 T x = std::accumulate(std::next(v1.begin()), v1.end(), std::exp(v1[0] - M),
698 return y + std::exp(z - M);
701 return std::log(x) + M;
711 static T
logSumExp(
const std::vector<T>& v1,
const std::vector<T>& v2)
713 if (v1.size() != v2.size())
716 size_t size = v1.size();
722 T x = v2[0] * std::exp(v1[0] - M);
723 for (
size_t i = 1; i < size; i++)
725 x += v2[i] * std::exp(v1[i] - M);
727 return std::log(x) + M;
748 static T
sumExp(
const std::vector<T>& v1)
751 return std::exp(v1[0]);
755 return M < 0 ? 0 : M;
757 T x = std::accumulate(std::next(v1.begin()), v1.end(), std::exp(v1[0] - M),
759 return y + std::exp(z - M);
761 return x * std::exp(M);
771 static T
sumExp(
const std::vector<T>& v1,
const std::vector<T>& v2)
773 if (v1.size() != v2.size())
776 size_t size = v1.size();
779 return v2[0] * std::exp(v1[0]);
785 T x = v2[0] * std::exp(v1[0] - M);
786 for (
size_t i = 1; i < size; i++)
788 x += v2[i] * std::exp(v1[i] - M);
790 return x * std::exp(M);
801 static std::vector<T>
log(
const std::vector<T>& v1)
803 std::vector<T> v2(v1.size());
804 for (
size_t i = 0; i < v2.size(); i++)
812 static double log(
const T& x)
818 static std::vector<double>
log(
const std::vector<T>& v1,
double base)
820 std::vector<double> v2(v1.size());
821 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::log(v1[i]) / std::log(base); }
826 static double exp(
const T& x)
832 static std::vector<T>
exp(
const std::vector<T>& v1)
834 std::vector<T> v2(v1.size());
840 static std::vector<double>
cos(
const std::vector<T>& v1)
842 std::vector<double> v2(v1.size());
843 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::cos(v1[i]); }
848 static std::vector<double>
sin(
const std::vector<T>& v1)
850 std::vector<double> v2(v1.size());
851 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::sin(v1[i]); }
856 static std::vector<double>
log10(
const std::vector<T>& v1)
858 std::vector<double> v2(v1.size());
859 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = std::log10(v1[i]); }
864 static std::vector<T>
fact(
const std::vector<T>& v1)
866 std::vector<T> v2(v1.size());
867 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = NumTools::fact<T>(v1[i]); }
872 static std::vector<T>
sqr(
const std::vector<T>& v1)
874 std::vector<T> v2(v1.size());
875 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = NumTools::sqr<T>(v1[i]); }
880 static std::vector<T>
pow(
const std::vector<T>& v1, T& b)
882 std::vector<T> v2(v1.size());
883 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = std::pow(v1[i], b); }
895 static std::string
paste(
const std::vector<T>& v,
const std::string& delim =
" ")
897 std::ostringstream out;
899 for (
size_t i = 0; i < v.size(); i++)
902 if (i < v.size() - 1)
917 for (
size_t i = 0; i < v1.size(); i++)
920 if (i < v1.size() - 1)
929 size_t vs = v1.size();
931 for (
size_t i = 0; i < vs; i++)
937 if (v1[j] == v1[j - 1] + 1)
943 out << rangeDelim << v1[j - 1];
958 static void printForR(
const std::vector<T>& v1, std::string variableName =
"x", std::ostream& out = std::cout)
961 out << variableName <<
"<-c(";
962 for (
size_t i = 0; i < v1.size(); i++)
965 if (i < v1.size() - 1)
968 out <<
")" << std::endl;
977 template<
class InputType,
class OutputType>
978 static OutputType
scalar(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2)
980 if (v1.size() != v2.size())
984 OutputType result = 0;
985 for (
size_t i = 0; i < v1.size(); i++)
987 result += v1[i] * v2[i];
1007 template<
class InputType,
class OutputType>
1008 static OutputType
scalar(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w)
1010 if (v1.size() != w.size())
1014 if (v2.size() != w.size())
1018 OutputType result = 0;
1019 for (
size_t i = 0; i < v1.size(); i++)
1021 result += v1[i] * v2[i] * w[i];
1033 static std::vector<T>
kroneckerMult(
const std::vector<T>& v1,
const std::vector<T>& v2)
1035 size_t n1 = v1.size();
1036 size_t n2 = v2.size();
1037 std::vector<T> v3(n1 * n2);
1038 for (
size_t i = 0; i < n1; i++)
1041 for (
size_t j = 0; j < n2; j++)
1043 v3[i * n2 + j] = v1i * v2[j];
1053 template<
class InputType,
class OutputType>
1054 static OutputType
norm(
const std::vector<InputType>& v1)
1056 OutputType result = 0;
1057 for (
size_t i = 0; i < v1.size(); i++)
1059 result += v1[i] * v1[i];
1061 return sqrt(result);
1071 template<
class InputType,
class OutputType>
1072 static OutputType
norm(
const std::vector<InputType>& v1,
const std::vector<InputType>& w)
1074 if (v1.size() != w.size())
1078 OutputType result = 0;
1079 for (
size_t i = 0; i < v1.size(); i++)
1081 result += v1[i] * v1[i] * w[i];
1083 return sqrt(result);
1092 template<
class InputType,
class OutputType>
1093 static OutputType
cos(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2)
1095 return scalar<InputType, OutputType>(v1, v2)
1096 / (norm<InputType, OutputType>(v1) * norm<InputType, OutputType>(v2));
1106 template<
class InputType,
class OutputType>
1107 static OutputType
cos(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w)
1109 return scalar<InputType, OutputType>(v1, v2, w)
1110 / (norm<InputType, OutputType>(v1, w) * norm<InputType, OutputType>(v2, w));
1129 static T
min(
const std::vector<T>& v)
1133 for (
size_t i = 1; i < v.size(); i++)
1135 if (v[i] < mini) mini = v[i];
1150 static T
max(
const std::vector<T>& v)
1154 for (
size_t i = 1; i < v.size(); i++)
1156 if (v[i] > maxi) maxi = v[i];
1177 for (
size_t i = 1; i < v.size(); i++)
1204 for (
size_t i = 1; i < v.size(); i++)
1230 std::vector<size_t> pos;
1231 for (
size_t i = 0; i < v.size(); i++)
1256 std::vector<size_t> pos;
1257 for (
size_t i = 0; i < v.size(); i++)
1278 static std::vector<T>
range(
const std::vector<T>& v)
1282 std::vector<T> r(2);
1284 for (
size_t i = 1; i < v.size(); i++)
1286 if (v[i] < r[0]) r[0] = v[i];
1287 if (v[i] > r[1]) r[1] = v[i];
1313 static std::vector<size_t>
order(
const std::vector<T>& v)
1318 std::vector<size_t> index(v.size());
1319 for (
size_t i = 0; i < index.size(); ++i)
1337 static std::vector<T>
abs(
const std::vector<T>& v)
1339 std::vector<T> vabs(v.size());
1340 for (
size_t i = 0; i < v.size(); i++)
1342 vabs[i] = std::abs(v[i]);
1351 template<
class InputType,
class OutputType>
1352 static OutputType
mean(
const std::vector<InputType>& v1)
1354 return (OutputType)sum<InputType>(v1) / (OutputType)v1.size();
1362 template<
class InputType,
class OutputType>
1363 static OutputType
mean(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool normalizeWeights =
true)
1365 if (normalizeWeights)
1367 std::vector<InputType> wn = w /
sum(w);
1368 return scalar<InputType, OutputType>(v1, wn);
1372 return scalar<InputType, OutputType>(v1, w);
1380 template<
class InputType>
1381 static InputType
median(std::vector<InputType>& v1)
1384 if (v1.size() == 0)
return med;
1385 if (v1.size() == 1)
return v1[0];
1386 sort(v1.begin(), v1.end());
1387 size_t i = v1.size() / 2;
1388 if (v1.size() % 2 == 0)
1391 med = double((v1[i - 1] + v1[i]) / 2);
1407 template<
class InputType,
class OutputType>
1408 static std::vector<OutputType>
center(
const std::vector<InputType>& v1)
1410 OutputType m = mean<InputType, OutputType>(v1);
1411 std::vector<OutputType> v(v1.size());
1412 for (
size_t i = 0; i < v1.size(); i++)
1414 v[i] = (OutputType)v1[i] - m;
1426 template<
class InputType,
class OutputType>
1427 static std::vector<OutputType>
center(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool normalizeWeights =
true)
1429 OutputType m = mean<InputType, OutputType>(v1, w, normalizeWeights);
1430 std::vector<OutputType> v(v1.size());
1431 for (
size_t i = 0; i < v1.size(); i++)
1433 v[i] = (OutputType)v1[i] - m;
1445 template<
class InputType,
class OutputType>
1446 static OutputType
cov(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
bool unbiased =
true)
1448 OutputType n = (OutputType)v1.size();
1449 OutputType x = scalar<InputType, OutputType>(
1450 center<InputType, OutputType>(v1),
1451 center<InputType, OutputType>(v2)
1453 if (unbiased) x = x * n / (n - 1);
1467 template<
class InputType,
class OutputType>
1468 static OutputType
cov(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true)
1470 if (normalizeWeights)
1472 std::vector<InputType> wn = w /
sum(w);
1473 OutputType x = scalar<InputType, OutputType>(
1474 center<InputType, OutputType>(v1, wn,
false),
1475 center<InputType, OutputType>(v2, wn,
false),
1480 x = x / (1 -
sum(sqr<double>(wn)));
1486 OutputType x = scalar<InputType, OutputType>(
1487 center<InputType, OutputType>(v1, w,
false),
1488 center<InputType, OutputType>(v2, w,
false),
1493 x = x / (1 -
sum(
sqr(w)));
1503 template<
class InputType,
class OutputType>
1504 static OutputType
var(
const std::vector<InputType>& v1,
bool unbiased =
true)
1506 return cov<InputType, OutputType>(v1, v1, unbiased);
1516 template<
class InputType,
class OutputType>
1517 static OutputType
var(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true)
1519 return cov<InputType, OutputType>(v1, v1, w, unbiased, normalizeWeights);
1527 template<
class InputType,
class OutputType>
1528 static OutputType
sd(
const std::vector<InputType>& v1,
bool unbiased =
true)
1530 return sqrt(var<InputType, OutputType>(v1, unbiased));
1541 template<
class InputType,
class OutputType>
1542 static OutputType
sd(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true)
1544 return sqrt(var<InputType, OutputType>(v1, w, unbiased, normalizeWeights));
1553 template<
class InputType,
class OutputType>
1554 static OutputType
cor(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2)
1556 return cov<InputType, OutputType>(v1, v2)
1557 / ( sd<InputType, OutputType>(v1) * sd<InputType, OutputType>(v2) );
1568 template<
class InputType,
class OutputType>
1569 static OutputType
cor(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w,
bool normalizeWeights =
true)
1571 if (normalizeWeights)
1573 std::vector<InputType> wn = w /
sum(w);
1574 return cov<InputType, OutputType>(v1, v2, wn,
false,
false)
1575 / ( sd<InputType, OutputType>(v1, wn,
false,
false) * sd<InputType, OutputType>(v2, wn,
false,
false) );
1579 return cov<InputType, OutputType>(v1, v2, w,
false,
false)
1580 / ( sd<InputType, OutputType>(v1, w,
false,
false) * sd<InputType, OutputType>(v2, w,
false,
false) );
1598 template<
class InputType,
class OutputType>
1599 static OutputType
shannon(
const std::vector<InputType>& v,
double base = 2.7182818)
1605 s +=
static_cast<OutputType
>(x * std::log(x) / std::log(base));
1624 template<
class InputType,
class OutputType>
1625 static OutputType
shannonDiscrete(
const std::vector<InputType>& v,
double base = 2.7182818)
1627 std::map<InputType, double> counts;
1633 double n =
static_cast<double>(v.size());
1634 for (
auto& it : counts)
1636 s +=
static_cast<OutputType
>((it.second / n) * std::log(it.second / n) / std::log(base));
1656 template<
class InputType,
class OutputType>
1657 static OutputType
miDiscrete(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
double base = 2.7182818)
1659 if (v1.size() != v2.size())
1660 throw DimensionException(
"VectorTools::miDiscrete. The two samples must have the same length.", v2.size(), v1.size());
1661 std::map<InputType, double> counts1;
1662 std::map<InputType, double> counts2;
1663 std::map<InputType, std::map<InputType, double> > counts12;
1664 for (
size_t i = 0; i < v1.size(); i++)
1668 counts12[v1[i]][v2[i]]++;
1671 double n =
static_cast<double>(v1.size());
1672 for (
auto& it1 : counts12)
1674 for (
auto& it2 : it1.second)
1676 s +=
static_cast<OutputType
>((it2.second / n) * std::log(it2.second * n / (counts1[it1.first] * counts2[it2.first])) / std::log(base));
1697 template<
class InputType,
class OutputType>
1701 for (
size_t i = 0; i < v.size(); i++)
1707 std::vector<double> x(1);
1710 x[0] =
static_cast<double>(it);
1711 s +=
static_cast<OutputType
>(std::log(kd.
kDensity(x)) / std::log(base));
1713 return -s /
static_cast<double>(v.size());
1735 template<
class InputType,
class OutputType>
1736 static OutputType
miContinuous(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
double base = 2.7182818)
1738 if (v1.size() != v2.size())
1739 throw DimensionException(
"VectorTools::miContinuous. The two samples must have the same length.", v2.size(), v1.size());
1743 for (
size_t i = 0; i < v1.size(); i++)
1745 m1(0, i) = m12(0, i) = v1[i];
1746 m2(0, i) = m12(1, i) = v2[i];
1752 std::vector<double> x1(1);
1753 std::vector<double> x2(1);
1754 std::vector<double> x12(2);
1755 for (
size_t i = 0; i < v1.size(); i++)
1757 x1[0] = x12[0] =
static_cast<double>(v1[i]);
1758 x2[0] = x12[1] =
static_cast<double>(v2[i]);
1759 s +=
static_cast<OutputType
>(std::log(kd12.
kDensity(x12) / (kd1.
kDensity(x1) * kd2.
kDensity(x2))) / std::log(base));
1761 return s /
static_cast<double>(v1.size());
1772 std::vector<T> u1(v1);
1773 std::vector<T> u2(v2);
1774 if (u1.size() != u2.size())
return false;
1775 std::sort(u1.begin(), u1.end());
1776 std::sort(u2.begin(), u2.end());
1791 if (v1.size() != v2.size())
return false;
1792 std::sort(v1.begin(), v1.end());
1793 std::sort(v2.begin(), v2.end());
1807 if (it == el)
return true;
1812 template<
class T,
class U>
1817 if (it == (T)el)
return true;
1833 std::sort(v1.begin(), v1.end());
1834 std::sort(v2.begin(), v2.end());
1836 for (
size_t i = 0; i < v2.size(); i++)
1838 if (i > 0 && v2[i] == v2[i - 1])
continue;
1839 while (j < v1.size() - 1 && v1[j] < v2[i]) j++;
1840 if (v1[j] != v2[i])
return false;
1852 static std::vector<T>
vectorUnion(
const std::vector<T>& vec1,
const std::vector<T>& vec2)
1854 std::vector<T> unionEl = vec1;
1855 for (
auto it : vec2)
1858 unionEl.push_back(it);
1869 static std::vector<T>
vectorUnion(
const std::vector< std::vector<T> >& vecElementL)
1871 std::vector<T> unionEl;
1872 for (
auto it : vecElementL)
1877 unionEl.push_back(it2);
1891 std::vector<T> interEl;
1892 for (
auto it : vec1)
1894 if (
contains(vec2, it)) interEl.push_back(it);
1899 template<
class T,
class U>
1902 std::vector<T> interEl;
1903 for (
auto it : vec1)
1905 if (
contains(vec2, it)) interEl.push_back(it);
1917 if (vecElementL.size() == 1)
return vecElementL[0];
1918 std::vector<T> interEl;
1919 if (vecElementL.size() == 0)
return interEl;
1920 for (
auto it : vecElementL[0])
1923 for (
size_t j = 1;
test && j < vecElementL.size(); j++)
1927 if (
test) interEl.push_back(it);
1938 static void append(std::vector<T>& vec1,
const std::vector<T>& vec2)
1940 vec1.insert(vec1.end(), vec2.begin(), vec2.end());
1949 static void prepend(std::vector<T>& vec1,
const std::vector<T>& vec2)
1951 vec1.insert(vec1.begin(), vec2.begin(), vec2.end());
1960 static std::vector<T>
append(
const std::vector< std::vector<T> >& vecElementL)
1962 if (vecElementL.size() == 1)
return vecElementL[0];
1964 if (vecElementL.size() == 0)
return v;
1965 for (
auto it : vecElementL[0])
1978 static void extend(std::vector<T>& vec1,
const std::vector<T>& vec2)
1980 for (
auto it : vec2)
1993 static std::vector<T>
rep(
const std::vector<T>& vec,
size_t n)
1995 if (n == 1)
return vec;
1997 if (n == 0)
return v;
1998 v.resize(vec.size() * n);
1999 for (
size_t i = 0; i < v.size(); i++)
2001 v[i] = vec[i % vec.size()];
2016 static void diff(std::vector<T>& v1, std::vector<T>& v2, std::vector<T>& v3)
2018 if (v2.size() == 0)
append(v3, v1);
2019 std::sort(v1.begin(), v1.end());
2020 std::sort(v2.begin(), v2.end());
2022 for (
size_t i = 0; i < v1.size(); i++)
2024 if (i > 0 && v1[i] == v1[i - 1])
continue;
2025 while (j < v2.size() - 1 && v2[j] < v1[i]) j++;
2026 if (v2[j] != v1[i]) v3.push_back(v1[i]);
Density estimation using the adaptive kernel method.
double kDensity(const std::vector< double > &x)
Number exception: doubles.
Exception thrown when a dimension problem occured.
Exception thrown when a given element was not found in the vector.
Exception thrown when an empty vector was found.
Matrix storage in one vector.
T to(const std::string &s)
Template to string conversion.
std::vector< VVVint > VVVVint
std::vector< std::complex< double > > Vcomplex
std::vector< VVVldouble > VVVVldouble
std::vector< double > Vdouble
std::vector< VVcomplex > VVVcomplex
std::vector< T > operator-(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVVuint > VVVVuint
std::vector< VVVdouble > VVVVdouble
std::vector< Vuint > VVuint
std::vector< std::complex< long double > > Vlcomplex
std::vector< Vlcomplex > VVlcomplex
std::vector< T > operator*(const std::vector< T > &v1, const std::vector< T > &v2)
void operator/=(std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVlcomplex > VVVlcomplex
std::vector< T > operator+(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVuint > VVVuint
std::vector< Vcomplex > VVcomplex
std::vector< Vint > VVint
std::vector< Vldouble > VVldouble
void operator&=(std::vector< T > &v1, const C &c)
std::vector< T > operator/(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVint > VVVint
std::vector< long double > Vldouble
std::vector< VVdouble > VVVdouble
void operator*=(std::vector< T > &v1, const std::vector< T > &v2)
void operator-=(std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVldouble > VVVldouble
void operator+=(std::vector< T > &v1, const std::vector< T > &v2)
std::vector< Vdouble > VVdouble
std::vector< unsigned int > Vuint