clbustos / distribution Goto Github PK
View Code? Open in Web Editor NEWStatistical Distributions multi library wrapper. Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
License: Other
Statistical Distributions multi library wrapper. Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
License: Other
When including the gem, division of two integers returns a rational, whereas normally it would return another integer. Is there a way to turn this off? I would like to use the gem for statistics, but it's clashing with other parts of the code.
ruby-1.8.7-p352 :001 > require 'rubygems'
=> true
ruby-1.8.7-p352 :002 > 3/2
=> 1
ruby-1.8.7-p352 :003 > require 'distribution'
=> true
ruby-1.8.7-p352 :004 > 3/2
=> 3/2
ruby-1.8.7-p352 :005 > (3/2).class
=> Rational
Hi,
With commit 6a7d8c0, the license changed to BSD-3-clause, but some file headers (I think only lib/distribution.rb) still points to the GPL-2+. You should remove them.
Thanks,
Cédric
Report:
Seems to give incorrect value. For example:
a=[0,0,0,1,1,1,2,2,2].to_scale
b=[2,2,2,3,3,3,4,4,4].to_scale
t_2 = Statsample::Test::T::TwoSamplesIndependent.new(a,b)
t_2.probability_not_equal_variance
this gives the result: => 0.03333672278567579
However, the result should be: 0.00016053418045947065
Which actually is the value of t_2.probability_equal_variance
The issue seems to be with Distribution::T.cdf which treats df different if its a Fixnum vs a Float.
For the two vectors, where the variance actually is the same, the t statistic and the df should be the same for the equal_variance case and the not_equal_variance case.
But Distribution::T.cdf(-4.8990,16) doesn't give the same result as Distribution::T.cdf(-4.8990,16.0)
I only just started using statsample today, so I don't know if this is a new issue or a long-standing one.
Dear @clbustos,
Thanks for your work on the awesome gem distribution
!
I'd like to use the gem for some projects but I'm a bit confused about the future: This repository, the original clbustos/distribution
, references the SciRuby-Fork as its homepage (See here in the gemspec). Also, the SciRuby-Fork, (sciruby/distribution) contains some constructive work that is not contained in the original, and, confusingly, vice versa, the original contains some work (from 2019) that is not in the Sciruby-fork.
So, of course I completely understand how we may run into this, but I'm asking myself: Shall we invest some work to bring these two forks together again? If yes, what should be the "common" place to continue development? As you are also member of SciRuby
: Should it be the original repository, this one or should it be where the SciRuby
-fork lives? So, would it be good
to investing work to move the work contained in sciruby/distribution into this one, or would it be good trying to get the work of clbustos/distribution into Sciruby?
Thanks in advance!
Hi again,
After adding the requirement for weibull, I have now two more tests failing:
Failures:
1) Distribution::Exponential rng should default to Kernel#rand if no :random is given
Failure/Error: Random.should_receive(:rand).and_return(0.5)
(Random (class)).rand(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
# ./spec/exponential_spec.rb:82:in `block (3 levels) in <top (required)>'
2) Distribution::Exponential rng should use a given rng if one is passed during construction
Failure/Error: rng = Distribution::Exponential::rng 1.0, :random => random
ArgumentError:
wrong number of arguments (2 for 1)
# ./spec/exponential_spec.rb:90:in `block (3 levels) in <top (required)>
when trying to run bundle exec derailed bundle:mem
/distribution-0.7.3/lib/distribution/normal/ruby.rb:2:in `<module:Distribution>': Normal is not a module (TypeError)
block at top of said file:
module Distribution
module Normal
module Ruby_
class << self
I've had to add require: false
to the Gem, just to get passed this and for the commands to finally work.
Distribution::Normal.cdf(-36)
=> 0.0
Distribution::Normal.cdf(-37)
=> 0.0
Distribution::Normal.cdf(-38)
=> 0.0
Distribution::Normal.cdf(-39)
=> 0.5
Distribution::Normal.cdf(38)
=> 1.0
Distribution::Normal.cdf(39)
=> 0.5
Since I just discovered that the Ruby Math library has an erf function, I switched to just using
0.5*(1.0+Math.erf(x.to_f/Math.sqrt(2.0)))
Maybe fixing this bug could help others, though.
2.1.6 :112 > Distribution::ChiSquare.q_chi2(4000, 1487)
=> 1.1715358426793223
2.1.6 :113 > Distribution::ChiSquare.q_chi2(4000, 1488)
=> 1.287980205519492
2.1.6 :114 > Distribution::ChiSquare.q_chi2(4000, 1489)
=> 1.0610471112556463
2.1.6 :115 > Distribution::ChiSquare.q_chi2(4000, 1490)
=> 1.7505434400435371
2.1.6 :116 > Distribution::ChiSquare.q_chi2(4000, 1491)
=> 0.0
2.1.6 :117 > Distribution::ChiSquare.q_chi2(4000, 1492)
=> 0.0
it is expected Distribution::ChiSquare.q_chi2 to be within [0..1] range
I have an array of data x=[0.1, 0.04, 0.3]
How can I use this library to estimate alpha and beta of a beta distribution?
Hi,
Currently, when I run rspec
, I get the following error:
/home/boutil/src/ruby/distribution/distribution/spec/weibull_spec.rb:5:in `<top (required)>': uninitialized constant Distribution::Weibull (NameError)
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1327:in `load'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1325:in `each'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1325:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:103:in `setup'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:89:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:74:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:42:in `invoke'
from /usr/bin/rspec:4:in `<main>'
For some strange reason, when loading the spec_helper, distribution/weibull.rb
is not loaded, whereas distribution.rb
is. Adding require "distribution/weibull"
to spec/weibull_spec.rb does the trick, but it is just a workaround.
I wonder if it needs to be in manifest.txt?
Each module should have a method to return an array of random numbers, or adapts #rng to return an array.
Passing a fixed seed is necessary to allow debugging of functions using Distribution sampling.
Distribution::Normal.rng(0, 1, 1) == Distribution::Normal.rng(0, 1, 1)
# => false
Should return true
instead.
Version info:
p Distribution::Normal.rng(0, 1, 1)
# => #<Proc:0x000000013533f0@/home/user/.rvm/gems/ruby-2.2.1/gems/distribution-0.7.3/lib/distribution/normal/ruby.rb:17 (lambda)>
Notably, you seem to have a test set up in spec/normal_spec.rb:27
, but I can't get it executed.
# cd to gem folder
rspec spec/normal_spec.rb:27 2>&1 | grep 'seed'
# => no output
rspec spec/normal_spec.rb 2>&1 | grep 'seed'
# => no output
rspec spec/ 2>&1 | grep 'seed'
# => no output
rspec 2>&1 | grep 'seed'
# => no output
I find the README quite hard to read because it seems to be in plain text but perhaps formatted for some sort of conversion that github doesn't recognise perhaps?
Anyway, assuming the other version is not needed somewhere else. I have changed the README to README.md and reformatted accordingly for github to make the document more palatable.
The result can be viewed on my own branch which is forked from this repo. I will make a pull request for this change if you agree with what I did there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.