<commit_before>require 'bernoulli/math'
require 'bernoulli/version'

module Bernoulli
  class Distribution
  
    def initialize(n, p)
      if n < 0 or p > 1.0 or p < 0.0 or not n.is_a? Integer
        raise 'Could not initialize Bernoulli experiment'
      end
      @n = n
      @p = p
    end
    
    def to_s
      "#<Bernoulli::Distribution @n=#{@n}, @p=#{@p}>"
    end
    
    def probability(k)
      Math.binomial(@n, k) * @p**k * (1 - @p)**(@n - k)
    end
    
    def [](k)
      if k.is_a? Integer
        raise Math::DomainError if not (k <= @n and k >= 0)
        probability(k).to_f
      elsif k.is_a? Range
        raise Math::DomainError if not (k.begin >= 0 and k.end <= @n)
        sum = 0
        k.each do |i|
          sum += probability(i)
        end
        sum.to_f
      else
        raise TypeError
      end
    end
    
    def sample
      s = []
      @n.times do
        s << (rand < @p ? 1 : 0)
      end
      s
    end
    
    def sample_value
      sample.count(1)
    end
    alias :sv :sample_value
    
    def expected_value
      @n * @p
    end
    alias :ev :expected_value
    
    def variance
      @n * @p * (1 - @p)
    end
    alias :v :variance
    
    def standard_deviation
      Math.sqrt(variance)
    end
    alias :sd :standard_deviation
    
    def skewness
      (1 - 2 * @p) / (Math.sqrt(@n * @p * (1 - @p)))
    end
    
    def excess
      (1 - 6 * @p * (1 - @p)) / (@n * @p * (1 - @p))
    end
    
    def table
      csv = ""
      (0..@n).each do |n|
        csv << n.to_s << "," << probability(n).to_s << "\n"
      end
      csv
    end
  
  end
end

<commit_msg>don't use {} around instance variables being interpolated<commit_after>require 'bernoulli/math'
require 'bernoulli/version'

module Bernoulli
  class Distribution
  
    def initialize(n, p)
      if n < 0 or p > 1.0 or p < 0.0 or not n.is_a? Integer
        raise 'Could not initialize Bernoulli experiment'
      end
      @n = n
      @p = p
    end
    
    def to_s
      "#<Bernoulli::Distribution @n=#@n, @p=#@p>"
    end
    
    def probability(k)
      Math.binomial(@n, k) * @p**k * (1 - @p)**(@n - k)
    end
    
    def [](k)
      if k.is_a? Integer
        raise Math::DomainError if not (k <= @n and k >= 0)
        probability(k).to_f
      elsif k.is_a? Range
        raise Math::DomainError if not (k.begin >= 0 and k.end <= @n)
        sum = 0
        k.each do |i|
          sum += probability(i)
        end
        sum.to_f
      else
        raise TypeError
      end
    end
    
    def sample
      s = []
      @n.times do
        s << (rand < @p ? 1 : 0)
      end
      s
    end
    
    def sample_value
      sample.count(1)
    end
    alias :sv :sample_value
    
    def expected_value
      @n * @p
    end
    alias :ev :expected_value
    
    def variance
      @n * @p * (1 - @p)
    end
    alias :v :variance
    
    def standard_deviation
      Math.sqrt(variance)
    end
    alias :sd :standard_deviation
    
    def skewness
      (1 - 2 * @p) / (Math.sqrt(@n * @p * (1 - @p)))
    end
    
    def excess
      (1 - 6 * @p * (1 - @p)) / (@n * @p * (1 - @p))
    end
    
    def table
      csv = ""
      (0..@n).each do |n|
        csv << n.to_s << "," << probability(n).to_s << "\n"
      end
      csv
    end
  
  end
end


{'fraction_non_alphanumeric': 0.12869198312236288, 'fraction_numerical': 0.012658227848101266, 'mean_word_length': 1.4476401179941003, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 11, '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': '1407078', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1221, 'n_words': 354}