Class: Iriq::PositionEvidence
- Inherits:
-
Struct
- Object
- Struct
- Iriq::PositionEvidence
- Defined in:
- lib/iriq/position_evidence.rb
Overview
The slice of a position's stats that classifying one value reads (Corpus#classify). A backend can answer it without materializing every value tracked at the position.
Instance Attribute Summary collapse
-
#cardinality ⇒ Object
Returns the value of attribute cardinality.
-
#total ⇒ Object
Returns the value of attribute total.
-
#type_counts ⇒ Object
Returns the value of attribute type_counts.
-
#value_count ⇒ Object
Returns the value of attribute value_count.
Class Method Summary collapse
-
.from_stats(stats, value) ⇒ Object
value_count is nil when the value isn't tracked (never seen, or dropped at the cap).
Instance Method Summary collapse
-
#value_fraction ⇒ Object
Same as PositionStats#value_fraction for the probed value.
-
#variable_fraction(classifier) ⇒ Object
Same as PositionStats#variable_fraction.
Instance Attribute Details
#cardinality ⇒ Object
Returns the value of attribute cardinality
5 6 7 |
# File 'lib/iriq/position_evidence.rb', line 5 def cardinality @cardinality end |
#total ⇒ Object
Returns the value of attribute total
5 6 7 |
# File 'lib/iriq/position_evidence.rb', line 5 def total @total end |
#type_counts ⇒ Object
Returns the value of attribute type_counts
5 6 7 |
# File 'lib/iriq/position_evidence.rb', line 5 def type_counts @type_counts end |
#value_count ⇒ Object
Returns the value of attribute value_count
5 6 7 |
# File 'lib/iriq/position_evidence.rb', line 5 def value_count @value_count end |
Class Method Details
.from_stats(stats, value) ⇒ Object
value_count is nil when the value isn't tracked (never seen, or dropped at the cap).
8 9 10 11 12 13 14 15 |
# File 'lib/iriq/position_evidence.rb', line 8 def self.from_stats(stats, value) new( total: stats.total, type_counts: stats.type_counts, cardinality: stats.cardinality, value_count: stats.value_counts.fetch(value, nil), ) end |
Instance Method Details
#value_fraction ⇒ Object
Same as PositionStats#value_fraction for the probed value.
25 26 27 28 29 |
# File 'lib/iriq/position_evidence.rb', line 25 def value_fraction return 0.0 if total.zero? (value_count || 0).to_f / total end |
#variable_fraction(classifier) ⇒ Object
Same as PositionStats#variable_fraction.
18 19 20 21 22 |
# File 'lib/iriq/position_evidence.rb', line 18 def variable_fraction(classifier) return 0.0 if total.zero? type_counts.sum { |t, c| classifier.variable?(t) ? c : 0 }.to_f / total end |