alglib4 0.0.0 → 0.0.2

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.
@@ -0,0 +1,338 @@
1
+ #include "alglib_statistics.h"
2
+
3
+ // 1D array statistical functions
4
+ Hash rb_samplemoments(Array x)
5
+ {
6
+ Hash result;
7
+ auto a = ruby_array_to_real_1d_array(x);
8
+ double mean, variance, skewness, kurtosis;
9
+
10
+ alglib::samplemoments(a, x.size(), mean, variance, skewness, kurtosis, alglib::xdefault);
11
+
12
+ result["mean"] = mean;
13
+ result["variance"] = variance;
14
+ result["skewness"] = skewness;
15
+ result["kurtosis"] = kurtosis;
16
+
17
+ return result;
18
+ }
19
+
20
+ double rb_samplemean(Array x)
21
+ {
22
+ auto a = ruby_array_to_real_1d_array(x);
23
+ return alglib::samplemean(a, x.size());
24
+ }
25
+
26
+ double rb_samplevariance(Array x)
27
+ {
28
+ auto a = ruby_array_to_real_1d_array(x);
29
+ return alglib::samplevariance(a, x.size());
30
+ }
31
+
32
+ double rb_sampleskewness(Array x)
33
+ {
34
+ auto a = ruby_array_to_real_1d_array(x);
35
+ return alglib::sampleskewness(a, x.size());
36
+ }
37
+
38
+ double rb_samplekurtosis(Array x)
39
+ {
40
+ auto a = ruby_array_to_real_1d_array(x);
41
+ return alglib::samplekurtosis(a, x.size());
42
+ }
43
+
44
+ double rb_sampleadev(Array x)
45
+ {
46
+ auto a = ruby_array_to_real_1d_array(x);
47
+ double adev;
48
+ alglib::sampleadev(a, x.size(), adev);
49
+ return adev;
50
+ }
51
+
52
+ double rb_samplemedian(Array x)
53
+ {
54
+ auto a = ruby_array_to_real_1d_array(x);
55
+ double median;
56
+ alglib::samplemedian(a, x.size(), median);
57
+ return median;
58
+ }
59
+
60
+ double rb_samplepercentile(Array x, double p)
61
+ {
62
+ auto a = ruby_array_to_real_1d_array(x);
63
+ double v;
64
+ alglib::samplepercentile(a, x.size(), p, v);
65
+ return v;
66
+ }
67
+
68
+ double rb_cov2(Array x, Array y)
69
+ {
70
+ check_size(x, y);
71
+ auto a = ruby_array_to_real_1d_array(x);
72
+ auto b = ruby_array_to_real_1d_array(y);
73
+ return alglib::cov2(a, b, x.size());
74
+ }
75
+
76
+ double rb_pearsoncorr2(Array x, Array y)
77
+ {
78
+ check_size(x, y);
79
+ auto a = ruby_array_to_real_1d_array(x);
80
+ auto b = ruby_array_to_real_1d_array(y);
81
+ return alglib::pearsoncorr2(a, b, x.size());
82
+ }
83
+
84
+ double rb_spearmancorr2(Array x, Array y)
85
+ {
86
+ check_size(x, y);
87
+ auto a = ruby_array_to_real_1d_array(x);
88
+ auto b = ruby_array_to_real_1d_array(y);
89
+ return alglib::spearmancorr2(a, b, x.size());
90
+ }
91
+
92
+ // 2D array/matrix statistical functions
93
+
94
+ // Covariance matrix
95
+ Array rb_covm(Array x)
96
+ {
97
+ auto a = ruby_array_to_real_2d_array(x);
98
+ int n = a.rows();
99
+ int m = a.cols();
100
+ alglib::real_2d_array c;
101
+ c.setlength(m, m);
102
+ alglib::covm(a, n, m, c, alglib::xdefault);
103
+ return real_2d_array_to_ruby_array(c);
104
+ }
105
+
106
+ Array rb_covm_with_size(Array x, int n, int m)
107
+ {
108
+ auto a = ruby_array_to_real_2d_array(x);
109
+ alglib::real_2d_array c;
110
+ c.setlength(m, m);
111
+ alglib::covm(a, n, m, c, alglib::xdefault);
112
+ return real_2d_array_to_ruby_array(c);
113
+ }
114
+
115
+ // Pearson correlation matrix
116
+ Array rb_pearsoncorrm(Array x)
117
+ {
118
+ auto a = ruby_array_to_real_2d_array(x);
119
+ int n = a.rows();
120
+ int m = a.cols();
121
+ alglib::real_2d_array c;
122
+ c.setlength(m, m);
123
+ alglib::pearsoncorrm(a, n, m, c, alglib::xdefault);
124
+ return real_2d_array_to_ruby_array(c);
125
+ }
126
+
127
+ Array rb_pearsoncorrm_with_size(Array x, int n, int m)
128
+ {
129
+ auto a = ruby_array_to_real_2d_array(x);
130
+ alglib::real_2d_array c;
131
+ c.setlength(m, m);
132
+ alglib::pearsoncorrm(a, n, m, c, alglib::xdefault);
133
+ return real_2d_array_to_ruby_array(c);
134
+ }
135
+
136
+ // Spearman correlation matrix
137
+ Array rb_spearmancorrm(Array x)
138
+ {
139
+ auto a = ruby_array_to_real_2d_array(x);
140
+ int n = a.rows();
141
+ int m = a.cols();
142
+ alglib::real_2d_array c;
143
+ c.setlength(m, m);
144
+ alglib::spearmancorrm(a, n, m, c, alglib::xdefault);
145
+ return real_2d_array_to_ruby_array(c);
146
+ }
147
+
148
+ Array rb_spearmancorrm_with_size(Array x, int n, int m)
149
+ {
150
+ auto a = ruby_array_to_real_2d_array(x);
151
+ alglib::real_2d_array c;
152
+ c.setlength(m, m);
153
+ alglib::spearmancorrm(a, n, m, c, alglib::xdefault);
154
+ return real_2d_array_to_ruby_array(c);
155
+ }
156
+
157
+ // Cross-covariance matrix
158
+ Array rb_covm2(Array x, Array y)
159
+ {
160
+ auto a = ruby_array_to_real_2d_array(x);
161
+ auto b = ruby_array_to_real_2d_array(y);
162
+ int n = a.rows();
163
+ int m1 = a.cols();
164
+ int m2 = b.cols();
165
+ alglib::real_2d_array c;
166
+ c.setlength(m1, m2);
167
+ alglib::covm2(a, b, n, m1, m2, c, alglib::xdefault);
168
+ return real_2d_array_to_ruby_array(c);
169
+ }
170
+
171
+ Array rb_covm2_with_size(Array x, Array y, int n, int m1, int m2)
172
+ {
173
+ auto a = ruby_array_to_real_2d_array(x);
174
+ auto b = ruby_array_to_real_2d_array(y);
175
+ alglib::real_2d_array c;
176
+ c.setlength(m1, m2);
177
+ alglib::covm2(a, b, n, m1, m2, c, alglib::xdefault);
178
+ return real_2d_array_to_ruby_array(c);
179
+ }
180
+
181
+ // Pearson cross-correlation matrix
182
+ Array rb_pearsoncorrm2(Array x, Array y)
183
+ {
184
+ auto a = ruby_array_to_real_2d_array(x);
185
+ auto b = ruby_array_to_real_2d_array(y);
186
+ int n = a.rows();
187
+ int m1 = a.cols();
188
+ int m2 = b.cols();
189
+ alglib::real_2d_array c;
190
+ c.setlength(m1, m2);
191
+ alglib::pearsoncorrm2(a, b, n, m1, m2, c, alglib::xdefault);
192
+ return real_2d_array_to_ruby_array(c);
193
+ }
194
+
195
+ Array rb_pearsoncorrm2_with_size(Array x, Array y, int n, int m1, int m2)
196
+ {
197
+ auto a = ruby_array_to_real_2d_array(x);
198
+ auto b = ruby_array_to_real_2d_array(y);
199
+ alglib::real_2d_array c;
200
+ c.setlength(m1, m2);
201
+ alglib::pearsoncorrm2(a, b, n, m1, m2, c, alglib::xdefault);
202
+ return real_2d_array_to_ruby_array(c);
203
+ }
204
+
205
+ // Spearman cross-correlation matrix
206
+ Array rb_spearmancorrm2(Array x, Array y)
207
+ {
208
+ auto a = ruby_array_to_real_2d_array(x);
209
+ auto b = ruby_array_to_real_2d_array(y);
210
+ int n = a.rows();
211
+ int m1 = a.cols();
212
+ int m2 = b.cols();
213
+ alglib::real_2d_array c;
214
+ c.setlength(m1, m2);
215
+ alglib::spearmancorrm2(a, b, n, m1, m2, c, alglib::xdefault);
216
+ return real_2d_array_to_ruby_array(c);
217
+ }
218
+
219
+ Array rb_spearmancorrm2_with_size(Array x, Array y, int n, int m1, int m2)
220
+ {
221
+ auto a = ruby_array_to_real_2d_array(x);
222
+ auto b = ruby_array_to_real_2d_array(y);
223
+ alglib::real_2d_array c;
224
+ c.setlength(m1, m2);
225
+ alglib::spearmancorrm2(a, b, n, m1, m2, c, alglib::xdefault);
226
+ return real_2d_array_to_ruby_array(c);
227
+ }
228
+
229
+ Array rb_rankdata(Array xy)
230
+ {
231
+ auto a = ruby_array_to_real_2d_array(xy);
232
+ int npoints = a.rows();
233
+ int nfeatures = a.cols();
234
+ alglib::rankdata(a, npoints, nfeatures, alglib::xdefault);
235
+ return real_2d_array_to_ruby_array(a);
236
+ }
237
+
238
+ Array rb_rankdata_with_size(Array xy, int npoints, int nfeatures)
239
+ {
240
+ auto a = ruby_array_to_real_2d_array(xy);
241
+ alglib::rankdata(a, npoints, nfeatures, alglib::xdefault);
242
+ return real_2d_array_to_ruby_array(a);
243
+ }
244
+
245
+ Array rb_rankdatacentered(Array xy)
246
+ {
247
+ auto a = ruby_array_to_real_2d_array(xy);
248
+ int npoints = a.rows();
249
+ int nfeatures = a.cols();
250
+ alglib::rankdatacentered(a, npoints, nfeatures, alglib::xdefault);
251
+ return real_2d_array_to_ruby_array(a);
252
+ }
253
+
254
+ Array rb_rankdatacentered_with_size(Array xy, int npoints, int nfeatures)
255
+ {
256
+ auto a = ruby_array_to_real_2d_array(xy);
257
+ alglib::rankdatacentered(a, npoints, nfeatures, alglib::xdefault);
258
+ return real_2d_array_to_ruby_array(a);
259
+ }
260
+
261
+ // Helper function to generic statistical tests
262
+ template <typename Func, typename... Args>
263
+ Hash perform_test(Func test, Args... args)
264
+ {
265
+ Hash result;
266
+ double bothtails, lefttail, righttail;
267
+ test(args..., bothtails, lefttail, righttail, alglib::xdefault);
268
+ result["bothtails"] = bothtails;
269
+ result["lefttail"] = lefttail;
270
+ result["righttail"] = righttail;
271
+ return result;
272
+ }
273
+
274
+ Hash rb_pearsoncorrelationsignificance(double r, alglib::ae_int_t n)
275
+ {
276
+ return perform_test(alglib::pearsoncorrelationsignificance, r, n);
277
+ }
278
+
279
+ Hash rb_spearmanrankcorrelationsignificance(double r, alglib::ae_int_t n)
280
+ {
281
+ return perform_test(alglib::spearmanrankcorrelationsignificance, r, n);
282
+ }
283
+
284
+ Hash rb_jarqueberatest(Array x)
285
+ {
286
+ Hash result;
287
+ auto a = ruby_array_to_real_1d_array(x);
288
+ double p;
289
+ alglib::jarqueberatest(a, x.size(), p);
290
+ result["p"] = p;
291
+ return result;
292
+ }
293
+
294
+ Hash rb_ftest(Array x, Array y)
295
+ {
296
+ auto a = ruby_array_to_real_1d_array(x);
297
+ auto b = ruby_array_to_real_1d_array(y);
298
+ return perform_test(alglib::ftest, a, x.size(), b, y.size());
299
+ }
300
+
301
+ Hash rb_onesamplevariancetest(Array x, double variance)
302
+ {
303
+ auto a = ruby_array_to_real_1d_array(x);
304
+ return perform_test(alglib::onesamplevariancetest, a, x.size(), variance);
305
+ }
306
+
307
+ Hash rb_wilcoxonsignedranktest(Array x, double e)
308
+ {
309
+ auto a = ruby_array_to_real_1d_array(x);
310
+ return perform_test(alglib::wilcoxonsignedranktest, a, x.size(), e);
311
+ }
312
+
313
+ Hash rb_mannwhitneyutest(Array x, Array y)
314
+ {
315
+ auto a = ruby_array_to_real_1d_array(x);
316
+ auto b = ruby_array_to_real_1d_array(y);
317
+ return perform_test(alglib::mannwhitneyutest, a, x.size(), b, y.size());
318
+ }
319
+
320
+ Hash rb_studentttest1(Array x, double mean)
321
+ {
322
+ auto a = ruby_array_to_real_1d_array(x);
323
+ return perform_test(alglib::studentttest1, a, x.size(), mean);
324
+ }
325
+
326
+ Hash rb_studentttest2(Array x, Array y)
327
+ {
328
+ auto a = ruby_array_to_real_1d_array(x);
329
+ auto b = ruby_array_to_real_1d_array(y);
330
+ return perform_test(alglib::studentttest2, a, x.size(), b, y.size());
331
+ }
332
+
333
+ Hash rb_unequalvariancettest(Array x, Array y)
334
+ {
335
+ auto a = ruby_array_to_real_1d_array(x);
336
+ auto b = ruby_array_to_real_1d_array(y);
337
+ return perform_test(alglib::unequalvariancettest, a, x.size(), b, y.size());
338
+ }
@@ -0,0 +1,48 @@
1
+ #include <rice/rice.hpp>
2
+ #include <rice/stl.hpp>
3
+ #include "statistics.h"
4
+ #include "alglib_converters.h"
5
+ #include "alglib_utils.h"
6
+
7
+ using namespace Rice;
8
+
9
+ Hash rb_samplemoments(Array x);
10
+ double rb_samplemean(Array x);
11
+ double rb_samplevariance(Array x);
12
+ double rb_sampleskewness(Array x);
13
+ double rb_samplekurtosis(Array x);
14
+ double rb_sampleadev(Array x);
15
+ double rb_samplemedian(Array x);
16
+ double rb_samplepercentile(Array x, double p);
17
+ double rb_cov2(Array x, Array y);
18
+ double rb_pearsoncorr2(Array x, Array y);
19
+ double rb_spearmancorr2(Array x, Array y);
20
+
21
+ // 2D array/matrix statistical functions
22
+ Array rb_covm(Array x);
23
+ Array rb_covm_with_size(Array x, int n, int m);
24
+ Array rb_pearsoncorrm(Array x);
25
+ Array rb_pearsoncorrm_with_size(Array x, int n, int m);
26
+ Array rb_spearmancorrm(Array x);
27
+ Array rb_spearmancorrm_with_size(Array x, int n, int m);
28
+ Array rb_covm2(Array x, Array y);
29
+ Array rb_covm2_with_size(Array x, Array y, int n, int m1, int m2);
30
+ Array rb_pearsoncorrm2(Array x, Array y);
31
+ Array rb_pearsoncorrm2_with_size(Array x, Array y, int n, int m1, int m2);
32
+ Array rb_spearmancorrm2(Array x, Array y);
33
+ Array rb_spearmancorrm2_with_size(Array x, Array y, int n, int m1, int m2);
34
+ Array rb_rankdata(Array xy);
35
+ Array rb_rankdata_with_size(Array xy, int npoints, int nfeatures);
36
+ Array rb_rankdatacentered(Array xy);
37
+ Array rb_rankdatacentered_with_size(Array xy, int npoints, int nfeatures);
38
+
39
+ Hash rb_pearsoncorrelationsignificance(double r, alglib::ae_int_t n);
40
+ Hash rb_spearmanrankcorrelationsignificance(double r, alglib::ae_int_t n);
41
+ Hash rb_jarqueberatest(Array x);
42
+ Hash rb_ftest(Array x, Array y);
43
+ Hash rb_onesamplevariancetest(Array x, double variance);
44
+ Hash rb_wilcoxonsignedranktest(Array x, double e);
45
+ Hash rb_mannwhitneyutest(Array x, Array y);
46
+ Hash rb_studentttest1(Array x, double mean);
47
+ Hash rb_studentttest2(Array x, Array y);
48
+ Hash rb_unequalvariancettest(Array x, Array y);
@@ -1,3 +1,3 @@
1
1
  module Alglib
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alglib4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rice
@@ -33,8 +33,17 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - README.md
35
35
  - ext/alglib/alglib.cpp
