forked from neurodata/SPORF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforestPacking.cpp
More file actions
39 lines (29 loc) · 1011 Bytes
/
forestPacking.cpp
File metadata and controls
39 lines (29 loc) · 1011 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
32
33
34
35
36
37
#include <RcppArmadillo.h>
#include <improv8.h>
#include <vector>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
void packForestRCPP(){
const std::string forestFileName = "forestPackTempFile.csv";
const std::string traversalFileName = "traversalPackTempFile.csv";
const std::string packedFileName = "forest.out";
improv8 tester(forestFileName,1,traversalFileName,16, 3);
tester.writeForest(packedFileName);
}
// [[Rcpp::export]]
Rcpp::NumericVector predictRF(const NumericMatrix mat, const int numCores){
int numObservations = mat.nrow();
int numFeatures = mat.ncol();
std::vector<double> currObs(numFeatures);
Rcpp::NumericVector predictions(numObservations);
const std::string packedFileName = "forest.out";
improv8 tester(packedFileName);
for(int i = 0; i < numObservations; i++){
for(int j = 0; j < numFeatures; j++){
currObs[j] = mat(i,j);
}
predictions[i] = tester.makePrediction(currObs)+1;
}
return predictions;
}