lib/fathom/plausible_range.rb in fathom-0.1.0 vs lib/fathom/plausible_range.rb in fathom-0.2.0
- old
+ new
@@ -50,11 +50,15 @@
end
alias :std :standard_deviation
# Not using specific distributions yet
def rand
- rng.gaussian(std) + midpoint
+ value = get_rand
+ until is_bounded?(value) do
+ value= get_rand
+ end
+ value
end
def array_of_random_values(n=10)
n.times.map {self.rand}
end
@@ -64,9 +68,25 @@
GSL::Vector.alloc(array_of_random_values(n))
end
alias :to_v :vector_of_random_values
protected
+
+ def is_bounded?(value)
+ return true unless hard_lower_bound or hard_upper_bound
+ if hard_lower_bound and hard_upper_bound
+ value >= hard_lower_bound and value <= hard_upper_bound
+ elsif hard_lower_bound
+ value >= hard_lower_bound
+ elsif hard_upper_bound
+ value <= hard_upper_bound
+ end
+ end
+
+ def get_rand
+ rng.gaussian(std) + midpoint
+ end
+
def rng
@rng ||= GSL::Rng.alloc
end
end