Module: MachineLearningWorkbench::Monkey::MatrixApproximatable
- Defined in:
- lib/machine_learning_workbench/monkey.rb
Instance Method Summary collapse
-
#approximates?(other, epsilon = 1e-5) ⇒ Boolean
Verifies if all values at corresponding indices approximate each other.
Instance Method Details
#approximates?(other, epsilon = 1e-5) ⇒ Boolean
Verifies if all values at corresponding indices approximate each other.
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/machine_learning_workbench/monkey.rb', line 196 def approximates? other, epsilon=1e-5 return false unless self.shape == other.shape # two ways to go here: # - epsilon is aggregated: total cumulative accepted error # => `(self - other).reduce(:+) < epsilon` # - epsilon is local: per element accepted error # => `v.approximates? other[*idxs], epsilon` # Given the use I make (near-equality), I choose the first interpretation # Note the second is sensitive to opposite signs balancing up self.each_stored_with_indices.all? do |v,*idxs| v.approximates? other[*idxs], epsilon end end |