コード例 #1
0
 def _write_overlap_info(self, perturbation, M, sim_type=''):
     r"""computes and saves overlap matrix plots and info
     Parameters:
     -----------
     perturbation : string
         string identifying the perturbation for which the overlap is being computed
     M : 2D numpy array
         matrix containing the overlap information
     sim_type : string
         Identifier for bound type or free type simulation
     """
     diag_elements = numpy.array([numpy.diag(M, k=1), numpy.diag(M, k=-1)])
     fname = os.path.join(self._outputdir,
                          perturbation) + '_' + sim_type + '_matrix.dat'
     fh = open(fname, 'wb')
     fh.write(bytes('#Overlap matrix\n', "UTF-8"))
     if numpy.min(diag_elements) < 0.03:
         fh.write(
             bytes(
                 '#Off diagonal elements of the overlap matrix are smaller than 0.03! Your free energy estimate is \n'
                 '#not reliable!\n', "UTF-8"))
     numpy.savetxt(fh, M, fmt='%.4f')
     fh.close()
     #now plotting the matrix
     fplot = os.path.join(self._outputdir,
                          perturbation) + '_' + sim_type + '_matrix.png'
     # turns off interactive plotting
     plt.ioff()
     plt.matshow(M)
     plt.colorbar()
     plt.savefig(fplot, dpi=100)
コード例 #2
0
def main():
    args = parse_args()
    protein = args.protein
    cm = Protein(protein[0:4], protein[4]).cm
    plt.matshow(cm, origin='lower', cmap='Greys')
    plt.savefig(os.path.join(PATHS.periscope, 'data', f'{protein}_cm.png'))
    plt.close()
コード例 #3
0
ファイル: mirrorImageViz.py プロジェクト: willwilliams/nupic
def drawFile(dataset, matrix, patterns, cells, w, fnum):
    '''The similarity of two patterns in the bit-encoding space is displayed alongside
  their similarity in the sp-coinc space.'''
    score = 0
    count = 0
    assert len(patterns) == len(cells)
    for p in xrange(len(patterns) - 1):
        matrix[p + 1:, p] = [
            len(Set(patterns[p]).intersection(Set(q))) * 100 / w
            for q in patterns[p + 1:]
        ]
        matrix[p, p + 1:] = [
            len(Set(cells[p]).intersection(Set(r))) * 5 / 2
            for r in cells[p + 1:]
        ]

        score += sum(
            abs(np.array(matrix[p + 1:, p]) - np.array(matrix[p, p + 1:])))
        count += len(matrix[p + 1:, p])

    print 'Score', score / count

    fig = pyl.figure(figsize=(10, 10), num=fnum)
    pyl.matshow(matrix, fignum=fnum)
    pyl.colorbar()
    pyl.title('Coincidence Space', verticalalignment='top', fontsize=12)
    pyl.xlabel('The Mirror Image Visualization for ' + dataset, fontsize=17)
    pyl.ylabel('Encoding space', fontsize=12)
コード例 #4
0
def plot_confusion_matrix(cm, meow_list, name, title):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(meow_list)))
    ax.set_xticklabels(meow_list)
    ax.xaxis.set_ticks_position("bottom")
コード例 #5
0
def main():
    # process data
    data = np.genfromtxt("../Data/train_data.csv", delimiter=",")
    corr_data = data[:, 1:9]

    # execute model
    test_dataframe = pandas.DataFrame(
        corr_data,
        columns=[
            "GRE Score",
            "TOEFL Score",
            "University Rating",
            "SOP",
            "LOR",
            "CGPA",
            "Research",
            "Chance of Admit",
        ],
    )
    plt.matshow(test_dataframe.corr())
    # use shape 1 for x-axis
    plt.xticks(range(test_dataframe.shape[1]),
               test_dataframe.columns,
               fontsize=7,
               rotation=90)
    plt.yticks(range(test_dataframe.shape[1]),
               test_dataframe.columns,
               fontsize=7)
    plt.colorbar()
    plt.legend()
    plt.savefig("../Out/2.png")
コード例 #6
0
def draw(G, A, cluster_map):
    import networkx as nx
    import matplotlib.pyplot as plt

    clust_map = {}
    for k, vals in cluster_map.items():
        for v in vals:
            clust_map[v] = k

    colors = []
    for i in range(len(G.nodes())):
        colors.append(clust_map.get(i, 100))

    pos = nx.spring_layout(G)

    from matplotlib.pylab import matshow, show, cm
    plt.figure(2)
    nx.draw_networkx_nodes(G,
                           pos,
                           node_size=200,
                           node_color=colors,
                           cmap=plt.cm.Blues)
    nx.draw_networkx_edges(G, pos, alpha=0.5)
    matshow(A, fignum=1, cmap=cm.gray)
    plt.show()
    show()
コード例 #7
0
    def test_H(self):
        # Setup feature track
        track_id = 0
        frame_id = 3
        data0 = KeyPoint(np.array([0.0, 0.0]), 21)
        data1 = KeyPoint(np.array([0.0, 0.0]), 21)
        track = FeatureTrack(track_id, frame_id, data0, data1)

        # Setup track cam states
        self.msckf.augment_state()
        self.msckf.augment_state()
        self.msckf.augment_state()
        track_cam_states = self.msckf.track_cam_states(track)

        # Feature position
        p_G_f = np.array([[1.0], [2.0], [3.0]])

        # Test
        H_f_j, H_x_j = self.msckf.H(track, track_cam_states, p_G_f)

        # Assert
        self.assertEqual(H_f_j.shape, (4, 3))
        self.assertEqual(H_x_j.shape, (4, 39))

        # Plot matrix
        debug = True
        # debug = False
        if debug:
            plt.matshow(H_f_j)
            plt.show()
            plt.matshow(H_x_j)
            plt.show()
