Class: GEPA::Strategies::EpochShuffledBatchSampler
- Inherits:
-
Object
- Object
- GEPA::Strategies::EpochShuffledBatchSampler
- Extended by:
- T::Sig
- Defined in:
- lib/gepa/strategies/batch_sampler.rb
Instance Method Summary collapse
-
#initialize(minibatch_size, rng: nil, telemetry: nil) ⇒ EpochShuffledBatchSampler
constructor
A new instance of EpochShuffledBatchSampler.
- #next_minibatch_indices(trainset_size, iteration) ⇒ Object
Constructor Details
#initialize(minibatch_size, rng: nil, telemetry: nil) ⇒ EpochShuffledBatchSampler
Returns a new instance of EpochShuffledBatchSampler.
11 12 13 14 15 16 17 18 |
# File 'lib/gepa/strategies/batch_sampler.rb', line 11 def initialize(minibatch_size, rng: nil, telemetry: nil) @minibatch_size = minibatch_size @rng = rng || Random.new(0) @telemetry = telemetry @shuffled_ids = [] @epoch = -1 @id_freqs = Hash.new(0) end |
Instance Method Details
#next_minibatch_indices(trainset_size, iteration) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gepa/strategies/batch_sampler.rb', line 21 def next_minibatch_indices(trainset_size, iteration) with_span( 'gepa.strategies.batch_sampler', minibatch_size: @minibatch_size, trainset_size: trainset_size, iteration: iteration ) do ensure_epoch(trainset_size, iteration) base_idx = (iteration * @minibatch_size) % @shuffled_ids.length end_idx = base_idx + @minibatch_size @shuffled_ids[base_idx...end_idx] end end |