00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "RandomForestModel.h"
00034
00035 using namespace rfmodel;
00036
00037 double Model::weakTest(const DataMatrix& X) const {
00038
00039 double final_yhat = 1.0;
00040 int N = X.num_rows;
00041 int D = X.num_cols;
00042 #ifdef DEBUG_RF
00043 if (classifierID == 2.0)
00044 printf("\nTesting on weakmodel r1[%d], r2[%d], w[%lf,%lf,%lf]\n", r1, r2, w[0], w[1],
00045 w[2]);
00046 #endif
00047
00048
00049 #if 0
00050 if (classifierID == 1) {
00051
00052
00053 yhat = (double)X(:, model->r) < model->t;
00054
00055 int* select_cols;
00056 select_cols = new int[1];
00057 select_cols[0] = r;
00058
00059 DataMatrix *yhat_op = MatrixOp::_subset_cols(X, num_rows, num_cols, select_cols,
00060 1);
00061 yhat = yhat_op->data;
00062 final_yhat = MatrixOp::findIndicesLT(yhat,N, t);
00063 } else
00064 #endif
00065 if (classifierID == 2) {
00066
00067
00068 int select_cols[2];
00069 select_cols[0] = r1 - 1;
00070 select_cols[1] = r2 - 1;
00071
00072 DataMatrix subset_arr(X.num_rows, 2);
00073 X.subset_cols(select_cols, 2, subset_arr);
00074 const DataMatrix ones_arr(N, 1, true);
00075 DataMatrix combined_arr(subset_arr.num_rows, subset_arr.num_cols + ones_arr.num_rows);
00076 combined_arr.combine((const DataMatrix)subset_arr, ones_arr);
00077 const DataMatrix w_arr(w, 3, 1);
00078 DataMatrix mm(combined_arr.num_rows, w_arr.num_cols);
00079 mm.matrix_multiply(combined_arr, w_arr);
00080
00081 double zero = 0.0;
00082 DataMatrix yhat(mm.num_rows, mm.num_cols);
00083 mm.findIndicesLT(zero, yhat);
00084 if (yhat.data.size() == 0)
00085 final_yhat = 0.0;
00086 else
00087 final_yhat = yhat.data[0] + 1;
00088 }
00089
00090 return final_yhat;
00091 }