コード例 #8
0
ファイル: kolmogorov3d.py プロジェクト: bnikolic/oof
def PlotTurbulenceIllustr(a):

    """
    Can generate the grid with
    g=kolmogorovutils.GenerateKolmogorov3D( 1025, 129, 129)
    a=kolmogorovutils.GridToNumarray(g)

    """

    for x in [1,10,100]:

        suba= numarray.sum(a[:,:,0:x], axis=2)

        suba.transpose()
        pylab.clf()
        pylab.matshow(suba)
        pylab.savefig("temp/turb3d-sum%03i.eps" % x)

    for x in [1,10,100]:

        for j in [0,1,2]:

            suba= numarray.sum(a[:,:200,j*x:(j+1)*x], axis=2)

            suba.transpose()
            pylab.clf()
            pylab.matshow(suba)
            pylab.savefig("temp/turb3d-sum%03i-s%i.eps" % (x,j))        
コード例 #9
0
ファイル: kolmogorov3d.py プロジェクト: bnikolic/oof
def Animate(g):
    for i in range(1,64,5):
        pylab.clf()
        x= g[0:i,:,:]
        y= numarray.sum(x, axis=0)
        pylab.matshow( y)
        pylab.savefig("temp/3dturb-%03i.png" % i)
コード例 #10
0
ファイル: ker.py プロジェクト: silasxue/Sentiment-Analysis
def showKernel(dataOrMatrix, fileName = None, useLabels = True, **args) :
 
    labels = None
    if hasattr(dataOrMatrix, 'type') and dataOrMatrix.type == 'dataset' :
	data = dataOrMatrix
	k = data.getKernelMatrix()
	labels = data.labels
    else :
	k = dataOrMatrix
	if 'labels' in args :
	    labels = args['labels']

    import matplotlib

    if fileName is not None and fileName.find('.eps') > 0 :
        matplotlib.use('PS')
    from matplotlib import pylab

    pylab.matshow(k)
    #pylab.show()

    if useLabels and labels.L is not None :
	numPatterns = 0
	for i in range(labels.numClasses) :
	    numPatterns += labels.classSize[i]
	    #pylab.figtext(0.05, float(numPatterns) / len(labels), labels.classLabels[i])
	    #pylab.figtext(float(numPatterns) / len(labels), 0.05, labels.classLabels[i])
	    pylab.axhline(numPatterns, color = 'black', linewidth = 1)
	    pylab.axvline(numPatterns, color = 'black', linewidth = 1)
    pylab.axis([0, len(labels), 0, len(labels)])
    if fileName is not None :
        pylab.savefig(fileName)
	pylab.close()
コード例 #11
0
    def plot_pixels(self):
        """
        Makes a pixelchart of every embedding in the set.

        Usage:

        ```python
        from whatlies.language import SpacyLanguage
        from whatlies.transformers import Pca

        lang = SpacyLanguage("en_core_web_sm")

        names = ['red', 'blue', 'green', 'yellow',
                 'cat', 'dog', 'mouse', 'rat',
                 'bike', 'car', 'motor', 'cycle',
                 'firehydrant', 'japan', 'germany', 'belgium']
        emb = lang[names].transform(Pca(12)).filter(lambda e: 'pca' not in e.name)
        emb.plot_pixels()
        ```

        ![](https://rasahq.github.io/whatlies/images/pixels.png)
        """
        names = self.embeddings.keys()
        df = self.to_dataframe()
        plt.matshow(df)
        plt.yticks(range(len(names)), names)
コード例 #12
0
def plot_confusion_matrix(cm, meow_list, name, title):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(meow_list)))
    ax.set_xticklabels(meow_list)
    ax.xaxis.set_ticks_position("bottom")
コード例 #13
0
ファイル: linedetect.py プロジェクト: truls/almique
def main():
    show_graph = False
    do_run = True
    show_result = True
    show_trace = False

    simdata = np.fromfile('plank.dat', dtype=np.uint8)

    simdata.shape = (151, 1080)

    if show_graph:
        camera = System('Camera', 15, 200, 200, simdata, [])
        debug(camera.plot())

    result = [0] * (151 * 1080)
    if do_run:
        sme = SME()
        sme.network = System('Camera', 151, 151 * 1080, 200, simdata, result)
        sme.network.clock(1080 * 200 + (1080 * 151))

    if show_result:
        plt.rc("font", size=18)
        result = np.array(result)
        debug(len(result))
        result.shape = (1080, 151)
        pylab.matshow(result.T, fignum=100, cmap=pylab.cm.gray)

    if show_trace:
        debug(camera.trace())

    pylab.show()
コード例 #14
0
ファイル: kolmogorov.py プロジェクト: bnikolic/oof
def BreakIllustration(seed=11):

    for x in [1 , 2 , 4, 8, 16 , 25, 100]:
        pylab.clf()
        m4=GenKolmogorovV2(1025, seed,  pybnlib.Kol3DBreakLaw(1.0/x) )
        pylab.matshow(m4)
        pylab.savefig("temp/breakill-%03i.png" % x)
コード例 #15
0
ファイル: datadraw.py プロジェクト: neoinmatrix/neocode
def plot_confusion_matrix(cm, genre_list, name, title,max,save=False):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Greens', vmin=0, vmax=max)
    ax = pylab.axes()
    ax.set_xticks(range(len(genre_list)))
    ax.set_xticklabels(genre_list)
    ax.xaxis.set_ticks_position("bottom")
    ax.set_yticks(range(len(genre_list)))
    ax.set_yticklabels(genre_list)
    cm=cm.T
    for i in range(len(cm)):
        # t=len(cm[0])-i
        for j in range(len(cm[0])):
            if cm[i,j]<1e-2:
                continue
            pylab.text(i, j, '%.2f'%cm[i,j])

    pylab.title(title)
    pylab.colorbar()
    pylab.grid(True)
    pylab.show()
    pylab.xlabel('Predicted class')
    pylab.ylabel('True class')
    pylab.grid(True)
    if save==True:
        pylab.savefig(os.path.join(CHART_DIR, "confusion_matrix_%s.png"%name), bbox_inches="tight")
