예제 #1
0
    def wsim(self):

        model = self.model
        #y = model.generate(**expe)
        theta, phi = model.get_params()
        # NB mean/var
        mean, var = model.get_nb_ss()

        phi = mean

        print(theta.shape, theta.min(), theta.max())
        print(phi.shape, phi.min(), phi.max())

        description = '/'.join(
            (self.expe._refdir, os.path.basename(self.output_path)))
        adjshow(theta, title='theta', colorbar=True)
        adjshow(phi, title='Phi Mean', colorbar=True)

        data = self.frontend.data
        sim = np.random.poisson(theta.dot(phi).dot(theta.T))
        print('data shape', data.shape)
        print('sim shape', sim.shape)

        # l2 norm
        l2 = ((data - sim)**2).sum()**(0.5)
        print('l2', l2)
예제 #2
0
    def zipf(self, clusters_org='source'):
        ''' Zipf Analysis
            Local/Global Preferential attachment effect analysis

            Parameters
            ----------
            clusters_org: str
                cluster origin if from either ['source'|'model']
        '''
        expe = self.expe
        frontend = FrontendManager.load(expe)

        #
        # Get the Class/Cluster and local degree information
        # Reordering Adjacency Mmatrix based on Clusters/Class/Communities
        #
        clusters = None
        K = None
        if clusters_org == 'source':
            clusters = frontend.get_clusters()
        elif clusters_org == 'model':
            model = ModelManager.from_expe(expe, load=True)
            #clusters = model.get_clusters(K, skip=1)
            #clusters = model.get_communities(K)
            clusters = Louvain.get_clusters(frontend.to_directed(),
                                            resolution=10)
            if len(np.unique(clusters)) > 20 or False:
                self.log.info('Using Annealing clustering')
                clusters = Annealing(frontend.data,
                                     iterations=200,
                                     C_init=5,
                                     grow_rate=0).search()
            else:
                self.log.info('Using Louvain clustering')

        if clusters is None:
            lgg.error('No clusters here...passing')
            data_r = frontend.data
        else:
            block_hist = np.bincount(clusters)
            K = (block_hist != 0).sum()
            lgg.info('%d Clusters from `%s\':' % (K, clusters_org))
            data_r = reorder_mat(frontend.data, clusters)

        np.fill_diagonal(data_r, 0)

        from pymake.util.math import dilate
        dlt = lambda x: dilate(x) if x.sum() / x.shape[0]**2 < 0.1 else x
        ### Plot Adjacency matrix
        fig, (ax1, ax2) = plt.subplots(1, 2)
        fig.tight_layout(pad=1.6)
        adjshow(dlt(data_r), title=self.specname(expe.corpus), ax=ax1)
        #plt.figtext(.15, .1, homo_text, fontsize=12)
        #plt.suptitle(self.specname(expe.corpus))

        ### Plot Degree
        plot_degree_poly(data_r, ax=ax2)

        if expe._write:
            self.write_frames([fig], suffix='dd')
예제 #3
0
파일: generate.py 프로젝트: dtrckd/ml
    def clustering(self):
        algo = 'Louvain'
        algo = 'Annealing'
        data = self.frontend.data

        mat = data
        #mat = phi

        alg = getattr(A, algo)(mat)
        clusters = alg.search()

        mat = draw_boundary(alg.hi_phi(), alg.B)
        #mat = draw_boundary(mat, clusters)

        adjshow(mat, algo)
        plt.colorbar()
예제 #4
0
파일: generate.py 프로젝트: dtrckd/ml
    def draw(self):
        #if expe._mode == 'predictive':
        #    model = self.frontend
        #    y = model.data
        #    # move this in draw data
        #elif expe._mode == 'generative':
        #    model = self.model
        #    y = model.generate(**expe)
        model = self.model
        y = model.generate(**expe)

        #clustering = 'modularity'
        #print('@heeere, push commmunities annalysis outside static method of frontendnetwork')
        #comm = model.communities_analysis(y, clustering=clustering)
        #clusters = comm['clusters']
        #draw_graph_spring(y, clusters)
        #draw_graph_spectral(y, clusters)
        #draw_graph_circular(y, clusters)

        description = '/'.join(
            (self.expe._refdir, os.path.basename(self.output_path)))
        adjshow(y, title=description)
예제 #5
0
    def wsim(self):
        expe = self.expe
        frontend = self.frontend
        model = self.load_model(load=True)

        #y = model.generate(**expe)
        theta, phi = model.get_params()
        # NB mean/var
        mean, var = model.get_nb_ss()

        phi = mean

        print(theta.shape, theta.min(), theta.max())
        print(phi.shape, phi.min(), phi.max())

        adjshow(theta, title='theta', colorbar=True)
        adjshow(phi, title='Phi Mean', colorbar=True)

        y = self.frontend.adj()
        sim = np.random.poisson(theta.dot(phi).dot(theta.T))

        # l2 norm
        l2 = ((y - sim)**2).sum()**(0.5)
        print('l2', l2)