<commit_before>require 't_learn'

#
# === 混合正規分布を生成する
#
def gaussian_mix_1dim()
  # r = self.normal_rand(0.0,1.0 )
  r = normal_rand(rand(100),rand(100))
  # r = gauusian([rand()*100], [1.0], [[ 2.0 ]])
  # r2 = normal_rand(5.0, 5.0)
  # r3 = normal_rand(20.0, 1.0)
  r2 = normal_rand(rand(100), rand(100))
  # r2 = gauusian([rand()*100], [20.0], [[5.0]])
  # return [0.2*r + 0.8*r2]
  rand = rand()
  if (rand < 0.3)
    return [r]
  else
    return [r2]
  end

  # if (rand < 0.3)
  #   return [r]
  # elsif(rand < 0.5)
  #   return [r2]
  # else
  #   return [r3]
  # end
end

#
# ===ボックス―ミューラー法をよる正規分布乱数発生
# @param mu flout 平均
# @param sigma flout 標準偏差
# @return ボックスミューラー法に従う正規分布に従う乱数を生成
#
def normal_rand(mu = 0,sigma = 1.0)
  a, b = rand(), rand() ;
  return (Math.sqrt(-2*Math.log(rand()))*Math.sin(2*Math::PI*rand()) * sigma) + mu
end

def gaussian_mix_2dim()
    r1_x = self.normal_rand()
    r1_y = self.normal_rand()
    r2_x = self.normal_rand(10.0, 50.0)
    r2_y = self.normal_rand(10.0, 50.0)

      if (rand() < 0.15)
        return [r1_x, r1_y]
      else
        return [r2_x, r2_y]
      end
    end

em= TLearn::EM_Gaussian.new()
data_list = JSON.load(open("./faithful.json"))
# data_list = 100.times.map{|i| gaussian_mix_1dim()}
em.fit(data_list, 2)
<commit_msg>minor change<commit_after>require 't_learn'

em= TLearn::EM_Gaussian.new()
data_list = JSON.load(open("./faithful.json"))
em.fit(data_list, 2)

{'fraction_non_alphanumeric': 0.1913104414856342, 'fraction_numerical': 0.06587245970567625, 'mean_word_length': 3.262686567164179, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5488726', 'n_tokens_mistral': 740, 'n_tokens_neox': 707, 'n_words': 120}