コード例 #16
0
def plot_layer_mat(layer_mat,
                   layernames=None,
                   titstr="Correlation of Amplification in BigGAN"):
    """Formatting function for ploting Layer by Layer matrix"""
    Lnum = layer_mat.shape[0]
    fig = plt.figure(figsize=[9, 8])
    plt.matshow(layer_mat, fignum=0)
    layermat_nan = layer_mat.copy()
    np.fill_diagonal(layermat_nan, np.nan)
    plt.title(
        "%s across %d layers"
        "\nNon-Diagonal mean %.3f median %.3f" %
        (titstr, Lnum, np.nanmean(layermat_nan), np.nanmedian(layermat_nan)),
        fontsize=15)
    fig.axes[0].tick_params(axis="x",
                            bottom=True,
                            top=False,
                            labelbottom=True,
                            labeltop=False)
    if layernames is not None:
        plt.yticks(range(Lnum), layernames)
        plt.ylim(-0.5, Lnum - 0.5)
        plt.xticks(range(Lnum),
                   layernames,
                   rotation=35,
                   rotation_mode='anchor',
                   ha='right')
        plt.xlim(-0.5, Lnum - 0.5)
    plt.colorbar()
    plt.subplots_adjust(top=0.85)
    plt.show()
    return fig
コード例 #17
0
def combine_fullrank_matrix(A, A_add, b, b_add, print_out=False):
    """ Add rows as long as the resulting matrix is fullrank.
    """

    assert np.linalg.matrix_rank(A) == A.shape[0]

    counter = 0
    for i in range(A_add.shape[0]):
        A_addedrow = np.vstack((A, A_add[i, :]))
        if np.linalg.matrix_rank(A_addedrow) > np.linalg.matrix_rank(A):
            counter += 1
            A = A_addedrow
            b = np.r_[b, b_add[i]]
        # Visualization of dependent matrices.
        else:
            if print_out:
                alpha = np.linalg.lstsq(A.T, A_add[i, :].reshape(-1, 1))[0]
                alpha = alpha.reshape(1, -1)[0, :]
                alpha[alpha < 1e-12] = 0.0
                indices = np.where(alpha > 0.0)[0]
                plt.matshow(A)
                plt.title('lin indep. rows')
                plt.matshow(np.vstack((A_add[i, :], A_add[i, :])))
                plt.title('lin. dep. row: {}*{}'.format(indices, alpha[indices]))
    if (print_out):
        print('added {} linearly independent rows.'.format(counter))
    return A, b
コード例 #18
0
ファイル: kNeighbor.py プロジェクト: tlabruyere/CS544-Cyber
def validate(X_test, y_test, pipe, title, fileName):
    
    print('Test Accuracy: %.3f' % pipe.score(X_test, y_test))

    y_predict = pipe.predict(X_test)

    confusion_matrix = np.zeros((9,9))

    for p,r in zip(y_predict, y_test):
        confusion_matrix[p-1,r-1] = confusion_matrix[p-1,r-1] + 1

    print (confusion_matrix) 

    confusion_normalized = confusion_matrix.astype('float') / confusion_matrix.sum(axis=1)[:, np.newaxis]
    print (confusion_normalized)

    pylab.clf()
    pylab.matshow(confusion_normalized, fignum=False, cmap='Blues', vmin=0.0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(families)))
    ax.set_xticklabels(families,  fontsize=4)
    ax.xaxis.set_label_position('top') 
    ax.xaxis.set_ticks_position("top")
    ax.set_yticks(range(len(families)))
    ax.set_yticklabels(families, fontsize=4)
    pylab.title(title)
    pylab.colorbar()
    pylab.grid(False)
    pylab.grid(False)
    pylab.savefig(fileName, dpi=900)
コード例 #19
0
def VisualizeM(
    matrix
):  # pour visualiser une matrice rapidement (permet de détecter une erreur aussi)
    plt.matshow(
        matrix, cmap=plt.cm.jet_r
    )  # on peut toujours changer de cmap ici aussi, le jet_r assure bleu = humide, rouge = aride
    plt.show()
コード例 #20
0
ファイル: fdtd.py プロジェクト: wanygen/uestc-cemlab-fdtd
def show_profile(task, fn):
    data = zeros((task.Sx, task.Sy))
    for i in range(task.Sx):
        for j in range(task.Sy):
            data[i][j] = fn(task.Gp(i, j, task.Sz / 2))
    plb.matshow(data.transpose())
    plb.colorbar()
    plb.show()
コード例 #21
0
    def plot_grid(self, name="", save_figure=True):
        #gambar 2D dari grid

        plt.matshow(self.matrix_grid(), cmap="RdBl", fignum=0)
        # buat save image
        if save_figure:
            plt.savefig(self.path + name + '.png')
        plt.draw()
コード例 #22
0
def plot_assortativity_matrix(degree_correlation_matrix):

    # Rappresento la degree correlation matrix con matshow

    plt.matshow(degree_correlation_matrix, cmap='hot')
    plt.title('Matrice di correlazione')

    plt.show()
コード例 #23
0
ファイル: k3d_structretest.py プロジェクト: bnikolic/oof
def PlotSTest(a):

    from matplotlib import pylab

    x = numpy.mean(a, axis=0)
    x.shape = (int(len(x) ** 0.5), int(len(x) ** 0.5))
    pylab.matshow(x)
    pylab.colorbar()
コード例 #24
0
def plot_dependency_posterior(df, meta, t, num_joints=None):
    if num_joints is None:
        num_joints = determine_num_joints(df)

    plt.figure()
    posterior=np.array([df["Posterior%d"%j].iloc[t] for j in range(num_joints)])
    plt.matshow(posterior, interpolation='nearest')
    plt.show()
コード例 #25
0
ファイル: fdtd.py プロジェクト: xj361685640/fdtd-2
def show_profile(task, fn):
    data = zeros((task.Sx, task.Sy))
    for i in range(task.Sx):
        for j in range(task.Sy):
            data[i][j] = fn(task.Gp(i, j, task.Sz / 2))
    plb.matshow(data.transpose())
    plb.colorbar()
    plb.show()
