40 #ifndef _VECTORTOOLS_H_ 41 #define _VECTORTOOLS_H_ 47 #include "../Io/OutputStream.h" 48 #include "../App/ApplicationTools.h" 59 typedef std::vector<std::complex<double> >
Vcomplex;
63 typedef std::vector<std::complex<long double> >
Vlcomplex;
77 typedef std::vector<int>
Vint;
78 typedef std::vector<Vint>
VVint;
91 if (v1.size() != v2.size())
99 std::vector<T> result(size);
100 for (
size_t i = 0; i < size; i++)
102 result[i] = v1[i] + v2[i];
111 if (v1.size() != v2.size())
119 std::vector<T> result(size);
120 for (
size_t i = 0; i < size; i++)
122 result[i] = v1[i] - v2[i];
131 if (v1.size() != v2.size())
139 std::vector<T> result(size);
140 for (
size_t i = 0; i < size; i++)
142 result[i] = v1[i] * v2[i];
151 if (v1.size() != v2.size())
159 std::vector<T> result(size);
160 for (
size_t i = 0; i < size; i++)
162 result[i] = v1[i] / v2[i];
168 template<
class T,
class C>
169 std::vector<T>
operator+(
const std::vector<T>& v1,
const C& c)
171 std::vector<T> result(v1.size());
172 for (
size_t i = 0; i < result.size(); i++)
174 result[i] = v1[i] + c;
178 template<
class T,
class C>
179 std::vector<T>
operator+(
const C& c,
const std::vector<T>& v1)
181 std::vector<T> result(v1.size());
182 for (
size_t i = 0; i < result.size(); i++)
184 result[i] = c + v1[i];
189 template<
class T,
class C>
190 std::vector<T>
operator-(
const std::vector<T>& v1,
const C& c)
192 std::vector<T> result(v1.size());
193 for (
size_t i = 0; i < result.size(); i++)
195 result[i] = v1[i] - c;
199 template<
class T,
class C>
200 std::vector<T>
operator-(
const C& c,
const std::vector<T>& v1)
202 std::vector<T> result(v1.size());
203 for (
size_t i = 0; i < result.size(); i++)
205 result[i] = c - v1[i];
210 template<
class T,
class C>
211 std::vector<T>
operator*(
const std::vector<T>& v1,
const C& c)
213 std::vector<T> result(v1.size());
214 for (
size_t i = 0; i < result.size(); i++)
216 result[i] = v1[i] * c;
220 template<
class T,
class C>
221 std::vector<T>
operator*(
const C& c,
const std::vector<T>& v1)
223 std::vector<T> result(v1.size());
224 for (
size_t i = 0; i < result.size(); i++)
226 result[i] = c * v1[i];
231 template<
class T,
class C>
232 std::vector<T>
operator/(
const std::vector<T>& v1,
const C& c)
234 std::vector<T> result(v1.size());
235 for (
size_t i = 0; i < result.size(); i++)
237 result[i] = v1[i] / c;
241 template<
class T,
class C>
242 std::vector<T>
operator/(
const C& c,
const std::vector<T>& v1)
244 std::vector<T> result(v1.size());
245 for (
size_t i = 0; i < result.size(); i++)
247 result[i] = c / v1[i];
256 for (
size_t i = 0; i < v1.size(); i++)
265 for (
size_t i = 0; i < v1.size(); i++)
274 for (
size_t i = 0; i < v1.size(); i++)
283 for (
size_t i = 0; i < v1.size(); i++)
290 template<
class T,
class C>
293 for (
size_t i = 0; i < v1.size(); i++)
299 template<
class T,
class C>
302 for (
size_t i = 0; i < v1.size(); i++)
308 template<
class T,
class C>
311 for (
size_t i = 0; i < v1.size(); i++)
317 template<
class T,
class C>
320 for (
size_t i = 0; i < v1.size(); i++)
345 for (
size_t i = 0; i < n1; i++) { vv[i].resize(n2); }
352 for (
size_t i = 0; i < n1; i++)
355 for (
size_t j = 0; j < n2; j++)
357 vvv[i][j].resize(n3);
365 for (
size_t i = 0; i < n1; i++)
368 for (
size_t j = 0; j < n2; j++)
370 vvvv[i][j].resize(n3);
371 for (
size_t k = 0; k < n3; k++)
373 vvvv[i][j][k].resize(n4);
381 static void fill(std::vector<T>& v, T value)
383 for (
typename std::vector<T>::iterator it = v.begin(); it < v.end(); it++)
402 static std::vector<T>
seq(T from, T to, T by)
408 for (T i = from; i <= to + (by / 100); i += by)
415 for (T i = from; i >= to - (by / 100); i -= by)
436 for (
size_t i = 0; i < v.size(); i++)
438 if (v[i] ==
which)
return i;
456 std::vector<size_t> w;
457 for (
size_t i = 0; i < v.size(); i++)
459 if (v[i] ==
which) w.push_back(i);
478 static std::vector<T>
unique(
const std::vector<T>& v)
480 if (v.size() == 0)
return v;
481 std::vector<T> sortedV(v.begin(), v.end());
482 sort(sortedV.begin(), sortedV.end());
484 uniq.push_back(sortedV[0]);
485 for (
size_t i = 1; i < sortedV.size(); i++)
487 if (sortedV[i] != sortedV[i - 1]) uniq.push_back(sortedV[i]);
505 if (v.size() == 0)
return true;
506 std::vector<T> sortedV(v.begin(), v.end());
507 sort(sortedV.begin(), sortedV.end());
508 for (
size_t i = 1; i < sortedV.size(); i++)
510 if (sortedV[i] == sortedV[i - 1])
return false;
523 static std::vector<T>
extract(
const std::vector<T>& v1,
const std::vector<int>& v2)
525 std::vector<T> v(v2.size());
526 for (
size_t i = 0; i < v2.size(); i++)
542 std::map<T, size_t> c;
543 for (
size_t i = 0; i < v.size(); i++)
560 static std::vector<double>
breaks(
const std::vector<double>& v,
unsigned int n);
578 double h = 3.5 * VectorTools::sd<T, double>(v) * std::pow(n, -1. / 3);
579 return (
size_t) ceil(r / h);
587 static T
prod(
const std::vector<T>& v1)
590 for (
size_t i = 0; i < v1.size(); i++) { p *= v1[i]; }
600 static std::vector<T>
cumProd(
const std::vector<T>& v1)
602 std::vector<T> p(v1.size());
603 if (v1.size() == 0)
return p;
605 for (
size_t i = 1; i < v1.size(); i++) { p[i] = v1[i] * p[i - 1]; }
614 static T
sum(
const std::vector<T>& v1)
617 for (
size_t i = 0; i < v1.size(); i++) { s += v1[i]; }
627 static std::vector<T>
cumSum(
const std::vector<T>& v1)
629 std::vector<T> s(v1.size());
630 if (v1.size() == 0)
return s;
632 for (
size_t i = 1; i < v1.size(); i++) { s[i] = v1[i] + s[i - 1]; }
646 T x = std::exp(v[0] - M);
647 for (
size_t i = 1; i < v.size(); i++)
649 x += std::exp(v[i] - M);
651 v -= M + std::log(x);
663 T x = std::exp(v1[0] - M);
664 for (
size_t i = 1; i < v1.size(); i++)
666 x += std::exp(v1[i] - M);
668 return std::log(x) + M;
678 static T
logSumExp(
const std::vector<T>& v1,
const std::vector<T>& v2)
681 if (v1.size() != v2.size())
687 T x = v2[0] * std::exp(v1[0] - M);
688 for (
size_t i = 1; i < size; i++)
690 x += v2[i] * std::exp(v1[i] - M);
692 return std::log(x) + M;
704 T x = std::exp(v1[0] - M);
705 for (
size_t i = 1; i < v1.size(); i++)
707 x += std::exp(v1[i] - M);
709 return std::log(x) + M - std::log(v1.size());
719 static T
sumExp(
const std::vector<T>& v1)
722 T x = std::exp(v1[0] - M);
723 for (
size_t i = 1; i < v1.size(); i++)
725 x += std::exp(v1[i] - M);
727 return x * std::exp(M);
737 static T
sumExp(
const std::vector<T>& v1,
const std::vector<T>& v2)
740 if (v1.size() != v2.size())
746 T x = v2[0] * std::exp(v1[0] - M);
747 for (
size_t i = 1; i < size; i++)
749 x += v2[i] * std::exp(v1[i] - M);
751 return x * std::exp(M);
761 static std::vector<double>
log(
const std::vector<T>& v1)
763 std::vector<double> v2(v1.size());
764 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::log(v1[i]); }
768 static std::vector<double>
log(
const std::vector<T>& v1,
double base)
770 std::vector<double> v2(v1.size());
771 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::log(v1[i]) / std::log(base); }
776 static std::vector<double>
exp(
const std::vector<T>& v1)
778 std::vector<double> v2(v1.size());
779 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::exp(v1[i]); }
784 static std::vector<double>
cos(
const std::vector<T>& v1)
786 std::vector<double> v2(v1.size());
787 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::cos(v1[i]); }
792 static std::vector<double>
sin(
const std::vector<T>& v1)
794 std::vector<double> v2(v1.size());
795 for (
size_t i = 0; i < v2.size(); i++) { v2[i] = std::sin(v1[i]); }
800 static std::vector<double>
log10(
const std::vector<T>& v1)
802 std::vector<double> v2(v1.size());
803 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = std::log10(v1[i]); }
808 static std::vector<T>
fact(
const std::vector<T>& v1)
810 std::vector<T> v2(v1.size());
811 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = NumTools::fact<T>(v1[i]); }
816 static std::vector<T>
sqr(
const std::vector<T>& v1)
818 std::vector<T> v2(v1.size());
819 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = NumTools::sqr<T>(v1[i]); }
824 static std::vector<T>
pow(
const std::vector<T>& v1, T& b)
826 std::vector<T> v2(v1.size());
827 for (
size_t i = 0; i < v1.size(); i++) { v2[i] = std::pow(v1[i], b); }
839 static std::string
paste(
const std::vector<T>& v,
const std::string& delim =
" ")
841 std::ostringstream out;
843 for (
size_t i = 0; i < v.size(); i++)
846 if (i < v.size() - 1)
861 for (
size_t i = 0; i < v1.size(); i++)
864 if (i < v1.size() - 1)
877 static void printForR(
const std::vector<T>& v1, std::string variableName =
"x", std::ostream& out = std::cout)
880 out << variableName <<
"<-c(";
881 for (
size_t i = 0; i < v1.size(); i++)
884 if (i < v1.size() - 1)
887 out <<
")" << std::endl;
896 template<
class InputType,
class OutputType>
899 if (v1.size() != v2.size())
903 OutputType result = 0;
904 for (
size_t i = 0; i < v1.size(); i++)
906 result += v1[i] * v2[i];
926 template<
class InputType,
class OutputType>
927 static OutputType
scalar(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w)
throw (
DimensionException)
929 if (v1.size() != w.size())
933 if (v2.size() != w.size())
937 OutputType result = 0;
938 for (
size_t i = 0; i < v1.size(); i++)
940 result += v1[i] * v2[i] * w[i];
954 size_t n1 = v1.size();
955 size_t n2 = v2.size();
956 std::vector<T> v3(n1 * n2);
957 for (
size_t i = 0; i < n1; i++)
960 for (
size_t j = 0; j < n2; j++)
962 v3[i * n2 + j] = v1i * v2[j];
972 template<
class InputType,
class OutputType>
973 static OutputType
norm(
const std::vector<InputType>& v1)
975 OutputType result = 0;
976 for (
size_t i = 0; i < v1.size(); i++)
978 result += v1[i] * v1[i];
990 template<
class InputType,
class OutputType>
993 if (v1.size() != w.size())
997 OutputType result = 0;
998 for (
size_t i = 0; i < v1.size(); i++)
1000 result += v1[i] * v1[i] * w[i];
1002 return sqrt(result);
1011 template<
class InputType,
class OutputType>
1014 return scalar<InputType, OutputType>(v1, v2)
1015 / (norm<InputType, OutputType>(v1) * norm<InputType, OutputType>(v2));
1025 template<
class InputType,
class OutputType>
1026 static OutputType
cos(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w)
throw (
DimensionException)
1028 return scalar<InputType, OutputType>(v1, v2, w)
1029 / (norm<InputType, OutputType>(v1, w) * norm<InputType, OutputType>(v2, w));
1052 for (
size_t i = 1; i < v.size(); i++)
1054 if (v[i] < mini) mini = v[i];
1073 for (
size_t i = 1; i < v.size(); i++)
1075 if (v[i] > maxi) maxi = v[i];
1096 for (
size_t i = 1; i < v.size(); i++)
1123 for (
size_t i = 1; i < v.size(); i++)
1149 std::vector<size_t> pos;
1150 for (
size_t i = 0; i < v.size(); i++)
1175 std::vector<size_t> pos;
1176 for (
size_t i = 0; i < v.size(); i++)
1201 std::vector<T> r(2);
1203 for (
size_t i = 1; i < v.size(); i++)
1205 if (v[i] < r[0]) r[0] = v[i];
1206 if (v[i] > r[1]) r[1] = v[i];
1237 std::vector<size_t> index(v.size());
1238 for (
size_t i = 0; i < index.size(); ++i)
1258 std::vector<T> vabs(v.size());
1259 for (
size_t i = 1; i < v.size(); i++)
1261 vabs[i] = std::abs(v[i]);
1270 template<
class InputType,
class OutputType>
1271 static OutputType
mean(
const std::vector<InputType>& v1)
1273 return (OutputType)sum<InputType>(v1) / (OutputType)v1.size();
1281 template<
class InputType,
class OutputType>
1282 static OutputType
mean(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool normalizeWeights =
true)
1284 if (normalizeWeights)
1286 std::vector<InputType> wn = w /
sum(w);
1287 return scalar<InputType, OutputType>(v1, wn);
1291 return scalar<InputType, OutputType>(v1, w);
1299 template<
class InputType>
1300 static InputType
median(std::vector<InputType>& v1)
1303 if (v1.size() == 0)
return med;
1304 if (v1.size() == 1)
return v1[0];
1305 sort(v1.begin(), v1.end());
1306 size_t i = v1.size() / 2;
1307 if (v1.size() % 2 == 0)
1310 med = double((v1[i - 1] + v1[i]) / 2);
1326 template<
class InputType,
class OutputType>
1327 static std::vector<OutputType>
center(
const std::vector<InputType>& v1)
1329 OutputType m = mean<InputType, OutputType>(v1);
1330 std::vector<OutputType> v(v1.size());
1331 for (
size_t i = 0; i < v1.size(); i++)
1333 v[i] = (OutputType)v1[i] - m;
1345 template<
class InputType,
class OutputType>
1346 static std::vector<OutputType>
center(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool normalizeWeights =
true)
1348 OutputType m = mean<InputType, OutputType>(v1, w, normalizeWeights);
1349 std::vector<OutputType> v(v1.size());
1350 for (
size_t i = 0; i < v1.size(); i++)
1352 v[i] = (OutputType)v1[i] - m;
1364 template<
class InputType,
class OutputType>
1365 static OutputType
cov(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
bool unbiased =
true) throw (
DimensionException)
1367 OutputType n = (OutputType)v1.size();
1368 OutputType x = scalar<InputType, OutputType>(
1369 center<InputType, OutputType>(v1),
1370 center<InputType, OutputType>(v2)
1372 if (unbiased) x = x * n / (n - 1);
1386 template<
class InputType,
class OutputType>
1387 static OutputType
cov(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true) throw (
DimensionException)
1389 if (normalizeWeights)
1391 std::vector<InputType> wn = w /
sum(w);
1392 OutputType x = scalar<InputType, OutputType>(
1393 center<InputType, OutputType>(v1, wn,
false),
1394 center<InputType, OutputType>(v2, wn,
false),
1399 x = x / (1 -
sum(sqr<double>(wn)));
1405 OutputType x = scalar<InputType, OutputType>(
1406 center<InputType, OutputType>(v1, w,
false),
1407 center<InputType, OutputType>(v2, w,
false),
1412 x = x / (1 -
sum(
sqr(w)));
1422 template<
class InputType,
class OutputType>
1423 static OutputType
var(
const std::vector<InputType>& v1,
bool unbiased =
true)
1425 return cov<InputType, OutputType>(v1, v1, unbiased);
1435 template<
class InputType,
class OutputType>
1436 static OutputType
var(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true) throw (
DimensionException)
1438 return cov<InputType, OutputType>(v1, v1, w, unbiased, normalizeWeights);
1446 template<
class InputType,
class OutputType>
1447 static OutputType
sd(
const std::vector<InputType>& v1,
bool unbiased =
true)
1449 return sqrt(var<InputType, OutputType>(v1, unbiased));
1460 template<
class InputType,
class OutputType>
1461 static OutputType
sd(
const std::vector<InputType>& v1,
const std::vector<InputType>& w,
bool unbiased =
true,
bool normalizeWeights =
true) throw (
DimensionException)
1463 return sqrt(var<InputType, OutputType>(v1, w, unbiased, normalizeWeights));
1472 template<
class InputType,
class OutputType>
1475 return cov<InputType, OutputType>(v1, v2)
1476 / ( sd<InputType, OutputType>(v1) * sd<InputType, OutputType>(v2) );
1487 template<
class InputType,
class OutputType>
1488 static OutputType
cor(
const std::vector<InputType>& v1,
const std::vector<InputType>& v2,
const std::vector<InputType>& w,
bool normalizeWeights =
true) throw (
DimensionException)
1490 if (normalizeWeights)
1492 std::vector<InputType> wn = w /
sum(w);
1493 return cov<InputType, OutputType>(v1, v2, wn,
false,
false)
1494 / ( sd<InputType, OutputType>(v1, wn,
false,
false) * sd<InputType, OutputType>(v2, wn,
false,
false) );
1498 return cov<InputType, OutputType>(v1, v2, w,
false,
false)
1499 / ( sd<InputType, OutputType>(v1, w,
false,
false) * sd<InputType, OutputType>(v2, w,
false,
false) );
1517 template<
class InputType,
class OutputType>
1518 static OutputType
shannon(
const std::vector<InputType>& v,
double base = 2.7182818)
1521 for (
size_t i = 0; i < v.size(); i++)
1523 if (v[i] > 0) s +=
static_cast<OutputType
>(v[i] * std::log(v[i]) / std::log(base));
1542 template<
class InputType,
class OutputType>
1543 static OutputType
shannonDiscrete(
const std::vector<InputType>& v,
double base = 2.7182818)
1545 std::map<InputType, double> counts;
1546 for (
size_t i = 0; i < v.size(); i++)
1551 double n =
static_cast<double>(v.size());
1552 for (
typename std::map<InputType, double>::iterator it = counts.begin(); it != counts.end(); it++)
1554 s +=
static_cast<OutputType
>((it->second / n) * std::log(it->second / n) / std::log(base));
1574 template<
class InputType,
class OutputType>
1577 if (v1.size() != v2.size())
1578 throw DimensionException(
"VectorTools::miDiscrete. The two samples must have the same length.", v2.size(), v1.size());
1579 std::map<InputType, double> counts1;
1580 std::map<InputType, double> counts2;
1581 std::map<InputType, std::map<InputType, double> > counts12;
1582 for (
size_t i = 0; i < v1.size(); i++)
1586 counts12[v1[i]][v2[i]]++;
1589 double n =
static_cast<double>(v1.size());
1590 for (
typename std::map<InputType, std::map<InputType, double> >::iterator it1 = counts12.begin(); it1 != counts12.end(); it1++)
1592 for (
typename std::map<InputType, double>::iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
1594 s +=
static_cast<OutputType
>((it2->second / n) * std::log(it2->second * n / (counts1[it1->first] * counts2[it2->first])) / std::log(base));
1615 template<
class InputType,
class OutputType>
1619 for (
size_t i = 0; i < v.size(); i++)
1625 std::vector<double> x(1);
1626 for (
size_t i = 0; i < v.size(); i++)
1628 x[0] =
static_cast<double>(v[i]);
1629 s +=
static_cast<OutputType
>(std::log(kd.
kDensity(x)) / std::log(base));
1631 return -s /
static_cast<double>(v.size());
1653 template<
class InputType,
class OutputType>
1656 if (v1.size() != v2.size())
1657 throw DimensionException(
"VectorTools::miContinuous. The two samples must have the same length.", v2.size(), v1.size());
1661 for (
size_t i = 0; i < v1.size(); i++)
1663 m1(0, i) = m12(0, i) = v1[i];
1664 m2(0, i) = m12(1, i) = v2[i];
1670 std::vector<double> x1(1);
1671 std::vector<double> x2(1);
1672 std::vector<double> x12(2);
1673 for (
size_t i = 0; i < v1.size(); i++)
1675 x1[0] = x12[0] =
static_cast<double>(v1[i]);
1676 x2[0] = x12[1] =
static_cast<double>(v2[i]);
1677 s +=
static_cast<OutputType
>(std::log(kd12.
kDensity(x12) / (kd1.
kDensity(x1) * kd2.
kDensity(x2))) / std::log(base));
1679 return s /
static_cast<double>(v1.size());
1690 std::vector<T> u1(v1);
1691 std::vector<T> u2(v2);
1692 if (u1.size() != u2.size())
return false;
1693 std::sort(u1.begin(), u1.end());
1694 std::sort(u2.begin(), u2.end());
1709 if (v1.size() != v2.size())
return false;
1710 std::sort(v1.begin(), v1.end());
1711 std::sort(v2.begin(), v2.end());
1723 for (
size_t i = 0; i < vec.size(); i++)
1725 if (vec[i] == el)
return true;
1741 std::sort(v1.begin(), v1.end());
1742 std::sort(v2.begin(), v2.end());
1744 for (
size_t i = 0; i < v2.size(); i++)
1746 if (i > 0 && v2[i] == v2[i - 1])
continue;
1747 while (j < v1.size() - 1 && v1[j] < v2[i]) j++;
1748 if (v1[j] != v2[i])
return false;
1760 static std::vector<T>
vectorUnion(
const std::vector<T>& vec1,
const std::vector<T>& vec2)
1762 std::vector<T> unionEl = vec1;
1763 for (
size_t j = 0; j < vec2.size(); j++)
1766 unionEl.push_back(vec2[j]);
1777 static std::vector<T>
vectorUnion(
const std::vector< std::vector<T> >& vecElementL)
1779 std::vector<T> unionEl;
1780 for (
size_t i = 0; i < vecElementL.size(); i++)
1782 for (
size_t j = 0; j < vecElementL[i].size(); j++)
1784 if (!
contains(unionEl, vecElementL[i][j]))
1785 unionEl.push_back(vecElementL[i][j]);
1799 std::vector<T> interEl;
1800 for (
size_t i = 0; i < vec1.size(); i++)
1802 if (
contains(vec2, vec1[i])) interEl.push_back(vec1[i]);
1814 if (vecElementL.size() == 1)
return vecElementL[0];
1815 std::vector<T> interEl;
1816 if (vecElementL.size() == 0)
return interEl;
1817 for (
size_t i = 0; i < vecElementL[0].size(); i++)
1820 for (
size_t j = 1;
test && j < vecElementL.size(); j++)
1822 if (!
contains(vecElementL[j], vecElementL[0][i]))
test =
false;
1824 if (
test) interEl.push_back(vecElementL[0][i]);
1835 static void append(std::vector<T>& vec1,
const std::vector<T>& vec2)
1837 vec1.insert(vec1.end(), vec2.begin(), vec2.end());
1850 static void prepend(std::vector<T>& vec1,
const std::vector<T>& vec2)
1852 vec1.insert(vec1.begin(), vec2.begin(), vec2.end());
1861 static std::vector<T>
append(
const std::vector< std::vector<T> >& vecElementL)
1863 if (vecElementL.size() == 1)
return vecElementL[0];
1865 if (vecElementL.size() == 0)
return v;
1866 for (
size_t i = 0; i < vecElementL[0].size(); i++)
1868 v.push_back(vecElementL[0][i]);
1879 static void extend(std::vector<T>& vec1,
const std::vector<T>& vec2)
1881 for (
size_t i = 0; i < vec2.size(); i++)
1884 vec1.push_back(vec2[i]);
1894 static std::vector<T>
rep(
const std::vector<T>& vec,
size_t n)
1896 if (n == 1)
return vec;
1898 if (n == 0)
return v;
1899 v.resize(vec.size() * n);
1900 for (
size_t i = 0; i < v.size(); i++)
1902 v[i] = vec[i % vec.size()];
1917 static void diff(std::vector<T>& v1, std::vector<T>& v2, std::vector<T>& v3)
1919 if (v2.size() == 0)
append(v3, v1);
1920 std::sort(v1.begin(), v1.end());
1921 std::sort(v2.begin(), v2.end());
1923 for (
size_t i = 0; i < v1.size(); i++)
1925 if (i > 0 && v1[i] == v1[i - 1])
continue;
1926 while (j < v2.size() - 1 && v2[j] < v1[i]) j++;
1927 if (v2[j] != v1[i]) v3.push_back(v1[i]);
1939 #endif // _VECTORTOOLS_H_ void operator/=(std::vector< T > &v1, const std::vector< T > &v2)
This class allows to perform a correspondence analysis.
std::vector< T > operator+(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< long double > Vldouble
Exception thrown when a given element was not found in the vector.
std::vector< VVlcomplex > VVVlcomplex
Matrix storage in one vector.
std::vector< VVldouble > VVVldouble
std::vector< VVcomplex > VVVcomplex
void operator+=(std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > operator-(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< VVint > VVVint
std::vector< std::complex< double > > Vcomplex
std::vector< VVVint > VVVVint
std::vector< Vcomplex > VVcomplex
Exception thrown when an empty vector was found.
std::vector< Vint > VVint
std::vector< double > Vdouble
std::vector< T > operator/(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > operator*(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< std::complex< long double > > Vlcomplex
std::vector< VVVdouble > VVVVdouble
double kDensity(const std::vector< double > &x)
Density estimation using the adaptive kernel method.
std::vector< Vldouble > VVldouble
void operator-=(std::vector< T > &v1, const std::vector< T > &v2)
Exception thrown when a dimension problem occured.
std::vector< VVVldouble > VVVVldouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble
void operator*=(std::vector< T > &v1, const std::vector< T > &v2)
std::vector< Vlcomplex > VVlcomplex