forked from bleutner/RStoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictMlc.cpp
More file actions
31 lines (27 loc) · 816 Bytes
/
predictMlc.cpp
File metadata and controls
31 lines (27 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat predictMlcCpp(NumericMatrix newdata, List model, int nclasses){
int ns = newdata.nrow();
arma::mat out(ns, nclasses + 1, arma::fill::zeros);
for(int c = 0; c < nclasses; c++){
List classMod = model[c];
NumericVector m = classMod["m"];
for(int s = 0; s < ns; s++){
NumericVector xm(m.size());
for(int i = 0; i < m.size(); i++){
xm[i] = newdata(s,i) - m[i] ;
}
arma::mat dum = arma::rowvec(xm) * as<arma::mat>(classMod["I"]) * arma::colvec(xm);
double dummy = dum(0,0);
double deter = classMod["D"];
out(s,c + 1) = deter - dummy;
}
}
arma::uword index;
for(int s = 0; s < ns; s++){
out.submat(s, 1, s, nclasses).max(index);
out(s,0) = index + 1;
}
return out;
}