コード例 #26
0
def plot(x, mode=None, **kwargs):
    """Plots a tensor/numpy array

        If the array has no spatial extend, it will
        draw only a single line plot. If the array
        has no temporal extend (and no color channels etc.),
        it will plot a single frame.
        Otherwise it will use `plot_tensor`.

        Examples
        --------


        .. plot::
            :include-source:

            import convis
            inp = convis.samples.moving_grating(2000,50,50)
            convis.utils.plot(inp[None,None])


    See Also
    --------
    plot_tensor
    plot_5d_matshow
    plot_5d_time
    """
    import matplotlib.pylab as plt
    try:
        # assuming a torch Variable on the gpu
        x = x.data.cpu().numpy()
    except:
        x = np.array(x)
    if len(x.shape) > 5:
        while len(x.shape) > 5:
            x = x[0]
    if len(x.shape) == 4:
        x = x[None]
    if len(x.shape) == 3:
        x = x[None, None]
    if len(x.shape) == 2:
        x = x[None, None, None]
    if len(x.shape) == 1:
        x = x[None, None, :, None, None]
    shp = x.shape
    if len(shp) == 5:
        if mode == 'matshow' or np.prod(shp[:3]) == 1:
            # a single frame
            plt.matshow(x, **kwargs)
        elif mode == 'lines' or (np.prod(shp[:2]) == 1
                                 and np.prod(shp[3:]) == 1):
            # a single time line
            plt.plot(x.mean((0, 1, 3, 4)), **kwargs)
        else:
            # a set of images?
            plot_tensor(x, **kwargs)
    else:
        print('x has dimensions:', shp)
コード例 #27
0
def group_causality(sig_list, condition, freqs, ROI_labels=None,
                    out_path=None, submount=10):

    """
    Make group causality analysis, by evaluating significant matrices across
    subjects.
    ----------
    sig_list: list
        The path list of individual significant causal matrix.
    condition: string
        One condition of the experiments.
    freqs: list
        The list of interest frequency band.
    min_subject: string
        The subject for the common brain space.
    submount: int
        Significant interactions come out at least in 'submount' subjects.
    """
    print 'Running group causality...'
    set_directory(out_path)
    sig_caus = []

    for f in sig_list:
        sig_cau = np.load(f)
        print sig_cau.shape[-1]
        sig_caus.append(sig_cau)

    sig_caus = np.array(sig_caus)
    sig_group = sig_caus.sum(axis=0)
    plt.close()
    for i in xrange(len(sig_group)):
        fmin, fmax = freqs[i][0], freqs[i][1]
        cau_band = sig_group[i]
        # cau_band[cau_band < submount] = 0
        cau_band[cau_band < submount] = 0
        # fig, ax = pl.subplots()
        cmap = plt.get_cmap('hot', cau_band.max()+1-submount)
        cmap.set_under('gray')
        plt.matshow(cau_band, interpolation='nearest', vmin=submount, cmap=cmap)
        if ROI_labels == None:
            ROI_labels = np.arange(cau_band.shape[0]) + 1
        pl.xticks(np.arange(cau_band.shape[0]), ROI_labels, fontsize=9, rotation='vertical')
        pl.yticks(np.arange(cau_band.shape[0]), ROI_labels, fontsize=9)
        # pl.imshow(cau_band, interpolation='nearest')
        # pl.set_cmap('BlueRedAlpha')
        np.save(out_path + '/%s_%s_%sHz.npy' %
                (condition, str(fmin), str(fmax)), cau_band)
        v = np.arange(submount, cau_band.max()+1, 1)

        # cax = ax.scatter(x, y, c=z, s=100, cmap=cmap, vmin=10, vmax=z.max())
        # fig.colorbar(extend='min')

        plt.colorbar(ticks=v, extend='min')
        # pl.show()
        plt.savefig(out_path + '/%s_%s_%sHz.png' %
                    (condition, str(fmin), str(fmax)), dpi=300)
        plt.close()
    return
コード例 #28
0
def VizAttenMat(atten_Matrix):
    """
    A function that takes an input 2D Tensor and visualize it using matplotlib
    """
    assert len(atten_Matrix.shape)==2, "your input should be a symetrical 2D matrix"
    assert atten_Matrix.shape[0]==atten_Matrix.shape[1], "your input should be a symetrical 2D matrix"
    plt.matshow(atten_Matrix)
    plt.colorbar()
    plt.show()
コード例 #29
0
def plot_sparsity_pattern(A, tick_frequency):
    """:param A: np array containing the matrix"""
    A[np.where(A != 0)] = 1
    plt.matshow(A, fignum=None)
    plt.colorbar()
    plt.xticks(np.arange(0, A.shape[0], tick_frequency))
    plt.yticks(np.arange(0, A.shape[0], tick_frequency))
    plt.grid()
    plt.show()
コード例 #30
0
def savematrixplot(datasetname,tumorname, A, k):
    """    
    plt.figure("%s_consensus_rank_%d.png" % (tumorname,k))
    plt.subplot(211)
    plt.matshow(A)
    plt.savefig("./" + datasetname + "_results/%s_consensus_rank_%d.png" % (tumorname,k))
    """
    mplpl.matshow(A)
    mplpl.savefig("./" + datasetname + "_results/%s_consensus_rank_%d.png" % (tumorname,k))
コード例 #31
0
ファイル: my_DLA_2.py プロジェクト: ssto579/CS_789
 def plot_grid(self):
     truth = self.order_matrix > 1
     truth = self.item_matrix > 4
     dot_only = self.order_matrix * truth  # removes all the bordering ones
     #		dot_only = self.item_matrix * truth # removes all the bordering ones
     dot_only = dot_only + truth * self.num_iter // 6  # need to differentiate the early dots from the background of 0 for human eye. + max/6 seemed like the easiest way
     plt.matshow(dot_only, cmap=plt.cm.inferno)
     plt.colorbar()
     plt.show()
コード例 #32
0
def plot_dependency_posterior(df, meta, t, num_joints=None):
    if num_joints is None:
        num_joints = determine_num_joints(df)

    plt.figure()
    posterior = np.array(
        [df["Posterior%d" % j].iloc[t] for j in range(num_joints)])
    plt.matshow(posterior, interpolation='nearest')
    plt.show()
コード例 #33
0
 def plot_grid(self, name="", save_figure=True):
     """
     This plots the 2D representation of the grid
     :param name: the name of the image to save
     :return:
     """
     plt.matshow(self.matrix_grid(), cmap="RdBu", fignum=0)
     # Option to save images
     if save_figure:
         plt.savefig(self.path + name + '.png')