36
- - ext/alglib/alglib_array_converters.cpp
37
- - ext/alglib/alglib_array_converters.h
36
+ - ext/alglib/alglib.h
37
+ - ext/alglib/alglib_alglibmisc.cpp
38
+ - ext/alglib/alglib_alglibmisc.h
39
+ - ext/alglib/alglib_converters.cpp
40
+ - ext/alglib/alglib_converters.h
41
+ - ext/alglib/alglib_dataanalysis.cpp
42
+ - ext/alglib/alglib_dataanalysis.h
43
+ - ext/alglib/alglib_specialfunctions.cpp
44
+ - ext/alglib/alglib_specialfunctions.h
45
+ - ext/alglib/alglib_statistics.cpp
46
+ - ext/alglib/alglib_statistics.h
38
47
  - ext/alglib/alglib_utils.cpp
39
48
  - ext/alglib/alglib_utils.h
40
49
  - ext/alglib/alglibinternal.cpp
@@ -95,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
104
  - !ruby/object:Gem::Version
96
105
  version: '0'
97
106
  requirements: []
98
- rubygems_version: 3.6.2
107
+ rubygems_version: 3.6.7
99
108
  specification_version: 4
100
109
  summary: ALGLIB for Ruby
101
110
  test_files: []
@@ -1,86 +0,0 @@
1
- #include "alglib_array_converters.h"
2
-
3
- alglib::real_1d_array ruby_array_to_real_1d_array(Array ruby_array)
4
- {
5
- alglib::real_1d_array real_array;
6
- real_array.setlength(ruby_array.size());
7
- for (size_t i = 0; i < ruby_array.size(); i++)
8
- {
9
- real_array[i] = detail::From_Ruby<double>().convert(ruby_array[i].value());
10
- }
11
- return real_array;
12
- }
13
-
14
- alglib::integer_1d_array ruby_array_to_integer_1d_array(Array ruby_array)
15
- {
16
- alglib::integer_1d_array integer_array;
17
- integer_array.setlength(ruby_array.size());
18
- for (size_t i = 0; i < ruby_array.size(); i++)
19
- {
20
- integer_array[i] = detail::From_Ruby<int>().convert(ruby_array[i].value());
21
- }
22
- return integer_array;
23
- }
24
-
25
- Array real_1d_array_to_ruby_array(const alglib::real_1d_array &arr)
26
- {
27
- Array ruby_array;
28
- for (int i = 0; i < arr.length(); ++i)
29
- {
30
- ruby_array.push(arr[i]);
31
- }
32
- return ruby_array;
33
- }
34
-
35
- Array integer_1d_array_to_ruby_array(const alglib::integer_1d_array &arr)
36
- {
37
- Array ruby_array;
38
- for (int i = 0; i < arr.length(); ++i)
39
- {
40
- ruby_array.push(arr[i]);
41
- }
42
- return ruby_array;
43
- }
44
-
45
- alglib::real_2d_array ruby_array_to_real_2d_array(Array ruby_array)
46
- {
47
- if (ruby_array.size() == 0)
48
- {
49
- throw std::invalid_argument("Input array is empty");
50
- }
51
-
52
- int rows = ruby_array.size();
53
- int cols = detail::From_Ruby<Array>().convert(ruby_array.call("first")).size();
54
-
55
- alglib::real_2d_array real_array;
56
- real_array.setlength(rows, cols);
57
-
58
- for (int i = 0; i < rows; ++i)
59
- {
60
- Array row = detail::From_Ruby<Array>().convert(ruby_array[i].value());
61
- if (row.size() != cols)
62
- {
63
- throw std::invalid_argument("All rows must have the same size");
64
- }
65
- for (int j = 0; j < cols; ++j)
66
- {
67
- real_array[i][j] = detail::From_Ruby<double>().convert(row[j].value());
68
- }
69
- }
70
- return real_array;
71
- }
72
-
73
- Array real_2d_array_to_ruby_array(const alglib::real_2d_array &real_array)
74
- {
75
- Array result;
76
- for (int i = 0; i < real_array.rows(); i++)
77
- {
78
- Array row;
79
- for (int j = 0; j < real_array.cols(); j++)
80
- {
81
- row.push(real_array[i][j]);
82
- }
83
- result.push(row);
84
- }
85
- return result;
86
- }
@@ -1,15 +0,0 @@
1
- #include <rice/rice.hpp>
2
- #include <rice/stl.hpp>
3
- #include "ap.h"
4
-
5
- using namespace Rice;
6
-
7
- extern "C"
8
- {
9
- alglib::real_1d_array ruby_array_to_real_1d_array(Array ruby_array);
10
- alglib::integer_1d_array ruby_array_to_integer_1d_array(Array ruby_array);
11
- alglib::real_2d_array ruby_array_to_real_2d_array(Array ruby_array);
12
- Array real_1d_array_to_ruby_array(const alglib::real_1d_array &arr);
13
- Array real_2d_array_to_ruby_array(const alglib::real_2d_array &real_array);
14
- Array integer_1d_array_to_ruby_array(const alglib::integer_1d_array &arr);
15
- }