This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "reversi" | |
# 盤面の状態を出力する際の見た目設定 | |
Reversi.configure do |config| | |
config.disk_color_b = 'cyan' | |
config.disk_b = "O" | |
config.disk_w = "O" | |
end | |
# 初期状態から始まっている8x8盤面のみ読み込む |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matrix' | |
require 'open3' | |
require 'pp' | |
require 'pry' | |
require "./utils" | |
require "./vbem" | |
LOOP = 150 # 更新回数 | |
THRESHOLD = 0.1 # 描画する分布の混合係数のしきい値 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gtk2' | |
include Math | |
WIDTH = 1280 # 画面の幅 | |
HEIGHT = 800 # 画面の高さ | |
MAX = 30 # 表示するウィンドウの数 | |
# 使用する色 | |
COLOR_DICT = { | |
:yellow => Gdk::Color.new(65535, 65535, 0), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./perceptron" | |
require 'gnuplot' | |
# クラス1とクラス2それぞれの学習パターン | |
learning_patterns = [ | |
[12, 5, 2, -2], | |
[-4, -6, -15] | |
] | |
perceptron = Perceptron.new(learning_patterns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./perceptron" | |
require 'gnuplot' | |
learning_patterns = [ | |
[ [14], [17] ], | |
[ [12], [5], [2], [-2] ], | |
[ [-4], [-6], [-15] ] | |
] | |
perceptron = Perceptron.new(learning_patterns, 1) |