Class: Maxima::Histogram
Instance Attribute Summary collapse
-
#points ⇒ Object
Returns the value of attribute points.
Attributes inherited from Unit
Class Method Summary collapse
- .between(min, max, function = ->(x) { x }, steps = 100) ⇒ Object
- .from_csv(csv) ⇒ Object
- .parse(s) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(*points, **options) ⇒ Histogram
constructor
A new instance of Histogram.
-
#integral ⇒ Object
literal CDF.
- #polynomial_fit(degrees) ⇒ Object
- #to_a ⇒ Object
- #to_gnu_plot ⇒ Object
-
#to_percentage ⇒ Object
PDF.
Methods inherited from Unit
#==, #===, #at, #gnu_plot_options, #gnu_plot_text, #gnu_plot_w, #imaginary?, #inspect, #negative?, parse_float, #positive?, #real?, #simplified, #through_maxima, #to_f, #to_maxima_input, #to_pdf, #to_s, #with_plot_title, #zero?
Constructor Details
#initialize(*points, **options) ⇒ Histogram
Returns a new instance of Histogram.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/maxima/histogram.rb', line 29 def initialize(*points, **) super(**) while points.is_a?(Array) && points.first.is_a?(Array) && points.first.first.is_a?(Array) points = points.flatten(1) end unless points.is_a?(Array) && points.first.is_a?(Array) && points.first.length == 2 throw :invalid_histogram_points end @points = points end |
Instance Attribute Details
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/maxima/histogram.rb', line 3 def points @points end |
Class Method Details
.between(min, max, function = ->(x) { x }, steps = 100) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/maxima/histogram.rb', line 5 def self.between(min, max, function = ->(x) { x }, steps = 100) Histogram.new( *[].tap do |points| (min..max).step((max - min).fdiv(steps)).each do |x| points.push([x, function.call(x)]) end end ) end |
Instance Method Details
#<=>(other) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/maxima/histogram.rb', line 80 def <=>(other) case other when Array, Histogram self.to_a <=> other.to_a else -1 end end |
#integral ⇒ Object
literal CDF
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/maxima/histogram.rb', line 64 def integral() begin sum = 0 Histogram.new( points.map do |(x, y)| sum += y [x, sum] end ) end end |
#polynomial_fit(degrees) ⇒ Object
15 16 17 |
# File 'lib/maxima/histogram.rb', line 15 def polynomial_fit(degrees) Polynomial.fit(self, degrees)[:function] end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/maxima/histogram.rb', line 43 def to_a @points end |
#to_gnu_plot ⇒ Object
76 77 78 |
# File 'lib/maxima/histogram.rb', line 76 def to_gnu_plot() [*points.map(&:to_a).transpose, w: "points"] end |