plot_statistics 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/bin/plot_statistics CHANGED
@@ -13,20 +13,24 @@ ARGV.each do |filename|
13
13
  lines = file.readlines
14
14
  file.close
15
15
 
16
- puts "\n"
17
- puts '##########################'
18
- puts "# #{filename}"
19
- puts '##########################'
20
- puts "\n"
21
-
16
+ puts "Analyzing #{filename}"
17
+ printf "Importing Clams"
22
18
  clams = lines.map do |line|
23
- x, y = line.strip.split("\t")
19
+ line = line.strip.split("\t")
20
+ next if line.empty?
21
+ x, y = line
22
+ printf "."
24
23
  PlotStatistics::Clam.new(:x => x, :y => y)
25
- end
24
+ end.compact
26
25
 
26
+ puts "Running Ripley's K analysis of plot"
27
27
  actual_plot = PlotStatistics::ClamPlot.new(clams)
28
+
29
+ puts "Running Monte Carlo Simulations of plot"
28
30
  monte_carlo = PlotStatistics::MonteCarlo.new(actual_plot.number_of_clams)
29
31
 
30
32
  output_filename = filename + '.ripleys_k.csv'
31
33
  PlotStatistics::Output.new(:clam_plot => actual_plot, :monte_carlo => monte_carlo).write_to_file(output_filename)
34
+
35
+ puts "Done™"
32
36
  end
@@ -11,5 +11,10 @@ class PlotStatistics
11
11
  def self.create_random
12
12
  new( :x => rand(100), :y => rand(100) )
13
13
  end
14
+
15
+ def ==(other)
16
+ return super(other) unless other.kind_of?(PlotStatistics::Clam)
17
+ self.x == other.x && self.y == other.y
18
+ end
14
19
  end
15
20
  end
@@ -14,6 +14,12 @@ class PlotStatistics
14
14
  end
15
15
 
16
16
  def self.create_random(number_of_clams)
17
+ clams = []
18
+ while clams.size < 100 do
19
+ new_clam = Clam.create_random
20
+ next if clams.any? { |clam| clam == new_clam }
21
+ clams << new_clam
22
+ end
17
23
  clams = (1..number_of_clams).map { Clam.create_random }
18
24
  new(clams)
19
25
  end
@@ -51,21 +57,30 @@ class PlotStatistics
51
57
  def calculate_stats
52
58
  (1..MAX_RADIUS).each do |radius|
53
59
 
54
- sums = clams.inject(0.0) do |sum, clam|
55
- clams_inside_circle = clam.distances.select { |distance| distance <= radius }
60
+ k_t = calculate_k_t(radius)
61
+ l_t = calculate_l_t(k_t, radius)
56
62
 
57
- circle_proportion = Circle.new(:clam => clam, :radius => radius).proportion_inside_plot
58
- reciprocal_proportion = 1.0 / circle_proportion
63
+ stats.k_ts << k_t
64
+ stats.l_ts << l_t
65
+ end
66
+ end
59
67
 
60
- reciprocal_proportion * clams_inside_circle.size
61
- end
68
+ def calculate_k_t(radius)
69
+ sums = clams.inject(0.0) do |sum, clam|
70
+ clams_inside_circle = clam.distances.select { |distance| distance <= radius }
62
71
 
63
- k_t = AREA_OF_PLOT * sums / (number_of_clams ** 2)
64
- l_t = radius - Math.sqrt( k_t / Math::PI)
72
+ circle_proportion = Circle.new(:clam => clam, :radius => radius).proportion_inside_plot
73
+ reciprocal_proportion = 1.0 / circle_proportion
65
74
 
66
- stats.k_ts << k_t
67
- stats.l_ts << l_t
75
+ inner_sum = reciprocal_proportion * clams_inside_circle.size
76
+ sum += inner_sum
68
77
  end
78
+
79
+ AREA_OF_PLOT * sums / (number_of_clams ** 2)
80
+ end
81
+
82
+ def calculate_l_t(k_t, radius)
83
+ radius - Math.sqrt( k_t / Math::PI)
69
84
  end
70
85
  end
71
86
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plot_statistics}
8
- s.version = "1.2.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Asa Wilson"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Asa Wilson