Sha256: 81f8e8ddca42d45637e39cb08e530321f28d505416b4e3e6bf62c6bffeacc115

Contents?: true

Size: 552 Bytes

Versions: 1

Compression:

Stored size: 552 Bytes

Contents

# frozen_string_literal: true

module Zapata
  module Predictor
    class Chooser
      def initialize(possible_values)
        @possible_values = possible_values.dup
      end

      def by_probability
        return if @possible_values.empty?

        by_count
      end

      private

      def by_count
        group_with_counts(@possible_values).max_by { |_, v| v }.first
      end

      def group_with_counts(values)
        values.each_with_object(Hash.new(0)) do |value, obj|
          obj[value] += 1
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zapata-1.0.0 lib/zapata/predictor/chooser.rb