コード例 #34
0
ファイル: test_pandas.py プロジェクト: ice3/VAST_2015
def create_heatmaps(df, key=lambda t: t.minute):
	for group, data in df.groupby(df.index.map(key)):
		all_mat = np.zeros((100,100), dtype=np.int)
		for x, y in zip(data.x, data.y):
			all_mat[x, y] += 1
		all_mat = all_mat*1.0/len(data)
		plt.matshow(all_mat)
		plt.title(data.ix[0].name)
		print("saving: ", group)
		plt.savefig("{:02}.png".format(group))
コード例 #35
0
 def plot_grid(self, name="", save_figure=True):
     """
     Gridin 2 boyutlu gösterimi
     :param name: kaydedilecek resmin adı
     :return:
     """
     plt.matshow(self.matrix_grid(), cmap="RdBu", fignum=0)  #
     # Resmi kaydetme opsiyonu
     if save_figure:
         plt.savefig(self.path + name + '.png')
コード例 #36
0
def savematrixplot(datasetname, tumorname, A, k):
    """    
    plt.figure("%s_consensus_rank_%d.png" % (tumorname,k))
    plt.subplot(211)
    plt.matshow(A)
    plt.savefig("./" + datasetname + "_results/%s_consensus_rank_%d.png" % (tumorname,k))
    """
    mplpl.matshow(A)
    mplpl.savefig("./" + datasetname + "_results/%s_consensus_rank_%d.png" %
                  (tumorname, k))
コード例 #37
0
ファイル: markov.py プロジェクト: SRHerzog/ut
 def plot_matrix_prod(self, n=1, display_transpose=False):
     cond_prob_matrix = np.matrix(self.cond_probs.as_matrix())
     cond_prob_matrix = cond_prob_matrix**n
     if display_transpose:
         cond_prob_matrix = cond_prob_matrix.T
     plt.matshow(cond_prob_matrix)
     ax = plt.gca()
     plt.xticks(range(len(self.labels)))
     ax.set_xticklabels(self.labels, rotation=90)
     plt.yticks(range(len(self.labels)))
     ax.set_yticklabels(self.labels)
     plt.grid('off')
コード例 #38
0
def PlotCorrelationMatrix(dirin):

    from matplotlib import pylab
    
    fnamein=os.path.join(dirin, "cvmatrix.csv")
    fnameout=os.path.join(dirin,"plots", "cvmatrix.png")    

    m=bnmin1io.LoadCVSFile(fnamein)
    pylab.clf()
    pylab.matshow(m)
    pylab.colorbar()
    pylab.savefig(fnameout)
