Browse Source

Improve normale distribution and update v0.1.6

- NormaleDistribution functions takes "min" and "max" named parameters
  instead of "a" "b" to be less confusing.
- Add specs for NormalDistribution.between/less_than/more_than
- update shard version to v0.1.6
- update changelog and readme
pull/2/head v0.1.6
Arthur POULET 5 years ago
parent
commit
d1c58e474f
No known key found for this signature in database GPG Key ID: 7C42395DCA99B923
  1. 7
      CHANGELOG.md
  2. 2
      README.md
  3. 2
      shard.yml
  4. 9
      spec/normale_distribution.cr
  5. 14
      src/stats/normale_distribution.cr
  6. 12
      src/stats/normale_distribution/persistant.cr

7
CHANGELOG.md

@ -1,7 +1,8 @@
# v0.1.6
- improve factorial (handle BigInt)
- improve distributions (handle BigFloat and BigInt)
- more tests
- Improve factorial (handle BigInt)
- Improve distributions (handle BigFloat and BigInt)
- Define more specs
- Improve Normale Distribution parameters (min-max instead of a-b)
# v0.1.5
- add specs for every function

2
README.md

@ -22,7 +22,7 @@ require "stats"
You should read the specs to understand how it works.
```crystal
NormaleDistribution::between standard_deviation: 15, esperance: 100, a: 85, b: 115 # => 0.6826894921370859
NormaleDistribution::between standard_deviation: 15, esperance: 100, min: 85, max: 115 # => 0.6826894921370859
Math.binomial_distribution(tries: 3, probability: 0.5, success: 1) # => 0.375
```

2
shard.yml

@ -1,5 +1,5 @@
name: stats
version: 0.1.5
version: 0.1.6
authors:
- Arthur Poulet <arthur.poulet@mailoo.org>

9
spec/normale_distribution.cr

@ -1,4 +1,13 @@
describe NormaleDistribution do
it "between" do
bet = NormaleDistribution.between standard_deviation: 1, esperance: 0, min: -1, max: 1
less = NormaleDistribution.less_than standard_deviation: 1, esperance: 0, max: -1
greater = NormaleDistribution.greater_than standard_deviation: 1, esperance: 0, min: 1
bet.should eq 1 - less - greater
end
end
describe NormaleDistribution::Persistant do
it "instances" do
NormaleDistribution::Persistant.new

14
src/stats/normale_distribution.cr

@ -2,16 +2,18 @@ require "./normale_distribution/persistant"
module NormaleDistribution
def self.between(standard_deviation : Float::All, esperance : Float::All, a : Float::All, b : Float::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).between a, b
def between(standard_deviation : Number::All, esperance : Number::All, min : Number::All, max : Number::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).between min, max
end
def self.greater_than(standard_deviation : Float::All, esperance : Float::All, a : Float::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).greater_than a
def greater_than(standard_deviation : Number::All, esperance : Number::All, min : Number::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).greater_than min
end
def self.less_than(standard_deviation : Float::All, esperance : Float::All, a : Float::All, b : Float::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).less_than a
def less_than(standard_deviation : Number::All, esperance : Number::All, max : Number::All)
NormaleDistribution::Persistant.new(standard_deviation: standard_deviation, esperance: esperance).less_than max
end
extend self
end

12
src/stats/normale_distribution/persistant.cr

@ -11,16 +11,16 @@ module NormaleDistribution
raise ArgumentError.new "standard_deviation must be > 0" unless @standard_deviation > 0.0
end
def greater_than(a : Number::All)
1.0 - repartition(a)
def greater_than(min : Number::All)
1.0 - repartition(min)
end
def less_than(a : Number::All)
repartition a
def less_than(max : Number::All)
repartition max
end
def between(a : Number::All, b : Number::All)
repartition(b) - repartition(a)
def between(min : Number::All, max : Number::All)
repartition(max) - repartition(min)
end
private def density(t : Number::All)

Loading…
Cancel
Save