5.8 从网上下载或者实现自己的SOM网络,并观察其在西瓜会聚集3.0alpha上的结果。
书上关于SOM的介绍太简洁了,只看书上的内容基本上不可能明白SOM到底是怎么回事儿。可以阅读这篇博客:自组织映射网络SOM,增加对SOM的了解。
"""
Author: Victoria
Created on 2017.9.19 21:00
"""
import numpy as np
import matplotlib.pyplot as plt
import random
import xlrd
class SOMNet():
def __init__(self, input_dims, output_nums, sigma0, rta0, tau1, tau2, iterations):
self.input_dims = input_dims
self.output_nums = output_nums
self.sigma0 = sigma0
self.eta0 = eta0
self.tau1 = tau1
self.tau2 = tau2
self.iterations = iterations
self.weights = np.random.rand(output_nums, input_dims)
def distance(self, w, x):
"""
Compute distance between array w and vector v2.
Input:
w: np.array with shape [m, d]
x: np.array with shape [1, d]
Return:
dist_square: np.array with shape [m, 1] when w is array or float when w is vector
"""
m