コード例 #39
0
ファイル: exp_utils.py プロジェクト: suryadheeshjith/CFXGB
def plot_forest_all_proba(y_proba_all, y_gt):
    from matplotlib import pylab
    N = len(y_gt)
    num_tree = len(y_proba_all)
    pylab.clf()
    mat = np.zeros((num_tree, N))
    LOGGER.info('mat.shape={}'.format(mat.shape))
    for i in range(num_tree):
        mat[i, :] = y_proba_all[i][(range(N), y_gt)]
    pylab.matshow(mat, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    pylab.grid(False)
    pylab.show()
コード例 #40
0
def predictTest(X_test, y_test):
    # 加载模型
    print("load GBDT model ...")
    model = joblib.load('clfGBDT.model')

    # 用测试集验证最优模型
    t0 = time()
    print("Predicting label on the test set")
    y_pre = model.predict(X_test)

    # 创建output file(label=0/1 feature1 feature2)
    print("create modelResult.txt")
    outputFileName = "modelResult.txt"
    outputFile = open(outputFileName, 'w')
    line = len(y_pre)  # txt的行
    for i in range(0, line):
        outputFile.write(str(y_pre[i]))
        outputFile.write('\t')
        outputFile.write(str(X_test[i][0]))
        outputFile.write('\t')
        outputFile.write(str(X_test[i][1]))
        outputFile.write('\n')
    outputFile.close()
    print("modelResult.txt finished ...")

    y_preprob = model.predict_proba(X_test)[:, 1]
    print('Accuaracy: %.4g' % metrics.accuracy_score(y_test, y_pre))
    print('AUC Score (Test): %f' % metrics.roc_auc_score(y_test, y_preprob))
    print("done in %0.3fs" % (time() - t0))

    # classification_report
    # 输入:测试集真实的结果和预测的结果
    # 返回:每个类别的准确率召回率F值以及宏平均值。
    print("classification report:")
    print(classification_report(y_test, y_pre))

    # 混淆矩阵
    # 输出:
    # 第0行第0列的数表示y_true中值为0,y_pred中值也为0的个数;第0行第1列的数表示y_true中值为0,y_pred中值为1的个数
    # 第1行第0列的数表示y_true中值为1,y_pred中值也为0的个数;第1行第1列的数表示y_true中值为1,y_pred中值为1的个数
    matrix = confusion_matrix(y_test, y_pre)
    print("confusion matrix:")
    print(matrix)
    # 画出混淆矩阵
    font = FontProperties(fname=r"c:\windows\fonts\msyh.ttc", size=10)  # 字体
    plt.matshow(matrix)
    plt.colorbar()
    plt.xlabel('预测类型', fontproperties=font)
    plt.ylabel('实际类型', fontproperties=font)
    labels = ['0', '1']
    plt.xticks(np.arange(matrix.shape[1]), labels)
    plt.yticks(np.arange(matrix.shape[1]), labels)
    plt.show()
コード例 #41
0
def plotArray( xyarray, colormap=mpl.cm.gnuplot2, normMin=None, normMax=None, showMe=True,
              cbar=False, cbarticks=None, cbarlabels=None, plotFileName='arrayPlot.png',
              plotTitle='', sigma=None):
    """
    Plots the 2D array to screen or if showMe is set to False, to file.  If normMin and
    normMax are None, the norm is just set to the full range of the array.
    """
    if sigma != None:
       meanVal = np.mean(accumulatePositive(xyarray))
       stdVal = np.std(accumulatePositive(xyarray))
       normMin = meanVal - sigma*stdVal
       normMax = meanVal + sigma*stdVal
    if normMin == None:
       normMin = xyarray.min()
    if normMax == None:
       normMax = xyarray.max()
    norm = mpl.colors.Normalize(vmin=normMin,vmax=normMax)

    figWidthPt = 550.0
    inchesPerPt = 1.0/72.27                 # Convert pt to inch
    figWidth = figWidthPt*inchesPerPt       # width in inches
    figHeight = figWidth*1.0                # height in inches
    figSize =  [figWidth,figHeight]
    params = {'backend': 'ps',
              'axes.labelsize': 10,
              'axes.titlesize': 12,
              'text.fontsize': 10,
              'legend.fontsize': 10,
              'xtick.labelsize': 10,
              'ytick.labelsize': 10,
              'figure.figsize': figSize}
    plt.rcParams.update(params)

    plt.matshow(xyarray, cmap=colormap, origin='lower',norm=norm)

    if cbar:
        if cbarticks == None:
           cbar = plt.colorbar(shrink=0.8)
        else:
           cbar = plt.colorbar(ticks=cbarticks, shrink=0.8)
        if cbarlabels != None:
           cbar.ax.set_yticklabels(cbarlabels)
    
    plt.ylabel('Row Number')
    plt.xlabel('Column Number')
    plt.title(plotTitle)

    if showMe == False:
        plt.savefig(plotFileName)
#    else:    
#        plt.show()
    plt.close()
コード例 #42
0
ファイル: plot_.py プロジェクト: liusong299/HK_DataMiner
def plot_block_matrix(labels, tProb_, name='BlockMatrix'):
    print "Plot Block Matrix"
    indices = np.argsort(labels)
    #print indices
    block_matrix = tProb_[:,indices]
    block_matrix = block_matrix[indices,:]
    block_matrix = 1 - block_matrix
    #print block_matrix
    pylab.matshow(block_matrix, cmap=plt.cm.OrRd)
    plt.colorbar()
    plt.savefig('./' + name + '.png', dpi=400)
    #pylab.show()
    plt.close()
コード例 #43
0
def plot_block_matrix(labels, tProb_, name='BlockMatrix'):
    print("Plot Block Matrix")
    indices = np.argsort(labels)
    #print indices
    block_matrix = tProb_[:, indices]
    block_matrix = block_matrix[indices, :]
    block_matrix = 1 - block_matrix
    #print block_matrix
    pylab.matshow(block_matrix, cmap=plt.cm.OrRd)
    plt.colorbar()
    plt.savefig('./' + name + '.png', dpi=400)
    #pylab.show()
    plt.close()
コード例 #44
0
ファイル: patch_class.py プロジェクト: cwein3/im-seg
def predict(X, y, model):
    labels = model.predict(X).flatten()
    n_samples = X.shape[0]
    err = float(np.sum(y != labels))/n_samples
    print "Prediction error of ", err, "."
    cm = sklearn.metrics.confusion_matrix(y, labels)
    row_sum = cm.sum(axis=1).reshape(cm.shape[0], 1)
    print "Frequencies of each class:", row_sum
    cm = cm.astype(float)/row_sum
    plt.matshow(cm)
    plt.title("Confusion Matrix")
    plt.colorbar()
    plt.show()
コード例 #45
0
def plot_target(A, cd):
    X = []
    Y = []
    for line in cd:
        X.append(float(line.split('\t')[0]))
        Y.append(float(line.split('\t')[1]))
    for h in range(len(X)):
        ax = plt.axes(projection='3d')
        a = int(X[h])
        b = int(Y[h])
        x_st = a - 25
        x_en = a + 25
        y_st = b - 25
        y_en = b + 25
        z = []
        for i in range(y_st, y_en + 1, 1):
            temp = []
            for j in range(x_st, x_en + 1, 1):
                temp.append(A[i][j])
            z.append(temp)
        x = np.linspace(x_st, x_en, (x_en - x_st) + 1)
        y = np.linspace(y_st, y_en, (y_en - y_st) + 1)
        Xin, Yin = np.meshgrid(x, y)
        z = np.array(z)
        data = z
        plt.matshow(data, cmap=plt.cm.gist_earth_r)
        params = fitgaussian(data)
        fit = gaussian(*params)
        p = ax.plot_surface(Xin,
                            Yin,
                            fit(*np.indices(data.shape)),
                            cmap=plt.cm.copper)
        q = ax.scatter(Xin, Yin, z, marker='.')
        plt.xlabel('X axis')
        plt.ylabel('Y axis')
        plt.colorbar()
        ax.set_xlabel('X axis')
        ax.set_ylabel('Y axis')
        ax.set_zlabel('pixel count')
        ax = plt.gca()
        (height, x, y, width_x, width_y, base) = params
        fwhm_x = 2 * sqrt(log(2.0)) * width_x
        fwhm_y = 2 * sqrt(log(2.0)) * width_y
        print 'Coordinates of the target object', (a, b)
        #print 'FWHM-X =', fwhm_x, '\nFWHM-Y =', fwhm_y
        print 'Sky base =', base
        print 'Peak value =', height
        print 'Mean (x,y) =', (x, y)
        plt.show()

    return None
コード例 #46
0
ファイル: Percolation.py プロジェクト: juankp/PercolacionCP
	def simular(self):
		pass
		i=0
		g = []
		while True:
			pass
			if (self.uf.find(self.cell(0,0),self.cell(self.N-1,self.N-1))):
				plt.plot(g)
				plt.show()
				pll.matshow(self.celda)
				pll.show()
				return int(i)
			i=i+1
			g.append(i/self.N*self.N)
			self.step()
コード例 #47
0
ファイル: patch_class_splits.py プロジェクト: cwein3/im-seg
def main():
    parser = ap.ArgumentParser()
    parser.add_argument('--data_dir', type=str, default='../data_helpers/', help='Folder containing data splits.')
    parser.add_argument('--data', type=str, help='The location of the data file we are using.')
    parser.add_argument('--mode', type=str, help='Either PREDICT or TRAIN. Will predict on test dataset or train on new dataset accordingly.')
    parser.add_argument('--old_model', type=str, default=None, help='The file location of the neural network model. If this is None, we will train a model from scratch, but this needs to be specified for predict.')
    parser.add_argument('--num_hidden', type=int, default=1000, help='The number of hidden layers in the classifier.')
    parser.add_argument('--n_iter', type=int, default=2, help='Number of iterations of gradient descent to use.')
    parser.add_argument('--outfile', type=str, help='The file which we output the trained model to.')
    parser.add_argument('--lr', type=float, default=0.01, help='Learning rate to use.')
    parser.add_argument('--allowed_num', type=int, help='The allowed number of training examples for one class.')
    parser.add_argument('--name_map', type=str, default='classmap.pkl', help='Name of the pickle file which stores the class map.')
    parser.add_argument('--num_split', type=int, default='13', help='The number of training splits to do.')
    parser.add_argument('--predict_set', type=str, default='test', help='Whether we predict on train or test.')
    parser.add_argument('--lr_decay', type=float, default=0.75, help='Learning rate decay every time we pass over a split.')
    parser.add_argument('--hardcode', type=bool, default=False, help='Whether to hardcode allowed number of classes.')
    global args
    args = parser.parse_args()
    class_map = allowed_classes if args.hardcode else pickle.load(open(args.name_map, "r"))
    num_classes = len(class_map)
    model = None if args.old_model is None else pickle.load(open(args.old_model, "r"))
    if args.mode == 'TRAIN':
	lr = args.lr
	for _ in xrange(args.n_iter):
            for split in xrange(args.num_split):
                data_loc = args.data_dir + ("trainsplit%d" % split) + args.data
                X, y, w = convert_data(data_loc, class_map)
                model = train(X, y, w, num_classes, model, lr)
		lr *= args.lr_decay 
    if args.mode == 'PREDICT':
	all_predict = np.array([])
	all_labels = np.array([])
	for split in xrange(args.num_split):
	    data_loc = args.data_dir + (args.predict_set + "split%d" % split) + args.data
            X, y, _ = convert_data(data_loc, class_map)
            all_predict = np.concatenate((all_predict, predict_split(X, y, model)), axis=0)
	    all_labels = np.concatenate((all_labels, y), axis=0)
       	n_samples = all_labels.size
       	err = float(np.sum(all_predict != all_labels))/n_samples
       	print "Prediction error of ", err, "."
       	cm = sklearn.metrics.confusion_matrix(all_labels, all_predict)
       	row_sum = cm.sum(axis=1).reshape(cm.shape[0], 1)
       	print "Frequencies of each class:", row_sum
       	cm = cm.astype(float)/row_sum
       	plt.matshow(cm)
       	plt.title("Confusion Matrix")
       	plt.colorbar()
       	plt.show()
コード例 #48
0
def savepic(mat, maxscale, picname):
    fig = plt.matshow(mat, vmin=0, vmax=maxscale)
    plt.axis('off')
    fig.axes.get_xaxis().set_visible(False)
    fig.axes.get_yaxis().set_visible(False)
    plt.savefig(picname, bbox_inches='tight', pad_inches = 0, dpi=100)
    plt.close()
コード例 #49
0
 def plot_grade(self, titulo, nome, args, save_figure=True):
     """
     Metodo que plota a representacao 2D da grade
     :param titulo: Contador das imagens
     :param nome: Nome da imagem a ser salva
     :param args: Argumentos usados para executar o teste
     """
     #Opcoes de cor: "RdBu" "seismic" , "RdYlGn", "jet"
     # mais em: http://matplotlib.org/users/colormaps.html
     plt.matshow(self.matriz_grade(), cmap="RdBu", fignum=0)
     # Opcao para salvar imagens
     if save_figure:
         plt.savefig(self.pasta + nome + '.png')
     plt.title(titulo)
     plt.xlabel("Argumentos: " + str(args))
     plt.draw()
def plot_confusion_matrix(cm, genre_list, name="", title=""):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap=plt.cm.Blues)
    ax = pylab.axes()
    ax.set_xticks(range(len(genre_list)))
    ax.set_xticklabels(genre_list)
    ax.xaxis.set_ticks_position("bottom")
    ax.set_yticks(range(len(genre_list)))
    ax.set_yticklabels(genre_list)
    #pylab.title(title)
    pylab.colorbar()
    pylab.grid(False)
    pylab.xlabel('Predicted class')
    pylab.ylabel('True class')
    pylab.grid(False)
    pylab.show()
