Skip to content

Instantly share code, notes, and snippets.

@seinosuke
seinosuke / load_ggf.rb
Created September 10, 2017 05:59
リバーシのGGFファイルから局面と評価値のセットを抽出するスクリプト
require "reversi"
# 盤面の状態を出力する際の見た目設定
Reversi.configure do |config|
config.disk_color_b = 'cyan'
config.disk_b = "O"
config.disk_w = "O"
end
# 初期状態から始まっている8x8盤面のみ読み込む
@seinosuke
seinosuke / main.rb
Last active September 7, 2016 07:06
【Ruby】 VBEMアルゴリズム 参照→( http://syoshinsyakangeisagi.blogspot.com/2016/09/ruby-vbemprml10.html
require 'matrix'
require 'open3'
require 'pp'
require 'pry'
require "./utils"
require "./vbem"
LOOP = 150 # 更新回数
THRESHOLD = 0.1 # 描画する分布の混合係数のしきい値
@seinosuke
seinosuke / main.rb
Last active March 19, 2016 06:15
Ruby GTK 警告ウィンドウ
require 'gtk2'
include Math
WIDTH = 1280 # 画面の幅
HEIGHT = 800 # 画面の高さ
MAX = 30 # 表示するウィンドウの数
# 使用する色
COLOR_DICT = {
:yellow => Gdk::Color.new(65535, 65535, 0),
@seinosuke
seinosuke / ema.rb
Last active January 6, 2016 11:44
【Ruby】 EMアルゴリズムでクラスタリング 参照→( http://syoshinsyakangeisagi.blogspot.com/2016/01/ruby-em.html )
class EMA
attr_reader :all_patterns, :k
def initialize(options = {})
@dimension = options[:dimension]
@k = options[:k]
orig_patterns = options[:patterns].map do |pattern|
Matrix[pattern.map(&:to_f)]
end
@means = orig_patterns.sample(@k)
@seinosuke
seinosuke / lvq.rb
Last active November 24, 2015 09:59
Rubyで学習ベクトル量子化 参照→( http://syoshinsyakangeisagi.blogspot.com/2015/11/ruby.html )
class LVQ
attr_accessor :log
ALPHA = 0.005
def initialize(learning_patterns, dimension)
@log = []
@dimension = dimension
@class_num = learning_patterns.size
@learning_patterns = learning_patterns.map do |patterns|
patterns.map { |pattern| Vector[*pattern.map(&:to_f)] }
@seinosuke
seinosuke / voronoi.gif
Last active September 26, 2015 10:55
Rubyでなんちゃって離散ボロノイ図 参照→http://syoshinsyakangeisagi.blogspot.com/2015/09/ruby_11.html
voronoi.gif
@seinosuke
seinosuke / main.rb
Created September 10, 2015 03:28
Rubyでパーセプトロン (1次元2クラスにしか対応してない版)
require "./perceptron"
require 'gnuplot'
# クラス1とクラス2それぞれの学習パターン
learning_patterns = [
[12, 5, 2, -2],
[-4, -6, -15]
]
perceptron = Perceptron.new(learning_patterns)
@seinosuke
seinosuke / example01.rb
Last active September 9, 2015 09:35
Rubyでパーセプトロンを実装してみた 参照→http://syoshinsyakangeisagi.blogspot.com/2015/09/ruby.html
require "./perceptron"
require 'gnuplot'
learning_patterns = [
[ [14], [17] ],
[ [12], [5], [2], [-2] ],
[ [-4], [-6], [-15] ]
]
perceptron = Perceptron.new(learning_patterns, 1)