西瓜书《机器学习》课后答案——chapter5_5.8 SOM网络

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
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值