chaine 3.13.1__cp312-cp312-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chaine might be problematic. Click here for more details.
- chaine/__init__.py +2 -0
- chaine/_core/crf.cpp +19854 -0
- chaine/_core/crf.cpython-312-x86_64-linux-musl.so +0 -0
- chaine/_core/crf.pyx +271 -0
- chaine/_core/crfsuite/COPYING +27 -0
- chaine/_core/crfsuite/README +183 -0
- chaine/_core/crfsuite/include/crfsuite.h +1077 -0
- chaine/_core/crfsuite/include/crfsuite.hpp +649 -0
- chaine/_core/crfsuite/include/crfsuite_api.hpp +406 -0
- chaine/_core/crfsuite/include/os.h +65 -0
- chaine/_core/crfsuite/lib/cqdb/COPYING +28 -0
- chaine/_core/crfsuite/lib/cqdb/include/cqdb.h +518 -0
- chaine/_core/crfsuite/lib/cqdb/src/cqdb.c +639 -0
- chaine/_core/crfsuite/lib/cqdb/src/lookup3.c +1271 -0
- chaine/_core/crfsuite/lib/cqdb/src/main.c +184 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d.h +354 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_context.c +788 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_encode.c +1020 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_feature.c +382 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_model.c +1085 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_tag.c +582 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite.c +500 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite_internal.h +233 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite_train.c +302 -0
- chaine/_core/crfsuite/lib/crf/src/dataset.c +115 -0
- chaine/_core/crfsuite/lib/crf/src/dictionary.c +127 -0
- chaine/_core/crfsuite/lib/crf/src/holdout.c +83 -0
- chaine/_core/crfsuite/lib/crf/src/json.c +1497 -0
- chaine/_core/crfsuite/lib/crf/src/json.h +120 -0
- chaine/_core/crfsuite/lib/crf/src/logging.c +85 -0
- chaine/_core/crfsuite/lib/crf/src/logging.h +49 -0
- chaine/_core/crfsuite/lib/crf/src/params.c +370 -0
- chaine/_core/crfsuite/lib/crf/src/params.h +84 -0
- chaine/_core/crfsuite/lib/crf/src/quark.c +180 -0
- chaine/_core/crfsuite/lib/crf/src/quark.h +46 -0
- chaine/_core/crfsuite/lib/crf/src/rumavl.c +1178 -0
- chaine/_core/crfsuite/lib/crf/src/rumavl.h +144 -0
- chaine/_core/crfsuite/lib/crf/src/train_arow.c +409 -0
- chaine/_core/crfsuite/lib/crf/src/train_averaged_perceptron.c +237 -0
- chaine/_core/crfsuite/lib/crf/src/train_l2sgd.c +491 -0
- chaine/_core/crfsuite/lib/crf/src/train_lbfgs.c +323 -0
- chaine/_core/crfsuite/lib/crf/src/train_passive_aggressive.c +442 -0
- chaine/_core/crfsuite/lib/crf/src/vecmath.h +360 -0
- chaine/_core/crfsuite/swig/crfsuite.cpp +1 -0
- chaine/_core/crfsuite_api.pxd +67 -0
- chaine/_core/liblbfgs/COPYING +22 -0
- chaine/_core/liblbfgs/README +71 -0
- chaine/_core/liblbfgs/include/lbfgs.h +745 -0
- chaine/_core/liblbfgs/lib/arithmetic_ansi.h +142 -0
- chaine/_core/liblbfgs/lib/arithmetic_sse_double.h +303 -0
- chaine/_core/liblbfgs/lib/arithmetic_sse_float.h +312 -0
- chaine/_core/liblbfgs/lib/lbfgs.c +1531 -0
- chaine/_core/tagger_wrapper.hpp +58 -0
- chaine/_core/trainer_wrapper.cpp +32 -0
- chaine/_core/trainer_wrapper.hpp +26 -0
- chaine/crf.py +505 -0
- chaine/logging.py +214 -0
- chaine/optimization/__init__.py +10 -0
- chaine/optimization/metrics.py +129 -0
- chaine/optimization/spaces.py +394 -0
- chaine/optimization/trial.py +103 -0
- chaine/optimization/utils.py +119 -0
- chaine/training.py +184 -0
- chaine/typing.py +18 -0
- chaine/validation.py +43 -0
- chaine-3.13.1.dist-info/METADATA +348 -0
- chaine-3.13.1.dist-info/RECORD +70 -0
- chaine-3.13.1.dist-info/WHEEL +4 -0
- chaine.libs/libgcc_s-a0b57c20.so.1 +0 -0
- chaine.libs/libstdc++-0d31ccbe.so.6.0.32 +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Mathematical operations for vectors.
|
|
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
|
+
#ifndef __VECMATH_H__
|
|
34
|
+
#define __VECMATH_H__
|
|
35
|
+
|
|
36
|
+
#include <math.h>
|
|
37
|
+
#include <memory.h>
|
|
38
|
+
|
|
39
|
+
#ifdef USE_SSE
|
|
40
|
+
#include <emmintrin.h>
|
|
41
|
+
#endif /*USE_SSE*/
|
|
42
|
+
|
|
43
|
+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
|
|
44
|
+
#include <malloc.h>
|
|
45
|
+
#else
|
|
46
|
+
#include <stdlib.h>
|
|
47
|
+
static inline void *_aligned_malloc(size_t size, size_t alignment)
|
|
48
|
+
{
|
|
49
|
+
void *p;
|
|
50
|
+
int ret = posix_memalign(&p, alignment, size);
|
|
51
|
+
return (ret == 0) ? p : 0;
|
|
52
|
+
}
|
|
53
|
+
static inline void _aligned_free(void *p)
|
|
54
|
+
{
|
|
55
|
+
free(p);
|
|
56
|
+
}
|
|
57
|
+
#endif
|
|
58
|
+
|
|
59
|
+
#ifdef _MSC_VER
|
|
60
|
+
#define MIE_ALIGN(x) __declspec(align(x))
|
|
61
|
+
#else
|
|
62
|
+
#define MIE_ALIGN(x) __attribute__((aligned(x)))
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
#define CONST_128D(var, val) \
|
|
66
|
+
MIE_ALIGN(16) \
|
|
67
|
+
static const double var[2] = {(val), (val)}
|
|
68
|
+
|
|
69
|
+
inline static void veczero(floatval_t *x, const int n)
|
|
70
|
+
{
|
|
71
|
+
if (n)
|
|
72
|
+
{
|
|
73
|
+
memset(x, 0, sizeof(floatval_t) * n);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
inline static void vecset(floatval_t *x, const floatval_t a, const int n)
|
|
78
|
+
{
|
|
79
|
+
int i;
|
|
80
|
+
for (i = 0; i < n; ++i)
|
|
81
|
+
{
|
|
82
|
+
x[i] = a;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
inline static void veccopy(floatval_t *y, const floatval_t *x, const int n)
|
|
87
|
+
{
|
|
88
|
+
if (n)
|
|
89
|
+
{
|
|
90
|
+
memcpy(y, x, sizeof(floatval_t) * n);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
inline static void vecadd(floatval_t *y, const floatval_t *x, const int n)
|
|
95
|
+
{
|
|
96
|
+
int i;
|
|
97
|
+
for (i = 0; i < n; ++i)
|
|
98
|
+
{
|
|
99
|
+
y[i] += x[i];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
inline static void vecaadd(floatval_t *y, const floatval_t a, const floatval_t *x, const int n)
|
|
104
|
+
{
|
|
105
|
+
int i;
|
|
106
|
+
for (i = 0; i < n; ++i)
|
|
107
|
+
{
|
|
108
|
+
y[i] += a * x[i];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
inline static void vecsub(floatval_t *y, const floatval_t *x, const int n)
|
|
113
|
+
{
|
|
114
|
+
int i;
|
|
115
|
+
for (i = 0; i < n; ++i)
|
|
116
|
+
{
|
|
117
|
+
y[i] -= x[i];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
inline static void vecasub(floatval_t *y, const floatval_t a, const floatval_t *x, const int n)
|
|
122
|
+
{
|
|
123
|
+
int i;
|
|
124
|
+
for (i = 0; i < n; ++i)
|
|
125
|
+
{
|
|
126
|
+
y[i] -= a * x[i];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
inline static void vecmul(floatval_t *y, const floatval_t *x, const int n)
|
|
131
|
+
{
|
|
132
|
+
int i;
|
|
133
|
+
for (i = 0; i < n; ++i)
|
|
134
|
+
{
|
|
135
|
+
y[i] *= x[i];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
inline static void vecinv(floatval_t *y, const int n)
|
|
140
|
+
{
|
|
141
|
+
int i;
|
|
142
|
+
for (i = 0; i < n; ++i)
|
|
143
|
+
{
|
|
144
|
+
y[i] = 1. / y[i];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
inline static void vecscale(floatval_t *y, const floatval_t a, const int n)
|
|
149
|
+
{
|
|
150
|
+
int i;
|
|
151
|
+
for (i = 0; i < n; ++i)
|
|
152
|
+
{
|
|
153
|
+
y[i] *= a;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
inline static floatval_t vecdot(const floatval_t *x, const floatval_t *y, const int n)
|
|
158
|
+
{
|
|
159
|
+
int i;
|
|
160
|
+
floatval_t s = 0;
|
|
161
|
+
for (i = 0; i < n; ++i)
|
|
162
|
+
{
|
|
163
|
+
s += x[i] * y[i];
|
|
164
|
+
}
|
|
165
|
+
return s;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
inline static floatval_t vecsum(floatval_t *x, const int n)
|
|
169
|
+
{
|
|
170
|
+
int i;
|
|
171
|
+
floatval_t s = 0.;
|
|
172
|
+
|
|
173
|
+
for (i = 0; i < n; ++i)
|
|
174
|
+
{
|
|
175
|
+
s += x[i];
|
|
176
|
+
}
|
|
177
|
+
return s;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
inline static floatval_t vecsumlog(floatval_t *x, const int n)
|
|
181
|
+
{
|
|
182
|
+
int i;
|
|
183
|
+
floatval_t s = 0.;
|
|
184
|
+
for (i = 0; i < n; ++i)
|
|
185
|
+
{
|
|
186
|
+
s += log(x[i]);
|
|
187
|
+
}
|
|
188
|
+
return s;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#ifdef USE_SSE
|
|
192
|
+
|
|
193
|
+
inline static void vecexp(double *values, const int n)
|
|
194
|
+
{
|
|
195
|
+
int i;
|
|
196
|
+
CONST_128D(one, 1.);
|
|
197
|
+
CONST_128D(log2e, 1.4426950408889634073599);
|
|
198
|
+
CONST_128D(maxlog, 7.09782712893383996843e2); // log(2**1024)
|
|
199
|
+
CONST_128D(minlog, -7.08396418532264106224e2); // log(2**-1022)
|
|
200
|
+
CONST_128D(c1, 6.93145751953125E-1);
|
|
201
|
+
CONST_128D(c2, 1.42860682030941723212E-6);
|
|
202
|
+
CONST_128D(w11, 3.5524625185478232665958141148891055719216674475023e-8);
|
|
203
|
+
CONST_128D(w10, 2.5535368519306500343384723775435166753084614063349e-7);
|
|
204
|
+
CONST_128D(w9, 2.77750562801295315877005242757916081614772210463065e-6);
|
|
205
|
+
CONST_128D(w8, 2.47868893393199945541176652007657202642495832996107e-5);
|
|
206
|
+
CONST_128D(w7, 1.98419213985637881240770890090795533564573406893163e-4);
|
|
207
|
+
CONST_128D(w6, 1.3888869684178659239014256260881685824525255547326e-3);
|
|
208
|
+
CONST_128D(w5, 8.3333337052009872221152811550156335074160546333973e-3);
|
|
209
|
+
CONST_128D(w4, 4.1666666621080810610346717440523105184720007971655e-2);
|
|
210
|
+
CONST_128D(w3, 0.166666666669960803484477734308515404418108830469798);
|
|
211
|
+
CONST_128D(w2, 0.499999999999877094481580370323249951329122224389189);
|
|
212
|
+
CONST_128D(w1, 1.0000000000000017952745258419615282194236357388884);
|
|
213
|
+
CONST_128D(w0, 0.99999999999999999566016490920259318691496540598896);
|
|
214
|
+
const __m128i offset = _mm_setr_epi32(1023, 1023, 0, 0);
|
|
215
|
+
|
|
216
|
+
for (i = 0; i < n; i += 4)
|
|
217
|
+
{
|
|
218
|
+
__m128i k1, k2;
|
|
219
|
+
__m128d p1, p2;
|
|
220
|
+
__m128d a1, a2;
|
|
221
|
+
__m128d xmm0, xmm1;
|
|
222
|
+
__m128d x1, x2;
|
|
223
|
+
|
|
224
|
+
/* Load four double values. */
|
|
225
|
+
xmm0 = _mm_load_pd(maxlog);
|
|
226
|
+
xmm1 = _mm_load_pd(minlog);
|
|
227
|
+
x1 = _mm_load_pd(values + i);
|
|
228
|
+
x2 = _mm_load_pd(values + i + 2);
|
|
229
|
+
x1 = _mm_min_pd(x1, xmm0);
|
|
230
|
+
x2 = _mm_min_pd(x2, xmm0);
|
|
231
|
+
x1 = _mm_max_pd(x1, xmm1);
|
|
232
|
+
x2 = _mm_max_pd(x2, xmm1);
|
|
233
|
+
|
|
234
|
+
/* a = x / log2; */
|
|
235
|
+
xmm0 = _mm_load_pd(log2e);
|
|
236
|
+
xmm1 = _mm_setzero_pd();
|
|
237
|
+
a1 = _mm_mul_pd(x1, xmm0);
|
|
238
|
+
a2 = _mm_mul_pd(x2, xmm0);
|
|
239
|
+
|
|
240
|
+
/* k = (int)floor(a); p = (float)k; */
|
|
241
|
+
p1 = _mm_cmplt_pd(a1, xmm1);
|
|
242
|
+
p2 = _mm_cmplt_pd(a2, xmm1);
|
|
243
|
+
xmm0 = _mm_load_pd(one);
|
|
244
|
+
p1 = _mm_and_pd(p1, xmm0);
|
|
245
|
+
p2 = _mm_and_pd(p2, xmm0);
|
|
246
|
+
a1 = _mm_sub_pd(a1, p1);
|
|
247
|
+
a2 = _mm_sub_pd(a2, p2);
|
|
248
|
+
k1 = _mm_cvttpd_epi32(a1);
|
|
249
|
+
k2 = _mm_cvttpd_epi32(a2);
|
|
250
|
+
p1 = _mm_cvtepi32_pd(k1);
|
|
251
|
+
p2 = _mm_cvtepi32_pd(k2);
|
|
252
|
+
|
|
253
|
+
/* x -= p * log2; */
|
|
254
|
+
xmm0 = _mm_load_pd(c1);
|
|
255
|
+
xmm1 = _mm_load_pd(c2);
|
|
256
|
+
a1 = _mm_mul_pd(p1, xmm0);
|
|
257
|
+
a2 = _mm_mul_pd(p2, xmm0);
|
|
258
|
+
x1 = _mm_sub_pd(x1, a1);
|
|
259
|
+
x2 = _mm_sub_pd(x2, a2);
|
|
260
|
+
a1 = _mm_mul_pd(p1, xmm1);
|
|
261
|
+
a2 = _mm_mul_pd(p2, xmm1);
|
|
262
|
+
x1 = _mm_sub_pd(x1, a1);
|
|
263
|
+
x2 = _mm_sub_pd(x2, a2);
|
|
264
|
+
|
|
265
|
+
xmm0 = _mm_load_pd(w11);
|
|
266
|
+
xmm1 = _mm_load_pd(w10);
|
|
267
|
+
a1 = _mm_mul_pd(x1, xmm0);
|
|
268
|
+
a2 = _mm_mul_pd(x2, xmm0);
|
|
269
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
270
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
271
|
+
|
|
272
|
+
xmm0 = _mm_load_pd(w9);
|
|
273
|
+
xmm1 = _mm_load_pd(w8);
|
|
274
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
275
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
276
|
+
a1 = _mm_add_pd(a1, xmm0);
|
|
277
|
+
a2 = _mm_add_pd(a2, xmm0);
|
|
278
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
279
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
280
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
281
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
282
|
+
|
|
283
|
+
xmm0 = _mm_load_pd(w7);
|
|
284
|
+
xmm1 = _mm_load_pd(w6);
|
|
285
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
286
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
287
|
+
a1 = _mm_add_pd(a1, xmm0);
|
|
288
|
+
a2 = _mm_add_pd(a2, xmm0);
|
|
289
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
290
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
291
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
292
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
293
|
+
|
|
294
|
+
xmm0 = _mm_load_pd(w5);
|
|
295
|
+
xmm1 = _mm_load_pd(w4);
|
|
296
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
297
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
298
|
+
a1 = _mm_add_pd(a1, xmm0);
|
|
299
|
+
a2 = _mm_add_pd(a2, xmm0);
|
|
300
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
301
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
302
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
303
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
304
|
+
|
|
305
|
+
xmm0 = _mm_load_pd(w3);
|
|
306
|
+
xmm1 = _mm_load_pd(w2);
|
|
307
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
308
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
309
|
+
a1 = _mm_add_pd(a1, xmm0);
|
|
310
|
+
a2 = _mm_add_pd(a2, xmm0);
|
|
311
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
312
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
313
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
314
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
315
|
+
|
|
316
|
+
xmm0 = _mm_load_pd(w1);
|
|
317
|
+
xmm1 = _mm_load_pd(w0);
|
|
318
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
319
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
320
|
+
a1 = _mm_add_pd(a1, xmm0);
|
|
321
|
+
a2 = _mm_add_pd(a2, xmm0);
|
|
322
|
+
a1 = _mm_mul_pd(a1, x1);
|
|
323
|
+
a2 = _mm_mul_pd(a2, x2);
|
|
324
|
+
a1 = _mm_add_pd(a1, xmm1);
|
|
325
|
+
a2 = _mm_add_pd(a2, xmm1);
|
|
326
|
+
|
|
327
|
+
/* p = 2^k; */
|
|
328
|
+
k1 = _mm_add_epi32(k1, offset);
|
|
329
|
+
k2 = _mm_add_epi32(k2, offset);
|
|
330
|
+
k1 = _mm_slli_epi32(k1, 20);
|
|
331
|
+
k2 = _mm_slli_epi32(k2, 20);
|
|
332
|
+
k1 = _mm_shuffle_epi32(k1, 0x72);
|
|
333
|
+
k2 = _mm_shuffle_epi32(k2, 0x72);
|
|
334
|
+
p1 = _mm_castsi128_pd(k1);
|
|
335
|
+
p2 = _mm_castsi128_pd(k2);
|
|
336
|
+
|
|
337
|
+
/* a *= 2^k. */
|
|
338
|
+
a1 = _mm_mul_pd(a1, p1);
|
|
339
|
+
a2 = _mm_mul_pd(a2, p2);
|
|
340
|
+
|
|
341
|
+
/* Store the results. */
|
|
342
|
+
_mm_store_pd(values + i, a1);
|
|
343
|
+
_mm_store_pd(values + i + 2, a2);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
#else
|
|
348
|
+
|
|
349
|
+
inline static void vecexp(double *values, const int n)
|
|
350
|
+
{
|
|
351
|
+
int i;
|
|
352
|
+
for (i = 0; i < n; ++i)
|
|
353
|
+
{
|
|
354
|
+
values[i] = exp(values[i]);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
#endif /*USE_SSE*/
|
|
359
|
+
|
|
360
|
+
#endif /*__VECMATH_H__*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include <crfsuite.hpp>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from libcpp.string cimport string
|
|
2
|
+
from libcpp.vector cimport vector
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
cdef extern from "crfsuite/include/crfsuite.h":
|
|
6
|
+
ctypedef enum:
|
|
7
|
+
CRFSUITE_SUCCESS
|
|
8
|
+
CRFSUITEERR_UNKNOWN
|
|
9
|
+
CRFSUITEERR_OUTOFMEMORY
|
|
10
|
+
CRFSUITEERR_NOTSUPPORTED
|
|
11
|
+
CRFSUITEERR_INCOMPATIBLE
|
|
12
|
+
CRFSUITEERR_INTERNAL_LOGIC
|
|
13
|
+
CRFSUITEERR_OVERFLOW
|
|
14
|
+
CRFSUITEERR_NOTIMPLEMENTED
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
cdef extern from "crfsuite/include/crfsuite_api.hpp" namespace "CRFSuite":
|
|
18
|
+
cdef cppclass Attribute:
|
|
19
|
+
string attr
|
|
20
|
+
double value
|
|
21
|
+
|
|
22
|
+
Attribute()
|
|
23
|
+
Attribute(string)
|
|
24
|
+
Attribute(string, double)
|
|
25
|
+
|
|
26
|
+
ctypedef vector[Attribute] Item
|
|
27
|
+
ctypedef vector[Item] ItemSequence
|
|
28
|
+
ctypedef vector[string] StringList
|
|
29
|
+
|
|
30
|
+
cdef string version()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
cdef extern from "trainer_wrapper.hpp" namespace "CRFSuiteWrapper":
|
|
34
|
+
|
|
35
|
+
ctypedef object (*messagefunc)(object self, string message)
|
|
36
|
+
|
|
37
|
+
cdef cppclass Trainer:
|
|
38
|
+
Trainer() except +
|
|
39
|
+
void set_handler(object, messagefunc) except +
|
|
40
|
+
void clear() except +
|
|
41
|
+
void append(ItemSequence, StringList, int) except +
|
|
42
|
+
bint select(string, string) except +
|
|
43
|
+
int train(string, int) except +
|
|
44
|
+
StringList params() except +
|
|
45
|
+
void set(string, string) except +
|
|
46
|
+
string get(string) except +
|
|
47
|
+
string help(string) except +
|
|
48
|
+
void _init_trainer() except +
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
cdef extern from "tagger_wrapper.hpp" namespace "CRFSuiteWrapper":
|
|
52
|
+
|
|
53
|
+
ctypedef object (*messagefunc)(object self, string message)
|
|
54
|
+
|
|
55
|
+
cdef cppclass Tagger:
|
|
56
|
+
Tagger() except +
|
|
57
|
+
int open(string) except +
|
|
58
|
+
int open(const void*, size_t) except +
|
|
59
|
+
void close() except +
|
|
60
|
+
StringList labels() except +
|
|
61
|
+
StringList tag(ItemSequence) except +
|
|
62
|
+
void set(ItemSequence) except +
|
|
63
|
+
StringList viterbi() except +
|
|
64
|
+
double probability(StringList) except +
|
|
65
|
+
double marginal(string, int) except +
|
|
66
|
+
void dump_transitions(int) except +
|
|
67
|
+
void dump_states(int) except +
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 1990 Jorge Nocedal
|
|
4
|
+
Copyright (c) 2007-2010 Naoaki Okazaki
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
7
|
+
copy of this software and associated documentation files (the "Software"),
|
|
8
|
+
to deal in the Software without restriction, including without limitation
|
|
9
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
10
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
libLBFGS: C library of limited-memory BFGS (L-BFGS)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 1990, Jorge Nocedal
|
|
5
|
+
Copyright (c) 2007-2010, Naoaki Okazaki
|
|
6
|
+
|
|
7
|
+
=========================================================================
|
|
8
|
+
1. Introduction
|
|
9
|
+
=========================================================================
|
|
10
|
+
libLBFGS is a C port of the implementation of Limited-memory
|
|
11
|
+
Broyden-Fletcher-Goldfarb-Shanno (L-BFGS) method written by Jorge Nocedal.
|
|
12
|
+
The original FORTRAN source code is available at:
|
|
13
|
+
http://www.ece.northwestern.edu/~nocedal/lbfgs.html
|
|
14
|
+
|
|
15
|
+
The L-BFGS method solves the unconstrainted minimization problem:
|
|
16
|
+
minimize F(x), x = (x1, x2, ..., xN),
|
|
17
|
+
only if the objective function F(x) and its gradient G(x) are computable.
|
|
18
|
+
|
|
19
|
+
Refer to the libLBFGS web site for more information.
|
|
20
|
+
http://www.chokkan.org/software/liblbfgs/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
=========================================================================
|
|
25
|
+
2. How to build
|
|
26
|
+
=========================================================================
|
|
27
|
+
[Microsoft Visual Studio 2008]
|
|
28
|
+
Open the solution file "lbfgs.sln" and build it.
|
|
29
|
+
|
|
30
|
+
[GCC]
|
|
31
|
+
$ ./configure
|
|
32
|
+
$ make
|
|
33
|
+
$ make install # To install libLBFGS library and header.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
=========================================================================
|
|
38
|
+
3. Note on SSE/SSE2 optimization
|
|
39
|
+
=========================================================================
|
|
40
|
+
This library has SSE/SSE2 optimization routines for vector arithmetic
|
|
41
|
+
operations on Intel/AMD processors. The SSE2 routine is for 64 bit double
|
|
42
|
+
values, and the SSE routine is for 32 bit float values. Since the default
|
|
43
|
+
parameters in libLBFGS are tuned for double precision values, it may need
|
|
44
|
+
to modify these parameters to use the SSE optimization routines.
|
|
45
|
+
|
|
46
|
+
To use the SSE2 optimization routine, specify --enable-sse2 option to the
|
|
47
|
+
configure script.
|
|
48
|
+
|
|
49
|
+
$ ./configure --enable-sse2
|
|
50
|
+
|
|
51
|
+
To build libLBFGS with SSE2 optimization enabled on Microsoft Visual
|
|
52
|
+
Studio 2005, define USE_SSE and __SSE2__ symbols.
|
|
53
|
+
|
|
54
|
+
Make sure to run libLBFGS on processors where SSE2 instrunctions are
|
|
55
|
+
available. The library does not check the existence of SSE2 instructions.
|
|
56
|
+
|
|
57
|
+
To package maintainers,
|
|
58
|
+
|
|
59
|
+
Please do not enable SSE/SSE2 optimization routine. The library built
|
|
60
|
+
with SSE/SSE2 optimization will crash without any notice when necessary
|
|
61
|
+
SSE/SSE2 instructions are unavailable on CPUs.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
=========================================================================
|
|
66
|
+
4. License
|
|
67
|
+
=========================================================================
|
|
68
|
+
libLBFGS is distributed under the term of the MIT license.
|
|
69
|
+
Please refer to COPYING file in the distribution.
|
|
70
|
+
|
|
71
|
+
$Id$
|