plot_statistics 1.2.0 → 1.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.
- data/VERSION +1 -1
- data/bin/plot_statistics +12 -8
- data/lib/plot_statistics/clam.rb +5 -0
- data/lib/plot_statistics/clam_plot.rb +25 -10
- data/plot_statistics.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
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 "
|
17
|
-
|
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
|
-
|
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
|
data/lib/plot_statistics/clam.rb
CHANGED
@@ -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
|
-
|
55
|
-
|
60
|
+
k_t = calculate_k_t(radius)
|
61
|
+
l_t = calculate_l_t(k_t, radius)
|
56
62
|
|
57
|
-
|
58
|
-
|
63
|
+
stats.k_ts << k_t
|
64
|
+
stats.l_ts << l_t
|
65
|
+
end
|
66
|
+
end
|
59
67
|
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
72
|
+
circle_proportion = Circle.new(:clam => clam, :radius => radius).proportion_inside_plot
|
73
|
+
reciprocal_proportion = 1.0 / circle_proportion
|
65
74
|
|
66
|
-
|
67
|
-
|
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
|
data/plot_statistics.gemspec
CHANGED