Sha256: 6a1e683429757a72c0de50698a2082f0d89d40526633232426c9e427eb33af73

Contents?: true

Size: 689 Bytes

Versions: 6

Compression:

Stored size: 689 Bytes

Contents

module DNN
  module Util
    #Create a mini batch for batch size.
    def self.get_minibatch(x, y, batch_size)
      indexes = (0...x.shape[0]).to_a.sample(batch_size)
      [x[indexes, false], y[indexes, false]]
    end

    #Categorize labels into "num_classes" classes.
    def self.to_categorical(y, num_classes, narray_type = nil)
      narray_type ||= y.class
      y2 = narray_type.zeros(y.shape[0], num_classes)
      y.shape[0].times do |i|
        y2[i, y[i]] = 1
      end
      y2
    end
  
    #Perform numerical differentiation on "forward" of "layer".
    def self.numerical_grad(x, func)
      (func.(x + 1e-7) - func.(x)) / 1e-7
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-dnn-0.1.5 lib/dnn/core/util.rb
ruby-dnn-0.1.4 lib/dnn/core/util.rb
ruby-dnn-0.1.3 lib/dnn/core/util.rb
ruby-dnn-0.1.2 lib/dnn/core/util.rb
ruby-dnn-0.1.1 lib/dnn/core/util.rb
ruby-dnn-0.1.0 lib/dnn/core/util.rb