<commit_before>module Stat
  module Basic
    def arithmetic_mean(values)
      values.reduce(&:+) / values.length
    end
    alias_method :mean, :arithmetic_mean

    def geometric_mean(values)
      values.reduce(&:*) ** (1.0/values.length)
    end
    
    def median(values)
      n = values.length
      if n.odd? 
        values.sort[n / 2]
      else
        index = n / 2 - 1
        mean values.sort[index, 2]
      end
    end

    def mode(values)
      # Maybe there's a better way to do this...
      values.sort.
        group_by {|i| i }.
        max_by {|k,v| v.length }.
        first
    end

    def variance(values, type=:population)
      n = type == :population ? values.length : values.length - 1
      mean = mean values
      1.0 / n * values.reduce {|x| (x - mean) ** 2 }
    end

    def std(values, type=:population)
      Math.sqrt variance(values, type)
    end

    def stderr(values)
      n = values.length
      std(values, :sample) / sqrt(n)
    end
    alias :sem, :stderr

    def relative_stderr(values)
      stderr(values) / mean(values) * 100
    end
    alias :rse, :relative_stderr

    def coefficient_of_variation(values, type=:population)
      std(values, type) / mean(values) * 100
    end
    alias :cv, :coefficient_of_variation
  end
end
<commit_msg>make all methods class methods<commit_after>module Stat
  module Basic
    def self.arithmetic_mean(values)
      values.reduce(&:+) / values.length
    end
    alias_method :mean, :arithmetic_mean

    def self.geometric_mean(values)
      values.reduce(&:*) ** (1.0/values.length)
    end
    
    def self.median(values)
      n = values.length
      if n.odd? 
        values.sort[n / 2]
      else
        index = n / 2 - 1
        mean values.sort[index, 2]
      end
    end

    def self.mode(values)
      # Maybe there's a better way to do this...
      values.sort.
        group_by {|i| i }.
        max_by {|k,v| v.length }.
        first
    end

    def self.variance(values, type=:population)
      n = type == :population ? values.length : values.length - 1
      mean = mean values
      1.0 / n * values.reduce {|x| (x - mean) ** 2 }
    end

    def self.std(values, type=:population)
      Math.sqrt variance(values, type)
    end

    def self.stderr(values)
      n = values.length
      std(values, :sample) / sqrt(n)
    end
    alias :sem, :stderr

    def self.relative_stderr(values)
      stderr(values) / mean(values) * 100
    end
    alias :rse, :relative_stderr

    def self.coefficient_of_variation(values, type=:population)
      std(values, type) / mean(values) * 100
    end
    alias :cv, :coefficient_of_variation
  end
end

{'fraction_non_alphanumeric': 0.11290322580645161, 'fraction_numerical': 0.012003000750187547, 'mean_word_length': 2.093967517401392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2710209', 'n_tokens_mistral': 929, 'n_tokens_neox': 868, 'n_words': 232}