mathpack 0.0.4 → 0.0.5
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 +34 -2
- data/lib/mathpack/version.rb +1 -1
- data/lib/statistics.rb +45 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63319450c8c08826bd20cc32d890ad3225cfc538
|
4
|
+
data.tar.gz: a22f13bac087a05b611ad21397435e3fe46188f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad1132540e8025082c33228ade051e3770fa5bd2b8a5924c6057a0d10931de33ceae1b4454d031037007983b9d0aa4a1bd644a737d452a5578f078641c0c5616
|
7
|
+
data.tar.gz: e89cdd83724bac1f79b15a20be818d74471dabd77ccdf1cb8ed8661f57c0439c839c6eaababe9ef758a7fc156420a555386278001ca12ce13182fff72eb29530
|
data/README.md
CHANGED
@@ -16,10 +16,42 @@ And then execute:
|
|
16
16
|
Or install it yourself as:
|
17
17
|
|
18
18
|
$ gem install mathpack
|
19
|
+
## Information
|
20
|
+
Gem `mathpack` allows to count statistical functions throught `Statistics` class
|
21
|
+
## Statistics
|
22
|
+
`Statistics` class have following methods
|
23
|
+
- **number** - returns a number of elements in series
|
24
|
+
- **mean** - returns a mean of series
|
25
|
+
- **variance** - returns a variance of series
|
26
|
+
- **skewness** - returns a skewness of series
|
27
|
+
- **kurtosis** - returns a kurtosis
|
28
|
+
- **min** - returns the minimal element of series
|
29
|
+
- **max** - returns the maxinal element of series
|
30
|
+
- **number** - returns a number of elements in array
|
31
|
+
- **raw_moment** - returns the *nth* raw moment of series
|
32
|
+
- **central_moment** - returns the *nth* central moment of series
|
33
|
+
- **empirical_cdf** - returns *empirical distribution function* value in some point
|
34
|
+
- **empirical_pdf** - returns *empirical probability density function* value in some point
|
35
|
+
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf grafic values to `.csv` file with name *filename*
|
36
|
+
- **print_empirical_cdf_to_csv** - allows to print empirical_cdf grafic values to `.csv` file with name *filename*
|
19
37
|
|
20
38
|
## Usage
|
21
|
-
|
22
|
-
|
39
|
+
```ruby
|
40
|
+
stat = Mathpack::Statistics.new([1, 2, 5, 6])
|
41
|
+
stat.number() #=> 4
|
42
|
+
stat.mean() #=> 3.5
|
43
|
+
stat.variance() #=> 4.25
|
44
|
+
stat.kurtosis() #=> -1.778546712802768
|
45
|
+
stat.skewness() #=> 0.0
|
46
|
+
stat.min() #=> 1
|
47
|
+
stat.max() #=> 6
|
48
|
+
stat.raw_moment(3) #=> 87.5
|
49
|
+
stat.central_moment(4) #=> 22.0625
|
50
|
+
stat.empirical_cdf(5.5) #=> 0.75
|
51
|
+
stat.empirical_pdf(3) #=> 0.07639393483317147
|
52
|
+
stat.print_empirical_cdf_to_csv('cdf.csv') #=> nil
|
53
|
+
stat.print_empirical_pdf_to_csv('pdf.csv') #=> nil
|
54
|
+
```
|
23
55
|
|
24
56
|
## Contributing
|
25
57
|
|
data/lib/mathpack/version.rb
CHANGED
data/lib/statistics.rb
CHANGED
@@ -17,11 +17,11 @@ module Mathpack
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def skewness
|
20
|
-
central_moment(3)
|
20
|
+
central_moment(3) / variance**1.5
|
21
21
|
end
|
22
22
|
|
23
23
|
def kurtosis
|
24
|
-
central_moment(4) / variance
|
24
|
+
central_moment(4) / variance**2 - 3
|
25
25
|
end
|
26
26
|
|
27
27
|
def max
|
@@ -44,5 +44,48 @@ module Mathpack
|
|
44
44
|
@series.each{ |x| central_moment += (x - m)**power }
|
45
45
|
central_moment / number
|
46
46
|
end
|
47
|
+
|
48
|
+
def emperical_cdf(x)
|
49
|
+
result = 0.0
|
50
|
+
@series.each{ |val| result += e(x - val) }
|
51
|
+
result / number
|
52
|
+
end
|
53
|
+
|
54
|
+
def print_emperical_cdf_to_csv(filename)
|
55
|
+
step = 0.25
|
56
|
+
val = min - step
|
57
|
+
File.open(filename, 'w+') do |file|
|
58
|
+
while val <= max + step do
|
59
|
+
file.write("#{val};")
|
60
|
+
file.write("#{emperical_cdf(val)}\n")
|
61
|
+
val += step
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def emperical_pdf(x)
|
67
|
+
h = variance**0.5 * number**(-1.0/6)
|
68
|
+
result = 0.0
|
69
|
+
@series.each{ |val| result += (e(x - val + h) - e(x - val - h))/(2*h) }
|
70
|
+
result / number
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_emperical_pdf_to_csv(filename)
|
74
|
+
step = 0.25
|
75
|
+
val = min - 2*step
|
76
|
+
File.open(filename, 'w+') do |file|
|
77
|
+
while val <= max + 2*step do
|
78
|
+
file.write("#{val};")
|
79
|
+
file.write("#{emperical_pdf(val)}\n")
|
80
|
+
val += step
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def e(x)
|
88
|
+
x <= 0 ? 0 : 1
|
89
|
+
end
|
47
90
|
end
|
48
91
|
end
|