当前位置: 首页>>代码示例>>Python>>正文


Python MiniSom.activation_response方法代码示例

本文整理汇总了Python中minisom.MiniSom.activation_response方法的典型用法代码示例。如果您正苦于以下问题:Python MiniSom.activation_response方法的具体用法?Python MiniSom.activation_response怎么用?Python MiniSom.activation_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在minisom.MiniSom的用法示例。


在下文中一共展示了MiniSom.activation_response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import activation_response [as 别名]
class TestMinisom:

    def setUp(self):
        self.som = MiniSom(5, 5, 1)
        for w in self.som.weights:  # checking weights normalization
            assert_almost_equal(1.0, np.linalg.norm(w))
        self.som.weights = np.zeros((5, 5))  # fake weights
        self.som.weights[2, 3] = 5.0
        self.som.weights[1, 1] = 2.0

    def test_fast_norm(self):
        assert minisom.fast_norm(np.array([1, 3])) == sqrt(1 + 9)

    def test_gaussian(self):
        bell = minisom.gaussian((2, 2), 1, self.som.neigx, self.som.neigy)
        assert bell.max() == 1.0
        assert bell.argmax() == 12  # unravel(12) = (2,2)

    def test_win_map(self):
        winners = self.som.win_map([5.0, 2.0])
        assert winners[(2, 3)][0] == 5.0
        assert winners[(1, 1)][0] == 2.0

    def test_activation_reponse(self):
        response = self.som.activation_response([5.0, 2.0])
        assert response[2, 3] == 1
        assert response[1, 1] == 1

    def test_activate(self):
        assert self.som.activate(5.0).argmin() == 13.0  # unravel(13) = (2,3)

    def test_quantization_error(self):
        self.som.quantization_error([5, 2]) == 0.0
        self.som.quantization_error([4, 1]) == 0.5

    def test_quantization(self):
        q = self.som.quantization(np.array([4, 2]))
        assert q[0] == 5.0
        assert q[1] == 2.0

    # def test_random_seed(self):
    #     som1 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som2 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     # same initialization
    #     assert_array_almost_equal(som1.weights, som2.weights)
    #     data = np.random.rand(100, 2)
    #     som1 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som1.train_random(data, 10)
    #     som2 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som2.train_random(data, 10)
    #     # same state after training
    #     assert_array_almost_equal(som1.weights, som2.weights)

    def test_train_batch(self):
        som = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
        data = np.array([[4, 2], [3, 1]])
        q1 = som.quantization_error(data)
        som.train_batch(data, 10)
        assert q1 > som.quantization_error(data)

    # def test_train_random(self):
    #     som = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     data = np.array([[4, 2], [3, 1]])
    #     q1 = som.quantization_error(data)
    #     som.train_random(data, 10)
    #     assert q1 > som.quantization_error(data)

    def test_random_weights_init(self):
        som = MiniSom(2, 2, 2, sigma=0.1, random_seed=1)
        som.random_weights_init(np.array([[1.0, .0]]))
        for w in som.weights:
            assert_array_equal(w[0], np.array([1.0, .0]))
开发者ID:vitorhirota,项目名称:minisom,代码行数:74,代码来源:test.py


注:本文中的minisom.MiniSom.activation_response方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。