Soft Confidence Weightedも書いてみた
CW(Confidence Weighted)を実装したので調子に乗ってSCW(Soft Confidence Weighted)も書いてみた。
SCWには1と2があって、それぞれL1,L2正則化っぽい感じのことをしている。今回はSCW1を実装した。
またCWは学習時に使う共分散行列が対角成分しかなかったのだが、SCWは対角成分以外にも値が入ってくるので取りうる特徴量が多い場合はなんらかの工夫が必要かも。
test.plの最後でRGBそれぞれの重みをダンプした。scwのほうが重みが控えめになっているっぽい。
$$ perl test.pl 0.7 cw 1 3 < colors.csv update: 1,255 0 0 update: -1,0 255 0 update: -1,0 0 255 update: -1,0 255 255 update: 1,255 0 255 update: 1,255 255 0 classify: 1,255 0 0 classify: -1,0 255 0 classify: -1,0 0 255 classify: -1,0 255 255 classify: 1,255 0 255 classify: 1,255 255 0 $VAR1 = [ '1.38449968592977', '-0.569744439069359', '-0.493665917624053' ]; $$ perl test.pl 0.7 scw 1 3 < colors.csv update: 1,255 0 0 update: -1,0 255 0 update: -1,0 0 255 update: -1,0 255 255 update: 1,255 0 255 update: 1,255 255 0 classify: 1,255 0 0 classify: -1,0 255 0 classify: -1,0 0 255 classify: -1,0 255 255 classify: 1,255 0 255 classify: 1,255 255 0 $VAR1 = [ '0.900076122812987', '-0.302082751656195', '-0.19109406702321' ];