示例#1
0
    def display(self):
	GL.glClearColor( 0.0, 0.0, 0.0, 0.0)
	GL.glClear( GL.GL_COLOR_BUFFER_BIT)
	GL.glColor3f( 1.0,1.0,0.0)
	self.x = self.x + self.move_x
	self.y = self.y + self.move_y
	self.age = self.age + 1
	which = Numeric.greater( self.age, MAX_AGE)
	self.x = Numeric.choose( which, (self.x, RandomArray.random( NUMDOTS)))
	selfy = Numeric.choose( which, (self.y, RandomArray.random( NUMDOTS)))
	self.age = Numeric.choose( which, (self.age, 0))
	self.x = Numeric.choose( Numeric.greater( self.x, 1.0), (self.x, self.x - 1.0)) 
	self.y = Numeric.choose( Numeric.greater( self.y, 1.0), (self.y, self.y - 1.0))
	x2 = RandomArray.random( NUMDOTS2)
	y2 = RandomArray.random( NUMDOTS2)
	v = Numeric.concatenate(
		(Numeric.transpose( Numeric.array( [self.x, self.y])),
		 Numeric.transpose( Numeric.array( [self.x - 0.005, self.y + 0.005])),
		 Numeric.transpose( Numeric.array( [self.x + 0.005, self.y - 0.005])),
		 Numeric.transpose( Numeric.array( [x2, y2]))))
        #from opengltk.util import GLdouble
        #av = bufarray.readArray( v, GLdouble)
	#GL.glVertexPointer( 2, av)
        GL.glVertexPointer( 2, v)
	GL.glEnableClientState( GL.GL_VERTEX_ARRAY)
	#glplus.DrawArrays( GL.POINTS, len( av))
        from opengltk import  glplus
        glplus.DrawArrays( GL.GL_POINTS, len( v))
	#GL.glDisableClientState( GL.VERTEX_ARRAY)
	GL.glFlush()
	GLUT.glutSwapBuffers()
示例#2
0
def randomRotation():
    """
    Get random rotation matrix.

    @author: Michael Habeck

    @return: 3 x 3 array of float
    @rtype: array
    """
    alpha = RandomArray.random() * 2 * N.pi
    gamma = RandomArray.random() * 2 * N.pi
    beta = N.arccos(2 * (RandomArray.random() - 0.5))

    return eulerRotation(alpha, beta, gamma)
示例#3
0
    def setUp(self):
        from opengltk.OpenGL import GL, GLUT
        print "GL imported from: ", GL.__file__
        #print "Hit any key to quit."
        self.x = RandomArray.random( NUMDOTS) * 2 - 1
        self.y = RandomArray.random( NUMDOTS) * 2 - 1

        self.age = RandomArray.randint( 0,MAX_AGE, (NUMDOTS,))
        move_length = 0.005  # 1.0 = screen width
        angle = 0		 # in radians
        delta_angle = 0.2  # in radians
        self.move_x = move_length * Numeric.cos( angle)
        self.move_y = move_length * Numeric.sin( angle)
        self.halted = 0
示例#4
0
def randomRotation():
    """
    Get random rotation matrix.

    @author: Michael Habeck

    @return: 3 x 3 array of float
    @rtype: array
    """
    alpha = RandomArray.random() * 2 * N.pi
    gamma = RandomArray.random() * 2 * N.pi
    beta  = N.arccos(2*(RandomArray.random() - 0.5))

    return eulerRotation(alpha, beta, gamma)
示例#5
0
def avg_score_distribution(n, m, data_points=10e4, bins=100, visualize=False):
    '''
    Returns estimated mean and standard deviation of score distribution
    for randomized amino acid recognition result
     
    n := sum of all fragment lengths
    m := length of sequence
    '''
    
    assert n <= m
    
    scores = []
    for i in range(int(data_points)):
    
        p = random(n)
        avg = 1 - ((m - n + p.sum()) / m)
        scores.append(avg)
        
    data = array(scores)
    mu = mean(data) ## mean value
    sigma = std(data) ## standard deviation
    
    if visualize:
        n, bins, patches = plt.hist(data, bins, normed=1, alpha=.3)
        y = mlab.normpdf(bins, mu, sigma)
        plt.plot(bins, y, 'r-', linewidth=1)
        plt.vlines(mu, 0, mlab.normpdf([mu], mu, sigma), colors='r')
        plt.show()
    
    return mu, sigma
