Skip to content

Commit

Permalink
add randomForest.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
toxic-0518 committed Jul 22, 2015
1 parent a1fda80 commit 58736c4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Joint/Joint.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<ItemGroup>
<ClCompile Include="joint.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="randomforest.cpp" />
<ClCompile Include="randomForest.cpp" />
<ClCompile Include="tree.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Joint/Joint.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<ClCompile Include="joint.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="tree.cpp" />
<ClCompile Include="randomforest.cpp" />
<ClCompile Include="randomForest.cpp" />
</ItemGroup>
</Project>
53 changes: 53 additions & 0 deletions Joint/randomForest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// randomForest.cpp
//
// implementation of hough forest
//
// Toixc
//

#include "randomforest.h"

void RandomForest::Train(
vector<Sample> &samples,
const Shape &meanShape,
int stages_
) {
stages = stages_;
RNG randomGenerator(getTickCount());
vector<int> index;
bool* key;
for (int i = 0; i < numTrees; i++) {
for (int j = 0; j < numLandmarks; j++) {

for (int l = 0; l < samples.size(); l++) {
// update weight of each sample
samples[i].weight = exp(-samples[i].label * samples[i].weight);
}

// randomly select 2000 different samples
index.clear();
key = new bool[samples.size()];
memset(key, false, sizeof(bool)* samples.size());
int k = randomGenerator.uniform(0, (int)samples.size());
key[k] = true;
index.push_back(k);
while (index.size() < 2000) {
k = randomGenerator.next();
if (key[k] == false) {
index.push_back(k);
key[k] = true;
}
}
delete [] key;
key = nullptr;
vector<Sample> tempSamples;
for (int n = 0; n < index.size(); n++) {
tempSamples.push_back(samples[index[n]]);
}
rfs[i][j].Train(tempSamples, meanShape, stages, j);


}
}
}

0 comments on commit 58736c4

Please sign in to comment.