- ALGLIB for Ruby.
- ALGLIB is a numerical analysis and data processing library. This repository provides bindings primarily for statistics.
From source code:
git clone https://github.com/kojix2/ruby-alglib
cd ruby-alglib
bundle install
rake ext:alglib # Download ALGLIB Free Edition from https://www.alglib.net/ and extract to ext/alglib.
rake compile
rake install- Note that the license of ALGLIB Free Edition is GPL or Personal/Academic license.
- If you want to use ALGLIB in a commercial application, you will need to purchase a commercial license.
- You can also use the Commercial Edition of ALGLIB. In that case, you need to replace the files in
ext/alglibwith the files in the Commercial Edition. - Windows is not supported.
gamma_functionlngammaerror_functionerror_functioncnormal_pdfnormal_cdfinv_erfinv_normal_cdfbivariate_normal_pdfbivariate_normal_cdfincomplete_betainv_incomplete_betastudent_t_distributioninv_student_t_distributionf_distributionfc_distributioninv_f_distributionincomplete_gammaincomplete_gamma_cinv_incomplete_gamma_cchi_square_distributionchi_square_c_distributioninv_chi_square_distributionbinomial_distributionbinomial_c_distributioninv_binomial_distributionexponential_integraleiexponential_integralenpoisson_distributionpoisson_c_distributioninv_poisson_distributionbeta
pca_build_basis
hqrnd_normalhqrnd_normalv
sample_momentssample_meansample_variancesample_skewnesssample_kurtosissample_adevsample_mediansample_percentilecov2pearson_corr2spearman_corr2
cov_matrix,cov_matrix_with_sizepearson_corr_matrix,pearson_corr_matrix_with_sizespearman_corr_matrix,spearman_corr_matrix_with_sizecov_matrix2,cov_matrix2_with_sizepearson_corr_matrix2,pearson_corr_matrix2_with_sizespearman_corr_matrix2,spearman_corr_matrix2_with_sizerank_data,rank_data_with_sizerank_data_centered,rank_data_centered_with_size
pearson_correlation_significancespearman_rank_correlation_significancejarque_bera_testf_testone_sample_variance_testwilcoxon_signed_rank_testmann_whitney_u_teststudent_test_1student_test_2unequal_variance_t_test
require 'alglib'
# 1D statistics
arr = [1.0, 2.0, 3.0, 4.0]
mean = Alglib.sample_mean(arr)
variance = Alglib.sample_variance(arr)
moments = Alglib.sample_moments(arr) # => { "mean" => ..., "variance" => ..., ... }
# 2D statistics
mat = [[1, 2], [3, 4], [5, 6]]
cov = Alglib.cov_matrix(mat)
corr = Alglib.pearson_corr_matrix(mat)
ranked = Alglib.rank_data(mat)
centered_ranked = Alglib.rank_data_centered(mat)
# with_size version
cov2 = Alglib.cov_matrix_with_size(mat, 3, 2)
# Statistical test
result = Alglib.pearson_correlation_significance(0.8, 10) # => { "bothtails" => ..., ... }- This project includes comprehensive tests for all statistical functions, special functions, data analysis, and miscellaneous utilities.
- All results are compared with R's standard statistical functions (e.g.,
mean,var,cor,cov,rank, etc.) for correctness. - Both 1D and 2D array functions, all with_size variants, and special/data analysis/miscellaneous functions are covered by the test suite.
- Rank-related functions are compared as sets due to possible differences in tie-breaking order between ALGLIB and R.
- See
test/statistics_test.rb,test/dataanalysis_test.rb, and other test files for details.
- Creating namespaces under Alglib. (e.g. Alglib::Statistics)
- Trying to implement all functions even if you do not plan to use them.
- Adding features that will require frequent maintenance.
- Enforcing the above policies on forked repos.
We use Rice to create Ruby's C++ binding.
- Update the version number in
lib/alglib/version.rb. - Clean up the extension files:
rake ext:clean_alglib- Download the ALGLIB Free Edition:
rake ext:alglib- Publish the
alglib4gem:
rake releaseThis 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).
- ruby-alglib itself (the code in this repository) is distributed under the MIT license.
- However, ALGLIB for C++ Free Edition is under the GPL 2+ license.
- The algblib4 gem distributed with the RubyGem server is GPL 2+ licensed because it contains ALGLIB for C++ Free Edition code.
- Please read FAQ carefully before you use ALGLIB to understand what is allowed in the free version.
- Can I use ALGLIB Free Edition in a commercial application which runs on server?
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.
- Can I use ALGLIB Free Edition in a commercial application which runs on server?
- Theoretically, ruby-alglib should work with the commercial version. That is why it is MIT. But we have not verified this.