Class: Rational
- Inherits:
-
Numeric
- Object
- Numeric
- Rational
- Defined in:
- lib/fathom/archive/noodle.rb
Overview
Since Rational is the automatic choice for probabilistic data,
and since I don't want to override how mathn infers numbers,
I am adding some baggage to Rational:
* It still reduces to the LCD
* It keeps track of all events,
so that I can keep a new event proportional to old ones
* It has an add_event (add) which takes a true or false value
true values, records that a condition was found
This really only works for binary data, but this is a noodle file.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_event(positive = true) ⇒ Object
(also: #add)
Uses the Rational constructor to calculate the lowest common denominator.
- #positive_events(val = nil) ⇒ Object (also: #positive)
- #positive_events=(val) ⇒ Object
- #total_events(val = nil) ⇒ Object (also: #events, #total)
- #total_events=(val) ⇒ Object
Class Method Details
.orig_reduce ⇒ Object
78 |
# File 'lib/fathom/archive/noodle.rb', line 78 alias :orig_reduce :reduce |
.reduce(num, den = 1) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/fathom/archive/noodle.rb', line 79 def reduce(num, den=1) val = orig_reduce(num, den) val.total_events = den val.positive_events = num val end |
Instance Method Details
#add_event(positive = true) ⇒ Object Also known as: add
Uses the Rational constructor to calculate the lowest common denominator
111 112 113 114 115 116 117 |
# File 'lib/fathom/archive/noodle.rb', line 111 def add_event(positive=true) num = positive ? self.positive_events + 1 : self.positive_events den = self.total_events + 1 other = Rational(num, den) @numerator, @denominator, @positive_events, @total_events = other.numerator, other.denominator, num, den self end |
#positive_events(val = nil) ⇒ Object Also known as: positive
99 100 101 102 103 |
# File 'lib/fathom/archive/noodle.rb', line 99 def positive_events(val=nil) @positive_events ||= 0 @positive_events = val if val @positive_events end |
#positive_events=(val) ⇒ Object
106 107 108 |
# File 'lib/fathom/archive/noodle.rb', line 106 def positive_events=(val) positive_events(val) end |
#total_events(val = nil) ⇒ Object Also known as: events, total
87 88 89 90 91 |
# File 'lib/fathom/archive/noodle.rb', line 87 def total_events(val=nil) @total_events ||= 0 @total_events = val if val @total_events end |
#total_events=(val) ⇒ Object
95 96 97 |
# File 'lib/fathom/archive/noodle.rb', line 95 def total_events=(val) total_events(val) end |