示例#6
0
    def __call__(self,**params_to_override):
        p = ParamOverrides(self,params_to_override)

        xsize,ysize = SheetCoordinateSystem(p.bounds,p.xdensity,p.ydensity).shape
        xsize,ysize = int(round(xsize)),int(round(ysize))

        xdisparity  = int(round(xsize*p.xdisparity))
        ydisparity  = int(round(xsize*p.ydisparity))
        dotsize     = int(round(xsize*p.dotsize))

        bigxsize = 2*xsize
        bigysize = 2*ysize
        ndots=int(round(p.dotdensity * (bigxsize+2*dotsize) * (bigysize+2*dotsize) /
                        min(dotsize,xsize) / min(dotsize,ysize)))
        halfdot = floor(dotsize/2)

        # Choose random colors and locations of square dots
        random_seed = p.random_seed

        random_array.seed(random_seed*12,random_seed*99)
        col=where(random_array.random((ndots))>=0.5, 1.0, -1.0)

        random_array.seed(random_seed*122,random_seed*799)
        xpos=floor(random_array.random((ndots))*(bigxsize+2*dotsize)) - halfdot

        random_array.seed(random_seed*1243,random_seed*9349)
        ypos=floor(random_array.random((ndots))*(bigysize+2*dotsize)) - halfdot

        # Construct arrays of points specifying the boundaries of each
        # dot, cropping them by the big image size (0,0) to (bigxsize,bigysize)
        x1=xpos.astype(Int) ; x1=choose(less(x1,0),(x1,0))
        y1=ypos.astype(Int) ; y1=choose(less(y1,0),(y1,0))
        x2=(xpos+(dotsize-1)).astype(Int) ; x2=choose(greater(x2,bigxsize),(x2,bigxsize))
        y2=(ypos+(dotsize-1)).astype(Int) ; y2=choose(greater(y2,bigysize),(y2,bigysize))

        # Draw each dot in the big image, on a blank background
        bigimage = zeros((bigysize,bigxsize))
        for i in range(ndots):
            bigimage[y1[i]:y2[i]+1,x1[i]:x2[i]+1] = col[i]

        result = p.offset + p.scale*bigimage[ (ysize/2)+ydisparity:(3*ysize/2)+ydisparity ,
                                              (xsize/2)+xdisparity:(3*xsize/2)+xdisparity ]

        for of in p.output_fns:
            of(result)

        return result
示例#7
0
    def __call__(self,**params_to_override):
        p = ParamOverrides(self,params_to_override)

        xsize,ysize = SheetCoordinateSystem(p.bounds,p.xdensity,p.ydensity).shape
        xsize,ysize = int(round(xsize)),int(round(ysize))
        
        xdisparity  = int(round(xsize*p.xdisparity))  
        ydisparity  = int(round(xsize*p.ydisparity))   
        dotsize     = int(round(xsize*p.dotsize))
        
        bigxsize = 2*xsize
        bigysize = 2*ysize
        ndots=int(round(p.dotdensity * (bigxsize+2*dotsize) * (bigysize+2*dotsize) /
                        min(dotsize,xsize) / min(dotsize,ysize)))
        halfdot = floor(dotsize/2)
    
        # Choose random colors and locations of square dots
        random_seed = p.random_seed

        random_array.seed(random_seed*12,random_seed*99)
        col=where(random_array.random((ndots))>=0.5, 1.0, -1.0)

        random_array.seed(random_seed*122,random_seed*799)
        xpos=floor(random_array.random((ndots))*(bigxsize+2*dotsize)) - halfdot
    
        random_array.seed(random_seed*1243,random_seed*9349)
        ypos=floor(random_array.random((ndots))*(bigysize+2*dotsize)) - halfdot
      
        # Construct arrays of points specifying the boundaries of each
        # dot, cropping them by the big image size (0,0) to (bigxsize,bigysize)
        x1=xpos.astype(Int) ; x1=choose(less(x1,0),(x1,0))
        y1=ypos.astype(Int) ; y1=choose(less(y1,0),(y1,0))
        x2=(xpos+(dotsize-1)).astype(Int) ; x2=choose(greater(x2,bigxsize),(x2,bigxsize))
        y2=(ypos+(dotsize-1)).astype(Int) ; y2=choose(greater(y2,bigysize),(y2,bigysize))

        # Draw each dot in the big image, on a blank background
        bigimage = zeros((bigysize,bigxsize))
        for i in range(ndots):
            bigimage[y1[i]:y2[i]+1,x1[i]:x2[i]+1] = col[i]
            
        result = p.offset + p.scale*bigimage[ (ysize/2)+ydisparity:(3*ysize/2)+ydisparity ,
                                              (xsize/2)+xdisparity:(3*xsize/2)+xdisparity ]

        for of in p.output_fns:
            of(result)

        return result
示例#8
0
    def test_FuzzyCluster( self):
        """FuzzyCluster test"""
        import gnuplot as G

        x1 = random((500,2))
        x2 = random((500,2)) + 1
        x3 = random((500,2)) + 2

        self.x = N.concatenate((x1, x2, x3))

        self.fuzzy = FuzzyCluster(self.x, n_cluster=5, weight=1.5)

        self.centers = self.fuzzy.go(1.e-30, n_iterations=50, nstep=10,
                                     verbose=self.local)

        if self.local:
            print "cluster centers are displayed in green"
            G.scatter( self.x, self.centers )

        self.assertEqual( N.shape(self.centers), (5, 2) )
示例#9
0
    def create_membership_matrix(self):
        """
        Create a random membership matrix.

        @return: random array of shape length of data to
                 cluster times number of clusters
        @rtype: array('f')
        """
        seed(self.seedx, self.seedy)

        r = random((self.npoints, self.n_cluster))
        return N.transpose(r / N.sum(r))
示例#10
0
    def activate(self):
        """
        For now, this is the same as the parent's activate(), plus
        fixed+dynamic thresholding. Overloading was necessary to
        avoid self.send_output() being invoked before thresholding.
        This function also updates and maintains internal values such as
        membrane_potential, spike, etc.
        """

        self.activity *= 0.0

        for proj in self.in_connections:
            self.activity += proj.activity

        if self.apply_output_fns:
            for of in self.output_fns:
                of(self.activity)

        # Add noise, based on the noise_rate.
        if self.noise_rate > 0.0:
            self.activity = self.activity * (1.0-self.noise_rate) \
                + RandomArray.random(self.activity.shape) * self.noise_rate

        # Thresholding: baseline + dynamic threshold + absolute refractory
        # period
        rows, cols = self.activity.shape

        for r in xrange(rows):
            for c in xrange(cols):

                thresh = self.threshold + self.dynamic_threshold[r, c]

                # Calculate membrane potential
                self.membrane_potential[r, c] = self.activity[r, c] - thresh

                if (self.activity[r, c] > thresh
                        and self.spike_history[r, c] <= 0):
                    self.activity[r, c] = self.spike_amplitude
                    self.dynamic_threshold[r, c] = self.dynamic_threshold_init
                    # set absolute refractory period for "next" timestep
                    # (hence the "-1")
                    self.spike_history[r, c] = self.absolute_refractory - 1.0
                else:
                    self.activity[r, c] = 0.0
                    self.dynamic_threshold[r, c] = self.dynamic_threshold[
                        r, c] * exp(-(self.threshold_decay_rate))
                    self.spike_history[r, c] -= 1.0

                # Append spike to the membrane potential
                self.membrane_potential[r, c] += self.activity[r, c]

        self._update_trace()
        self.send_output(src_port='Activity', data=self.activity)
示例#11
0
    def create_membership_matrix(self):
        """
        Create a random membership matrix.

        @return: random array of shape length of data to
                 cluster times number of clusters
        @rtype: array('f')
        """
        seed(self.seedx, self.seedy)

        r = random((self.npoints, self.n_cluster))
        return N.transpose(r / N.sum(r))
示例#12
0
    def test_FuzzyCluster(self):
        """FuzzyCluster test"""
        import gnuplot as G

        x1 = random((500, 2))
        x2 = random((500, 2)) + 1
        x3 = random((500, 2)) + 2

        self.x = N.concatenate((x1, x2, x3))

        self.fuzzy = FuzzyCluster(self.x, n_cluster=5, weight=1.5)

        self.centers = self.fuzzy.go(1.e-30,
                                     n_iterations=50,
                                     nstep=10,
                                     verbose=self.local)

        if self.local:
            print "cluster centers are displayed in green"
            G.scatter(self.x, self.centers)

        self.assertEqual(N.shape(self.centers), (5, 2))
示例#13
0
    def activate(self):
        """
        For now, this is the same as the parent's activate(), plus
        fixed+dynamic thresholding. Overloading was necessary to
        avoid self.send_output() being invoked before thresholding.
        This function also updates and maintains internal values such as
        membrane_potential, spike, etc. 
        """
        
        self.activity *= 0.0

        for proj in self.in_connections:
            self.activity += proj.activity

        if self.apply_output_fns:
            for of in self.output_fns:
                of(self.activity)

        # Add noise, based on the noise_rate.
        if self.noise_rate > 0.0:
            self.activity = self.activity * (1.0-self.noise_rate) \
                + RandomArray.random(self.activity.shape) * self.noise_rate

        # Thresholding: baseline + dynamic threshold + absolute refractory 
        # period
        rows,cols = self.activity.shape

        for r in xrange(rows):
            for c in xrange(cols):

                thresh = self.threshold + self.dynamic_threshold[r,c]

                # Calculate membrane potential
                self.membrane_potential[r,c] = self.activity[r,c] - thresh

                if (self.activity[r,c] > thresh and self.spike_history[r,c]<=0):
                    self.activity[r,c] = self.spike_amplitude
                    self.dynamic_threshold[r,c] = self.dynamic_threshold_init
                    # set absolute refractory period for "next" timestep
                    # (hence the "-1")
                    self.spike_history[r,c] = self.absolute_refractory-1.0
                else:
                    self.activity[r,c] = 0.0
                    self.dynamic_threshold[r,c] = self.dynamic_threshold[r,c] * exp(-(self.threshold_decay_rate))
                    self.spike_history[r,c] -= 1.0

                # Append spike to the membrane potential
                self.membrane_potential[r,c] += self.activity[r,c]

        self._update_trace()
        self.send_output(src_port='Activity',data=self.activity)
示例#14
0
    def __random_translation(self):
        """
        Random translation on a sphere around 0,0,0 with fixed radius
        The radius is the sum of the (max) radius of receptor and ligand

        @return: translation array 3 x 1 of float
        @rtype: array
        """
        radius = (self.d_max_rec + self.d_max_lig) / 2.0
        xyz = ra.random(3) - 0.5

        scale = radius * 1.0 / N.sqrt(N.sum(xyz**2))

        return scale * xyz
示例#15
0
    def __random_translation( self ):
        """
        Random translation on a sphere around 0,0,0 with fixed radius
        The radius is the sum of the (max) radius of receptor and ligand

        @return: translation array 3 x 1 of float
        @rtype: array
        """
        radius = (self.d_max_rec + self.d_max_lig) / 2.0
        xyz = ra.random( 3 ) - 0.5

        scale = radius*1.0 / N.sqrt( N.sum( xyz**2 ) )

        return scale * xyz
示例#16
0
      def testRandomMat(self):
          eps = 2.2204460492503131E-16
          n = 30; m = 60; k = 30

          for i in range(100):
              A = spmatrix_util.ll_mat_rand(n, k, 0.9)
              B = spmatrix_util.ll_mat_rand(k, m, 0.4)
              C = spmatrix.matrixmultiply(A, B)
              t = numpy.zeros(k, 'd')
              y1 = numpy.zeros(n, 'd')
              y2 = numpy.zeros(n, 'd')
              for s in range(10):
                  x = RandomArray.random((m, ))
                  C.matvec(x, y1)
                  B.matvec(x, t)
                  A.matvec(t, y2)
                  self.failUnless(math.sqrt(numpy.dot(y1 - y2, y1 - y2)) < eps * n*m*k)
示例#17
0
    def testRandomMat(self):
        eps = 2.2204460492503131E-16
        n = 30
        m = 60
        k = 30

        for i in range(100):
            A = spmatrix_util.ll_mat_rand(n, k, 0.9)
            B = spmatrix_util.ll_mat_rand(k, m, 0.4)
            C = spmatrix.matrixmultiply(A, B)
            t = numpy.zeros(k, 'd')
            y1 = numpy.zeros(n, 'd')
            y2 = numpy.zeros(n, 'd')
            for s in range(10):
                x = RandomArray.random((m, ))
                C.matvec(x, y1)
                B.matvec(x, t)
                A.matvec(t, y2)
                self.failUnless(
                    math.sqrt(numpy.dot(y1 - y2, y1 - y2)) < eps * n * m * k)
示例#18
0
    def test_FlexMaster(self):
        """TrajFlexMaster test"""
        from Biskit.MatrixPlot import MatrixPlot
        from numpy.oldnumeric.random_array import random

        assert len(hosts.cpus_all) > 0,\
               'Master requires at least 1 PVM node for initialisation.'

        traj_1 = T.load( T.testRoot() + '/lig_pcr_00/traj.dat' )
        traj_1 = traj2ensemble( traj_1 )

        ## create fake second trajectory by adding
        ## increasing noise to first
        frames = []
        for i in range( len( traj_1 ) ):
            f = traj_1.frames[i]
            d = N.zeros( N.shape( f ), N.Float32)
            if i > 0:
                d = random( N.shape( f ) ) * ((i / 10) + 1) 
            frames += [f + d]

        traj_2 = traj_1.clone()
        traj_2.frames = frames

        master = TrajFlexMaster( traj_1, traj_2,
                                 hosts=hosts.cpus_all,
                                 show_output= self.local,
                                 add_hosts=1,
                                 log=None,
                                 slaveLog=None,
                                 verbose= self.local,
                                 only_cross_member=0 )

        r = master.calculateResult( mirror=0 )

        if self.local:
            p = MatrixPlot( r, palette='plasma2', legend=1 )
            p.show()            
示例#19
0
    def setUp(self):

        ### Simple case: we only pass a dictionnary to Plot()
        ### that does not belong to a Sheet:
        self.view_dict = {}

        ### SheetView1:
        ### Find a way to assign randomly the matrix.
        self.matrix1 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds1 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view1 = SheetView((self.matrix1, self.bounds1), src_name="TestInputParam")
        self.key1 = "sv1"
        self.view_dict[self.key1] = self.sheet_view1

        ### SheetView2:
        ### Find a way to assign randomly the matrix.
        self.matrix2 = zeros((10, 10), Float) + 0.3
        self.bounds2 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view2 = SheetView((self.matrix2, self.bounds2), src_name="TestInputParam")
        self.key2 = ("sv2", 0, 10)
        self.view_dict[self.key2] = self.sheet_view2

        ### SheetView3:
        ### Find a way to assign randomly the matrix.
        self.matrix3 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds3 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        self.sheet_view3 = SheetView((self.matrix3, self.bounds3), src_name="TestInputParam")
        self.key3 = ("sv3", 0, "hello", (10, 0))
        self.view_dict[self.key3] = self.sheet_view3

        ### SheetView4: for testing clipping + different bounding box
        ### Find a way to assign randomly the matrix.
        self.matrix4 = zeros((10, 10), Float) + 1.6
        self.bounds4 = BoundingBox(points=((-0.7, -0.7), (0.7, 0.7)))
        self.sheet_view4 = SheetView((self.matrix4, self.bounds4), src_name="TestInputParam")
        self.key4 = "sv4"
        self.view_dict[self.key4] = self.sheet_view4

        ### JCALERT! for the moment we can only pass a triple when creating plot
        ### adding more sheetView to test when plot will be fixed for accepting
        ### as much as you want.

        # plot0: empty plot + no sheetviewdict passed: error or empty plot?
        ### JCALERT! It has to be fixed what to do in this case in plot..
        ### disabled test for the moment.
        # self.plot0 = Plot((None,None,None),None,name='plot0')
        ### CATCH EXCEPTION

        plot_channels1 = {"Strength": None, "Hue": None, "Confidence": None}
        # plot1: empty plot
        self.plot1 = make_template_plot(plot_channels1, self.view_dict, density=10.0, name="plot1")

        plot_channels2 = {"Strength": self.key1, "Hue": None, "Confidence": None}
        # plot2: sheetView 1, no normalize, no clipping
        self.plot2 = make_template_plot(plot_channels2, self.view_dict, density=10.0, name="plot2")

        plot_channels3 = {"Strength": self.key1, "Hue": self.key2, "Confidence": None}
        # plot3: sheetView 1+2, no normalize, no clipping
        self.plot3 = make_template_plot(plot_channels3, self.view_dict, density=10.0, name="plot3")

        plot_channels4 = {"Strength": self.key1, "Hue": self.key2, "Confidence": self.key3}
        # plot4: sheetView 1+2+3, no normalize , no clipping
        self.plot4 = make_template_plot(plot_channels4, self.view_dict, density=10.0, name="plot4")

        plot_channels5 = {"Strength": self.key1, "Hue": None, "Confidence": self.key3}
        # plot5: sheetView 1+3, no normalize, no clipping
        self.plot5 = make_template_plot(plot_channels5, self.view_dict, density=10.0, name="plot5")

        plot_channels6 = {"Strength": None, "Hue": self.key2, "Confidence": self.key3}
        # plot6: sheetView 2+3, no normalize , no clipping
        self.plot6 = make_template_plot(plot_channels6, self.view_dict, density=10.0, name="plot6")

        plot_channels7 = {"Strength": self.key4, "Hue": self.key2, "Confidence": self.key3}
        # plot7: sheetView 1+2+3, no normalize , clipping
        self.plot7 = make_template_plot(plot_channels7, self.view_dict, density=10.0, name="plot7")

        plot_channels8 = {"Strength": self.key1, "Hue": self.key2, "Confidence": self.key3}
        # plot8: sheetView 1+2+3, normalize , no clipping
        self.plot8 = make_template_plot(plot_channels8, self.view_dict, density=10.0, normalize=True, name="plot8")

        ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE.
        ### WE WILL SEE IF IT REMAINS IN PLOT FIRST.

        ### also makes a sheet to test realease_sheetviews

        self.sheet = Sheet()
        self.sheet.sheet_views[self.key1] = self.sheet_view1
        self.sheet.sheet_views[self.key2] = self.sheet_view2
        self.sheet.sheet_views[self.key3] = self.sheet_view3
        self.sheet.sheet_views[self.key4] = self.sheet_view4

        plot_channels9 = {"Strength": self.key1, "Hue": self.key2, "Confidence": self.key3}
        self.plot9 = make_template_plot(plot_channels9, self.sheet.sheet_views, density=10.0, name="plot9")
示例#20
0
    def setUp(self):

        ### Simple case: we only pass a dictionary to Plot()
        ### that does not belong to a Sheet:
        views = {}

        time = 0
        metadata = AttrDict(timestamp=time)

        ### SheetView1:
        ### Find a way to assign randomly the matrix.
        self.matrix1 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds1 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        sv = SheetView(self.matrix1, self.bounds1, metadata=metadata)
        self.sheet_view1 = NdMapping((None, sv),
                                     src_name='TestInputParam',
                                     precedence=0.1,
                                     row_precedence=0.1,
                                     cyclic_range=None,
                                     timestamp=time)
        self.key1 = 'sv1'
        views[self.key1] = self.sheet_view1

        ### SheetView2:
        ### Find a way to assign randomly the matrix.
        self.matrix2 = zeros((10, 10), Float) + 0.3
        self.bounds2 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        sv = SheetView(self.matrix2, self.bounds2, metadata=metadata)
        self.sheet_view2 = NdMapping((None, sv),
                                     src_name='TestInputParam',
                                     precedence=0.2,
                                     row_precedence=0.2,
                                     cyclic_range=None,
                                     timestamp=time)
        self.key2 = ('sv2', 0, 10)
        views[self.key2] = self.sheet_view2

        ### SheetView3:
        ### Find a way to assign randomly the matrix.
        self.matrix3 = zeros((10, 10), Float) + RandomArray.random((10, 10))
        self.bounds3 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        sv = SheetView(self.matrix3, self.bounds3, metadata=metadata)
        self.sheet_view3 = NdMapping((None, sv),
                                     src_name='TestInputParam',
                                     precedence=0.3,
                                     row_precedence=0.3,
                                     cyclic_range=None,
                                     timestamp=time)
        self.key3 = ('sv3', 0, 'hello', (10, 0))
        views[self.key3] = self.sheet_view3

        ### SheetView4: for testing clipping + different bounding box
        ### Find a way to assign randomly the matrix.
        self.matrix4 = zeros((10, 10), Float) + 1.6
        self.bounds4 = BoundingBox(points=((-0.7, -0.7), (0.7, 0.7)))
        sv = SheetView(self.matrix4, self.bounds4, metadata=metadata)
        self.sheet_view4 = NdMapping((None, sv),
                                     src_name='TestInputParam',
                                     precedence=0.4,
                                     row_precedence=0.4,
                                     cyclic_range=None,
                                     timestamp=time)
        self.key4 = 'sv4'
        views[self.key4] = self.sheet_view4

        self.view_dict = {'Strength': views, 'Hue': views, 'Confidence': views}

        ### JCALERT! for the moment we can only pass a triple when creating plot
        ### adding more sheetView to test when plot will be fixed for accepting
        ### as much as you want.

        # plot0: empty plot + no sheetviewdict passed: error or empty plot?
        ### JCALERT! It has to be fixed what to do in this case in plot..
        ### disabled test for the moment.
        #self.plot0 = Plot((None,None,None),None,name='plot0')
        ### CATCH EXCEPTION

        plot_channels1 = {'Strength': None, 'Hue': None, 'Confidence': None}
        # plot1: empty plot
        self.plot1 = make_template_plot(plot_channels1,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot1')

        plot_channels2 = {
            'Strength': self.key1,
            'Hue': None,
            'Confidence': None
        }
        # plot2: sheetView 1, no normalize, no clipping
        self.plot2 = make_template_plot(plot_channels2,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot2')

        plot_channels3 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': None
        }
        # plot3: sheetView 1+2, no normalize, no clipping
        self.plot3 = make_template_plot(plot_channels3,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot3')

        plot_channels4 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot4: sheetView 1+2+3, no normalize , no clipping
        self.plot4 = make_template_plot(plot_channels4,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot4')

        plot_channels5 = {
            'Strength': self.key1,
            'Hue': None,
            'Confidence': self.key3
        }
        # plot5: sheetView 1+3, no normalize, no clipping
        self.plot5 = make_template_plot(plot_channels5,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot5')

        plot_channels6 = {
            'Strength': None,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot6: sheetView 2+3, no normalize , no clipping
        self.plot6 = make_template_plot(plot_channels6,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot6')

        plot_channels7 = {
            'Strength': self.key4,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot7: sheetView 1+2+3, no normalize , clipping
        self.plot7 = make_template_plot(plot_channels7,
                                        self.view_dict,
                                        density=10.0,
                                        name='plot7')

        plot_channels8 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        # plot8: sheetView 1+2+3, normalize , no clipping
        self.plot8 = make_template_plot(plot_channels8,
                                        self.view_dict,
                                        density=10.0,
                                        normalize=True,
                                        name='plot8')

        ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE.
        ### WE WILL SEE IF IT REMAINS IN PLOT FIRST.

        ### also makes a sheet to test realease_sheetviews

        self.sheet = Sheet()
        self.sheet.views.maps[self.key1] = self.sheet_view1
        self.sheet.views.maps[self.key2] = self.sheet_view2
        self.sheet.views.maps[self.key3] = self.sheet_view3
        self.sheet.views.maps[self.key4] = self.sheet_view4

        plot_channels9 = {
            'Strength': self.key1,
            'Hue': self.key2,
            'Confidence': self.key3
        }
        self.plot9 = make_template_plot(plot_channels9,
                                        self.sheet.views.maps,
                                        density=10.0,
                                        name='plot9')
示例#21
0
    def setUp(self):

        ### Simple case: we only pass a dictionary to Plot()
        ### that does not belong to a Sheet:
        views = {}

        time = 0
        metadata = AttrDict(timestamp=time)

        ### SheetView1:
        ### Find a way to assign randomly the matrix.
        self.matrix1 = zeros((10,10),Float) + RandomArray.random((10,10))
        self.bounds1 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5)))
        sv = SheetView(self.matrix1, self.bounds1, metadata=metadata)
        self.sheet_view1 = NdMapping((None, sv), src_name='TestInputParam',
                                     precedence=0.1, row_precedence=0.1,
                                     cyclic_range=None, timestamp=time)
        self.key1 = 'sv1'
        views[self.key1] = self.sheet_view1

        ### SheetView2:
        ### Find a way to assign randomly the matrix.
        self.matrix2 = zeros((10,10),Float) + 0.3
        self.bounds2 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5)))
        sv = SheetView(self.matrix2, self.bounds2, metadata=metadata)
        self.sheet_view2 = NdMapping((None, sv), src_name='TestInputParam',
                                     precedence=0.2, row_precedence=0.2,
                                     cyclic_range=None, timestamp=time)
        self.key2 = ('sv2',0,10)
        views[self.key2] = self.sheet_view2

        ### SheetView3:
        ### Find a way to assign randomly the matrix.
        self.matrix3 = zeros((10,10),Float) + RandomArray.random((10,10))
        self.bounds3 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5)))
        sv = SheetView(self.matrix3, self.bounds3, metadata=metadata)
        self.sheet_view3 = NdMapping((None, sv), src_name='TestInputParam',
                                     precedence=0.3, row_precedence=0.3,
                                     cyclic_range=None, timestamp=time)
        self.key3 = ('sv3',0,'hello',(10,0))
        views[self.key3] = self.sheet_view3

        ### SheetView4: for testing clipping + different bounding box
        ### Find a way to assign randomly the matrix.
        self.matrix4 = zeros((10,10),Float) + 1.6
        self.bounds4 = BoundingBox(points=((-0.7,-0.7),(0.7,0.7)))
        sv = SheetView(self.matrix4, self.bounds4, metadata=metadata)
        self.sheet_view4 = NdMapping((None, sv), src_name='TestInputParam',
                                     precedence=0.4, row_precedence=0.4,
                                     cyclic_range=None, timestamp=time)
        self.key4 = 'sv4'
        views[self.key4] = self.sheet_view4

        self.view_dict = {'Strength': views, 'Hue': views, 'Confidence': views}

        ### JCALERT! for the moment we can only pass a triple when creating plot
        ### adding more sheetView to test when plot will be fixed for accepting
        ### as much as you want.

        # plot0: empty plot + no sheetviewdict passed: error or empty plot?
        ### JCALERT! It has to be fixed what to do in this case in plot..
        ### disabled test for the moment.
        #self.plot0 = Plot((None,None,None),None,name='plot0')
        ### CATCH EXCEPTION

        plot_channels1 = {'Strength':None,'Hue':None,'Confidence':None}
        # plot1: empty plot
        self.plot1 = make_template_plot(plot_channels1,self.view_dict,density=10.0,name='plot1')

        plot_channels2 = {'Strength':self.key1,'Hue':None,'Confidence':None}
        # plot2: sheetView 1, no normalize, no clipping
        self.plot2 = make_template_plot(plot_channels2,self.view_dict,density=10.0,name='plot2')

        plot_channels3 = {'Strength':self.key1,'Hue':self.key2,'Confidence':None}
        # plot3: sheetView 1+2, no normalize, no clipping
        self.plot3 = make_template_plot(plot_channels3,self.view_dict,density=10.0,name='plot3')

        plot_channels4 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3}
        # plot4: sheetView 1+2+3, no normalize , no clipping
        self.plot4 = make_template_plot(plot_channels4,self.view_dict,density=10.0,name='plot4')

        plot_channels5 = {'Strength':self.key1,'Hue':None,'Confidence':self.key3}
        # plot5: sheetView 1+3, no normalize, no clipping
        self.plot5 = make_template_plot(plot_channels5,self.view_dict,density=10.0,name='plot5')

        plot_channels6 = {'Strength':None,'Hue':self.key2,'Confidence':self.key3}
        # plot6: sheetView 2+3, no normalize , no clipping
        self.plot6 = make_template_plot(plot_channels6,self.view_dict,density=10.0,name='plot6')

        plot_channels7 = {'Strength':self.key4,'Hue':self.key2,'Confidence':self.key3}
        # plot7: sheetView 1+2+3, no normalize , clipping
        self.plot7 = make_template_plot(plot_channels7,self.view_dict,density=10.0,name='plot7')

        plot_channels8 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3}
        # plot8: sheetView 1+2+3, normalize , no clipping
        self.plot8 = make_template_plot(plot_channels8,self.view_dict,density=10.0,normalize=True,name='plot8')

        ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE.
        ### WE WILL SEE IF IT REMAINS IN PLOT FIRST.

        ### also makes a sheet to test realease_sheetviews

        self.sheet = Sheet()
        self.sheet.views.maps[self.key1]=self.sheet_view1
        self.sheet.views.maps[self.key2]=self.sheet_view2
        self.sheet.views.maps[self.key3]=self.sheet_view3
        self.sheet.views.maps[self.key4]=self.sheet_view4

        plot_channels9 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3}
        self.plot9 = make_template_plot(plot_channels9,self.sheet.views.maps,density=10.0,name='plot9')
示例#22
0
    rl = [line.tolist()[:i] for i, line in enumerate(mtrx)]
    if startEmpty:
        return rl
    else:
        return rl[1:]


def raggedList2mtrx(raggedList):
    """convert a bottom triangular ragged list (with optional empty list at the beginning) to a square matrix"""
    if len(raggedList[0]) == 0:
        raggedList = raggedList[1:]
    rlLen = len(raggedList) + 1
    m = Numeric.zeros((rlLen, rlLen), Numeric.Float)
    idx = 0
    for lst in raggedList:
        idx += 1
        m[idx, :idx] = Numeric.array(lst, Numeric.Float)
        m[:idx, idx] = Numeric.array(lst, Numeric.Float)
    return m


if __name__ == "__main__":
    import numpy.oldnumeric.random_array as RandomArray
    vecta1 = RandomArray.random((10, 2))
    vect1 = vecta1.tolist()
    K = 8
    mcm = orngCluster.MClustering(vect1, k=K, metric=2)
    mce = orngCluster.MClustering(vect1, k=K, metric=1)
    print(mcm.bic())
    print(mce.bic())