Sha256: d5a2bebb33ad3e27d8fce9b154cce236eef0eff7ffd090d3837616d86acab258

Contents?: true

Size: 436 Bytes

Versions: 1

Compression:

Stored size: 436 Bytes

Contents

# frozen_string_literal: true

module SVMKit
  # @!visibility private
  module Utils
    module_function

    # @!visibility private
    def choice_ids(size, probs, rng = nil)
      rng ||= Random.new
      Array.new(size) do
        target = rng.rand
        chosen = 0
        probs.each_with_index do |p, idx|
          break (chosen = idx) if target <= p
          target -= p
        end
        chosen
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
svmkit-0.7.3 lib/svmkit/utils.rb