コード例 #51
0
	def dibujAutom(self):
		print self.bondad
		#ID = self.id_CI
		for i in xrange(self.nCI):
			c = (i)#ID)   # tupla que dara el numero de la regla y de la CI para guardar la imagen.
			matrizEstados = self.m_r[i]
			pylab.matshow(matrizEstados,cmap='binary')
			pylab.title("Celdas")
			pylab.ylabel("Tiempo")
			pylab.savefig("Test_Regla_CI%i.eps" %c)
			pylab.close()
			# Aqui salvamos el automata seleccionado
			f = open('automata_CI_%i.txt' %c,'w')
			fout = csv.writer(f,delimiter = '\t')
			fout.writerows(matrizEstados)
			f.close()
コード例 #52
0
ファイル: kolmogorov3d.py プロジェクト: bnikolic/oof
def PlotTurbulenceIllustrZFlat(g):


    "Like PlotTurbulenceIllustr but use the ZFlatten routine"

    Nx, Ny, Nz = g[1]    

    for x in [1,10,100]:
        res=ZFlatten(g,x)

        na=kolmogorovutils.GridToNumarray( (res, (Nx,Ny,1)))
        na=na[:,:,0]
        na.transpose()
        pylab.clf()
        pylab.matshow(na)
        pylab.savefig("temp/turb3d-zflatsum%03i.eps" % x)
コード例 #53
0
ファイル: __init__.py プロジェクト: BahulkarAmey/sklearnlab
def plot_confusion_matrix(cm, targetname):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(targetname)))
    ax.set_xticklabels(targetname)
    ax.xaxis.set_ticks_position("bottom")
    ax.set_yticks(range(len(targetname)))
    ax.set_yticklabels(targetname)
    pylab.title('Confusion Matrix')
    pylab.colorbar()
    pylab.grid(False)
    pylab.xlabel('Predicted class')
    pylab.ylabel('True class')
    pylab.grid(False)
    pylab.show()
コード例 #54
0
ファイル: visualize.py プロジェクト: hiyokon/ShotokuTaishi
def show_confusion_matrix(matrix, labels, title=""):
    pylab.clf()
    pylab.matshow(matrix, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    pylab.title(title)
    pylab.colorbar()
    pylab.grid(False)
    pylab.xlabel('Predicted Class')
    pylab.ylabel('True Class')
    nums = range(len(labels))
    axes = pylab.axes()
    axes.set_xticks(nums)
    axes.set_xticklabels(labels)
    axes.set_yticks(nums)
    axes.set_yticklabels(labels)
    axes.xaxis.set_ticks_position('bottom')
    pylab.show()
コード例 #55
0
ファイル: utils.py プロジェクト: haisland0909/python_practice
def plot_confusion_matrix(cm, genre_list, name, title):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(genre_list)))
    ax.set_xticklabels(genre_list)
    ax.xaxis.set_ticks_position("bottom")
    ax.set_yticks(range(len(genre_list)))
    ax.set_yticklabels(genre_list)
    pylab.title(title)
    pylab.colorbar()
    pylab.grid(False)
    pylab.xlabel('Predicted class')
    pylab.ylabel('True class')
    pylab.grid(False)
    pylab.savefig(
        os.path.join(CHART_DIR, "confusion_matrix_%s.png" % name), bbox_inches="tight")
コード例 #56
0
def plot_confusion_matrix(cm, genre_list, name, title, filename):
  pylab.clf()
  pylab.matshow(cm, fignum=False)
  ax = pylab.axes()
  ax.set_xticks(range(len(genre_list)))
  ax.set_xticklabels(genre_list)
  ax.xaxis.set_ticks_position("bottom")
  ax.set_yticks(range(len(genre_list)))
  ax.set_yticklabels(genre_list)
  pylab.title(title)
  pylab.colorbar()
  pylab.grid(False)
  pylab.xlabel('Predicted class')
  pylab.ylabel('True class')
  pylab.grid(False)
  pylab.show()
  filename = '/home/kaushik/Canopy/kaushik_py/music_wav/' + filename
  plt.savefig(filename) 
コード例 #57
0
def makeItt2():
    # makes the pretty latex tabular and prints matrix, emphasises edges, make sure to put a '-' at end
    #A = ['S','A','T','A','N','S','S','P','A','W','N','-','S','A','T','A','N','S','P','R','A','W','N','-']
    #A = ['S','A','T','A','N','-','S','P','A','W','N','-','P','A','T','A','N','S','-','P','R','A','W','N','-']
    A = ['V','E','L','V','E','T','R','Q','P','E','A','L','G','Q','R','I','T','H','M','R','Q','C','K','S']
    B = ['P','E','A','T','C','Q','A','T','V','E','L','V','E','T','R','Q','C','K','S','A','L','L','Q','R','I','T','H','A','M','Q','C','K','S','L','V','A','R','P','Q','E','V','T','Y','M','E','T']
    theMat, temp = MakeMatrixFull(A)
    string = "\\begin{tabular}{|"
    for i in range(len(A)-1):
        string = string + 'c'
    string = string + '|}'
    print string
    print '\hline'
    string = ""
    for i in range(len(A)-2):
        string = string + A[i] + " & "
    string = string + A[-2] + " \\\\"
    print string
    print '\hline'
    for i in range(len(A)-1):
        string = ""
        for j in range(len(A)):
            if theMat[i+1][j] == 0:
                if A[(j+i+1)%len(A)] == '-':
                    if j < len(A) - 1:
                        string = string + " \\textcolor{blue}{$\star$} "
                    theMat[i+1][j] = -1
                else:
                    if A[j] == '-':
                        if j < len(A) - 1:
                            string = string + " \\textcolor{blue}{$\star$} "
                        theMat[i+1][j] = -1
                    else:
                        string = string + " " + A[(j+i+1)%len(A)] + " "
            else:
                string = string + " \\textcolor{red}{" + A[(j+i+1)%len(A)] + "} "
            if j < len(A) - 2:
                string = string + "&"
            else:
                string = string + "\\"
        print string
    print '\hline'
    print '\end{tabular}'
    plt.matshow(theMat)
コード例 #58
0
def diff_mat(fmin, fmax, mat_dir=None, ROI_labels=None,
             incon_event=['LRst', 'RLst'], con_event=['LLst', 'RRst']):
    """
    Make comparisons between two conditions' group causal matrices
    ----------
    con_event: list
        The list of congruent conditions.
    incon_event: string
        The name of incongruent condition.
    ROI_labels: list
        The list of ROIs.
    fmin, fmax:int
        The interest bandwidth.
    min_subject: string
        The subject for the common brain space.
    """

    fn_con1 = mat_dir + '/%s_%d_%dHz.npy' % (con_event[0], fmin, fmax)
    fn_con2 = mat_dir + '/%s_%d_%dHz.npy' % (con_event[1], fmin, fmax)
    fn_incon1 = mat_dir + '/%s_%d_%dHz.npy' % (incon_event[0], fmin, fmax)
    fn_incon2 = mat_dir + '/%s_%d_%dHz.npy' % (incon_event[1], fmin, fmax)
    am_ROI = len(ROI_labels)
    con_cau1 = np.load(fn_con1)
    con_cau2 = np.load(fn_con2)
    con_cau = con_cau1 + con_cau2
    incon_cau = np.load(fn_incon1) + np.load(fn_incon2)
    con_cau[con_cau > 0] = 1
    incon_cau[incon_cau > 0] = 1
    dif_cau = incon_cau - con_cau
    dif_cau[dif_cau < 0] = 0
    com_cau = incon_cau - dif_cau
    com_cau[com_cau < 0] = 0
    fn_dif = mat_dir + '/incon_con_%d-%dHz.npy' % (fmin, fmax)
    fn_com = mat_dir + '/com_incon_con_%d-%dHz.npy' % (fmin, fmax)
    fig_dif = mat_dir + '/incon_con_%d-%dHz.png' % (fmin, fmax)
    plt.matshow(dif_cau, interpolation='nearest')
    plt.xticks(np.arange(am_ROI), ROI_labels, fontsize=9, rotation='vertical')
    plt.yticks(np.arange(am_ROI), ROI_labels, fontsize=9)
    # pl.tight_layout(pad=2)
    # pl.show()
    plt.savefig(fig_dif, dpi=300)
    plt.close()
    np.save(fn_dif, dif_cau)
    np.save(fn_com, com_cau)