Class: CmdStan::MCMC
Instance Attribute Summary collapse
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
-
#draws ⇒ Object
readonly
Returns the value of attribute draws.
Instance Method Summary collapse
-
#initialize(output_files) ⇒ MCMC
constructor
private TODO use runset for args.
- #sample ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize(output_files) ⇒ MCMC
private TODO use runset for args
9 10 11 12 |
# File 'lib/cmdstan/mcmc.rb', line 9 def initialize(output_files) @output_files = output_files validate_csv_files end |
Instance Attribute Details
#column_names ⇒ Object (readonly)
Returns the value of attribute column_names.
5 6 7 |
# File 'lib/cmdstan/mcmc.rb', line 5 def column_names @column_names end |
#draws ⇒ Object (readonly)
Returns the value of attribute draws.
5 6 7 |
# File 'lib/cmdstan/mcmc.rb', line 5 def draws @draws end |
Instance Method Details
#sample ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cmdstan/mcmc.rb', line 14 def sample sample = [] @output_files.each_with_index do |output_file, chain| i = 0 CSV.foreach(output_file.path, skip_lines: /^#/, headers: true) do |row| (sample[i] ||= [])[chain] = row.to_h.values.map(&:to_f) i += 1 end raise "Bug detected" if i != draws end sample end |
#summary ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cmdstan/mcmc.rb', line 27 def summary # add suffix since path can't already exist path = "#{Tempfile.new.path}.csv" run_command "#{CmdStan.path}/bin/stansummary#{extension}", "--csv_filename=#{path}", *@output_files.map(&:path) result = {} CSV.foreach(path, skip_lines: /^#/, headers: true, converters: :numeric) do |row| value = row.to_h name = value.delete("name") result[name] = value if name == "lp__" || !name.end_with?("__") end result end |