Sha256: 971fae4baea3cb9ef84f2d961e4f1baf23f4214109b5fc6d11c6a7e5759ec834
Contents?: true
Size: 692 Bytes
Versions: 3
Compression:
Stored size: 692 Bytes
Contents
# frozen_string_literal: true module Stats def mean(values, &block) return 0 if values.empty? values.sum(&block).to_f / values.length end def min(values, &block) return 0 if values.empty? block ||= :itself.to_proc block.call(values.min_by(&block)) end def max(values, &block) return 0 if values.empty? block ||= :itself.to_proc block.call(values.max_by(&block)) end def variance(values, &block) return 0 if values.empty? values.sum { |sample| (mean(values, &block) - (block ? block.call(sample) : sample))**2 }.to_f / values.length end def standard_deviation(values, &block) Math.sqrt(variance(values, &block)) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spellr-0.5.0 | lib/spellr/key_tuner/stats.rb |
spellr-0.4.1 | lib/spellr/key_tuner/stats.rb |
spellr-0.4.0 | lib/spellr/key_tuner/stats.rb |