alglib4 0.0.0

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +47 -0
  3. data/ext/alglib/alglib.cpp +537 -0
  4. data/ext/alglib/alglib_array_converters.cpp +86 -0
  5. data/ext/alglib/alglib_array_converters.h +15 -0
  6. data/ext/alglib/alglib_utils.cpp +10 -0
  7. data/ext/alglib/alglib_utils.h +6 -0
  8. data/ext/alglib/alglibinternal.cpp +21749 -0
  9. data/ext/alglib/alglibinternal.h +2168 -0
  10. data/ext/alglib/alglibmisc.cpp +9106 -0
  11. data/ext/alglib/alglibmisc.h +2114 -0
  12. data/ext/alglib/ap.cpp +20094 -0
  13. data/ext/alglib/ap.h +7244 -0
  14. data/ext/alglib/dataanalysis.cpp +52588 -0
  15. data/ext/alglib/dataanalysis.h +10601 -0
  16. data/ext/alglib/diffequations.cpp +1342 -0
  17. data/ext/alglib/diffequations.h +282 -0
  18. data/ext/alglib/extconf.rb +5 -0
  19. data/ext/alglib/fasttransforms.cpp +4696 -0
  20. data/ext/alglib/fasttransforms.h +1018 -0
  21. data/ext/alglib/integration.cpp +4249 -0
  22. data/ext/alglib/integration.h +869 -0
  23. data/ext/alglib/interpolation.cpp +74502 -0
  24. data/ext/alglib/interpolation.h +12264 -0
  25. data/ext/alglib/kernels_avx2.cpp +2171 -0
  26. data/ext/alglib/kernels_avx2.h +201 -0
  27. data/ext/alglib/kernels_fma.cpp +1065 -0
  28. data/ext/alglib/kernels_fma.h +137 -0
  29. data/ext/alglib/kernels_sse2.cpp +735 -0
  30. data/ext/alglib/kernels_sse2.h +100 -0
  31. data/ext/alglib/linalg.cpp +65182 -0
  32. data/ext/alglib/linalg.h +9927 -0
  33. data/ext/alglib/optimization.cpp +135331 -0
  34. data/ext/alglib/optimization.h +19235 -0
  35. data/ext/alglib/solvers.cpp +20488 -0
  36. data/ext/alglib/solvers.h +4781 -0
  37. data/ext/alglib/specialfunctions.cpp +10672 -0
  38. data/ext/alglib/specialfunctions.h +2305 -0
  39. data/ext/alglib/statistics.cpp +19791 -0
  40. data/ext/alglib/statistics.h +1359 -0
  41. data/ext/alglib/stdafx.h +2 -0
  42. data/gpl2.txt +339 -0
  43. data/gpl3.txt +674 -0
  44. data/lib/alglib/version.rb +3 -0
  45. data/lib/alglib.rb +4 -0
  46. metadata +101 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a3aee870b0d2e9667bd0e978a055f39ea975a4fb2fdba253139a4704a3569c25
