iRoCS Toolbox  1.1.0
lRandomForest.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Kun Liu, Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 /*
24  * lRandomForest.h
25  *
26  * Created on: Jun 11, 2011
27  * Author: liu
28  */
29 
30 #ifndef LRANDOMFOREST_H_
31 #define LRANDOMFOREST_H_
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.hh>
35 #endif
36 
37 #include<vector>
38 #include<sstream>
39 
40 #include "lRandomTree.hh"
41 
43 {
44 
45 public:
46 
47  lRandomForest(int nTree);
49 
50  void SetTrees(int n);
51  int GetSize() const;
52 
53  /******************
54  * for simplicity, assuming class labels are 0~maxLabel
55  */
56  int predict(float* f) const;
57  int predict(float* f, float& p) const;
58  int predict(float* f, float* p) const;
59 
60  double proximity(float* f, int cl, int self = -1) const;
61 
62  double rawOutlier(float* f, int cl, int self = -1) const;
63 
64  double outlier(float* f, int cl) const;
65 
66  // Training
67  /******************
68  * for simplicity, assuming class labels are 0~maxLabel
69  * max depth is not applied, as RF should use a fully grown tree.
70  */
71  void trainForest(
72  float** X, int* L, int m, int n, int m_try, int max_depth,
73  int min_samples = 1, int num_grid = 20);
74 
75  // IO functions
76  void saveForest(const char* filename, unsigned int offset = 0);
77  void loadForest(const char* filename, unsigned int offset = 0);
78  void saveForest(std::stringstream* & ss);
79  void loadForest(std::stringstream*& ss);
80  void selfTest();
81 
82  // Data
83  std::vector<lRandomTree*> vTrees;
84  int _nTree;
85  int nSample;
86  int _maxLabel;
87 
88  int* classCount;
89  float* classWeight;
90 
93 };
94 
95 #endif /* LRANDOMFOREST_H_ */
double outlier(float *f, int cl) const
void loadForest(const char *filename, unsigned int offset=0)
lRandomForest(int nTree)
void trainForest(float **X, int *L, int m, int n, int m_try, int max_depth, int min_samples=1, int num_grid=20)
double * absDevRawOutlier
float * classWeight
void SetTrees(int n)
int predict(float *f) const
int GetSize() const
double proximity(float *f, int cl, int self=-1) const
double * medianRawOutlier
double rawOutlier(float *f, int cl, int self=-1) const
std::vector< lRandomTree * > vTrees
void saveForest(const char *filename, unsigned int offset=0)