cmd_stan_rb 0.2.0 → 0.3.0

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.
@@ -1,3 +1,3 @@
1
1
  module CmdStanRb
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,5 +1,7 @@
1
1
  require "stan/model"
2
2
  require "stan/examples"
3
+ require "stan/histogram"
4
+ require "stan/fit_result"
3
5
 
4
6
  module Stan
5
7
  end
@@ -0,0 +1,31 @@
1
+ module Stan
2
+ class FitResult
3
+ attr_reader :rows, :headers, :data_rows
4
+
5
+ def initialize(original_output)
6
+ @rows = Array(original_output.split("\n"))
7
+ @headers = rows[38].to_s.split(",") # In L39 there is the header column
8
+ @data_rows = rows[43..].map { |r| r.split(",") } # From L44 on there is the raw data!
9
+
10
+ define_histograms!
11
+ end
12
+
13
+ def parameters
14
+ headers[7..]
15
+ end
16
+
17
+ private
18
+
19
+ def define_histograms!
20
+ headers.each do |parameter|
21
+ define_singleton_method parameter do
22
+ parameter_index = headers.index(parameter)
23
+ data_rows.each_with_object({}) do |row, hash|
24
+ v = row[parameter_index].to_f.round(1)
25
+ hash[v] = (hash[v] || 0) + 1
26
+ end.sort.to_h
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Stan
2
+ class Histogram
3
+ attr_reader :list, :bin_size
4
+
5
+ def initialize(list, bin_size: nil)
6
+ @list = list
7
+ @bin_size = bin_size
8
+ end
9
+
10
+ def to_a
11
+ @list.each_with_object({}) do |item, hash|
12
+ bin =
13
+ if bin_size.to_f > 0
14
+ (item.to_f / bin_size).round * bin_size
15
+ else
16
+ item
17
+ end
18
+
19
+ hash[bin] = hash[bin].to_i + 1
20
+ end.sort
21
+ end
22
+
23
+ def to_h
24
+ to_a.to_h
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmd_stan_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Robin Neumann
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-05-10 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2020-05-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
15
29
  description: Stan is a state-of-the-art platform for statistical modeling and high-performance
16
30
  statistical computation. Thousands of users rely on Stan for statistical modeling,
17
31
  data analysis, and prediction in the social, biological, and physical sciences,
@@ -36,11 +50,15 @@ files:
36
50
  - bin/setup
37
51
  - cmd_stan_rb.gemspec
38
52
  - demo.ipynb
53
+ - examples/exponential.ipynb
54
+ - examples/linear_regression.ipynb
39
55
  - lib/cmd_stan_rb.rb
40
56
  - lib/cmd_stan_rb/configuration.rb
41
57
  - lib/cmd_stan_rb/version.rb
42
58
  - lib/stan.rb
43
59
  - lib/stan/examples.rb
60
+ - lib/stan/fit_result.rb
61
+ - lib/stan/histogram.rb
44
62
  - lib/stan/model.rb
45
63
  homepage: https://github.com/neumanrq/cmd_stan_rb
46
64
  licenses: []