aboutsummaryrefslogtreecommitdiff
path: root/dist.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-05-15 18:10:52 -0300
committerSamuel Fadel <samuelfadel@gmail.com>2015-05-15 18:10:52 -0300
commit0b6df071d94ae8f7c9cdd3c96506a1420129e471 (patch)
treeea73a59457beba89ef6bab2b16d2d679d8dd1078 /dist.cpp
Initial commit. ForceScheme seems bugged.
Diffstat (limited to 'dist.cpp')
-rw-r--r--dist.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/dist.cpp b/dist.cpp
new file mode 100644
index 0000000..aaa2167
--- /dev/null
+++ b/dist.cpp
@@ -0,0 +1,20 @@
+#include "mp.h"
+
+double mp::euclidean(const arma::rowvec &x1, const arma::rowvec &x2)
+{
+ return arma::norm(x1 - x2, 2);
+}
+
+arma::mat mp::dist(const arma::mat &X, double (*distCalc)(const arma::rowvec &, const arma::rowvec &))
+{
+ arma::uword n = X.n_rows;
+ arma::mat D(n, n, arma::fill::zeros);
+
+ for (arma::uword i = 0; i < n; i++)
+ for (arma::uword j = 0; j < i; j++) {
+ D(i, j) = distCalc(X.row(i), X.row(j));
+ D(j, i) = D(i, j);
+ }
+
+ return D;
+}