Class: PlotStatistics::MonteCarlo
- Inherits:
-
Object
- Object
- PlotStatistics::MonteCarlo
- Defined in:
- lib/plot_statistics/monte_carlo.rb
Instance Attribute Summary collapse
-
#plots ⇒ Object
Returns the value of attribute plots.
-
#stats ⇒ Object
Returns the value of attribute stats.
Class Method Summary collapse
- .new_bivariate(actual_plot, number_of_plots = 500.0) ⇒ Object
- .new_univariate(number_of_clams, number_of_plots = 500.0) ⇒ Object
Instance Method Summary collapse
- #average_stat(radius, stat) ⇒ Object
- #bivariate_analysis ⇒ Object
- #calculate_limits(limits_for) ⇒ Object
- #calculate_means(means_for) ⇒ Object
-
#initialize(params = {}) ⇒ MonteCarlo
constructor
A new instance of MonteCarlo.
- #number_of_plots ⇒ Object
- #standard_deviation_stat(radius, stat) ⇒ Object
- #univariate_analysis ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ MonteCarlo
Returns a new instance of MonteCarlo.
5 6 7 |
# File 'lib/plot_statistics/monte_carlo.rb', line 5 def initialize(params={}) @plots = params[:plots] end |
Instance Attribute Details
#plots ⇒ Object
Returns the value of attribute plots.
3 4 5 |
# File 'lib/plot_statistics/monte_carlo.rb', line 3 def plots @plots end |
#stats ⇒ Object
Returns the value of attribute stats.
3 4 5 |
# File 'lib/plot_statistics/monte_carlo.rb', line 3 def stats @stats end |
Class Method Details
.new_bivariate(actual_plot, number_of_plots = 500.0) ⇒ Object
14 15 16 17 |
# File 'lib/plot_statistics/monte_carlo.rb', line 14 def self.new_bivariate(actual_plot, number_of_plots=500.0) plots = (1..number_of_plots).map { ClamPlot.create_random_from(actual_plot).bivariate_analysis } new(:plots => plots) end |
.new_univariate(number_of_clams, number_of_plots = 500.0) ⇒ Object
9 10 11 12 |
# File 'lib/plot_statistics/monte_carlo.rb', line 9 def self.new_univariate(number_of_clams, number_of_plots=500.0) plots = (1..number_of_plots).map { ClamPlot.create_random(number_of_clams).univariate_analysis } new(:plots => plots) end |
Instance Method Details
#average_stat(radius, stat) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/plot_statistics/monte_carlo.rb', line 64 def average_stat(radius, stat) sum = plots.inject(0.0) do |sum, plot| plot.stats.send(stat)[radius] end sum / number_of_plots end |
#bivariate_analysis ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/plot_statistics/monte_carlo.rb', line 19 def bivariate_analysis self.stats = OpenStruct.new(:mean => OpenStruct.new(:k_ts => [], :dead_k_ts => [], :l_ts => []), :upper_limit => OpenStruct.new(:k_ts => [], :dead_k_ts => [], :l_ts => []), :lower_limit => OpenStruct.new(:k_ts => [], :dead_k_ts => [], :l_ts => [])) calculate_means([:k_ts, :dead_k_ts, :l_ts]) calculate_limits([:k_ts, :dead_k_ts, :l_ts]) self end |
#calculate_limits(limits_for) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/plot_statistics/monte_carlo.rb', line 45 def calculate_limits(limits_for) (0...ClamPlot::MAX_RADIUS).each do |radius| limits_for.each do |stat| threshold = standard_deviation_stat(radius, stat) * 2.0 stats.upper_limit.send(stat) << (stats.mean.send(stat)[radius] + threshold) stats.lower_limit.send(stat) << (stats.mean.send(stat)[radius] - threshold) end end end |
#calculate_means(means_for) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/plot_statistics/monte_carlo.rb', line 37 def calculate_means(means_for) (0...ClamPlot::MAX_RADIUS).each do |radius| means_for.each do |stat| stats.mean.send(stat) << average_stat(radius, stat) end end end |
#number_of_plots ⇒ Object
72 73 74 |
# File 'lib/plot_statistics/monte_carlo.rb', line 72 def number_of_plots plots.size end |
#standard_deviation_stat(radius, stat) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/plot_statistics/monte_carlo.rb', line 56 def standard_deviation_stat(radius, stat) sum = plots.inject(0.0) do |sum, plot| (plot.stats.send(stat)[radius] - stats.mean.send(stat)[radius]) ** 2 end Math.sqrt(sum / number_of_plots) end |
#univariate_analysis ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/plot_statistics/monte_carlo.rb', line 28 def univariate_analysis self.stats = OpenStruct.new(:mean => OpenStruct.new(:k_ts => [], :l_ts => []), :upper_limit => OpenStruct.new(:k_ts => [], :l_ts => []), :lower_limit => OpenStruct.new(:k_ts => [], :l_ts => [])) calculate_means([:k_ts, :l_ts]) calculate_limits([:k_ts, :l_ts]) self end |