Module: MachineLearningWorkbench::Monkey::NumericallyApproximatable
- Defined in:
- lib/machine_learning_workbench/monkey.rb
Overview
# ‘NMatrix#to_a` has inconsistent behavior: single-row matrices are
# converted to one-dimensional Arrays rather than a 2D Array with
# only one row. Patching `#to_a` directly is not feasible as the
# constructor seems to depend on it, and I have little interest in
# investigating further.
# @return [Array<Array>] a consistent array representation, such that
# `nmat.to_consistent_a.to_nm == nmat` holds for single-row matrices
def to_consistent_a
dim == 2 && shape[0] == 1 ? [to_a] : to_a
end
alias :to_ca :to_consistent_a
end
Instance Method Summary collapse
-
#approximates?(other, epsilon = 1e-5) ⇒ Boolean
Verifies if ‘self` and `other` are withing `epsilon` of each other.
Instance Method Details
#approximates?(other, epsilon = 1e-5) ⇒ Boolean
Verifies if ‘self` and `other` are withing `epsilon` of each other.
187 188 189 190 |
# File 'lib/machine_learning_workbench/monkey.rb', line 187 def approximates? other, epsilon=1e-5 # Used for testing and NMatrix#approximates?, should I move to spec_helper? (self - other).abs < epsilon end |