plot_statistics 0.1.0 → 0.2.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,9 +1,16 @@
1
- = plot_statistics
1
+ # plot_statistics
2
2
 
3
- Description goes here.
3
+ This is a library originally designed to run Ripley's K analyses on Clam Plots. The input is any number of tab separated files with an x and a y column like so:
4
+
5
+ 21 23
6
+ 4 45
7
+ 32 99
8
+ 32 32
9
+
10
+ The output is a Tab separated file that shows the output of the Ripley's K analysis and then mean and upper and lower limits of a Monte Carlo simulation of the data.
11
+
12
+ ## Note on Patches/Pull Requests
4
13
 
5
- == Note on Patches/Pull Requests
6
-
7
14
  * Fork the project.
8
15
  * Make your feature addition or bug fix.
9
16
  * Add tests for it. This is important so I don't break it in a
@@ -12,6 +19,6 @@ Description goes here.
12
19
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
20
  * Send me a pull request. Bonus points for topic branches.
14
21
 
15
- == Copyright
22
+ ## Copyright
16
23
 
17
24
  Copyright (c) 2010 Asa Wilson. See LICENSE for details.
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "plot_statistics"
8
- gem.summary = %Q{Statistics on clam plots}
9
- gem.description = %Q{This is a gem I built for my wife to analyze various clam plots.}
8
+ gem.summary = %Q{This is a gem to do a Ripley's K analysis}
9
+ gem.description = %Q{This is a gem to do a Ripley's K analysis}
10
10
  gem.email = "acvwilson@gmail.com"
11
11
  gem.homepage = "http://github.com/acvwilson/plot_statistics"
12
12
  gem.authors = ["Asa Wilson"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,7 +1,8 @@
1
1
  class PlotStatistics
2
2
  require 'ostruct'
3
3
 
4
- require File.dirname(__FILE__) + '/plot_statistics/clam.rb'
4
+ require File.dirname(__FILE__) + '/plot_statistics/circle'
5
+ require File.dirname(__FILE__) + '/plot_statistics/clam'
5
6
  require File.dirname(__FILE__) + '/plot_statistics/clam_plot'
6
7
  require File.dirname(__FILE__) + '/plot_statistics/monte_carlo'
7
8
  end
@@ -0,0 +1,71 @@
1
+ class PlotStatistics
2
+ class Circle
3
+ attr_accessor :clam, :radius, :sample_points, :proportion_inside_plot
4
+
5
+ DEGREES = [15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345, 360]
6
+ RADIANS_TO_DEGREES = 360.0 / (2.0 * Math::PI)
7
+
8
+ def initialize(params={})
9
+ @clam = params[:clam]
10
+ @radius = params[:radius]
11
+ @sample_points = { :out_of_bounds => 0.0, :in_bounds => 0.0 }
12
+ @proportion_inside_plot = out_of_bounds? ? estimate_proportion_inside_plot : 1.0
13
+ end
14
+
15
+ def create_samples
16
+ sample_circles = radius * 2
17
+ sample_radius = 0.5
18
+ sample_circles.times do
19
+ DEGREES.each do |degrees|
20
+ x = clam.x + sample_radius * Math.cos(degrees / RADIANS_TO_DEGREES)
21
+ y = clam.y + sample_radius * Math.sin(degrees / RADIANS_TO_DEGREES)
22
+
23
+ if point_out_of_bounds?(x, y)
24
+ sample_points[:out_of_bounds] += 1
25
+ else
26
+ sample_points[:in_bounds] += 1
27
+ end
28
+ end
29
+
30
+ sample_radius += 0.5
31
+ end
32
+ end
33
+
34
+ def estimate_proportion_inside_plot
35
+ create_samples
36
+ sample_points[:in_bounds] / (sample_points[:in_bounds] + sample_points[:out_of_bounds])
37
+ end
38
+
39
+ def point_out_of_bounds?(x, y)
40
+ [x, y].each do |coordinate|
41
+ return true unless coordinate > 0 && coordinate < 100
42
+ end
43
+ false
44
+ end
45
+
46
+ def out_of_bounds?
47
+ right_out_of_bounds? ||
48
+ left_out_of_bounds? ||
49
+ top_out_of_bounds? ||
50
+ bottom_out_of_bounds?
51
+ end
52
+
53
+ def right_out_of_bounds?
54
+ clam.x + radius > 100
55
+ end
56
+
57
+ def left_out_of_bounds?
58
+ clam.x - radius < 0
59
+ end
60
+
61
+ def top_out_of_bounds?
62
+ clam.y + radius > 100
63
+ end
64
+
65
+ def bottom_out_of_bounds?
66
+ clam.y - radius < 0
67
+ end
68
+
69
+
70
+ end
71
+ end
@@ -23,7 +23,6 @@ class PlotStatistics
23
23
 
24
24
  def setup_clam_distances(clams)
25
25
  clams.each_with_index do |reference_clam, i|
26
- # next if (clams.size - 1) < i
27
26
  clams[(i + 1)..-1].each do |other_clam|
28
27
  distance = distance_between_clams(reference_clam, other_clam)
29
28
  reference_clam.distances << distance
@@ -38,13 +37,15 @@ class PlotStatistics
38
37
 
39
38
  def calculate_stats
40
39
  (1..MAX_RADIUS).each do |radius|
41
- circle_proportion = 1.0
42
40
 
43
41
  sums = clams.inject(0) do |sum, clam|
44
42
  clams_inside_circle = clam.distances.select { |distance| distance <= radius }
45
43
 
44
+ circle_proportion = Circle.new(:clam => clam, :radius => radius).proportion_inside_plot
45
+ reciprocal_proportion = 1 / circle_proportion
46
+
46
47
  clams_inside_circle.inject(0) do |sum, inside_clam|
47
- ( circle_proportion * 1.0 ) / ( number_of_clams ** 2 )
48
+ ( reciprocal_proportion * 1.0 ) / ( number_of_clams ** 2 )
48
49
  end
49
50
  end
50
51
 
@@ -5,28 +5,29 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plot_statistics}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.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"]
12
- s.date = %q{2010-03-03}
12
+ s.date = %q{2010-03-16}
13
13
  s.default_executable = %q{plot_statistics}
14
- s.description = %q{This is a gem I built for my wife to analyze various clam plots.}
14
+ s.description = %q{This is a gem to do a Ripley's K analysis}
15
15
  s.email = %q{acvwilson@gmail.com}
16
16
  s.executables = ["plot_statistics"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.rdoc"
19
+ "README.markdown"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
23
  ".gitignore",
24
24
  "LICENSE",
25
- "README.rdoc",
25
+ "README.markdown",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bin/plot_statistics",
29
29
  "lib/plot_statistics.rb",
30
+ "lib/plot_statistics/circle.rb",
30
31
  "lib/plot_statistics/clam.rb",
31
32
  "lib/plot_statistics/clam_plot.rb",
32
33
  "lib/plot_statistics/monte_carlo.rb",
@@ -39,7 +40,7 @@ Gem::Specification.new do |s|
39
40
  s.rdoc_options = ["--charset=UTF-8"]
40
41
  s.require_paths = ["lib"]
41
42
  s.rubygems_version = %q{1.3.6}
42
- s.summary = %q{Statistics on clam plots}
43
+ s.summary = %q{This is a gem to do a Ripley's K analysis}
43
44
  s.test_files = [
44
45
  "spec/plot_statistics_spec.rb",
45
46
  "spec/spec_helper.rb"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Asa Wilson
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-03 00:00:00 -05:00
17
+ date: 2010-03-16 00:00:00 -04:00
18
18
  default_executable: plot_statistics
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 1.2.9
32
32
  type: :development
33
33
  version_requirements: *id001
34
- description: This is a gem I built for my wife to analyze various clam plots.
34
+ description: This is a gem to do a Ripley's K analysis
35
35
  email: acvwilson@gmail.com
36
36
  executables:
37
37
  - plot_statistics
@@ -39,16 +39,17 @@ extensions: []
39
39
 
40
40
  extra_rdoc_files:
41
41
  - LICENSE
42
- - README.rdoc
42
+ - README.markdown
43
43
  files:
44
44
  - .document
45
45
  - .gitignore
46
46
  - LICENSE
47
- - README.rdoc
47
+ - README.markdown
48
48
  - Rakefile
49
49
  - VERSION
50
50
  - bin/plot_statistics
51
51
  - lib/plot_statistics.rb
52
+ - lib/plot_statistics/circle.rb
52
53
  - lib/plot_statistics/clam.rb
53
54
  - lib/plot_statistics/clam_plot.rb
54
55
  - lib/plot_statistics/monte_carlo.rb
@@ -85,7 +86,7 @@ rubyforge_project:
85
86
  rubygems_version: 1.3.6
86
87
  signing_key:
87
88
  specification_version: 3
88
- summary: Statistics on clam plots
89
+ summary: This is a gem to do a Ripley's K analysis
89
90
  test_files:
90
91
  - spec/plot_statistics_spec.rb
91
92
  - spec/spec_helper.rb