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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1255723e4f9c2d1da1d1c90653fce743fd400fb
4
- data.tar.gz: 1e3d47a5464a5998f0f4f45bd3a536a096029cb1
3
+ metadata.gz: 63319450c8c08826bd20cc32d890ad3225cfc538
4
+ data.tar.gz: a22f13bac087a05b611ad21397435e3fe46188f7
5
5
  SHA512:
6
- metadata.gz: 09abeba7ee1b21106b305768fa4be24038b9889015c369c663de87ecce9402f6ee80ebb6a8f15e1df2abd94016b6c74dbaabe35372689e988b2f49adac5d500b
7
- data.tar.gz: c5b965d3b6d2444cee93077e0826704fca0224dbe862cc4cac6fdc0e89c2be3f477f395e6efcac50c99709a64ebdd48d0cedf415e931df0b0bad3ac05e3ca8b1
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
- TODO: Write usage instructions here
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
 
@@ -1,3 +1,3 @@
1
1
  module Mathpack
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/statistics.rb CHANGED
@@ -17,11 +17,11 @@ module Mathpack
17
17
  end
18
18
 
19
19
  def skewness
20
- central_moment(3) /= variance**1.5
20
+ central_moment(3) / variance**1.5
21
21
  end
22
22
 
23
23
  def kurtosis
24
- central_moment(4) / variance ** 2 - 3
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxmilan