예제 #1
0
    def test_repeatability(self):
        r1 = makeGenerator("Sphere", 10, 1)
        r2 = makeGenerator("Sphere", 10, 2)
        s11 = r1.get(10)
        s12 = r1.get(10)
        r1.reset()
        s11a = r1.get(10)
        s2 = r2.get(10)

        self.assertNotEqual(s11.data, s12.data)
        self.assertEqual(s11.data, s11a.data)
        self.assertNotEqual(s11.data, s2.data)
    def test_repeatability(self):
        r1 = makeGenerator('Sphere', 10, 1)
        r2 = makeGenerator('Sphere', 10, 2)
        s11 = r1.get(10)
        s12 = r1.get(10)
        r1.reset()
        s11a = r1.get(10)
        s2 = r2.get(10)

        self.assertNotEqual(s11.data, s12.data)
        self.assertEqual(s11.data, s11a.data)
        self.assertNotEqual(s11.data, s2.data)
예제 #3
0
    def initialize_node(self):
        random = numpy.random.RandomState(seed=self.seed)

        if self.data_saturations is None:
            sr = self.saturation_range
            sat = random.uniform(sr[0], sr[1], (self.neurons, 1))
        else:
            N = len(self.data_saturations)
            sat = numpy.array(
                [[self.data_saturations[i % N] for i in range(self.neurons)]],
                dtype=numpy.dtype('float32')).T

        if self.data_thresholds is None:
            delta = (self.max - self.min) * (1 - self.threshold_coverage) * 0.5
            min_thresh = self.min + delta
            max_thresh = self.max - delta
            if self.threshold_min is not None: min_thresh = self.threshold_min
            if self.threshold_max is not None: max_thresh = self.threshold_max

            thresh = random.uniform(min_thresh, max_thresh, (self.neurons, 1))
        else:
            N = len(self.data_thresholds)
            thresh = numpy.array(
                [[self.data_thresholds[i % N] for i in range(self.neurons)]],
                dtype=numpy.dtype('float32')).T

        self.initialize_neurons(sat, thresh)

        if self.data_basis is None:
            g = makeGenerator(self.basis_style, self.dimensions,
                              int(random.randint(0x7FFFFFFF)))
            self.basis = g.get(self.neurons).T
        else:
            N = len(self.data_basis)
            self.basis = numpy.array(
                [self.data_basis[i % N] for i in range(self.neurons)],
                dtype=numpy.dtype('float32'))
            if len(self.basis.shape) == 1:
                self.basis.shape = (self.neurons, self.dimensions)

        self.sample_generator = makeGenerator(self.sample_style,
                                              self.dimensions,
                                              int(random.randint(0x7FFFFFFF)))
        if self.min != -1 or self.max != 1:
            scale = (self.max - self.min) / 2.0
            if scale != 1.0: self.sample_generator.scale = scale
            offset = (self.max + self.min) / 2.0
            if scale != 0.0: self.sample_generator.offset = offset
예제 #4
0
 def test_cube(self):
     s = makeGenerator("Cube", 3, None).get(1000)
     for v in s.T:
         x, y, z = v
         self.assert_(-1 < x < 1)
         self.assert_(-1 < y < 1)
         self.assert_(-1 < z < 1)
 def test_cube(self):
     s = makeGenerator('Cube', 3, None).get(1000)
     for v in s.T:
         x, y, z = v
         self.assert_(-1 < x < 1)
         self.assert_(-1 < y < 1)
         self.assert_(-1 < z < 1)
