Class: DNN::Dataset
- Inherits:
-
Object
- Object
- DNN::Dataset
- Defined in:
- lib/dnn/core/dataset.rb
Overview
This class manages input datas and output datas together.
Instance Method Summary collapse
-
#initialize(x_datas, y_datas, random = true) ⇒ Dataset
constructor
A new instance of Dataset.
-
#next_batch(batch_size) ⇒ Object
Return the next batch.
Constructor Details
#initialize(x_datas, y_datas, random = true) ⇒ Dataset
Returns a new instance of Dataset.
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 |