Class: DNN::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/dnn/core/dataset.rb

Overview

This class manages input datas and output datas together.

Instance Method Summary collapse

Constructor Details

#initialize(x_datas, y_datas, random = true) ⇒ Dataset

Returns a new instance of Dataset.

Parameters:

  • x_datas (Numo::SFloat) —

    input datas.

  • y_datas (Numo::SFloat) —

    output datas.

  • random (Bool) (defaults to: true) —

    Set true to return batches randomly. Setting false returns batches in order of index.



6
7
8
9
10
11
12
# File 'lib/dnn/core/dataset.rb', line 6

def initialize(x_datas, y_datas, random = true)
  @x_datas = x_datas
  @y_datas = y_datas
  @random = random
  @num_datas = x_datas.shape[0]
  reset_indexs
end

Instance Method Details

#next_batch(batch_size) ⇒ Object

Return the next batch. If the number of remaining data < batch size, if random = true, shuffle the data again and return a batch. If random = false, all remaining data will be returned regardless of the batch size.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dnn/core/dataset.rb', line 17

def next_batch(batch_size)
  if @indexes.length < batch_size
    batch_indexes = @indexes unless @random
    reset_indexs
    batch_indexes = @indexes.shift(batch_size) if @random
  else
    batch_indexes = @indexes.shift(batch_size)
  end
  x_batch = @x_datas[batch_indexes, false]
  y_batch = @y_datas[batch_indexes, false]
  [x_batch, y_batch]
end