def test_simple_som(self): colors = np.array( [ [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 1.0, 1.0], ] ) # only small SOM for speed reasons som = SimpleSOMMapper((10, 5), 200, learning_rate=0.05) # no acces when nothing is there self.failUnlessRaises(RuntimeError, som._access_kohonen) som.train(colors) fmapped = som.forward(colors) self.failUnless(fmapped.shape == (8, 2)) # reverse mapping rmapped = som.reverse(fmapped) if cfg.getboolean("tests", "labile", default="yes"): # should approximately restore the input, but could fail # with bad initialisation self.failUnless((np.round(rmapped) == colors).all())
def testSimpleSOM(self): colors = [[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.], [0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]] ds = Dataset(samples=colors, labels=1) # only small SOM for speed reasons som = SimpleSOMMapper((10, 5), 200, learning_rate=0.05) # no acces when nothing is there self.failUnlessRaises(RuntimeError, som._accessKohonen) self.failUnlessRaises(RuntimeError, som.getInSize) self.failUnlessRaises(RuntimeError, som.getOutSize) som.train(ds) self.failUnless(som.getInSize() == 3) self.failUnless(som.getOutSize() == (10,5)) fmapped = som(colors) self.failUnless(fmapped.shape == (8, 2)) for fm in fmapped: self.failUnless(som.isValidOutId(fm)) # reverse mapping rmapped = som.reverse(fmapped) if cfg.getboolean('tests', 'labile', default='yes'): # should approximately restore the input, but could fail # with bas initialisation self.failUnless((N.round(rmapped) == ds.samples).all())
def test_simple_som(self): colors = np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [1., 0., 0.], [0., 1., 1.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.]]) # only small SOM for speed reasons som = SimpleSOMMapper((10, 5), 200, learning_rate=0.05) # no acces when nothing is there self.failUnlessRaises(RuntimeError, som._access_kohonen) som.train(colors) fmapped = som(colors) self.failUnless(fmapped.shape == (8, 2)) # reverse mapping rmapped = som.reverse(fmapped) if cfg.getboolean('tests', 'labile', default='yes'): # should approximately restore the input, but could fail # with bad initialisation self.failUnless((np.round(rmapped) == colors).all())