khiva 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +404 -14
- data/lib/khiva.rb +8 -3
- data/lib/khiva/array.rb +1 -0
- data/lib/khiva/clustering.rb +19 -0
- data/lib/khiva/dimensionality.rb +11 -0
- data/lib/khiva/features.rb +173 -0
- data/lib/khiva/ffi.rb +105 -0
- data/lib/khiva/library.rb +35 -0
- data/lib/khiva/linalg.rb +11 -0
- data/lib/khiva/matrix.rb +29 -0
- data/lib/khiva/polynomial.rb +11 -0
- data/lib/khiva/regression.rb +15 -0
- data/lib/khiva/regularization.rb +11 -0
- data/lib/khiva/statistics.rb +42 -0
- data/lib/khiva/utils.rb +9 -1
- data/lib/khiva/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7e270535ccb0436961b438ccf0d6effd1976933e1c5a2f98920d207816d6c21
|
4
|
+
data.tar.gz: 8fa258b1c954a3cdd5ad02c0b1da57f6d175fc844e0fdabe2ae82f902a18d431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54ff69b81b37c7e206a46babc733ed1987e16ae84dd40a19eae0fb688b08e245a8df1b212debc5342f1e7da1a934aa972b8a936faf58b1300aa3cdecb519a70
|
7
|
+
data.tar.gz: aac9b7764789f171d5f7b33834148117a7423b2182303b4d45bd1307d9a57c187fa492499810692846f25b6f13e20f3243b8cba4b28c82a0faa4b3ce949fb478
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
[Khiva](https://github.com/shapelets/khiva) - high-performance time series algorithms - for Ruby
|
4
4
|
|
5
|
+
:fire: Runs on GPUs and CPUs
|
6
|
+
|
5
7
|
[![Build Status](https://github.com/ankane/khiva-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/khiva-ruby/actions)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
9
|
-
First, [install Khiva](#khiva-installation). For Homebrew use:
|
11
|
+
First, [install Khiva](#khiva-installation). For Homebrew, use:
|
10
12
|
|
11
13
|
```sh
|
12
14
|
brew install khiva
|
@@ -31,10 +33,32 @@ profile, index = Khiva::Matrix.stomp(a, b, 3)
|
|
31
33
|
Find discords
|
32
34
|
|
33
35
|
```ruby
|
34
|
-
|
36
|
+
distances, indices, subsequences = Khiva::Matrix.find_best_n_discords(profile, index, 2, 2)
|
37
|
+
```
|
38
|
+
|
39
|
+
Find motifs
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
distances, indices, subsequences = Khiva::Matrix.find_best_n_motifs(profile, index, 2, 2)
|
35
43
|
```
|
36
44
|
|
37
|
-
##
|
45
|
+
## Modules
|
46
|
+
|
47
|
+
- [Array](#array)
|
48
|
+
- [Clustering](#clustering)
|
49
|
+
- [Dimensionality](#dimensionality)
|
50
|
+
- [Distances](#distances)
|
51
|
+
- [Features](#features)
|
52
|
+
- [Library](#library)
|
53
|
+
- [Linalg](#linalg)
|
54
|
+
- [Matrix](#matrix)
|
55
|
+
- [Normalization](#normalization)
|
56
|
+
- [Polynomial](#polynomial)
|
57
|
+
- [Regression](#regression)
|
58
|
+
- [Regularization](#regularization)
|
59
|
+
- [Statistics](#statistics)
|
60
|
+
|
61
|
+
## Array
|
38
62
|
|
39
63
|
Create an array from a Ruby array
|
40
64
|
|
@@ -42,7 +66,7 @@ Create an array from a Ruby array
|
|
42
66
|
Khiva::Array.new([1, 2, 3])
|
43
67
|
```
|
44
68
|
|
45
|
-
Specify the type
|
69
|
+
Specify the type - `:b8`, `:f32`, `:f64`, `:s16`, `:s32`, `:s64`, `:u8`, `:u16`, `:u32`, `:u64`
|
46
70
|
|
47
71
|
```ruby
|
48
72
|
Khiva::Array.new([1, 2, 3], type: :s64)
|
@@ -77,6 +101,28 @@ a.le(b)
|
|
77
101
|
a.ge(b)
|
78
102
|
```
|
79
103
|
|
104
|
+
## Clustering
|
105
|
+
|
106
|
+
k-means algorithm
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
centroids, labels = Khiva::Clustering.k_means(tss, k)
|
110
|
+
```
|
111
|
+
|
112
|
+
k-Shape algorithm
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
centroids, labels = Khiva::Clustering.k_shape(tss, k)
|
116
|
+
```
|
117
|
+
|
118
|
+
## Dimensionality
|
119
|
+
|
120
|
+
Piecewise aggregate approximate (PAA)
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
Khiva::Dimensionality.paa(a, bins)
|
124
|
+
```
|
125
|
+
|
80
126
|
## Distances
|
81
127
|
|
82
128
|
Dynamic time warping (DTW) distance
|
@@ -115,34 +161,314 @@ Squared Euclidean distance
|
|
115
161
|
Khiva::Distances.squared_euclidean(tss)
|
116
162
|
```
|
117
163
|
|
164
|
+
## Features
|
165
|
+
|
166
|
+
Sum of square values
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
Khiva::Features.abs_energy(tss)
|
170
|
+
```
|
171
|
+
|
172
|
+
Absolute sum of changes
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
Khiva::Features.absolute_sum_of_changes(tss)
|
176
|
+
```
|
177
|
+
|
178
|
+
Number of values above the mean
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
Khiva::Features.count_above_mean(tss)
|
182
|
+
```
|
183
|
+
|
184
|
+
Number of values below the mean
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
Khiva::Features.count_below_mean(tss)
|
188
|
+
```
|
189
|
+
|
190
|
+
The spectral centroid (mean), variance, skew, and kurtosis of the absolute fourier transform spectrum
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
Khiva::Features.fft_aggregated(tss)
|
194
|
+
```
|
195
|
+
|
196
|
+
First location of the maximum value
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
Khiva::Features.first_location_of_maximum(tss)
|
200
|
+
```
|
201
|
+
|
202
|
+
First location of the minimum value
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
Khiva::Features.first_location_of_minimum(tss)
|
206
|
+
```
|
207
|
+
|
208
|
+
Last location of the maximum value
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Khiva::Features.last_location_of_maximum(tss)
|
212
|
+
```
|
213
|
+
|
214
|
+
Last location of the minimum value
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
Khiva::Features.last_location_of_minimum(tss)
|
218
|
+
```
|
219
|
+
|
220
|
+
Length of the series
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
Khiva::Features.length(tss)
|
224
|
+
```
|
225
|
+
|
226
|
+
Local maximals
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
Khiva::Features.local_maximals(tss)
|
230
|
+
```
|
231
|
+
|
232
|
+
Length of the longest consecutive subsequence above the mean
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
Khiva::Features.longest_strike_above_mean(tss)
|
236
|
+
```
|
237
|
+
|
238
|
+
Length of the longest consecutive subsequence below the mean
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
Khiva::Features.longest_strike_below_mean(tss)
|
242
|
+
```
|
243
|
+
|
244
|
+
Maximum
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
Khiva::Features.maximum(tss)
|
248
|
+
```
|
249
|
+
|
250
|
+
Mean
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
Khiva::Features.mean(tss)
|
254
|
+
```
|
255
|
+
|
256
|
+
Mean absolute change
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
Khiva::Features.mean_absolute_change(tss)
|
260
|
+
```
|
261
|
+
|
262
|
+
Mean change
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
Khiva::Features.mean_change(tss)
|
266
|
+
```
|
267
|
+
|
268
|
+
Mean of a central approximation of the second derivative
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
Khiva::Features.mean_second_derivative_central(tss)
|
272
|
+
```
|
273
|
+
|
274
|
+
Median
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
Khiva::Features.median(tss)
|
278
|
+
```
|
279
|
+
|
280
|
+
Minimum
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
Khiva::Features.minimum(tss)
|
284
|
+
```
|
285
|
+
|
286
|
+
Ratio of unique values
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
Khiva::Features.ratio_value_number_to_time_series_length(tss)
|
290
|
+
```
|
291
|
+
|
292
|
+
Sample entropy
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
Khiva::Features.sample_entropy(tss)
|
296
|
+
```
|
297
|
+
|
298
|
+
Skewness
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
Khiva::Features.skewness(tss)
|
302
|
+
```
|
303
|
+
|
304
|
+
Standard deviation
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
Khiva::Features.standard_deviation(tss)
|
308
|
+
```
|
309
|
+
|
310
|
+
Sum of values
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
Khiva::Features.sum_values(tss)
|
314
|
+
```
|
315
|
+
|
316
|
+
Number of occurrences of a value
|
317
|
+
|
318
|
+
```ruby
|
319
|
+
Khiva::Features.value_count(tss, v)
|
320
|
+
```
|
321
|
+
|
322
|
+
Variance
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
Khiva::Features.variance(tss)
|
326
|
+
```
|
327
|
+
|
328
|
+
If variance is larger than one
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
Khiva::Features.variance_larger_than_standard_deviation(tss)
|
332
|
+
```
|
333
|
+
|
334
|
+
## Library
|
335
|
+
|
336
|
+
Get backend info
|
337
|
+
|
338
|
+
```ruby
|
339
|
+
Khiva::Library.backend_info
|
340
|
+
```
|
341
|
+
|
342
|
+
Get current backend
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
Khiva::Library.backend
|
346
|
+
```
|
347
|
+
|
348
|
+
Get available backends
|
349
|
+
|
350
|
+
```ruby
|
351
|
+
Khiva::Library.backends
|
352
|
+
```
|
353
|
+
|
354
|
+
Set backend - `:default`, `:cpu`, `:cuda`, `:opencl`
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
Khiva::Library.set_backend(:cpu)
|
358
|
+
```
|
359
|
+
|
360
|
+
Set device
|
361
|
+
|
362
|
+
```ruby
|
363
|
+
Khiva::Library.set_device(device_id)
|
364
|
+
```
|
365
|
+
|
366
|
+
Get device id
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
Khiva::Library.device_id
|
370
|
+
```
|
371
|
+
|
372
|
+
Get device count
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
Khiva::Library.device_count
|
376
|
+
```
|
377
|
+
|
378
|
+
Set device memory in GB
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
Khiva::Library.set_device_memory_in_gb(1.5)
|
382
|
+
```
|
383
|
+
|
384
|
+
Get version
|
385
|
+
|
386
|
+
```ruby
|
387
|
+
Khiva::Library.version
|
388
|
+
```
|
389
|
+
|
390
|
+
## Linalg
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
Khiva::Linalg.lls(a, b)
|
394
|
+
```
|
395
|
+
|
396
|
+
## Matrix
|
397
|
+
|
398
|
+
Calculate the matrix profile between `ta` and `tb` using a subsequence length of `m` with the STOMP algorithm
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
profile, index = Khiva::Matrix.stomp(ta, tb, m)
|
402
|
+
```
|
403
|
+
|
404
|
+
Calculate the matrix profile between `t` and itself using a subsequence length of `m` with the STOMP algorithm
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
profile, index = Khiva::Matrix.stomp_self_join(t, m)
|
408
|
+
```
|
409
|
+
|
410
|
+
Calculate the matrix profile between `ta` and `tb` using a subsequence length of `m`
|
411
|
+
|
412
|
+
```ruby
|
413
|
+
profile, index = Khiva::Matrix.matrix_profile(ta, tb, m)
|
414
|
+
```
|
415
|
+
|
416
|
+
Calculate the matrix profile between `t` and itself using a subsequence length of `m`
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
profile, index = Khiva::Matrix.matrix_profile_self_join(t, m)
|
420
|
+
```
|
421
|
+
|
118
422
|
## Normalization
|
119
423
|
|
120
424
|
Decimal scaling
|
121
425
|
|
122
426
|
```ruby
|
123
|
-
Khiva::
|
124
|
-
Khiva::
|
427
|
+
Khiva::Normalization.decimal_scaling_norm(tss)
|
428
|
+
Khiva::Normalization.decimal_scaling_norm!(tss)
|
125
429
|
```
|
126
430
|
|
127
431
|
Max min
|
128
432
|
|
129
433
|
```ruby
|
130
|
-
Khiva::
|
131
|
-
Khiva::
|
434
|
+
Khiva::Normalization.max_min_norm(tss)
|
435
|
+
Khiva::Normalization.max_min_norm!(tss)
|
132
436
|
```
|
133
437
|
|
134
438
|
Mean
|
135
439
|
|
136
440
|
```ruby
|
137
|
-
Khiva::
|
138
|
-
Khiva::
|
441
|
+
Khiva::Normalization.mean_norm(tss)
|
442
|
+
Khiva::Normalization.mean_norm!(tss)
|
139
443
|
```
|
140
444
|
|
141
445
|
Znorm
|
142
446
|
|
143
447
|
```ruby
|
144
|
-
Khiva::
|
145
|
-
Khiva::
|
448
|
+
Khiva::Normalization.znorm(tss)
|
449
|
+
Khiva::Normalization.znorm!(tss)
|
450
|
+
```
|
451
|
+
|
452
|
+
## Polynomial
|
453
|
+
|
454
|
+
Least squares polynomial fit
|
455
|
+
|
456
|
+
```ruby
|
457
|
+
Khiva::Polynomial.polyfit(x, y, deg)
|
458
|
+
```
|
459
|
+
|
460
|
+
## Regression
|
461
|
+
|
462
|
+
Linear least squares regression
|
463
|
+
|
464
|
+
```ruby
|
465
|
+
slope, intercept, rvalue, pvalue, stderrest = Khiva::Regression.linear(xss, yss)
|
466
|
+
```
|
467
|
+
|
468
|
+
## Regularization
|
469
|
+
|
470
|
+
```ruby
|
471
|
+
Khiva::Regularization.group_by(tss, aggregation_function, columns_key: 1, n_columns_value: 1)
|
146
472
|
```
|
147
473
|
|
148
474
|
## Statistics
|
@@ -153,14 +479,78 @@ Covariance
|
|
153
479
|
Khiva::Statistics.covariance(tss, unbiased: false)
|
154
480
|
```
|
155
481
|
|
482
|
+
Kurtosis
|
483
|
+
|
484
|
+
```ruby
|
485
|
+
Khiva::Statistics.kurtosis(tss)
|
486
|
+
```
|
487
|
+
|
488
|
+
Ljung-Box
|
489
|
+
|
490
|
+
```ruby
|
491
|
+
Khiva::Statistics.ljung_box(tss, lags)
|
492
|
+
```
|
493
|
+
|
494
|
+
Moment
|
495
|
+
|
496
|
+
```ruby
|
497
|
+
Khiva::Statistics.moment(tss, k)
|
498
|
+
```
|
499
|
+
|
500
|
+
Quantile
|
501
|
+
|
502
|
+
```ruby
|
503
|
+
Khiva::Statistics.quantile(tss, q, precision: 1e-8)
|
504
|
+
```
|
505
|
+
|
506
|
+
Quantiles cut
|
507
|
+
|
508
|
+
```ruby
|
509
|
+
Khiva::Statistics.quantiles_cut(tss, quantiles, precision: 1e-8)
|
510
|
+
```
|
511
|
+
|
512
|
+
Standard deviation
|
513
|
+
|
514
|
+
```ruby
|
515
|
+
Khiva::Statistics.sample_stdev(tss)
|
516
|
+
```
|
517
|
+
|
518
|
+
Skewness
|
519
|
+
|
520
|
+
```ruby
|
521
|
+
Khiva::Statistics.skewness(tss)
|
522
|
+
```
|
523
|
+
|
156
524
|
## Khiva Installation
|
157
525
|
|
158
526
|
### Linux
|
159
527
|
|
160
|
-
|
528
|
+
Install Boost and Eigen. On Ubuntu, use:
|
529
|
+
|
530
|
+
```sh
|
531
|
+
sudo apt-get install libboost-all-dev libeigen3-dev
|
532
|
+
```
|
533
|
+
|
534
|
+
Install ArrayFire:
|
535
|
+
|
536
|
+
```sh
|
537
|
+
wget -q https://arrayfire.s3.amazonaws.com/3.7.3/ArrayFire-v3.7.3_Linux_x86_64.sh
|
538
|
+
chmod +x ./ArrayFire-v3.7.3_Linux_x86_64.sh
|
539
|
+
./ArrayFire-v3.7.3_Linux_x86_64.sh --include-subdir --prefix=/opt
|
540
|
+
echo /opt/arrayfire/lib64 | sudo tee /etc/ld.so.conf.d/arrayfire.conf
|
541
|
+
sudo ldconfig
|
542
|
+
```
|
543
|
+
|
544
|
+
And install Khiva:
|
161
545
|
|
162
546
|
```sh
|
163
|
-
|
547
|
+
git clone --recursive --branch v0.5.0 https://github.com/shapelets/khiva
|
548
|
+
cd khiva
|
549
|
+
mkdir build
|
550
|
+
cd build
|
551
|
+
cmake .. -DKHIVA_USE_CONAN=OFF -DKHIVA_BUILD_TESTS=OFF -DKHIVA_BUILD_BENCHMARKS=OFF -DKHIVA_BUILD_JNI_BINDINGS=OFF
|
552
|
+
make -j4
|
553
|
+
sudo make install
|
164
554
|
```
|
165
555
|
|
166
556
|
### Mac
|
data/lib/khiva.rb
CHANGED
@@ -3,10 +3,17 @@ require "fiddle/import"
|
|
3
3
|
|
4
4
|
# modules
|
5
5
|
require "khiva/array"
|
6
|
+
require "khiva/clustering"
|
7
|
+
require "khiva/dimensionality"
|
6
8
|
require "khiva/distances"
|
9
|
+
require "khiva/features"
|
7
10
|
require "khiva/library"
|
11
|
+
require "khiva/linalg"
|
8
12
|
require "khiva/matrix"
|
9
13
|
require "khiva/normalization"
|
14
|
+
require "khiva/polynomial"
|
15
|
+
require "khiva/regression"
|
16
|
+
require "khiva/regularization"
|
10
17
|
require "khiva/statistics"
|
11
18
|
require "khiva/utils"
|
12
19
|
require "khiva/version"
|
@@ -30,8 +37,6 @@ module Khiva
|
|
30
37
|
autoload :FFI, "khiva/ffi"
|
31
38
|
|
32
39
|
def self.lib_version
|
33
|
-
|
34
|
-
FFI.call(:version, v.ref)
|
35
|
-
v.to_s
|
40
|
+
Library.version
|
36
41
|
end
|
37
42
|
end
|
data/lib/khiva/array.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Khiva
|
2
|
+
module Clustering
|
3
|
+
class << self
|
4
|
+
def k_means(tss, k, tolerance: 1e-10, max_iterations: 100)
|
5
|
+
centroids = Utils.create_ptr
|
6
|
+
labels = Utils.create_ptr
|
7
|
+
FFI.call(:k_means, tss, Utils.int_ptr(k), centroids, labels, Utils.float_ptr(tolerance), Utils.int_ptr(max_iterations))
|
8
|
+
[Array.new(centroids), Array.new(labels)]
|
9
|
+
end
|
10
|
+
|
11
|
+
def k_shape(tss, k, tolerance: 1e-10, max_iterations: 100)
|
12
|
+
centroids = Utils.create_ptr
|
13
|
+
labels = Utils.create_ptr
|
14
|
+
FFI.call(:k_shape, tss, Utils.int_ptr(k), centroids, labels, Utils.float_ptr(tolerance), Utils.int_ptr(max_iterations))
|
15
|
+
[Array.new(centroids), Array.new(labels)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module Khiva
|
2
|
+
module Features
|
3
|
+
class << self
|
4
|
+
def abs_energy(arr)
|
5
|
+
result = Utils.create_ptr
|
6
|
+
FFI.call(:abs_energy, arr, result)
|
7
|
+
Array.new(result)
|
8
|
+
end
|
9
|
+
|
10
|
+
def absolute_sum_of_changes(arr)
|
11
|
+
result = Utils.create_ptr
|
12
|
+
FFI.call(:absolute_sum_of_changes, arr, result)
|
13
|
+
Array.new(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def count_above_mean(arr)
|
17
|
+
result = Utils.create_ptr
|
18
|
+
FFI.call(:count_above_mean, arr, result)
|
19
|
+
Array.new(result)
|
20
|
+
end
|
21
|
+
|
22
|
+
def count_below_mean(arr)
|
23
|
+
result = Utils.create_ptr
|
24
|
+
FFI.call(:count_below_mean, arr, result)
|
25
|
+
Array.new(result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fft_aggregated(arr)
|
29
|
+
result = Utils.create_ptr
|
30
|
+
FFI.call(:fft_aggregated, arr, result)
|
31
|
+
Array.new(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
def first_location_of_maximum(arr)
|
35
|
+
result = Utils.create_ptr
|
36
|
+
FFI.call(:first_location_of_maximum, arr, result)
|
37
|
+
Array.new(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
def first_location_of_minimum(arr)
|
41
|
+
result = Utils.create_ptr
|
42
|
+
FFI.call(:first_location_of_minimum, arr, result)
|
43
|
+
Array.new(result)
|
44
|
+
end
|
45
|
+
|
46
|
+
def last_location_of_maximum(arr)
|
47
|
+
result = Utils.create_ptr
|
48
|
+
FFI.call(:last_location_of_maximum, arr, result)
|
49
|
+
Array.new(result)
|
50
|
+
end
|
51
|
+
|
52
|
+
def last_location_of_minimum(arr)
|
53
|
+
result = Utils.create_ptr
|
54
|
+
FFI.call(:last_location_of_minimum, arr, result)
|
55
|
+
Array.new(result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def length(arr)
|
59
|
+
result = Utils.create_ptr
|
60
|
+
FFI.call(:length, arr, result)
|
61
|
+
Array.new(result)
|
62
|
+
end
|
63
|
+
|
64
|
+
def local_maximals(arr)
|
65
|
+
result = Utils.create_ptr
|
66
|
+
FFI.call(:local_maximals, arr, result)
|
67
|
+
Array.new(result)
|
68
|
+
end
|
69
|
+
|
70
|
+
def longest_strike_above_mean(arr)
|
71
|
+
result = Utils.create_ptr
|
72
|
+
FFI.call(:longest_strike_above_mean, arr, result)
|
73
|
+
Array.new(result)
|
74
|
+
end
|
75
|
+
|
76
|
+
def longest_strike_below_mean(arr)
|
77
|
+
result = Utils.create_ptr
|
78
|
+
FFI.call(:longest_strike_below_mean, arr, result)
|
79
|
+
Array.new(result)
|
80
|
+
end
|
81
|
+
|
82
|
+
def maximum(arr)
|
83
|
+
result = Utils.create_ptr
|
84
|
+
FFI.call(:maximum, arr, result)
|
85
|
+
Array.new(result)
|
86
|
+
end
|
87
|
+
|
88
|
+
def mean(arr)
|
89
|
+
result = Utils.create_ptr
|
90
|
+
FFI.call(:mean, arr, result)
|
91
|
+
Array.new(result)
|
92
|
+
end
|
93
|
+
|
94
|
+
def mean_absolute_change(arr)
|
95
|
+
result = Utils.create_ptr
|
96
|
+
FFI.call(:mean_absolute_change, arr, result)
|
97
|
+
Array.new(result)
|
98
|
+
end
|
99
|
+
|
100
|
+
def mean_change(arr)
|
101
|
+
result = Utils.create_ptr
|
102
|
+
FFI.call(:mean_change, arr, result)
|
103
|
+
Array.new(result)
|
104
|
+
end
|
105
|
+
|
106
|
+
def mean_second_derivative_central(arr)
|
107
|
+
result = Utils.create_ptr
|
108
|
+
FFI.call(:mean_second_derivative_central, arr, result)
|
109
|
+
Array.new(result)
|
110
|
+
end
|
111
|
+
|
112
|
+
def median(arr)
|
113
|
+
result = Utils.create_ptr
|
114
|
+
FFI.call(:median, arr, result)
|
115
|
+
Array.new(result)
|
116
|
+
end
|
117
|
+
|
118
|
+
def minimum(arr)
|
119
|
+
result = Utils.create_ptr
|
120
|
+
FFI.call(:minimum, arr, result)
|
121
|
+
Array.new(result)
|
122
|
+
end
|
123
|
+
|
124
|
+
def ratio_value_number_to_time_series_length(arr)
|
125
|
+
result = Utils.create_ptr
|
126
|
+
FFI.call(:ratio_value_number_to_time_series_length, arr, result)
|
127
|
+
Array.new(result)
|
128
|
+
end
|
129
|
+
|
130
|
+
def sample_entropy(arr)
|
131
|
+
result = Utils.create_ptr
|
132
|
+
FFI.call(:sample_entropy, arr, result)
|
133
|
+
Array.new(result)
|
134
|
+
end
|
135
|
+
|
136
|
+
def skewness(arr)
|
137
|
+
result = Utils.create_ptr
|
138
|
+
FFI.call(:skewness, arr, result)
|
139
|
+
Array.new(result)
|
140
|
+
end
|
141
|
+
|
142
|
+
def standard_deviation(arr)
|
143
|
+
result = Utils.create_ptr
|
144
|
+
FFI.call(:standard_deviation, arr, result)
|
145
|
+
Array.new(result)
|
146
|
+
end
|
147
|
+
|
148
|
+
def sum_values(arr)
|
149
|
+
result = Utils.create_ptr
|
150
|
+
FFI.call(:sum_values, arr, result)
|
151
|
+
Array.new(result)
|
152
|
+
end
|
153
|
+
|
154
|
+
def value_count(arr, v)
|
155
|
+
result = Utils.create_ptr
|
156
|
+
FFI.call(:value_count, arr, Utils.float_ptr(v), result)
|
157
|
+
Array.new(result)
|
158
|
+
end
|
159
|
+
|
160
|
+
def variance(arr)
|
161
|
+
result = Utils.create_ptr
|
162
|
+
FFI.call(:variance, arr, result)
|
163
|
+
Array.new(result)
|
164
|
+
end
|
165
|
+
|
166
|
+
def variance_larger_than_standard_deviation(arr)
|
167
|
+
result = Utils.create_ptr
|
168
|
+
FFI.call(:variance_larger_than_standard_deviation, arr, result)
|
169
|
+
Array.new(result)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/lib/khiva/ffi.rb
CHANGED
@@ -41,12 +41,99 @@ module Khiva
|
|
41
41
|
extern "void khiva_not(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
42
42
|
extern "void copy(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
43
43
|
|
44
|
+
# clustering.h
|
45
|
+
extern "void k_means(const khiva_array *tss, const int *k, khiva_array *centroids, khiva_array *labels, const float *tolerance, const int *max_iterations, int *error_code, char *error_message)"
|
46
|
+
extern "void k_shape(const khiva_array *tss, const int *k, khiva_array *centroids, khiva_array *labels, const float *tolerance, const int *max_iterations, int *error_code, char *error_message)"
|
47
|
+
|
48
|
+
# dimensionality.h
|
49
|
+
extern "void paa(const khiva_array *a, const int *bins, khiva_array *result, int *error_code, char *error_message)"
|
50
|
+
extern "void pip(const khiva_array *a, const int *number_ips, khiva_array *result, int *error_code, char *error_message)"
|
51
|
+
extern "void pla_bottom_up(const khiva_array *ts, const float *max_error, khiva_array *result, int *error_code, char *error_message)"
|
52
|
+
extern "void pla_sliding_window(const khiva_array *ts, const float *max_error, khiva_array *result, int *error_code, char *error_message)"
|
53
|
+
extern "void ramer_douglas_peucker(const khiva_array *points, const double *epsilon, khiva_array *res_points, int *error_code, char *error_message)"
|
54
|
+
extern "void sax(const khiva_array *a, const int *alphabet_size, khiva_array *result, int *error_code, char *error_message)"
|
55
|
+
extern "void visvalingam(const khiva_array *points, const int *num_points, khiva_array *res_points, int *error_code, char *error_message)"
|
56
|
+
|
57
|
+
# features.h
|
58
|
+
extern "void abs_energy(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
59
|
+
extern "void absolute_sum_of_changes(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
60
|
+
extern "void aggregated_autocorrelation(const khiva_array *array, const int *aggregation_function, khiva_array *result, int *error_code, char *error_message)"
|
61
|
+
extern "void aggregated_linear_trend(const khiva_array *array, const long *chunkSize, const int *aggregation_function, khiva_array *slope, khiva_array *intercept, khiva_array *rvalue, khiva_array *pvalue, khiva_array *stderrest, int *error_code, char *error_message)"
|
62
|
+
extern "void approximate_entropy(const khiva_array *array, const int *m, const float *r, khiva_array *result, int *error_code, char *error_message)"
|
63
|
+
extern "void cross_covariance(const khiva_array *xss, const khiva_array *yss, const bool *unbiased, khiva_array *result, int *error_code, char *error_message)"
|
64
|
+
extern "void auto_covariance(const khiva_array *array, const bool *unbiased, khiva_array *result, int *error_code, char *error_message)"
|
65
|
+
extern "void cross_correlation(const khiva_array *xss, const khiva_array *yss, const bool *unbiased, khiva_array *result, int *error_code, char *error_message)"
|
66
|
+
extern "void auto_correlation(const khiva_array *array, const long *max_lag, const bool *unbiased, khiva_array *result, int *error_code, char *error_message)"
|
67
|
+
extern "void binned_entropy(const khiva_array *array, const int *max_bins, khiva_array *result, int *error_code, char *error_message)"
|
68
|
+
extern "void c3(const khiva_array *array, const long *lag, khiva_array *result, int *error_code, char *error_message)"
|
69
|
+
extern "void cid_ce(const khiva_array *array, const bool *zNormalize, khiva_array *result, int *error_code, char *error_message)"
|
70
|
+
extern "void count_above_mean(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
71
|
+
extern "void count_below_mean(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
72
|
+
extern "void cwt_coefficients(const khiva_array *array, const khiva_array *width, const int *coeff, const int *w, khiva_array *result, int *error_code, char *error_message)"
|
73
|
+
extern "void energy_ratio_by_chunks(const khiva_array *array, const long *num_segments, const long *segment_focus, khiva_array *result, int *error_code, char *error_message)"
|
74
|
+
extern "void fft_aggregated(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
75
|
+
extern "void fft_coefficient(const khiva_array *array, const long *coefficient, khiva_array *real, khiva_array *imag, khiva_array *absolute, khiva_array *angle, int *error_code, char *error_message)"
|
76
|
+
extern "void first_location_of_maximum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
77
|
+
extern "void first_location_of_minimum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
78
|
+
extern "void friedrich_coefficients(const khiva_array *array, const int *m, const float *r, khiva_array *result, int *error_code, char *error_message)"
|
79
|
+
extern "void has_duplicates(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
80
|
+
extern "void has_duplicate_max(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
81
|
+
extern "void has_duplicate_min(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
82
|
+
extern "void index_mass_quantile(const khiva_array *array, const float *q, khiva_array *result, int *error_code, char *error_message)"
|
83
|
+
extern "void kurtosis(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
84
|
+
extern "void large_standard_deviation(const khiva_array *array, const float *r, khiva_array *result, int *error_code, char *error_message)"
|
85
|
+
extern "void last_location_of_maximum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
86
|
+
extern "void last_location_of_minimum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
87
|
+
extern "void length(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
88
|
+
extern "void linear_trend(const khiva_array *array, khiva_array *pvalue, khiva_array *rvalue, khiva_array *intercept, khiva_array *slope, khiva_array *stdrr, int *error_code, char *error_message)"
|
89
|
+
extern "void local_maximals(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
90
|
+
extern "void longest_strike_above_mean(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
91
|
+
extern "void longest_strike_below_mean(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
92
|
+
extern "void max_langevin_fixed_point(const khiva_array *array, const int *m, const float *r, khiva_array *result, int *error_code, char *error_message)"
|
93
|
+
extern "void maximum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
94
|
+
extern "void mean(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
95
|
+
extern "void mean_absolute_change(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
96
|
+
extern "void mean_change(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
97
|
+
extern "void mean_second_derivative_central(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
98
|
+
extern "void median(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
99
|
+
extern "void minimum(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
100
|
+
extern "void number_crossing_m(const khiva_array *array, const int *m, khiva_array *result, int *error_code, char *error_message)"
|
101
|
+
extern "void number_cwt_peaks(const khiva_array *array, const int *max_w, khiva_array *result, int *error_code, char *error_message)"
|
102
|
+
extern "void number_peaks(const khiva_array *array, const int *n, khiva_array *result, int *error_code, char *error_message)"
|
103
|
+
extern "void partial_autocorrelation(const khiva_array *array, const khiva_array *lags, khiva_array *result, int *error_code, char *error_message)"
|
104
|
+
extern "void percentage_of_reoccurring_datapoints_to_all_datapoints(const khiva_array *array, const bool *is_sorted, khiva_array *result, int *error_code, char *error_message)"
|
105
|
+
extern "void percentage_of_reoccurring_values_to_all_values(const khiva_array *array, const bool *is_sorted, khiva_array *result, int *error_code, char *error_message)"
|
106
|
+
extern "void quantile(const khiva_array *array, const khiva_array *q, const float *precision, khiva_array *result, int *error_code, char *error_message)"
|
107
|
+
extern "void range_count(const khiva_array *array, const float *min, const float *max, khiva_array *result, int *error_code, char *error_message)"
|
108
|
+
extern "void ratio_beyond_r_sigma(const khiva_array *array, const float *r, khiva_array *result, int *error_code,vchar *error_message)"
|
109
|
+
extern "void ratio_value_number_to_time_series_length(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
110
|
+
extern "void sample_entropy(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
111
|
+
extern "void skewness(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
112
|
+
extern "void spkt_welch_density(const khiva_array *array, const int *coeff, khiva_array *result, int *error_code, char *error_message)"
|
113
|
+
extern "void standard_deviation(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
114
|
+
extern "void sum_of_reoccurring_datapoints(const khiva_array *array, const bool *is_sorted, khiva_array *result, int *error_code, char *error_message)"
|
115
|
+
extern "void sum_of_reoccurring_values(const khiva_array *array, const bool *is_sorted, khiva_array *result, int *error_code, char *error_message)"
|
116
|
+
extern "void sum_values(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
117
|
+
extern "void symmetry_looking(const khiva_array *array, const float *r, khiva_array *result, int *error_code, char *error_message)"
|
118
|
+
extern "void time_reversal_asymmetry_statistic(const khiva_array *array, const int *lag, khiva_array *result, int *error_code, char *error_message)"
|
119
|
+
extern "void value_count(const khiva_array *array, const float *v, khiva_array *result, int *error_code, char *error_message)"
|
120
|
+
extern "void variance(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
121
|
+
extern "void variance_larger_than_standard_deviation(const khiva_array *array, khiva_array *result, int *error_code, char *error_message)"
|
122
|
+
|
44
123
|
# library.h
|
45
124
|
extern "void backend_info(char **info, int *error_code, char *error_message)"
|
46
125
|
extern "void set_backend(const int *backend, int *error_code, char *error_message)"
|
126
|
+
extern "void get_backend(int *backend, int *error_code, char *error_message)"
|
127
|
+
extern "void get_backends(int *backends, int *error_code, char *error_message)"
|
47
128
|
extern "void set_device(const int *device, int *error_code, char *error_message)"
|
129
|
+
extern "void get_device_id(int *device_id, int *error_code, char *error_message)"
|
130
|
+
extern "void get_device_count(int *device_count, int *error_code, char *error_message)"
|
131
|
+
extern "void set_device_memory_in_gb(const double *memory, int *error_code, char *error_message)"
|
48
132
|
extern "void version(char **v, int *error_code, char *error_message)"
|
49
133
|
|
134
|
+
# linalg.h
|
135
|
+
extern "void lls(const khiva_array *a, const khiva_array *b, khiva_array *result, int *error_code, char *error_message)"
|
136
|
+
|
50
137
|
# distances.h
|
51
138
|
extern "void dtw(const khiva_array *tss, khiva_array *result, int *error_code, char *error_message)"
|
52
139
|
extern "void euclidean(const khiva_array *tss, khiva_array *result, int *error_code, char *error_message)"
|
@@ -57,7 +144,15 @@ module Khiva
|
|
57
144
|
|
58
145
|
# matrix.h
|
59
146
|
extern "void find_best_n_discords(const khiva_array *profile, const khiva_array *index, long m, long n, khiva_array *discord_distances, khiva_array *discord_indices, khiva_array *subsequence_indices, bool self_join, int *error_code, char *error_message)"
|
147
|
+
extern "void find_best_n_motifs(const khiva_array *profile, const khiva_array *index, long m, long n, khiva_array *motif_distances, khiva_array *motif_indices, khiva_array *subsequence_indices, bool self_join, int *error_code, char *error_message)"
|
148
|
+
extern "void find_best_n_occurrences(const khiva_array *q, const khiva_array *t, long n, khiva_array *distances, khiva_array *indexes, int *error_code, char *error_message)"
|
149
|
+
extern "void mass(const khiva_array *q, const khiva_array *t, khiva_array *distances, int *error_code, char *error_message)"
|
60
150
|
extern "void stomp(const khiva_array *tssa, const khiva_array *tssb, long m, khiva_array *p, khiva_array *i, int *error_code, char *error_message)"
|
151
|
+
extern "void stomp_self_join(const khiva_array *tss, long m, khiva_array *p, khiva_array *i, int *error_code, char *error_message)"
|
152
|
+
extern "void matrix_profile(const khiva_array *tssa, const khiva_array *tssb, long m, khiva_array *p, khiva_array *i, int *error_code, char *error_message)"
|
153
|
+
extern "void matrix_profile_self_join(const khiva_array *tss, long m, khiva_array *p, khiva_array *i, int *error_code, char *error_message)"
|
154
|
+
extern "void matrix_profile_lr(const khiva_array *tss, long m, khiva_array *pleft, khiva_array *ileft, khiva_array *pright, khiva_array *iright, int *error_code, char *error_message)"
|
155
|
+
extern "void get_chains(const khiva_array *tss, long m, khiva_array *chains, int *error_code, char *error_message)"
|
61
156
|
|
62
157
|
# normalization.h
|
63
158
|
extern "void decimal_scaling_norm(const khiva_array *tss, khiva_array *result, int *error_code, char *error_message)"
|
@@ -69,6 +164,16 @@ module Khiva
|
|
69
164
|
extern "void znorm(const khiva_array *tss, const double *epsilon, khiva_array *result, int *error_code, char *error_message)"
|
70
165
|
extern "void znorm_in_place(khiva_array *tss, const double *epsilon, int *error_code, char *error_message)"
|
71
166
|
|
167
|
+
# polynomial.h
|
168
|
+
extern "void polyfit(const khiva_array *x, const khiva_array *y, const int *deg, khiva_array *result, int *error_code, char *error_message)"
|
169
|
+
extern "void roots(const khiva_array *p, khiva_array *result, int *error_code, char *error_message)"
|
170
|
+
|
171
|
+
# regression.h
|
172
|
+
extern "void linear(const khiva_array *xss, const khiva_array *yss, khiva_array *slope, khiva_array *intercept, khiva_array *rvalue, khiva_array *pvalue, khiva_array *stderrest, int *error_code, char *error_message)"
|
173
|
+
|
174
|
+
# regularization.h
|
175
|
+
extern "void group_by(const khiva_array *array, const int *aggregation_function, const int *n_columns_key, const int *n_columns_value, khiva_array *result, int *error_code, char *error_message)"
|
176
|
+
|
72
177
|
# statistics.h
|
73
178
|
extern "void covariance_statistics(const khiva_array *tss, const bool *unbiased, khiva_array *result, int *error_code, char *error_message)"
|
74
179
|
extern "void kurtosis_statistics(const khiva_array *tss, khiva_array *result, int *error_code, char *error_message)"
|
data/lib/khiva/library.rb
CHANGED
@@ -14,6 +14,19 @@ module Khiva
|
|
14
14
|
info.to_s
|
15
15
|
end
|
16
16
|
|
17
|
+
def backend
|
18
|
+
backend = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
|
19
|
+
FFI.call(:get_backend, backend)
|
20
|
+
BACKENDS.map(&:reverse).to_h[backend.to_s(backend.size).unpack1("i")]
|
21
|
+
end
|
22
|
+
|
23
|
+
def backends
|
24
|
+
backends = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
|
25
|
+
FFI.call(:get_backends, backends)
|
26
|
+
mask = backends.to_s(backends.size).unpack1("i")
|
27
|
+
BACKENDS.select { |_, v| mask & v != 0 }.map(&:first)
|
28
|
+
end
|
29
|
+
|
17
30
|
def set_backend(backend)
|
18
31
|
b = BACKENDS[backend]
|
19
32
|
raise Error, "Invalid backend: #{backend}" unless b
|
@@ -23,6 +36,28 @@ module Khiva
|
|
23
36
|
def set_device(device)
|
24
37
|
FFI.call(:set_device, Utils.int_ptr(device))
|
25
38
|
end
|
39
|
+
|
40
|
+
def device_id
|
41
|
+
device_id = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
|
42
|
+
FFI.call(:get_device_id, device_id)
|
43
|
+
device_id.to_s(device_id.size).unpack1("i")
|
44
|
+
end
|
45
|
+
|
46
|
+
def device_count
|
47
|
+
device_count = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
|
48
|
+
FFI.call(:get_device_count, device_count)
|
49
|
+
device_count.to_s(device_count.size).unpack1("i")
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_device_memory_in_gb(memory)
|
53
|
+
FFI.call(:set_device_memory_in_gb, Utils.double_ptr(memory))
|
54
|
+
end
|
55
|
+
|
56
|
+
def version
|
57
|
+
v = Fiddle::Pointer.malloc(20)
|
58
|
+
FFI.call(:version, v.ref)
|
59
|
+
v.to_s
|
60
|
+
end
|
26
61
|
end
|
27
62
|
end
|
28
63
|
end
|
data/lib/khiva/linalg.rb
ADDED
data/lib/khiva/matrix.rb
CHANGED
@@ -9,12 +9,41 @@ module Khiva
|
|
9
9
|
[Array.new(discord_distances), Array.new(discord_indices), Array.new(subsequence_indices)]
|
10
10
|
end
|
11
11
|
|
12
|
+
def find_best_n_motifs(profile, index, m, n, self_join: false)
|
13
|
+
motif_distances = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
14
|
+
motif_indices = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
15
|
+
subsequence_indices = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
16
|
+
FFI.call(:find_best_n_motifs, profile, index, m, n, motif_distances, motif_indices, subsequence_indices, self_join ? 1 : 0)
|
17
|
+
[Array.new(motif_distances), Array.new(motif_indices), Array.new(subsequence_indices)]
|
18
|
+
end
|
19
|
+
|
12
20
|
def stomp(tssa, tssb, m)
|
13
21
|
profile = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
14
22
|
index = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
15
23
|
FFI.call(:stomp, tssa, tssb, m, profile, index)
|
16
24
|
[Array.new(profile), Array.new(index)]
|
17
25
|
end
|
26
|
+
|
27
|
+
def stomp_self_join(tss, m)
|
28
|
+
profile = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
29
|
+
index = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
30
|
+
FFI.call(:stomp_self_join, tss, m, profile, index)
|
31
|
+
[Array.new(profile), Array.new(index)]
|
32
|
+
end
|
33
|
+
|
34
|
+
def matrix_profile(tssa, tssb, m)
|
35
|
+
profile = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
36
|
+
index = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
37
|
+
FFI.call(:matrix_profile, tssa, tssb, m, profile, index)
|
38
|
+
[Array.new(profile), Array.new(index)]
|
39
|
+
end
|
40
|
+
|
41
|
+
def matrix_profile_self_join(tss, m)
|
42
|
+
profile = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
43
|
+
index = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
|
44
|
+
FFI.call(:matrix_profile_self_join, tss, m, profile, index)
|
45
|
+
[Array.new(profile), Array.new(index)]
|
46
|
+
end
|
18
47
|
end
|
19
48
|
end
|
20
49
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Khiva
|
2
|
+
module Regression
|
3
|
+
class << self
|
4
|
+
def linear(xss, yss)
|
5
|
+
slope = Utils.create_ptr
|
6
|
+
intercept = Utils.create_ptr
|
7
|
+
rvalue = Utils.create_ptr
|
8
|
+
pvalue = Utils.create_ptr
|
9
|
+
stderrest = Utils.create_ptr
|
10
|
+
FFI.call(:linear, xss, yss, slope, intercept, rvalue, pvalue, stderrest)
|
11
|
+
[Array.new(slope), Array.new(intercept), Array.new(rvalue), Array.new(pvalue), Array.new(stderrest)]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Khiva
|
2
|
+
module Regularization
|
3
|
+
class << self
|
4
|
+
def group_by(tss, aggregation_function, n_columns_key: 1, n_columns_value: 1)
|
5
|
+
result = Utils.create_ptr
|
6
|
+
FFI.call(:group_by, tss, Utils.int_ptr(aggregation_function), Utils.int_ptr(n_columns_key), Utils.int_ptr(n_columns_value), result)
|
7
|
+
Array.new(result)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/khiva/statistics.rb
CHANGED
@@ -6,6 +6,48 @@ module Khiva
|
|
6
6
|
FFI.call(:covariance_statistics, tss, Utils.bool_ptr(unbiased), result)
|
7
7
|
Array.new(result)
|
8
8
|
end
|
9
|
+
|
10
|
+
def kurtosis(tss)
|
11
|
+
result = Utils.create_ptr
|
12
|
+
FFI.call(:kurtosis_statistics, tss, result)
|
13
|
+
Array.new(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ljung_box(tss, lags)
|
17
|
+
result = Utils.create_ptr
|
18
|
+
FFI.call(:ljung_box, tss, Utils.long_ptr(lags), result)
|
19
|
+
Array.new(result)
|
20
|
+
end
|
21
|
+
|
22
|
+
def moment(tss, k)
|
23
|
+
result = Utils.create_ptr
|
24
|
+
FFI.call(:moment_statistics, tss, Utils.int_ptr(k), result)
|
25
|
+
Array.new(result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def quantile(tss, q, precision: 1e-8)
|
29
|
+
result = Utils.create_ptr
|
30
|
+
FFI.call(:quantile_statistics, tss, q, Utils.float_ptr(precision), result)
|
31
|
+
Array.new(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
def quantiles_cut(tss, quantiles, precision: 1e-8)
|
35
|
+
result = Utils.create_ptr
|
36
|
+
FFI.call(:quantiles_cut_statistics, tss, Utils.float_ptr(quantiles), Utils.float_ptr(precision), result)
|
37
|
+
Array.new(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
def sample_stdev(tss)
|
41
|
+
result = Utils.create_ptr
|
42
|
+
FFI.call(:sample_stdev_statistics, tss, result)
|
43
|
+
Array.new(result)
|
44
|
+
end
|
45
|
+
|
46
|
+
def skewness(tss)
|
47
|
+
result = Utils.create_ptr
|
48
|
+
FFI.call(:skewness_statistics, tss, result)
|
49
|
+
Array.new(result)
|
50
|
+
end
|
9
51
|
end
|
10
52
|
end
|
11
53
|
end
|
data/lib/khiva/utils.rb
CHANGED
@@ -6,7 +6,15 @@ module Khiva
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def int_ptr(v)
|
9
|
-
Fiddle::Pointer[[v].pack("i
|
9
|
+
Fiddle::Pointer[[v].pack("i")]
|
10
|
+
end
|
11
|
+
|
12
|
+
def long_ptr(v)
|
13
|
+
Fiddle::Pointer[[v].pack("L!")]
|
14
|
+
end
|
15
|
+
|
16
|
+
def float_ptr(v)
|
17
|
+
Fiddle::Pointer[[v].pack("f")]
|
10
18
|
end
|
11
19
|
|
12
20
|
def double_ptr(v)
|
data/lib/khiva/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: khiva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@chartkick.com
|
@@ -21,11 +21,18 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- lib/khiva.rb
|
23
23
|
- lib/khiva/array.rb
|
24
|
+
- lib/khiva/clustering.rb
|
25
|
+
- lib/khiva/dimensionality.rb
|
24
26
|
- lib/khiva/distances.rb
|
27
|
+
- lib/khiva/features.rb
|
25
28
|
- lib/khiva/ffi.rb
|
26
29
|
- lib/khiva/library.rb
|
30
|
+
- lib/khiva/linalg.rb
|
27
31
|
- lib/khiva/matrix.rb
|
28
32
|
- lib/khiva/normalization.rb
|
33
|
+
- lib/khiva/polynomial.rb
|
34
|
+
- lib/khiva/regression.rb
|
35
|
+
- lib/khiva/regularization.rb
|
29
36
|
- lib/khiva/statistics.rb
|
30
37
|
- lib/khiva/utils.rb
|
31
38
|
- lib/khiva/version.rb
|