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.
- checksums.yaml +4 -4
- data/README.md +151 -5
- data/ext/alglib/alglib.cpp +28 -441
- data/ext/alglib/alglib.h +8 -0
- data/ext/alglib/alglib_alglibmisc.cpp +22 -0
- data/ext/alglib/alglib_alglibmisc.h +8 -0
- data/ext/alglib/alglib_converters.cpp +193 -0
- data/ext/alglib/alglib_converters.h +56 -0
- data/ext/alglib/alglib_dataanalysis.cpp +14 -0
- data/ext/alglib/alglib_dataanalysis.h +9 -0
- data/ext/alglib/alglib_specialfunctions.cpp +199 -0
- data/ext/alglib/alglib_specialfunctions.h +41 -0
- data/ext/alglib/alglib_statistics.cpp +338 -0
- data/ext/alglib/alglib_statistics.h +48 -0
- data/lib/alglib/version.rb +1 -1
- metadata +14 -5
- data/ext/alglib/alglib_array_converters.cpp +0 -86
- data/ext/alglib/alglib_array_converters.h +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32973f71af39bdcdb2ac898ba54b76842c4efdc0a19a82f21278715b9bee6a00
|
4
|
+
data.tar.gz: 4311f2affd506b8d8ca4ed9b2bdf62adbca2ddc34aee87647e87a8d880f7a15a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ca2def3f1027a868eddc32507023eb833c3771416c8f6b4a9d34871b7664627d34b056e8499e791616c5ddcbeb5e2f893e2330ca3b2913a29af07a46306264
|
7
|
+
data.tar.gz: 777fcade111e5011e094dd0c6f832400f17dd66805670e7a632cd4a1d407b6698c8261dc67d0f07de629f4cabdb035df9563501bd21349bce49b6899544b1165
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# ruby-alglib
|
2
2
|
|
3
3
|
[](https://github.com/kojix2/ruby-alglib/actions/workflows/ci.yml)
|
4
|
+
[](https://badge.fury.io/rb/alglib4)
|
4
5
|
|
5
|
-
-
|
6
|
+
- [ALGLIB](https://www.alglib.net/) for Ruby.
|
6
7
|
- ALGLIB is a numerical analysis and data processing library. This repository provides bindings primarily for statistics.
|
7
8
|
|
8
9
|
## Installation
|
@@ -26,21 +27,166 @@ rake install
|
|
26
27
|
|
27
28
|
## Usage
|
28
29
|
|
29
|
-
|
30
|
+
### Supported Statistical Functions
|
31
|
+
|
32
|
+
#### Special Functions (from alglib_specialfunctions.h)
|
33
|
+
|
34
|
+
- `gamma_function`
|
35
|
+
- `lngamma`
|
36
|
+
- `error_function`
|
37
|
+
- `error_functionc`
|
38
|
+
- `normal_pdf`
|
39
|
+
- `normal_cdf`
|
40
|
+
- `inv_erf`
|
41
|
+
- `inv_normal_cdf`
|
42
|
+
- `bivariate_normal_pdf`
|
43
|
+
- `bivariate_normal_cdf`
|
44
|
+
- `incomplete_beta`
|
45
|
+
- `inv_incomplete_beta`
|
46
|
+
- `student_t_distribution`
|
47
|
+
- `inv_student_t_distribution`
|
48
|
+
- `f_distribution`
|
49
|
+
- `fc_distribution`
|
50
|
+
- `inv_f_distribution`
|
51
|
+
- `incomplete_gamma`
|
52
|
+
- `incomplete_gamma_c`
|
53
|
+
- `inv_incomplete_gamma_c`
|
54
|
+
- `chi_square_distribution`
|
55
|
+
- `chi_square_c_distribution`
|
56
|
+
- `inv_chi_square_distribution`
|
57
|
+
- `binomial_distribution`
|
58
|
+
- `binomial_c_distribution`
|
59
|
+
- `inv_binomial_distribution`
|
60
|
+
- `exponential_integralei`
|
61
|
+
- `exponential_integralen`
|
62
|
+
- `poisson_distribution`
|
63
|
+
- `poisson_c_distribution`
|
64
|
+
- `inv_poisson_distribution`
|
65
|
+
- `beta`
|
66
|
+
|
67
|
+
#### Data Analysis Functions (from alglib_dataanalysis.h)
|
68
|
+
|
69
|
+
- `pca_build_basis`
|
70
|
+
|
71
|
+
#### Miscellaneous Functions (from alglib_alglibmisc.h)
|
72
|
+
|
73
|
+
- `hqrnd_normal`
|
74
|
+
- `hqrnd_normalv`
|
75
|
+
|
76
|
+
#### 1D Array Functions
|
77
|
+
|
78
|
+
- `sample_moments`
|
79
|
+
- `sample_mean`
|
80
|
+
- `sample_variance`
|
81
|
+
- `sample_skewness`
|
82
|
+
- `sample_kurtosis`
|
83
|
+
- `sample_adev`
|
84
|
+
- `sample_median`
|
85
|
+
- `sample_percentile`
|
86
|
+
- `cov2`
|
87
|
+
- `pearson_corr2`
|
88
|
+
- `spearman_corr2`
|
89
|
+
|
90
|
+
#### 2D Array / Matrix Functions
|
91
|
+
|
92
|
+
- `cov_matrix`, `cov_matrix_with_size`
|
93
|
+
- `pearson_corr_matrix`, `pearson_corr_matrix_with_size`
|
94
|
+
- `spearman_corr_matrix`, `spearman_corr_matrix_with_size`
|
95
|
+
- `cov_matrix2`, `cov_matrix2_with_size`
|
96
|
+
- `pearson_corr_matrix2`, `pearson_corr_matrix2_with_size`
|
97
|
+
- `spearman_corr_matrix2`, `spearman_corr_matrix2_with_size`
|
98
|
+
- `rank_data`, `rank_data_with_size`
|
99
|
+
- `rank_data_centered`, `rank_data_centered_with_size`
|
100
|
+
|
101
|
+
#### Statistical Tests
|
102
|
+
|
103
|
+
- `pearson_correlation_significance`
|
104
|
+
- `spearman_rank_correlation_significance`
|
105
|
+
- `jarque_bera_test`
|
106
|
+
- `f_test`
|
107
|
+
- `one_sample_variance_test`
|
108
|
+
- `wilcoxon_signed_rank_test`
|
109
|
+
- `mann_whitney_u_test`
|
110
|
+
- `student_test_1`
|
111
|
+
- `student_test_2`
|
112
|
+
- `unequal_variance_t_test`
|
113
|
+
|
114
|
+
### Example
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require 'alglib'
|
118
|
+
|
119
|
+
# 1D statistics
|
120
|
+
arr = [1.0, 2.0, 3.0, 4.0]
|
121
|
+
mean = Alglib.sample_mean(arr)
|
122
|
+
variance = Alglib.sample_variance(arr)
|
123
|
+
moments = Alglib.sample_moments(arr) # => { "mean" => ..., "variance" => ..., ... }
|
124
|
+
|
125
|
+
# 2D statistics
|
126
|
+
mat = [[1, 2], [3, 4], [5, 6]]
|
127
|
+
cov = Alglib.cov_matrix(mat)
|
128
|
+
corr = Alglib.pearson_corr_matrix(mat)
|
129
|
+
ranked = Alglib.rank_data(mat)
|
130
|
+
centered_ranked = Alglib.rank_data_centered(mat)
|
131
|
+
|
132
|
+
# with_size version
|
133
|
+
cov2 = Alglib.cov_matrix_with_size(mat, 3, 2)
|
134
|
+
|
135
|
+
# Statistical test
|
136
|
+
result = Alglib.pearson_correlation_significance(0.8, 10) # => { "bothtails" => ..., ... }
|
137
|
+
```
|
138
|
+
|
139
|
+
### Testing
|
140
|
+
|
141
|
+
- This project includes comprehensive tests for all statistical functions, special functions, data analysis, and miscellaneous utilities.
|
142
|
+
- All results are compared with R's standard statistical functions (e.g., `mean`, `var`, `cor`, `cov`, `rank`, etc.) for correctness.
|
143
|
+
- Both 1D and 2D array functions, all with_size variants, and special/data analysis/miscellaneous functions are covered by the test suite.
|
144
|
+
- Rank-related functions are compared as sets due to possible differences in tie-breaking order between ALGLIB and R.
|
145
|
+
- See `test/statistics_test.rb`, `test/dataanalysis_test.rb`, and other test files for details.
|
30
146
|
|
31
147
|
## Development
|
32
148
|
|
33
|
-
Not-To-Do List
|
149
|
+
### Not-To-Do List
|
34
150
|
|
35
151
|
- Creating namespaces under Alglib. (e.g. Alglib::Statistics)
|
36
152
|
- Trying to implement all functions even if you do not plan to use them.
|
37
153
|
- Adding features that will require frequent maintenance.
|
38
154
|
- Enforcing the above policies on forked repos.
|
39
155
|
|
156
|
+
### Rice - C++ binding
|
157
|
+
|
158
|
+
We use [Rice](https://github.com/ruby-rice/rice) to create Ruby's C++ binding.
|
159
|
+
|
160
|
+
### Ruby Gem Release
|
161
|
+
|
162
|
+
1. Update the version number in `lib/alglib/version.rb`.
|
163
|
+
2. Clean up the extension files:
|
164
|
+
|
165
|
+
```sh
|
166
|
+
rake ext:clean_alglib
|
167
|
+
```
|
168
|
+
|
169
|
+
3. Download the ALGLIB Free Edition:
|
170
|
+
|
171
|
+
```sh
|
172
|
+
rake ext:alglib
|
173
|
+
```
|
174
|
+
|
175
|
+
4. Publish the `alglib4` gem:
|
176
|
+
|
177
|
+
```sh
|
178
|
+
rake release
|
179
|
+
```
|
180
|
+
|
181
|
+
### Call for committers and owners
|
182
|
+
|
183
|
+
This project is looking for a committer and an owner. The original developer, kojix2, is not familiar with the C++ programming language or mathematical calculations. If there is a suitable owner, kojix2 will gladly transfer this project (provided that kojix2 can maintain commit rights).
|
184
|
+
|
40
185
|
## License
|
41
186
|
|
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.
|
187
|
+
- ruby-alglib itself (the code in this repository) is distributed under the **MIT** license.
|
188
|
+
- However, [ALGLIB for C++ Free Edition](https://www.alglib.net/download.php) is under the **GPL 2+** license.
|
189
|
+
- [The algblib4 gem](https://rubygems.org/gems/alglib4) distributed with the RubyGem server is **GPL 2+** licensed because it contains ALGLIB for C++ Free Edition code.
|
44
190
|
- Please read [FAQ](https://www.alglib.net/faq.php) carefully before you use ALGLIB to understand what is allowed in the free version.
|
45
191
|
- [Can I use ALGLIB Free Edition in a commercial application which runs on server?](https://www.alglib.net/faq.php#6bca163136cda10b16de68704cbea625)
|
46
192
|
> 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.
|
data/ext/alglib/alglib.cpp
CHANGED
@@ -2,449 +2,10 @@
|
|
2
2
|
#include <rice/stl.hpp>
|
3
3
|
#include <algorithm>
|
4
4
|
// #include "numo.hpp"
|
5
|
-
#include "
|
6
|
-
#include "statistics.h"
|
7
|
-
#include "alglib_array_converters.h"
|
8
|
-
#include "alglib_utils.h"
|
5
|
+
#include "alglib.h"
|
9
6
|
|
10
7
|
using namespace Rice;
|
11
8
|
|
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
9
|
extern "C" void Init_alglib()
|
449
10
|
{
|
450
11
|
Module rb_mAlglib = define_module("Alglib");
|
@@ -469,13 +30,22 @@ extern "C" void Init_alglib()
|
|
469
30
|
.define_constructor(Constructor<alglib::real_2d_array>())
|
470
31
|
.define_method("getcontent", static_cast<double *(alglib::real_2d_array::*)(alglib::ae_int_t)>(&alglib::real_2d_array::operator[]));
|
471
32
|
|
33
|
+
Data_Type<alglib::integer_2d_array> rb_cInteger2DArray =
|
34
|
+
define_class_under<alglib::integer_2d_array>(rb_mAlglib, "Integer2DArray")
|
35
|
+
.define_constructor(Constructor<alglib::integer_2d_array>())
|
36
|
+
.define_method("getcontent", static_cast<alglib::ae_int_t *(alglib::integer_2d_array::*)(alglib::ae_int_t)>(&alglib::integer_2d_array::operator[]));
|
37
|
+
|
472
38
|
rb_mAlglib
|
473
39
|
.define_module_function("ruby_array_to_real_1d_array", &ruby_array_to_real_1d_array)
|
474
40
|
.define_module_function("ruby_array_to_integer_1d_array", &ruby_array_to_integer_1d_array)
|
475
41
|
.define_module_function("ruby_array_to_real_2d_array", &ruby_array_to_real_2d_array)
|
42
|
+
.define_module_function("ruby_array_to_integer_2d_array", &ruby_array_to_integer_2d_array)
|
476
43
|
.define_module_function("real_1d_array_to_ruby_array", &real_1d_array_to_ruby_array)
|
477
44
|
.define_module_function("real_2d_array_to_ruby_array", &real_2d_array_to_ruby_array)
|
478
|
-
.define_module_function("
|
45
|
+
.define_module_function("integer_2d_array_to_ruby_array", &integer_2d_array_to_ruby_array)
|
46
|
+
.define_module_function("integer_1d_array_to_ruby_array", &integer_1d_array_to_ruby_array);
|
47
|
+
|
48
|
+
rb_mAlglib
|
479
49
|
.define_module_function("pca_build_basis", &rb_pcabuildbasis);
|
480
50
|
|
481
51
|
rb_mAlglib
|
@@ -490,6 +60,23 @@ extern "C" void Init_alglib()
|
|
490
60
|
.define_module_function("cov2", &rb_cov2)
|
491
61
|
.define_module_function("pearson_corr2", &rb_pearsoncorr2)
|
492
62
|
.define_module_function("spearman_corr2", &rb_spearmancorr2)
|
63
|
+
// 2D array/matrix statistical functions
|
64
|
+
.define_module_function("cov_matrix", &rb_covm)
|
65
|
+
.define_module_function("cov_matrix_with_size", &rb_covm_with_size)
|
66
|
+
.define_module_function("pearson_corr_matrix", &rb_pearsoncorrm)
|
67
|
+
.define_module_function("pearson_corr_matrix_with_size", &rb_pearsoncorrm_with_size)
|
68
|
+
.define_module_function("spearman_corr_matrix", &rb_spearmancorrm)
|
69
|
+
.define_module_function("spearman_corr_matrix_with_size", &rb_spearmancorrm_with_size)
|
70
|
+
.define_module_function("cov_matrix2", &rb_covm2)
|
71
|
+
.define_module_function("cov_matrix2_with_size", &rb_covm2_with_size)
|
72
|
+
.define_module_function("pearson_corr_matrix2", &rb_pearsoncorrm2)
|
73
|
+
.define_module_function("pearson_corr_matrix2_with_size", &rb_pearsoncorrm2_with_size)
|
74
|
+
.define_module_function("spearman_corr_matrix2", &rb_spearmancorrm2)
|
75
|
+
.define_module_function("spearman_corr_matrix2_with_size", &rb_spearmancorrm2_with_size)
|
76
|
+
.define_module_function("rank_data", &rb_rankdata)
|
77
|
+
.define_module_function("rank_data_with_size", &rb_rankdata_with_size)
|
78
|
+
.define_module_function("rank_data_centered", &rb_rankdatacentered)
|
79
|
+
.define_module_function("rank_data_centered_with_size", &rb_rankdatacentered_with_size)
|
493
80
|
.define_module_function("pearson_correlation_significance", &rb_pearsoncorrelationsignificance)
|
494
81
|
.define_module_function("spearman_rank_correlation_significance", &rb_spearmanrankcorrelationsignificance)
|
495
82
|
.define_module_function("jarque_bera_test", &rb_jarqueberatest)
|