lib/dnn/core/iterator.rb in ruby-dnn-0.16.2 vs lib/dnn/core/iterator.rb in ruby-dnn-1.0.0

- old
+ new

@@ -19,11 +19,11 @@ # Return the next batch. # @param [Integer] batch_size Required batch size. # @return [Array] Returns the mini batch in the form [x_batch, y_batch]. def next_batch(batch_size) - raise DNN_Error, "This iterator has not next batch. Please call reset." unless has_next? + raise DNNError, "This iterator has not next batch. Please call reset." unless has_next? if @indexes.length <= batch_size batch_indexes = @indexes @has_next = false else batch_indexes = @indexes.shift(batch_size) @@ -58,9 +58,12 @@ # Return the true if has next batch. def has_next? @has_next end + # Run a loop with all data separated by batch + # @param [Integer] batch_size Batch size. + # @yield Executes block by receiving the specified arguments (x_batch, y_batch). def foreach(batch_size, &block) steps = @last_round_down ? @num_datas / batch_size : (@num_datas.to_f / batch_size).ceil steps.times do |step| x_batch, y_batch = next_batch(batch_size) block.call(x_batch, y_batch, step)