4
+ data.tar.gz: c9beecf884b47e975e95eae558c068b5b8bd5485a35ed7515ffeacbde65e7486
5
+ SHA512:
6
+ metadata.gz: 52719d634e362bd7309fa56dcb383862f51197442f076a678980d9d7ed91a191fabf5804e1f9a453debf2001d703512e1ea1cc58a08a61e28d518222fc1fc963
7
+ data.tar.gz: 2fc1f983cf849ff546089d17ddde8ba9dc69713602308e7bc8f121c5bbd33422f4947eafd3a2e464adbdc9edfbc1afa02a235428ef1ec202644a2dd7718207ff
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # ruby-alglib
2
+
3
+ [![test](https://github.com/kojix2/ruby-alglib/actions/workflows/ci.yml/badge.svg)](https://github.com/kojix2/ruby-alglib/actions/workflows/ci.yml)
4
+
5
+ - `statistics.h` of [ALGLIB](https://www.alglib.net/) for Ruby.
6
+ - ALGLIB is a numerical analysis and data processing library. This repository provides bindings primarily for statistics.
7
+
8
+ ## Installation
9
+
10
+ From source code:
11
+
12
+ ```sh
13
+ git clone https://github.com/kojix2/ruby-alglib
14
+ cd ruby-alglib
15
+ bundle install
16
+ rake ext:alglib # Download ALGLIB Free Edition from https://www.alglib.net/ and extract to ext/alglib.
17
+ rake compile
18
+ rake install
19
+ ```
20
+
21
+ - Note that the license of ALGLIB Free Edition is GPL or Personal/Academic license.
22
+ - If you want to use ALGLIB in a commercial application, you will need to purchase a commercial license.
23
+ - [Can I use ALGLIB Free Edition in a commercial application which runs on server?](https://www.alglib.net/faq.php#6bca163136cda10b16de68704cbea625)
24
+ - You can also use the Commercial Edition of ALGLIB. In that case, you need to replace the files in `ext/alglib` with the files in the Commercial Edition.
25
+ - Windows is not supported.
26
+
27
+ ## Usage
28
+
29
+ `sample_moments` `sample_mean` `sample_variance` `sample_skewness` `sample_kurtosis` `sample_adev` `sample_median` `sample_percentile` `cov2` `pearson_corr2` `spearman_corr2` `pearson_correlation_significance` `spearman_rank_correlation_significance` `jarque_bera_test` `f_test` `one_sample_variance_test` `wilcoxon_signed_rank_test` `mann_whitney_u_test` `student_test_1` `student_test_2` `unequal_variance_t_test`
30
+
31
+ ## Development
32
+
33
+ Not-To-Do List
34
+
35
+ - Creating namespaces under Alglib. (e.g. Alglib::Statistics)
36
+ - Trying to implement all functions even if you do not plan to use them.
37
+ - Adding features that will require frequent maintenance.
38
+ - Enforcing the above policies on forked repos.
39
+
40
+ ## License
41
+
42
+ - ruby-alglib itself is distributed under the **MIT** license.
43
+ - However, [ALGLIB for C++ Free Edition](https://www.alglib.net/download.php) is under the **GPL+** license.
44
+ - Please read [FAQ](https://www.alglib.net/faq.php) carefully before you use ALGLIB to understand what is allowed in the free version.
45
+ - [Can I use ALGLIB Free Edition in a commercial application which runs on server?](https://www.alglib.net/faq.php#6bca163136cda10b16de68704cbea625)
46
+ > You can, but there is at least one reason to buy commercial license. Everything is OK while it is just running on your server. But any action connected with distribution - selling, sublicensing, transferring to someone under nondisclosure agreement - will trigger copyleft clause. So it is safer and more convenient to buy commercial license.
47
+ - Theoretically, ruby-alglib should work with the commercial version. That is why it is MIT. But we have not verified this.
@@ -0,0 +1,537 @@
1
+ #include <rice/rice.hpp>
2
+ #include <rice/stl.hpp>
3
+ #include <algorithm>
4
+ // #include "numo.hpp"
5
+ #include "dataanalysis.h"
6
+ #include "statistics.h"
7
+ #include "alglib_array_converters.h"
8
+ #include "alglib_utils.h"
9
+
10
+ using namespace Rice;
11
+
12
+ // pca subpackage
13
+
14
+ // void pcabuildbasis(const real_2d_array &x, real_1d_array &s2, real_2d_array &v, const xparams _xparams = alglib::xdefault);
15
+ Hash rb_pcabuildbasis(Array x)
16
+ {
17
+ Hash result;
18
+ auto a = ruby_array_to_real_2d_array(x);
19
+ alglib::real_1d_array s2;
20
+ alglib::real_2d_array v;
21
+ alglib::pcabuildbasis(a, s2, v, alglib::xdefault);
22
+ result["s2"] = real_1d_array_to_ruby_array(s2);
23
+ result["v"] = real_2d_array_to_ruby_array(v);
24
+ return result;
25
+ }
26
+
27
+ // statistics package
28
+
29
+ // void samplemoments(const real_1d_array &x, const ae_int_t n, double &mean, double &variance, double &skewness, double &kurtosis, const xparams _xparams = alglib::xdefault);
30
+ Hash rb_samplemoments(Array x)
31
+ {
32
+ Hash result;
33
+ auto a = ruby_array_to_real_1d_array(x);
34
+ double mean, variance, skewness, kurtosis;
35
+
36
+ alglib::samplemoments(a, x.size(), mean, variance, skewness, kurtosis, alglib::xdefault);
37
+
38
+ result["mean"] = mean;
39
+ result["variance"] = variance;
40
+ result["skewness"] = skewness;
41
+ result["kurtosis"] = kurtosis;
42
+
43
+ return result;
44
+ }
45
+
46
+ // double samplemean(const real_1d_array &x, const ae_int_t n, const xparams _xparams = alglib::xdefault);
47
+ double rb_samplemean(Array x)
48
+ {
49
+ auto a = ruby_array_to_real_1d_array(x);
50
+ return alglib::samplemean(a, x.size());
51
+ }
52
+
53
+ // double samplevariance(const real_1d_array &x, const ae_int_t n, const xparams _xparams = alglib::xdefault);
54
+ double rb_samplevariance(Array x)
55
+ {
56
+ auto a = ruby_array_to_real_1d_array(x);
57
+ return alglib::samplevariance(a, x.size());
58
+ }
59
+
60
+ // double sampleskewness(const real_1d_array &x, const ae_int_t n, const xparams _xparams = alglib::xdefault);
61
+ double rb_sampleskewness(Array x)
62
+ {
63
+ auto a = ruby_array_to_real_1d_array(x);
64
+ return alglib::sampleskewness(a, x.size());
65
+ }
66
+
67
+ // double samplekurtosis(const real_1d_array &x, const ae_int_t n, const xparams _xparams = alglib::xdefault);
68
+ double rb_samplekurtosis(Array x)
69
+ {
70
+ auto a = ruby_array_to_real_1d_array(x);
71
+ return alglib::samplekurtosis(a, x.size());
72
+ }
73
+
74
+ // void sampleadev(const real_1d_array &x, const ae_int_t n, double &adev, const xparams _xparams = alglib::xdefault);
75
+ double rb_sampleadev(Array x)
76
+ {
77
+ auto a = ruby_array_to_real_1d_array(x);
78
+ double adev;
79
+ alglib::sampleadev(a, x.size(), adev);
80
+ return adev;
81
+ }
82
+
83
+ // void samplemedian(const real_1d_array &x, const ae_int_t n, double &median, const xparams _xparams = alglib::xdefault);
84
+ double rb_samplemedian(Array x)
85
+ {
86
+ auto a = ruby_array_to_real_1d_array(x);
87
+ double median;
88
+ alglib::samplemedian(a, x.size(), median);
89
+ return median;
90
+ }
91
+
92
+ // void samplepercentile(const real_1d_array &x, const ae_int_t n, const double p, double &v, const xparams _xparams = alglib::xdefault);
93
+ double rb_samplepercentile(Array x, double p)
94
+ {
95
+ auto a = ruby_array_to_real_1d_array(x);
96
+ double v;
97
+ alglib::samplepercentile(a, x.size(), p, v);
98
+ return v;
99
+ }
100
+
101
+ // double cov2(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const xparams _xparams = alglib::xdefault);
102
+ double rb_cov2(Array x, Array y)
103
+ {
104
+ check_size(x, y);
105
+ auto a = ruby_array_to_real_1d_array(x);
106
+ auto b = ruby_array_to_real_1d_array(y);
107
+ return alglib::cov2(a, b, x.size());
108
+ }
109
+
110
+ // double pearsoncorr2(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const xparams _xparams = alglib::xdefault);
111
+ double rb_pearsoncorr2(Array x, Array y)
112
+ {
113
+ check_size(x, y);
114
+ auto a = ruby_array_to_real_1d_array(x);
115
+ auto b = ruby_array_to_real_1d_array(y);
116
+ return alglib::pearsoncorr2(a, b, x.size());
117
+ }
118
+
119
+ // double spearmancorr2(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const xparams _xparams = alglib::xdefault);
120
+ double rb_spearmancorr2(Array x, Array y)
121
+ {
122
+ check_size(x, y);
123
+ auto a = ruby_array_to_real_1d_array(x);
124
+ auto b = ruby_array_to_real_1d_array(y);
125
+ return alglib::spearmancorr2(a, b, x.size());
126
+ }
127
+
128
+ // void covm(const real_2d_array &x, const ae_int_t n, const ae_int_t m, real_2d_array &c, const xparams _xparams = alglib::xdefault);
129
+
130
+ // void pearsoncorrm(const real_2d_array &x, const ae_int_t n, const ae_int_t m, real_2d_array &c, const xparams _xparams = alglib::xdefault);
131
+
132
+ // void spearmancorrm(const real_2d_array &x, const ae_int_t n, const ae_int_t m, real_2d_array &c, const xparams _xparams = alglib::xdefault);
133
+
134
+ // void covm2(const real_2d_array &x, const real_2d_array &y, const ae_int_t n, const ae_int_t m1, const ae_int_t m2, real_2d_array &c, const xparams _xparams = alglib::xdefault);
135
+
136
+ // void pearsoncorrm2(const real_2d_array &x, const real_2d_array &y, const ae_int_t n, const ae_int_t m1, const ae_int_t m2, real_2d_array &c, const xparams _xparams = alglib::xdefault);
137
+
138
+ // void spearmancorrm2(const real_2d_array &x, const real_2d_array &y, const ae_int_t n, const ae_int_t m1, const ae_int_t m2, real_2d_array &c, const xparams _xparams = alglib::xdefault);
139
+
140
+ // void rankdata(real_2d_array &xy, const ae_int_t npoints, const ae_int_t nfeatures, const xparams _xparams = alglib::xdefault);
141
+
142
+ // void rankdatacentered(real_2d_array &xy, const ae_int_t npoints, const ae_int_t nfeatures, const xparams _xparams = alglib::xdefault);
143
+
144
+ // Helper function to generic statistical tests
145
+ template <typename Func, typename... Args>
146
+ Hash perform_test(Func test, Args... args)
147
+ {
148
+ Hash result;
149
+ double bothtails, lefttail, righttail;
150
+ test(args..., bothtails, lefttail, righttail, alglib::xdefault);
151
+ result["bothtails"] = bothtails;
152
+ result["lefttail"] = lefttail;
153
+ result["righttail"] = righttail;
154
+ return result;
155
+ }
156
+
157
+ // void pearsoncorrelationsignificance(const double r, const ae_int_t n, double &bothtails, double &lefttail, double &righttail, const xparams _xparams = alglib::xdefault);
158
+ Hash rb_pearsoncorrelationsignificance(double r, alglib::ae_int_t n)
159
+ {
160
+ return perform_test(alglib::pearsoncorrelationsignificance, r, n);
161
+ }
162
+
163
+ // void spearmanrankcorrelationsignificance(const double r, const ae_int_t n, double &bothtails, double &lefttail, double &righttail, const xparams _xparams = alglib::xdefault);
164
+ Hash rb_spearmanrankcorrelationsignificance(double r, alglib::ae_int_t n)
165
+ {
166
+ return perform_test(alglib::spearmanrankcorrelationsignificance, r, n);
167
+ }
168
+
169
+ Hash rb_jarqueberatest(Array x)
170
+ {
171
+ Hash result;
172
+ auto a = ruby_array_to_real_1d_array(x);
173
+ double p;
174
+ alglib::jarqueberatest(a, x.size(), p);
175
+ result["p"] = p;
176
+ return result;
177
+ }
178
+
179
+ Hash rb_ftest(Array x, Array y)
180
+ {
181
+ auto a = ruby_array_to_real_1d_array(x);
182
+ auto b = ruby_array_to_real_1d_array(y);
183
+ return perform_test(alglib::ftest, a, x.size(), b, y.size());
184
+ }
185
+
186
+ Hash rb_onesamplevariancetest(Array x, double variance)
187
+ {
188
+ auto a = ruby_array_to_real_1d_array(x);
189
+ return perform_test(alglib::onesamplevariancetest, a, x.size(), variance);
190
+ }
191
+
192
+ Hash rb_wilcoxonsignedranktest(Array x, double e)
193
+ {
194
+ auto a = ruby_array_to_real_1d_array(x);
195
+ return perform_test(alglib::wilcoxonsignedranktest, a, x.size(), e);
196
+ }
197
+
198
+ Hash rb_mannwhitneyutest(Array x, Array y)
199
+ {
200
+ auto a = ruby_array_to_real_1d_array(x);
201
+ auto b = ruby_array_to_real_1d_array(y);
202
+ return perform_test(alglib::mannwhitneyutest, a, x.size(), b, y.size());
203
+ }
204
+
205
+ Hash rb_studentttest1(Array x, double mean)
206
+ {
207
+ auto a = ruby_array_to_real_1d_array(x);
208
+ return perform_test(alglib::studentttest1, a, x.size(), mean);
209
+ }
210
+
211
+ Hash rb_studentttest2(Array x, Array y)
212
+ {
213
+ auto a = ruby_array_to_real_1d_array(x);
214
+ auto b = ruby_array_to_real_1d_array(y);
215
+ return perform_test(alglib::studentttest2, a, x.size(), b, y.size());
216
+ }
217
+
218
+ Hash rb_unequalvariancettest(Array x, Array y)
219
+ {
220
+ auto a = ruby_array_to_real_1d_array(x);
221
+ auto b = ruby_array_to_real_1d_array(y);
222
+ return perform_test(alglib::unequalvariancettest, a, x.size(), b, y.size());
223
+ }
224
+
225
+ // specialfunctions.h
226
+
227
+ // double gammafunction(const double x, const xparams _xparams = alglib::xdefault);
228
+ double rb_gammafunction(double x)
229
+ {
230
+ return alglib::gammafunction(x);
231
+ }
232
+
233
+ // double lngamma(const double x, double &sgngam, const xparams _xparams = alglib::xdefault);
234
+ Array rb_lngamma(double x)
235
+ {
236
+ Array result = Array(rb_ary_new2(2));
237
+ double sgngam;
238
+ result.push(alglib::lngamma(x, sgngam));
239
+ result.push(sgngam);
240
+ return result;
241
+ }
242
+
243
+ // double errorfunction(const double x, const xparams _xparams = alglib::xdefault);
244
+ double rb_errorfunction(double x)
245
+ {
246
+ return alglib::errorfunction(x);
247
+ }
248
+
249
+ // double errorfunctionc(const double x, const xparams _xparams = alglib::xdefault);
250
+ double rb_errorfunctionc(double x)
251
+ {
252
+ return alglib::errorfunctionc(x);
253
+ }
254
+
255
+ // double normalpdf(const double x, const xparams _xparams = alglib::xdefault);
256
+ double rb_normalpdf(double x)
257
+ {
258
+ return alglib::normalpdf(x);
259
+ }
260
+
261
+ // double normalcdf(const double x, const xparams _xparams = alglib::xdefault);
262
+ double rb_normalcdf(double x)
263
+ {
264
+ return alglib::normalcdf(x);
265
+ }
266
+
267
+ // double inverf(const double e, const xparams _xparams = alglib::xdefault);
268
+ double rb_inverf(double e)
269
+ {
270
+ return alglib::inverf(e);
271
+ }
272
+
273
+ // double invnormalcdf(const double y0, const xparams _xparams = alglib::xdefault);
274
+ double rb_invnormalcdf(double y0)
275
+ {
276
+ return alglib::invnormalcdf(y0);
277
+ }
278
+
279
+ // double bivariatenormalpdf(const double x, const double y, const double rho, const xparams _xparams = alglib::xdefault);
280
+ double rb_bivariatenormalpdf(double x, double y, double rho)
281
+ {
282
+ return alglib::bivariatenormalpdf(x, y, rho);
283
+ }
284
+
285
+ // double bivariatenormalcdf(const double x, const double y, const double rho, const xparams _xparams = alglib::xdefault);
286
+ double rb_bivariatenormalcdf(double x, double y, double rho)
287
+ {
288
+ return alglib::bivariatenormalcdf(x, y, rho);
289
+ }
290
+
291
+ // double incompletebeta(const double a, const double b, const double x, const xparams _xparams = alglib::xdefault);
292
+ double rb_incompletebeta(double a, double b, double x)
293
+ {
294
+ return alglib::incompletebeta(a, b, x);
295
+ }
296
+
297
+ // double invincompletebeta(const double a, const double b, const double y, const xparams _xparams = alglib::xdefault);
298
+ double rb_invincompletebeta(double a, double b, double y)
299
+ {
300
+ return alglib::invincompletebeta(a, b, y);
301
+ }
302
+
303
+ // double studenttdistribution(const ae_int_t k, const double t, const xparams _xparams = alglib::xdefault);
304
+ double rb_studenttdistribution(alglib::ae_int_t k, double t)
305
+ {
306
+ return alglib::studenttdistribution(k, t);
307
+ }
308
+
309
+ // double invstudenttdistribution(const ae_int_t k, const double p, const xparams _xparams = alglib::xdefault);
310
+ double rb_invstudenttdistribution(alglib::ae_int_t k, double p)
311
+ {
312
+ return alglib::invstudenttdistribution(k, p);
313
+ }
314
+
315
+ // double fdistribution(const ae_int_t a, const ae_int_t b, const double x, const xparams _xparams = alglib::xdefault);
316
+ double rb_fdistribution(alglib::ae_int_t a, alglib::ae_int_t b, double x)
317
+ {
318
+ return alglib::fdistribution(a, b, x);
319
+ }
320
+
321
+ // double fcdistribution(const ae_int_t a, const ae_int_t b, const double x, const xparams _xparams = alglib::xdefault);
322
+ double rb_fcdistribution(alglib::ae_int_t a, alglib::ae_int_t b, double x)
323
+ {
324
+ return alglib::fcdistribution(a, b, x);
325
+ }
326
+
327
+ // double invfdistribution(const ae_int_t a, const ae_int_t b, const double y, const xparams _xparams = alglib::xdefault);
328
+ double rb_invfdistribution(alglib::ae_int_t a, alglib::ae_int_t b, double y)
329
+ {
330
+ return alglib::invfdistribution(a, b, y);
331
+ }
332
+
333
+ // double incompletegamma(const double a, const double x, const xparams _xparams = alglib::xdefault);
334
+ double rb_incompletegamma(double a, double x)
335
+ {
336
+ return alglib::incompletegamma(a, x);
337
+ }
338
+
339
+ // double incompletegammac(const double a, const double x, const xparams _xparams = alglib::xdefault);
340
+ double rb_incompletegammac(double a, double x)
341
+ {
342
+ return alglib::incompletegammac(a, x);
343
+ }
344
+
345
+ // double invincompletegammac(const double a, const double y0, const xparams _xparams = alglib::xdefault);
346
+ double rb_invincompletegammac(double a, double y0)
347
+ {
348
+ return alglib::invincompletegammac(a, y0);
349
+ }
350
+
351
+ // double chisquaredistribution(const double v, const double x, const xparams _xparams = alglib::xdefault);
352
+ double rb_chisquaredistribution(double v, double x)
353
+ {
354
+ return alglib::chisquaredistribution(v, x);
355
+ }
356
+
357
+ // double chisquarecdistribution(const double v, const double x, const xparams _xparams = alglib::xdefault);
358
+ double rb_chisquarecdistribution(double v, double x)
359
+ {
360
+ return alglib::chisquarecdistribution(v, x);
361
+ }
362
+
363
+ // double invchisquaredistribution(const double v, const double y, const xparams _xparams = alglib::xdefault);
364
+ double rb_invchisquaredistribution(double v, double y)
365
+ {
366
+ return alglib::invchisquaredistribution(v, y);
367
+ }
368
+
369
+ // double binomialdistribution(const ae_int_t k, const ae_int_t n, const double p, const xparams _xparams = alglib::xdefault);
370
+ double rb_binomialdistribution(alglib::ae_int_t k, alglib::ae_int_t n, double p)
371
+ {
372
+ return alglib::binomialdistribution(k, n, p);
373
+ }
374
+
375
+ // double binomialcdistribution(const ae_int_t k, const ae_int_t n, const double p, const xparams _xparams = alglib::xdefault);
376
+ double rb_binomialcdistribution(alglib::ae_int_t k, alglib::ae_int_t n, double p)
377
+ {
378
+ return alglib::binomialcdistribution(k, n, p);
379
+ }
380
+
381
+ // double invbinomialdistribution(const ae_int_t k, const ae_int_t n, const double y, const xparams _xparams = alglib::xdefault);
382
+ double rb_invbinomialdistribution(alglib::ae_int_t k, alglib::ae_int_t n, double y)
383
+ {
384
+ return alglib::invbinomialdistribution(k, n, y);
385
+ }
386
+
387
+ // double exponentialintegralei(const double x, const xparams _xparams = alglib::xdefault);
388
+ double rb_exponentialintegralei(double x)
389
+ {
390
+ return alglib::exponentialintegralei(x);
391
+ }
392
+
393
+ // double exponentialintegralen(const double x, const ae_int_t n, const xparams _xparams = alglib::xdefault);
394
+ double rb_exponentialintegralen(double x, alglib::ae_int_t n)
395
+ {
396
+ return alglib::exponentialintegralen(x, n);
397
+ }
398
+
399
+ //
400
+
401
+ // double poissondistribution(const ae_int_t k, const double m, const xparams _xparams = alglib::xdefault);
402
+ double rb_poissondistribution(alglib::ae_int_t k, double m)
403
+ {
404
+ return alglib::poissondistribution(k, m);
405
+ }
406
+
407
+ // double poissoncdistribution(const ae_int_t k, const double m, const xparams _xparams = alglib::xdefault);
408
+ double rb_poissoncdistribution(alglib::ae_int_t k, double m)
409
+ {
410
+ return alglib::poissoncdistribution(k, m);
411
+ }
412
+
413
+ // double invpoissondistribution(const ae_int_t k, const double y, const xparams _xparams = alglib::xdefault);
414
+ double rb_invpoissondistribution(alglib::ae_int_t k, double y)
415
+ {
416
+ return alglib::invpoissondistribution(k, y);
417
+ }
418
+
419
+ // double beta(const double a, const double b, const xparams _xparams = alglib::xdefault);
420
+ double rb_beta(double a, double b)
421
+ {
422
+ return alglib::beta(a, b);
423
+ }
424
+
425
+ // alglibmisc.h
426
+
427
+ double rb_hqrndnormal()
428
+ {
429
+ alglib::hqrndstate state;
430
+ alglib::hqrndrandomize(state);
431
+ return alglib::hqrndnormal(state);
432
+ }
433
+
434
+ Array rb_hqrndnormalv(alglib::ae_int_t n)
435
+ {
436
+ Array result = Array(rb_ary_new2(n));
437
+ alglib::hqrndstate state;
438
+ alglib::hqrndrandomize(state);
439
+ alglib::real_1d_array x;
440
+ alglib::hqrndnormalv(state, n, x);
441
+ for (alglib::ae_int_t i = 0; i < n; i++)
442
+ {
443
+ result.push(x[i]);
444
+ }
445
+ return result;
446
+ }
447
+
448
+ extern "C" void Init_alglib()
449
+ {
450
+ Module rb_mAlglib = define_module("Alglib");
451
+
452
+ // Data_Type<alglib::hqrndstate> rb_cHqRndState =
453
+ // define_class_under<alglib::hqrndstate>(rb_mAlglib, "HqRndState")
454
+ // .define_constructor(Constructor<alglib::hqrndstate>())
455
+ // .define_method("initialize_copy", &alglib::hqrndstate::operator=);
456
+
457
+ Data_Type<alglib::real_1d_array> rb_cReal1DArray =
458
+ define_class_under<alglib::real_1d_array>(rb_mAlglib, "Real1DArray")
459
+ .define_constructor(Constructor<alglib::real_1d_array>())
460
+ .define_method("getcontent", static_cast<double *(alglib::real_1d_array::*)()>(&alglib::real_1d_array::getcontent));
461
+
462
+ Data_Type<alglib::integer_1d_array> rb_cInteger1DArray =
463
+ define_class_under<alglib::integer_1d_array>(rb_mAlglib, "Integer1DArray")
464
+ .define_constructor(Constructor<alglib::integer_1d_array>())
465
+ .define_method("getcontent", static_cast<alglib::ae_int_t *(alglib::integer_1d_array::*)()>(&alglib::integer_1d_array::getcontent));
466
+
467
+ Data_Type<alglib::real_2d_array> rb_cReal2DArray =
468
+ define_class_under<alglib::real_2d_array>(rb_mAlglib, "Real2DArray")
469
+ .define_constructor(Constructor<alglib::real_2d_array>())
470
+ .define_method("getcontent", static_cast<double *(alglib::real_2d_array::*)(alglib::ae_int_t)>(&alglib::real_2d_array::operator[]));
471
+
472
+ rb_mAlglib
473
+ .define_module_function("ruby_array_to_real_1d_array", &ruby_array_to_real_1d_array)
474
+ .define_module_function("ruby_array_to_integer_1d_array", &ruby_array_to_integer_1d_array)
475
+ .define_module_function("ruby_array_to_real_2d_array", &ruby_array_to_real_2d_array)
476
+ .define_module_function("real_1d_array_to_ruby_array", &real_1d_array_to_ruby_array)
477
+ .define_module_function("real_2d_array_to_ruby_array", &real_2d_array_to_ruby_array)
478
+ .define_module_function("integer_1d_array_to_ruby_array", &integer_1d_array_to_ruby_array)
479
+ .define_module_function("pca_build_basis", &rb_pcabuildbasis);
480
+
481
+ rb_mAlglib
482
+ .define_module_function("sample_moments", &rb_samplemoments)
483
+ .define_module_function("sample_mean", &rb_samplemean)
484
+ .define_module_function("sample_variance", &rb_samplevariance)
485
+ .define_module_function("sample_skewness", &rb_sampleskewness)
486
+ .define_module_function("sample_kurtosis", &rb_samplekurtosis)
487
+ .define_module_function("sample_adev", &rb_sampleadev)
488
+ .define_module_function("sample_median", &rb_samplemedian)
489
+ .define_module_function("sample_percentile", &rb_samplepercentile)
490
+ .define_module_function("cov2", &rb_cov2)
491
+ .define_module_function("pearson_corr2", &rb_pearsoncorr2)
492
+ .define_module_function("spearman_corr2", &rb_spearmancorr2)
493
+ .define_module_function("pearson_correlation_significance", &rb_pearsoncorrelationsignificance)
494
+ .define_module_function("spearman_rank_correlation_significance", &rb_spearmanrankcorrelationsignificance)
495
+ .define_module_function("jarque_bera_test", &rb_jarqueberatest)
496
+ .define_module_function("f_test", &rb_ftest)
497
+ .define_module_function("one_sample_variance_test", &rb_onesamplevariancetest)
498
+ .define_module_function("wilcoxon_signed_rank_test", &rb_wilcoxonsignedranktest)
499
+ .define_module_function("mann_whitney_u_test", &rb_mannwhitneyutest)
500
+ .define_module_function("student_test_1", &rb_studentttest1)
501
+ .define_module_function("student_test_2", &rb_studentttest2)
502
+ .define_module_function("unequal_variance_t_test", &rb_unequalvariancettest)
503
+ .define_module_function("hqrnd_normal", &rb_hqrndnormal)
504
+ .define_module_function("hqrnd_normalv", &rb_hqrndnormalv)
505
+ .define_module_function("gamma_function", &rb_gammafunction)
506
+ .define_module_function("lngamma", &rb_lngamma)
507
+ .define_module_function("error_function", &rb_errorfunction)
508
+ .define_module_function("error_functionc", &rb_errorfunctionc)
509
+ .define_module_function("normal_pdf", &rb_normalpdf)
510
+ .define_module_function("normal_cdf", &rb_normalcdf)
511
+ .define_module_function("inv_erf", &rb_inverf)
512
+ .define_module_function("inv_normal_cdf", &rb_invnormalcdf)
513
+ .define_module_function("bivariate_normal_pdf", &rb_bivariatenormalpdf)
514
+ .define_module_function("bivariate_normal_cdf", &rb_bivariatenormalcdf)
515
+ .define_module_function("incomplete_beta", &rb_incompletebeta)
516
+ .define_module_function("inv_incomplete_beta", &rb_invincompletebeta)
517
+ .define_module_function("student_t_distribution", &rb_studenttdistribution)
518
+ .define_module_function("inv_student_t_distribution", &rb_invstudenttdistribution)
519
+ .define_module_function("f_distribution", &rb_fdistribution)
520
+ .define_module_function("fc_distribution", &rb_fcdistribution)
521
+ .define_module_function("inv_f_distribution", &rb_invfdistribution)
522
+ .define_module_function("incomplete_gamma", &rb_incompletegamma)
523
+ .define_module_function("incomplete_gamma_c", &rb_incompletegammac)
524
+ .define_module_function("inv_incomplete_gamma_c", &rb_invincompletegammac)
525
+ .define_module_function("chi_square_distribution", &rb_chisquaredistribution)
526
+ .define_module_function("chi_square_c_distribution", &rb_chisquarecdistribution)
527
+ .define_module_function("inv_chi_square_distribution", &rb_invchisquaredistribution)
528
+ .define_module_function("binomial_distribution", &rb_binomialdistribution)
529
+ .define_module_function("binomial_c_distribution", &rb_binomialcdistribution)
530
+ .define_module_function("inv_binomial_distribution", &rb_invbinomialdistribution)
531
+ .define_module_function("exponential_integralei", &rb_exponentialintegralei)
532
+ .define_module_function("exponential_integralen", &rb_exponentialintegralen)
533
+ .define_module_function("poisson_distribution", &rb_poissondistribution)
534
+ .define_module_function("poisson_c_distribution", &rb_poissoncdistribution)
535
+ .define_module_function("inv_poisson_distribution", &rb_invpoissondistribution)
536
+ .define_module_function("beta", &rb_beta);
537
+ }
@@ -0,0 +1,86 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }