module MachineLearningWorkbench::Monkey::NArrayOuterFlattable

Public Instance Methods

outer_flat(other) { |self, other| ... } click to toggle source

Flat-output generalized outer relationship. Same as `#outer`, but the result is a 2-dim matrix of the interactions between all the elements in `self` (as rows) and all the elements in `other` (as columns) @param other [NArray] other matrix @return [NArray]

# File lib/machine_learning_workbench/monkey.rb, line 234
def outer_flat other
  # TODO: Xumo::NArray should be able to implement this with `#outer` and some other
  # function to flatten the right layer -- much faster
  raise ArgumentError, "Need to pass an operand block" unless block_given?
  self.class.zeros([self.size, other.size]).tap do |ret|
    self.size.times do |r|
      other.size.times do |c|
        ret[r,c] = yield self[r], other[c]
      end
    end
  end
end