module MachineLearningWorkbench::Monkey::NumericallyApproximatable

# `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

Public Instance Methods

approximates?(other, epsilon=1e-5) click to toggle source

Verifies if `self` and `other` are withing `epsilon` of each other. @param other [Numeric] @param epsilon [Numeric] @return [Boolean]

# 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