opener-opinion-detector-basic 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/ext/hack/Rakefile +0 -2
- data/lib/opener/opinion_detector_basic/version.rb +1 -1
- data/opener-opinion-detector-basic.gemspec +0 -1
- data/task/compile.rake +1 -1
- data/task/requirements.rake +0 -1
- metadata +2 -142
- data/core/vendor/src/crfsuite/AUTHORS +0 -1
- data/core/vendor/src/crfsuite/COPYING +0 -27
- data/core/vendor/src/crfsuite/ChangeLog +0 -103
- data/core/vendor/src/crfsuite/INSTALL +0 -236
- data/core/vendor/src/crfsuite/Makefile.am +0 -19
- data/core/vendor/src/crfsuite/Makefile.in +0 -783
- data/core/vendor/src/crfsuite/README +0 -183
- data/core/vendor/src/crfsuite/aclocal.m4 +0 -9018
- data/core/vendor/src/crfsuite/autogen.sh +0 -38
- data/core/vendor/src/crfsuite/compile +0 -143
- data/core/vendor/src/crfsuite/config.guess +0 -1502
- data/core/vendor/src/crfsuite/config.h.in +0 -198
- data/core/vendor/src/crfsuite/config.sub +0 -1714
- data/core/vendor/src/crfsuite/configure +0 -14273
- data/core/vendor/src/crfsuite/configure.in +0 -149
- data/core/vendor/src/crfsuite/crfsuite.sln +0 -42
- data/core/vendor/src/crfsuite/depcomp +0 -630
- data/core/vendor/src/crfsuite/example/chunking.py +0 -49
- data/core/vendor/src/crfsuite/example/crfutils.py +0 -179
- data/core/vendor/src/crfsuite/example/ner.py +0 -270
- data/core/vendor/src/crfsuite/example/pos.py +0 -78
- data/core/vendor/src/crfsuite/example/template.py +0 -88
- data/core/vendor/src/crfsuite/frontend/Makefile.am +0 -29
- data/core/vendor/src/crfsuite/frontend/Makefile.in +0 -640
- data/core/vendor/src/crfsuite/frontend/dump.c +0 -116
- data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +0 -129
- data/core/vendor/src/crfsuite/frontend/iwa.c +0 -273
- data/core/vendor/src/crfsuite/frontend/iwa.h +0 -65
- data/core/vendor/src/crfsuite/frontend/learn.c +0 -439
- data/core/vendor/src/crfsuite/frontend/main.c +0 -137
- data/core/vendor/src/crfsuite/frontend/option.c +0 -93
- data/core/vendor/src/crfsuite/frontend/option.h +0 -86
- data/core/vendor/src/crfsuite/frontend/readdata.h +0 -38
- data/core/vendor/src/crfsuite/frontend/reader.c +0 -136
- data/core/vendor/src/crfsuite/frontend/tag.c +0 -427
- data/core/vendor/src/crfsuite/genbinary.sh.in +0 -15
- data/core/vendor/src/crfsuite/include/Makefile.am +0 -11
- data/core/vendor/src/crfsuite/include/Makefile.in +0 -461
- data/core/vendor/src/crfsuite/include/crfsuite.h +0 -1063
- data/core/vendor/src/crfsuite/include/crfsuite.hpp +0 -555
- data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +0 -400
- data/core/vendor/src/crfsuite/include/os.h +0 -61
- data/core/vendor/src/crfsuite/install-sh +0 -520
- data/core/vendor/src/crfsuite/lib/cqdb/COPYING +0 -28
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +0 -21
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +0 -549
- data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +0 -86
- data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +0 -524
- data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +0 -587
- data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +0 -976
- data/core/vendor/src/crfsuite/lib/crf/Makefile.am +0 -46
- data/core/vendor/src/crfsuite/lib/crf/Makefile.in +0 -721
- data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +0 -216
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +0 -353
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +0 -705
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +0 -943
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +0 -352
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +0 -994
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +0 -550
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +0 -492
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +0 -236
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +0 -272
- data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +0 -106
- data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +0 -118
- data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +0 -80
- data/core/vendor/src/crfsuite/lib/crf/src/logging.c +0 -91
- data/core/vendor/src/crfsuite/lib/crf/src/logging.h +0 -48
- data/core/vendor/src/crfsuite/lib/crf/src/params.c +0 -335
- data/core/vendor/src/crfsuite/lib/crf/src/params.h +0 -80
- data/core/vendor/src/crfsuite/lib/crf/src/quark.c +0 -172
- data/core/vendor/src/crfsuite/lib/crf/src/quark.h +0 -46
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +0 -1107
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +0 -160
- data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +0 -408
- data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +0 -242
- data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +0 -507
- data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +0 -338
- data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +0 -435
- data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +0 -341
- data/core/vendor/src/crfsuite/ltmain.sh +0 -8413
- data/core/vendor/src/crfsuite/missing +0 -376
- data/core/vendor/src/crfsuite/swig/Makefile.am +0 -13
- data/core/vendor/src/crfsuite/swig/Makefile.in +0 -365
- data/core/vendor/src/crfsuite/swig/crfsuite.cpp +0 -2
- data/core/vendor/src/crfsuite/swig/export.i +0 -32
- data/core/vendor/src/crfsuite/swig/python/README +0 -92
- data/core/vendor/src/crfsuite/swig/python/crfsuite.py +0 -329
- data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +0 -14355
- data/core/vendor/src/crfsuite/swig/python/export_wrap.h +0 -63
- data/core/vendor/src/crfsuite/swig/python/prepare.sh +0 -9
- data/core/vendor/src/crfsuite/swig/python/sample_tag.py +0 -52
- data/core/vendor/src/crfsuite/swig/python/sample_train.py +0 -68
- data/core/vendor/src/crfsuite/swig/python/setup.py +0 -44
- data/core/vendor/src/crfsuite/win32/stdint.h +0 -679
- data/core/vendor/src/liblbfgs/AUTHORS +0 -1
- data/core/vendor/src/liblbfgs/COPYING +0 -22
- data/core/vendor/src/liblbfgs/ChangeLog +0 -120
- data/core/vendor/src/liblbfgs/INSTALL +0 -231
- data/core/vendor/src/liblbfgs/Makefile.am +0 -10
- data/core/vendor/src/liblbfgs/Makefile.in +0 -638
- data/core/vendor/src/liblbfgs/NEWS +0 -0
- data/core/vendor/src/liblbfgs/README +0 -71
- data/core/vendor/src/liblbfgs/aclocal.m4 +0 -6985
- data/core/vendor/src/liblbfgs/autogen.sh +0 -38
- data/core/vendor/src/liblbfgs/config.guess +0 -1411
- data/core/vendor/src/liblbfgs/config.h.in +0 -64
- data/core/vendor/src/liblbfgs/config.sub +0 -1500
- data/core/vendor/src/liblbfgs/configure +0 -21146
- data/core/vendor/src/liblbfgs/configure.in +0 -107
- data/core/vendor/src/liblbfgs/depcomp +0 -522
- data/core/vendor/src/liblbfgs/include/lbfgs.h +0 -745
- data/core/vendor/src/liblbfgs/install-sh +0 -322
- data/core/vendor/src/liblbfgs/lbfgs.sln +0 -26
- data/core/vendor/src/liblbfgs/lib/Makefile.am +0 -24
- data/core/vendor/src/liblbfgs/lib/Makefile.in +0 -499
- data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +0 -133
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +0 -294
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +0 -298
- data/core/vendor/src/liblbfgs/lib/lbfgs.c +0 -1371
- data/core/vendor/src/liblbfgs/lib/lib.vcxproj +0 -95
- data/core/vendor/src/liblbfgs/ltmain.sh +0 -6426
- data/core/vendor/src/liblbfgs/missing +0 -353
- data/core/vendor/src/liblbfgs/sample/Makefile.am +0 -15
- data/core/vendor/src/liblbfgs/sample/Makefile.in +0 -433
- data/core/vendor/src/liblbfgs/sample/sample.c +0 -81
- data/core/vendor/src/liblbfgs/sample/sample.cpp +0 -126
- data/core/vendor/src/liblbfgs/sample/sample.vcxproj +0 -105
- data/core/vendor/src/svm_light/LICENSE.txt +0 -59
- data/core/vendor/src/svm_light/Makefile +0 -105
- data/core/vendor/src/svm_light/kernel.h +0 -40
- data/core/vendor/src/svm_light/svm_classify.c +0 -197
- data/core/vendor/src/svm_light/svm_common.c +0 -985
- data/core/vendor/src/svm_light/svm_common.h +0 -301
- data/core/vendor/src/svm_light/svm_hideo.c +0 -1062
- data/core/vendor/src/svm_light/svm_learn.c +0 -4147
- data/core/vendor/src/svm_light/svm_learn.h +0 -169
- data/core/vendor/src/svm_light/svm_learn_main.c +0 -397
- data/core/vendor/src/svm_light/svm_loqo.c +0 -211
- data/task/c.rake +0 -36
- data/task/submodules.rake +0 -5
@@ -1,338 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Batch training with L-BFGS.
|
3
|
-
*
|
4
|
-
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
-
* All rights reserved.
|
6
|
-
*
|
7
|
-
* Redistribution and use in source and binary forms, with or without
|
8
|
-
* modification, are permitted provided that the following conditions are met:
|
9
|
-
* * Redistributions of source code must retain the above copyright
|
10
|
-
* notice, this list of conditions and the following disclaimer.
|
11
|
-
* * Redistributions in binary form must reproduce the above copyright
|
12
|
-
* notice, this list of conditions and the following disclaimer in the
|
13
|
-
* documentation and/or other materials provided with the distribution.
|
14
|
-
* * Neither the names of the authors nor the names of its contributors
|
15
|
-
* may be used to endorse or promote products derived from this
|
16
|
-
* software without specific prior written permission.
|
17
|
-
*
|
18
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
-
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
-
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
-
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
-
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
30
|
-
|
31
|
-
/* $Id$ */
|
32
|
-
|
33
|
-
#ifdef HAVE_CONFIG_H
|
34
|
-
#include <config.h>
|
35
|
-
#endif/*HAVE_CONFIG_H*/
|
36
|
-
|
37
|
-
#include <os.h>
|
38
|
-
|
39
|
-
#include <stdio.h>
|
40
|
-
#include <stdlib.h>
|
41
|
-
#include <string.h>
|
42
|
-
#include <limits.h>
|
43
|
-
#include <time.h>
|
44
|
-
|
45
|
-
#include <crfsuite.h>
|
46
|
-
#include "crfsuite_internal.h"
|
47
|
-
|
48
|
-
#include "logging.h"
|
49
|
-
#include "params.h"
|
50
|
-
#include "vecmath.h"
|
51
|
-
#include <lbfgs.h>
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Training parameters (configurable with crfsuite_params_t interface).
|
55
|
-
*/
|
56
|
-
typedef struct {
|
57
|
-
floatval_t c1;
|
58
|
-
floatval_t c2;
|
59
|
-
int memory;
|
60
|
-
floatval_t epsilon;
|
61
|
-
int stop;
|
62
|
-
floatval_t delta;
|
63
|
-
int max_iterations;
|
64
|
-
char* linesearch;
|
65
|
-
int linesearch_max_iterations;
|
66
|
-
} training_option_t;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Internal data structure for the callback function of lbfgs().
|
70
|
-
*/
|
71
|
-
typedef struct {
|
72
|
-
encoder_t *gm;
|
73
|
-
dataset_t *trainset;
|
74
|
-
dataset_t *testset;
|
75
|
-
logging_t *lg;
|
76
|
-
floatval_t c2;
|
77
|
-
floatval_t* best_w;
|
78
|
-
clock_t begin;
|
79
|
-
} lbfgs_internal_t;
|
80
|
-
|
81
|
-
static lbfgsfloatval_t lbfgs_evaluate(
|
82
|
-
void *instance,
|
83
|
-
const lbfgsfloatval_t *x,
|
84
|
-
lbfgsfloatval_t *g,
|
85
|
-
const int n,
|
86
|
-
const lbfgsfloatval_t step
|
87
|
-
)
|
88
|
-
{
|
89
|
-
int i;
|
90
|
-
floatval_t f, norm = 0.;
|
91
|
-
lbfgs_internal_t *lbfgsi = (lbfgs_internal_t*)instance;
|
92
|
-
encoder_t *gm = lbfgsi->gm;
|
93
|
-
dataset_t *trainset = lbfgsi->trainset;
|
94
|
-
|
95
|
-
/* Compute the objective value and gradients. */
|
96
|
-
gm->objective_and_gradients_batch(gm, trainset, x, &f, g);
|
97
|
-
|
98
|
-
/* L2 regularization. */
|
99
|
-
if (0 < lbfgsi->c2) {
|
100
|
-
const floatval_t c22 = lbfgsi->c2 * 2.;
|
101
|
-
for (i = 0;i < n;++i) {
|
102
|
-
g[i] += (c22 * x[i]);
|
103
|
-
norm += x[i] * x[i];
|
104
|
-
}
|
105
|
-
f += (lbfgsi->c2 * norm);
|
106
|
-
}
|
107
|
-
|
108
|
-
return f;
|
109
|
-
}
|
110
|
-
|
111
|
-
static int lbfgs_progress(
|
112
|
-
void *instance,
|
113
|
-
const lbfgsfloatval_t *x,
|
114
|
-
const lbfgsfloatval_t *g,
|
115
|
-
const lbfgsfloatval_t fx,
|
116
|
-
const lbfgsfloatval_t xnorm,
|
117
|
-
const lbfgsfloatval_t gnorm,
|
118
|
-
const lbfgsfloatval_t step,
|
119
|
-
int n,
|
120
|
-
int k,
|
121
|
-
int ls)
|
122
|
-
{
|
123
|
-
int i, num_active_features = 0;
|
124
|
-
clock_t duration, clk = clock();
|
125
|
-
lbfgs_internal_t *lbfgsi = (lbfgs_internal_t*)instance;
|
126
|
-
dataset_t *testset = lbfgsi->testset;
|
127
|
-
encoder_t *gm = lbfgsi->gm;
|
128
|
-
logging_t *lg = lbfgsi->lg;
|
129
|
-
|
130
|
-
/* Compute the duration required for this iteration. */
|
131
|
-
duration = clk - lbfgsi->begin;
|
132
|
-
lbfgsi->begin = clk;
|
133
|
-
|
134
|
-
/* Store the feature weight in case L-BFGS terminates with an error. */
|
135
|
-
for (i = 0;i < n;++i) {
|
136
|
-
lbfgsi->best_w[i] = x[i];
|
137
|
-
if (x[i] != 0.) ++num_active_features;
|
138
|
-
}
|
139
|
-
|
140
|
-
/* Report the progress. */
|
141
|
-
logging(lg, "***** Iteration #%d *****\n", k);
|
142
|
-
logging(lg, "Loss: %f\n", fx);
|
143
|
-
logging(lg, "Feature norm: %f\n", xnorm);
|
144
|
-
logging(lg, "Error norm: %f\n", gnorm);
|
145
|
-
logging(lg, "Active features: %d\n", num_active_features);
|
146
|
-
logging(lg, "Line search trials: %d\n", ls);
|
147
|
-
logging(lg, "Line search step: %f\n", step);
|
148
|
-
logging(lg, "Seconds required for this iteration: %.3f\n", duration / (double)CLOCKS_PER_SEC);
|
149
|
-
|
150
|
-
/* Send the tagger with the current parameters. */
|
151
|
-
if (testset != NULL) {
|
152
|
-
holdout_evaluation(gm, testset, x, lg);
|
153
|
-
}
|
154
|
-
|
155
|
-
logging(lg, "\n");
|
156
|
-
|
157
|
-
/* Continue. */
|
158
|
-
return 0;
|
159
|
-
}
|
160
|
-
|
161
|
-
static int exchange_options(crfsuite_params_t* params, training_option_t* opt, int mode)
|
162
|
-
{
|
163
|
-
BEGIN_PARAM_MAP(params, mode)
|
164
|
-
DDX_PARAM_FLOAT(
|
165
|
-
"c1", opt->c1, 0,
|
166
|
-
"Coefficient for L1 regularization."
|
167
|
-
)
|
168
|
-
DDX_PARAM_FLOAT(
|
169
|
-
"c2", opt->c2, 1.0,
|
170
|
-
"Coefficient for L2 regularization."
|
171
|
-
)
|
172
|
-
DDX_PARAM_INT(
|
173
|
-
"max_iterations", opt->max_iterations, INT_MAX,
|
174
|
-
"The maximum number of iterations for L-BFGS optimization."
|
175
|
-
)
|
176
|
-
DDX_PARAM_INT(
|
177
|
-
"num_memories", opt->memory, 6,
|
178
|
-
"The number of limited memories for approximating the inverse hessian matrix."
|
179
|
-
)
|
180
|
-
DDX_PARAM_FLOAT(
|
181
|
-
"epsilon", opt->epsilon, 1e-5,
|
182
|
-
"Epsilon for testing the convergence of the objective."
|
183
|
-
)
|
184
|
-
DDX_PARAM_INT(
|
185
|
-
"period", opt->stop, 10,
|
186
|
-
"The duration of iterations to test the stopping criterion."
|
187
|
-
)
|
188
|
-
DDX_PARAM_FLOAT(
|
189
|
-
"delta", opt->delta, 1e-5,
|
190
|
-
"The threshold for the stopping criterion; an L-BFGS iteration stops when the\n"
|
191
|
-
"improvement of the log likelihood over the last ${period} iterations is no\n"
|
192
|
-
"greater than this threshold."
|
193
|
-
)
|
194
|
-
DDX_PARAM_STRING(
|
195
|
-
"linesearch", opt->linesearch, "MoreThuente",
|
196
|
-
"The line search algorithm used in L-BFGS updates:\n"
|
197
|
-
"{ 'MoreThuente': More and Thuente's method,\n"
|
198
|
-
" 'Backtracking': Backtracking method with regular Wolfe condition,\n"
|
199
|
-
" 'StrongBacktracking': Backtracking method with strong Wolfe condition\n"
|
200
|
-
"}\n"
|
201
|
-
)
|
202
|
-
DDX_PARAM_INT(
|
203
|
-
"max_linesearch", opt->linesearch_max_iterations, 20,
|
204
|
-
"The maximum number of trials for the line search algorithm."
|
205
|
-
)
|
206
|
-
END_PARAM_MAP()
|
207
|
-
|
208
|
-
return 0;
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
void crfsuite_train_lbfgs_init(crfsuite_params_t* params)
|
213
|
-
{
|
214
|
-
exchange_options(params, NULL, 0);
|
215
|
-
}
|
216
|
-
|
217
|
-
int crfsuite_train_lbfgs(
|
218
|
-
encoder_t *gm,
|
219
|
-
dataset_t *trainset,
|
220
|
-
dataset_t *testset,
|
221
|
-
crfsuite_params_t *params,
|
222
|
-
logging_t *lg,
|
223
|
-
floatval_t **ptr_w
|
224
|
-
)
|
225
|
-
{
|
226
|
-
int ret = 0, lbret;
|
227
|
-
floatval_t *w = NULL;
|
228
|
-
clock_t begin = clock();
|
229
|
-
const int N = trainset->num_instances;
|
230
|
-
const int L = trainset->data->labels->num(trainset->data->labels);
|
231
|
-
const int A = trainset->data->attrs->num(trainset->data->attrs);
|
232
|
-
const int K = gm->num_features;
|
233
|
-
lbfgs_internal_t lbfgsi;
|
234
|
-
lbfgs_parameter_t lbfgsparam;
|
235
|
-
training_option_t opt;
|
236
|
-
|
237
|
-
/* Initialize the variables. */
|
238
|
-
memset(&lbfgsi, 0, sizeof(lbfgsi));
|
239
|
-
memset(&opt, 0, sizeof(opt));
|
240
|
-
lbfgs_parameter_init(&lbfgsparam);
|
241
|
-
|
242
|
-
/* Allocate an array that stores the current weights. */
|
243
|
-
w = (floatval_t*)calloc(sizeof(floatval_t), K);
|
244
|
-
if (w == NULL) {
|
245
|
-
ret = CRFSUITEERR_OUTOFMEMORY;
|
246
|
-
goto error_exit;
|
247
|
-
}
|
248
|
-
|
249
|
-
/* Allocate an array that stores the best weights. */
|
250
|
-
lbfgsi.best_w = (floatval_t*)calloc(sizeof(floatval_t), K);
|
251
|
-
if (lbfgsi.best_w == NULL) {
|
252
|
-
ret = CRFSUITEERR_OUTOFMEMORY;
|
253
|
-
goto error_exit;
|
254
|
-
}
|
255
|
-
|
256
|
-
/* Read the L-BFGS parameters. */
|
257
|
-
exchange_options(params, &opt, -1);
|
258
|
-
logging(lg, "L-BFGS optimization\n");
|
259
|
-
logging(lg, "c1: %f\n", opt.c1);
|
260
|
-
logging(lg, "c2: %f\n", opt.c2);
|
261
|
-
logging(lg, "num_memories: %d\n", opt.memory);
|
262
|
-
logging(lg, "max_iterations: %d\n", opt.max_iterations);
|
263
|
-
logging(lg, "epsilon: %f\n", opt.epsilon);
|
264
|
-
logging(lg, "stop: %d\n", opt.stop);
|
265
|
-
logging(lg, "delta: %f\n", opt.delta);
|
266
|
-
logging(lg, "linesearch: %s\n", opt.linesearch);
|
267
|
-
logging(lg, "linesearch.max_iterations: %d\n", opt.linesearch_max_iterations);
|
268
|
-
logging(lg, "\n");
|
269
|
-
|
270
|
-
/* Set parameters for L-BFGS. */
|
271
|
-
lbfgsparam.m = opt.memory;
|
272
|
-
lbfgsparam.epsilon = opt.epsilon;
|
273
|
-
lbfgsparam.past = opt.stop;
|
274
|
-
lbfgsparam.delta = opt.delta;
|
275
|
-
lbfgsparam.max_iterations = opt.max_iterations;
|
276
|
-
if (strcmp(opt.linesearch, "Backtracking") == 0) {
|
277
|
-
lbfgsparam.linesearch = LBFGS_LINESEARCH_BACKTRACKING;
|
278
|
-
} else if (strcmp(opt.linesearch, "StrongBacktracking") == 0) {
|
279
|
-
lbfgsparam.linesearch = LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE;
|
280
|
-
} else {
|
281
|
-
lbfgsparam.linesearch = LBFGS_LINESEARCH_MORETHUENTE;
|
282
|
-
}
|
283
|
-
lbfgsparam.max_linesearch = opt.linesearch_max_iterations;
|
284
|
-
|
285
|
-
/* Set regularization parameters. */
|
286
|
-
if (0 < opt.c1) {
|
287
|
-
lbfgsparam.orthantwise_c = opt.c1;
|
288
|
-
lbfgsparam.linesearch = LBFGS_LINESEARCH_BACKTRACKING;
|
289
|
-
} else {
|
290
|
-
lbfgsparam.orthantwise_c = 0;
|
291
|
-
}
|
292
|
-
|
293
|
-
/* Set other callback data. */
|
294
|
-
lbfgsi.gm = gm;
|
295
|
-
lbfgsi.trainset = trainset;
|
296
|
-
lbfgsi.testset = testset;
|
297
|
-
lbfgsi.c2 = opt.c2;
|
298
|
-
lbfgsi.lg = lg;
|
299
|
-
|
300
|
-
/* Call the L-BFGS solver. */
|
301
|
-
lbfgsi.begin = clock();
|
302
|
-
lbret = lbfgs(
|
303
|
-
K,
|
304
|
-
w,
|
305
|
-
NULL,
|
306
|
-
lbfgs_evaluate,
|
307
|
-
lbfgs_progress,
|
308
|
-
&lbfgsi,
|
309
|
-
&lbfgsparam
|
310
|
-
);
|
311
|
-
if (lbret == LBFGS_CONVERGENCE) {
|
312
|
-
logging(lg, "L-BFGS resulted in convergence\n");
|
313
|
-
} else if (lbret == LBFGS_STOP) {
|
314
|
-
logging(lg, "L-BFGS terminated with the stopping criteria\n");
|
315
|
-
} else if (lbret == LBFGSERR_MAXIMUMITERATION) {
|
316
|
-
logging(lg, "L-BFGS terminated with the maximum number of iterations\n");
|
317
|
-
} else {
|
318
|
-
logging(lg, "L-BFGS terminated with error code (%d)\n", lbret);
|
319
|
-
}
|
320
|
-
|
321
|
-
/* Restore the feature weights of the last call of lbfgs_progress(). */
|
322
|
-
veccopy(w, lbfgsi.best_w, K);
|
323
|
-
|
324
|
-
/* Report the run-time for the training. */
|
325
|
-
logging(lg, "Total seconds required for training: %.3f\n", (clock() - begin) / (double)CLOCKS_PER_SEC);
|
326
|
-
logging(lg, "\n");
|
327
|
-
|
328
|
-
/* Exit with success. */
|
329
|
-
free(lbfgsi.best_w);
|
330
|
-
*ptr_w = w;
|
331
|
-
return 0;
|
332
|
-
|
333
|
-
error_exit:
|
334
|
-
free(lbfgsi.best_w);
|
335
|
-
free(w);
|
336
|
-
*ptr_w = NULL;
|
337
|
-
return ret;
|
338
|
-
}
|