예제 #6
0
    def initialize_node(self):
        random=numpy.random.RandomState(seed=self.seed)
        
        if self.data_alphas is not None and self.data_Jbiases is not None:
            self.alpha=numpy.array([self.data_alphas[i%len(self.data_alphas)] for i in range(self.neurons)],dtype=numpy.dtype('float32'))
            self.Jbias=numpy.array([self.data_Jbiases[i%len(self.data_Jbiases)] for i in range(self.neurons)],dtype=numpy.dtype('float32'))
        else:
            if self.data_saturations is None:
                sr=self.saturation_range
                sat=random.uniform(sr[0],sr[1],(self.neurons,1))
            else:
                N=len(self.data_saturations)
                sat=numpy.array([[self.data_saturations[i%N] for i in range(self.neurons)]],dtype=numpy.dtype('float32')).T

            if self.data_thresholds is None:
                delta=(self.max-self.min)*(1-self.threshold_coverage)*0.5
                min_thresh=self.min+delta
                max_thresh=self.max-delta
                if self.threshold_min is not None: min_thresh=self.threshold_min
                if self.threshold_max is not None: max_thresh=self.threshold_max
                        
                thresh=random.uniform(min_thresh,max_thresh,(self.neurons,1))
            else:
                N=len(self.data_thresholds)
                thresh=numpy.array([[self.data_thresholds[i%N] for i in range(self.neurons)]],dtype=numpy.dtype('float32')).T
                
            self.initialize_neurons(sat,thresh)

        if self.data_basis is None:
            g=makeGenerator(self.basis_style,self.dimensions,int(random.randint(0x7FFFFFFF)))
            self.basis=g.get(self.neurons).T
        else:
            N=len(self.data_basis)
            self.basis=numpy.array([self.data_basis[i%N] for i in range(self.neurons)],dtype=numpy.dtype('float32'))
            if len(self.basis.shape)==1:
                self.basis.shape=(self.neurons,self.dimensions)

        self.sample_generator=makeGenerator(self.sample_style,self.dimensions,int(random.randint(0x7FFFFFFF)))
        if self.min!=-1 or self.max!=1:
            scale=(self.max-self.min)/2.0
            if scale!=1.0: self.sample_generator.scale=scale
            offset=(self.max+self.min)/2.0
            if scale!=0.0: self.sample_generator.offset=offset
예제 #7
0
 def test_grid(self):
     s = makeGenerator("Grid", 2, None).get(121)
     vals = [-1.0, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0]
     i = 0
     j = 0
     for v in s.T:
         x, y = v
         self.assertAlmostEqual(x, vals[i])
         self.assertAlmostEqual(y, vals[j])
         i += 1
         if i >= len(vals):
             i = 0
             j += 1
 def test_grid(self):
     s = makeGenerator('Grid', 2, None).get(121)
     vals = [-1.0, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0]
     i = 0
     j = 0
     for v in s.T:
         x, y = v
         self.assertAlmostEqual(x, vals[i])
         self.assertAlmostEqual(y, vals[j])
         i += 1
         if i >= len(vals):
             i = 0
             j += 1
예제 #9
0
 def test_aligned(self):
     s = makeGenerator("Aligned", 5, None).get(10)
     for v in s.T:
         self.assertEqual(numpy.linalg.norm(v), 1)
         self.assertEqual(numpy.max(numpy.abs(v)), 1)
예제 #10
0
 def test_ball(self):
     s = makeGenerator("Ball", 100, None).get(100)
     for v in s.T:
         self.assert_(numpy.linalg.norm(v) < 1)
예제 #11
0
 def test_sphere(self):
     s = makeGenerator("Sphere", 200, None).get(20)
     for v in s.T:
         self.assertAlmostEqual(numpy.linalg.norm(v), 1, 5)
 def test_aligned(self):
     s = makeGenerator('Aligned', 5, None).get(10)
     for v in s.T:
         self.assertEqual(numpy.linalg.norm(v), 1)
         self.assertEqual(numpy.max(numpy.abs(v)), 1)
 def test_ball(self):
     s = makeGenerator('Ball', 100, None).get(100)
     for v in s.T:
         self.assert_(numpy.linalg.norm(v) < 1)
 def test_sphere(self):
     s = makeGenerator('Sphere', 200, None).get(20)
     for v in s.T:
         self.assertAlmostEqual(numpy.linalg.norm(v), 1, 5)