ml4r 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/ml4r/LinearRegression/LinearRegression.cpp +305 -0
- data/ext/ml4r/LinearRegression/OLSLinearRegression.cpp +75 -0
- data/ext/ml4r/MachineLearning/DecisionTree/DecisionTreeExperiment.cpp +50 -0
- data/ext/ml4r/MachineLearning/DecisionTree/DecisionTreeNode.cpp +195 -0
- data/ext/ml4r/MachineLearning/DecisionTree/NodeSplitter.cpp +551 -0
- data/ext/ml4r/MachineLearning/DecisionTree/NodeSplitterCategorical.cpp +22 -0
- data/ext/ml4r/MachineLearning/DecisionTree/NodeSplitterContinuous.cpp +21 -0
- data/ext/ml4r/MachineLearning/DecisionTree/SplitDefinition.cpp +142 -0
- data/ext/ml4r/MachineLearning/GBM/BernoulliCalculator.cpp +95 -0
- data/ext/ml4r/MachineLearning/GBM/GBMEstimator.cpp +601 -0
- data/ext/ml4r/MachineLearning/GBM/GBMOutput.cpp +86 -0
- data/ext/ml4r/MachineLearning/GBM/GBMRunner.cpp +117 -0
- data/ext/ml4r/MachineLearning/GBM/GaussianCalculator.cpp +94 -0
- data/ext/ml4r/MachineLearning/GBM/ZenithGBM.cpp +317 -0
- data/ext/ml4r/MachineLearning/MLData/MLData.cpp +232 -0
- data/ext/ml4r/MachineLearning/MLData/MLDataFields.cpp +1 -0
- data/ext/ml4r/MachineLearning/MLData/MLDataReader.cpp +139 -0
- data/ext/ml4r/MachineLearning/MLData/ZenithMLData.cpp +96 -0
- data/ext/ml4r/MachineLearning/MLData/ZenithMLDataReader.cpp +113 -0
- data/ext/ml4r/MachineLearning/MLExperiment.cpp +69 -0
- data/ext/ml4r/MachineLearning/MLRunner.cpp +183 -0
- data/ext/ml4r/MachineLearning/MLUtils.cpp +15 -0
- data/ext/ml4r/MachineLearning/RandomForest/RandomForestEstimator.cpp +172 -0
- data/ext/ml4r/MachineLearning/RandomForest/RandomForestOutput.cpp +66 -0
- data/ext/ml4r/MachineLearning/RandomForest/RandomForestRunner.cpp +84 -0
- data/ext/ml4r/MachineLearning/RandomForest/ZenithRandomForest.cpp +184 -0
- data/ext/ml4r/ml4r.cpp +34 -0
- data/ext/ml4r/ml4r_wrap.cpp +15727 -0
- data/ext/ml4r/utils/MathUtils.cpp +204 -0
- data/ext/ml4r/utils/StochasticUtils.cpp +73 -0
- data/ext/ml4r/utils/Utils.cpp +14 -0
- data/ext/ml4r/utils/VlcMessage.cpp +3 -0
- metadata +33 -1
@@ -0,0 +1,184 @@
|
|
1
|
+
// #include "MachineLearning/RandomForest/ZenithRandomForest.h"
|
2
|
+
// #include "MachineLearning/RandomForest/RandomForestRunner.h"
|
3
|
+
// #include "MachineLearning/RandomForest/RandomForestParameters.h"
|
4
|
+
|
5
|
+
// #include "RubyUtils.h"
|
6
|
+
// using namespace RubyUtils;
|
7
|
+
|
8
|
+
// #include "stringConversion.h"
|
9
|
+
|
10
|
+
// void zenith_randomForest_Free(void* v)
|
11
|
+
// {
|
12
|
+
// delete (reinterpret_cast<RandomForestRunner*>(v));
|
13
|
+
// }
|
14
|
+
|
15
|
+
// OtInterface::VALUE zenith_randomForest_New(int argc, VALUE* argv, VALUE klass)
|
16
|
+
// {
|
17
|
+
// VALUE obj = otRuby->DataWrapStruct(klass, 0, zenith_randomForest_Free, 0);
|
18
|
+
// otRuby->rb_obj_call_init(obj, argc, argv);
|
19
|
+
// return obj;
|
20
|
+
// }
|
21
|
+
|
22
|
+
// OtInterface::VALUE zenith_randomForest_Initialize(VALUE self)
|
23
|
+
// {
|
24
|
+
// if (otRuby->GetDataPtr(self)) zenith_randomForest_Free(otRuby->GetDataPtr(self));
|
25
|
+
// otRuby->SetDataPtr(self, NULL);
|
26
|
+
|
27
|
+
// RandomForestRunner* randomForest = new RandomForestRunner();
|
28
|
+
// if (randomForest == NULL) otRuby->rb_sys_fail("ZenithRandomForest class could not be created");
|
29
|
+
// otRuby->SetDataPtr(self, randomForest);
|
30
|
+
// return self;
|
31
|
+
// }
|
32
|
+
|
33
|
+
// OtInterface::VALUE zenith_randomForest_estimate(VALUE self)
|
34
|
+
// {
|
35
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
36
|
+
// try
|
37
|
+
// {
|
38
|
+
// randomForest->execute();
|
39
|
+
// }
|
40
|
+
// catch (std::exception e)
|
41
|
+
// {
|
42
|
+
// vlcMessage.Raise((string("Caught error: ") + e.what()).c_str());
|
43
|
+
// }
|
44
|
+
|
45
|
+
// return TOtRubyInterface::Qnil;
|
46
|
+
// }
|
47
|
+
|
48
|
+
|
49
|
+
// OtInterface::VALUE zenith_randomForest_estimateMore(VALUE self, VALUE numTrees)
|
50
|
+
// {
|
51
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
52
|
+
// try
|
53
|
+
// {
|
54
|
+
// randomForest->estimateMore(RubyUtils::fromValue<int>(numTrees));
|
55
|
+
// }
|
56
|
+
// catch (std::exception e)
|
57
|
+
// {
|
58
|
+
// vlcMessage.Raise((string("Caught error: ") + e.what()).c_str());
|
59
|
+
// }
|
60
|
+
|
61
|
+
// return TOtRubyInterface::Qnil;
|
62
|
+
// }
|
63
|
+
|
64
|
+
|
65
|
+
// OtInterface::VALUE zenith_randomForest_setFeaturesToRun(VALUE self, VALUE featuresValue)
|
66
|
+
// {
|
67
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
68
|
+
// randomForest->parameters->featuresToRun = RubyUtils::fromValue<vector<string> >(featuresValue);
|
69
|
+
// return TOtRubyInterface::Qnil;
|
70
|
+
// }
|
71
|
+
|
72
|
+
// OtInterface::VALUE zenith_randomForest_setData(VALUE self, VALUE data)
|
73
|
+
// {
|
74
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
75
|
+
// MLData* mlData = (MLData*)otRuby->GetDataPtr(data);
|
76
|
+
// randomForest->setData(mlData);
|
77
|
+
// return TOtRubyInterface::Qnil;
|
78
|
+
// }
|
79
|
+
|
80
|
+
// OtInterface::VALUE zenith_randomForest_setTryMVariables(VALUE self, VALUE mVariablesValue)
|
81
|
+
// {
|
82
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
83
|
+
// randomForest->parameters->tryMVariables = RubyUtils::fromValue<int>(mVariablesValue);
|
84
|
+
// return TOtRubyInterface::Qnil;
|
85
|
+
// }
|
86
|
+
|
87
|
+
// OtInterface::VALUE zenith_randomForest_setNumIterations(VALUE self, VALUE numIterationsValue)
|
88
|
+
// {
|
89
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
90
|
+
// randomForest->parameters->numIterations = RubyUtils::fromValue<int>(numIterationsValue);
|
91
|
+
// return TOtRubyInterface::Qnil;
|
92
|
+
// }
|
93
|
+
|
94
|
+
// OtInterface::VALUE zenith_randomForest_setBagFraction(VALUE self, VALUE bagFractionValue)
|
95
|
+
// {
|
96
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
97
|
+
// randomForest->parameters->bagFraction = RubyUtils::fromValue<double>(bagFractionValue);
|
98
|
+
// return TOtRubyInterface::Qnil;
|
99
|
+
// }
|
100
|
+
|
101
|
+
// OtInterface::VALUE zenith_randomForest_predictions(VALUE self, VALUE newMlData)
|
102
|
+
// {
|
103
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
104
|
+
// MLData* data = (MLData*)otRuby->GetDataPtr(newMlData);
|
105
|
+
|
106
|
+
// vector<double> predictions;
|
107
|
+
|
108
|
+
// try
|
109
|
+
// {
|
110
|
+
// predictions = randomForest->getPredictions(data);
|
111
|
+
// }
|
112
|
+
// catch (std::exception e)
|
113
|
+
// {
|
114
|
+
// vlcMessage.Raise((string("Could not get predictions. Error: ") + e.what()).c_str());
|
115
|
+
// }
|
116
|
+
|
117
|
+
// return RubyUtils::toValue(predictions);
|
118
|
+
// }
|
119
|
+
|
120
|
+
// OtInterface::VALUE zenith_randomForest_training_predictions(VALUE self)
|
121
|
+
// {
|
122
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
123
|
+
// vector<double> predictions;
|
124
|
+
|
125
|
+
// try
|
126
|
+
// {
|
127
|
+
// predictions = randomForest->getMeanTrainingPredictions();
|
128
|
+
// }
|
129
|
+
// catch (std::exception e)
|
130
|
+
// {
|
131
|
+
// vlcMessage.Raise((string("Could not get training predictions. Error: ") + e.what()).c_str());
|
132
|
+
// }
|
133
|
+
|
134
|
+
// return RubyUtils::toValue(predictions);
|
135
|
+
// }
|
136
|
+
|
137
|
+
// OtInterface::VALUE zenith_randomForest_crossvalidation_predictions(VALUE self)
|
138
|
+
// {
|
139
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
140
|
+
// vector<double> predictions;
|
141
|
+
|
142
|
+
// try
|
143
|
+
// {
|
144
|
+
// predictions = randomForest->getCrossValidationPredictions();
|
145
|
+
// }
|
146
|
+
// catch (std::exception e)
|
147
|
+
// {
|
148
|
+
// vlcMessage.Raise((string("Could not get cross validation predictions. Error: ") + e.what()).c_str());
|
149
|
+
// }
|
150
|
+
|
151
|
+
// return RubyUtils::toValue(predictions);
|
152
|
+
// }
|
153
|
+
|
154
|
+
// OtInterface::VALUE zenith_randomForest_minObservations(VALUE self, VALUE minObservations)
|
155
|
+
// {
|
156
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
157
|
+
// randomForest->parameters->minObservations = RubyUtils::fromValue<int>(minObservations);
|
158
|
+
// return TOtRubyInterface::Qnil;
|
159
|
+
// }
|
160
|
+
|
161
|
+
// OtInterface::VALUE zenith_randomForest_verbose(VALUE self, VALUE rb_verbose)
|
162
|
+
// {
|
163
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
164
|
+
// bool verbose = RubyUtils::fromValue<bool>(rb_verbose);
|
165
|
+
// randomForest->parameters->verbose = verbose;
|
166
|
+
// return TOtRubyInterface::Qnil;
|
167
|
+
// }
|
168
|
+
|
169
|
+
// OtInterface::VALUE zenith_randomForest_withReplacement(VALUE self, VALUE rb_withReplacement)
|
170
|
+
// {
|
171
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
172
|
+
// bool withReplacement = RubyUtils::fromValue<bool>(rb_withReplacement);
|
173
|
+
// randomForest->parameters->withReplacement = withReplacement;
|
174
|
+
// return TOtRubyInterface::Qnil;
|
175
|
+
// }
|
176
|
+
|
177
|
+
// OtInterface::VALUE zenith_randomForest_setScale( VALUE self, VALUE rb_scale )
|
178
|
+
// {
|
179
|
+
// RandomForestRunner* randomForest = (RandomForestRunner*)otRuby->GetDataPtr(self);
|
180
|
+
// double scale = RubyUtils::fromValue<double>(rb_scale);
|
181
|
+
// randomForest->parameters->scale= scale;
|
182
|
+
// return TOtRubyInterface::Qnil;
|
183
|
+
// }
|
184
|
+
|
data/ext/ml4r/ml4r.cpp
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#include <boost/numeric/ublas/vector.hpp>
|
2
|
+
#include <boost/numeric/ublas/vector_proxy.hpp>
|
3
|
+
#include <boost/numeric/ublas/matrix.hpp>
|
4
|
+
#include <boost/numeric/ublas/triangular.hpp>
|
5
|
+
#include <boost/numeric/ublas/lu.hpp>
|
6
|
+
#include <boost/numeric/ublas/io.hpp>
|
7
|
+
namespace ublas = boost::numeric::ublas;
|
8
|
+
using ublas::matrix;
|
9
|
+
|
10
|
+
|
11
|
+
// #include <ruby.h>
|
12
|
+
//#include "LinearRegression/LinearRegression.h"
|
13
|
+
//#include "LinearRegression/ZenithRegression.h"
|
14
|
+
|
15
|
+
//VALUE rb_cRegression;
|
16
|
+
|
17
|
+
//void Init_ZenithRegression()
|
18
|
+
//{
|
19
|
+
// rb_cRegression = rb_define_class("ZenithRegression", rb_cObject);
|
20
|
+
// rb_define_singleton_method(rb_cRegression, "new", zenith_regression_New, -1);
|
21
|
+
// rb_define_method(rb_cRegression, "initialize", zenith_regression_Initialize, 0);
|
22
|
+
// rb_define_method(rb_cRegression, "observations=", zenith_regression_observations, 1);
|
23
|
+
// rb_define_method(rb_cRegression, "weights=", zenith_regression_weights, 1);
|
24
|
+
// rb_define_method(rb_cRegression, "setFixedConstant=", zenith_regression_setFixedConstant, 1);
|
25
|
+
// rb_define_method(rb_cRegression, "fittedYs", zenith_regression_getFittedYs, 0);
|
26
|
+
// rb_define_method(rb_cRegression, "predictedYs", zenith_regression_getPredictedYs, 0);
|
27
|
+
// rb_define_method(rb_cRegression, "regressionStatistics", zenith_regression_getRegressionStatistics, 0);
|
28
|
+
// rb_define_method(rb_cRegression, "execute", zenith_regression_execute, 0);
|
29
|
+
//}
|
30
|
+
|
31
|
+
/* ruby calls this to load the extension */
|
32
|
+
//extern "C" void Init_ml4r(void) {
|
33
|
+
// Init_ZenithRegression();
|
34
|
+
//}
|