Sha256: 7eedc839298c2feecd3718473697572aedba66c9236f2c59d5c24ee8cc2216d2
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
# This class manages input datas and output datas together. class DNN::Dataset # @param [Numo::SFloat] x_datas input datas. # @param [Numo::SFloat] y_datas output datas. # @param [Bool] random Set true to return batches randomly. Setting false returns batches in order of index. 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 # 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. 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 private def reset_indexs @indexes = @num_datas.times.to_a @indexes.shuffle! if @random end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-dnn-0.10.1 | lib/dnn/core/dataset.rb |
ruby-dnn-0.10.0 | lib/dnn/core/dataset.rb |