Ejemplo n.º 1
0
def mutual_information(dataframe, measure1, measure2, report):
	name = '%s - %s' % (measure1, measure2)

	vector_list_x = ee.vectorize(dataframe[measure1]) 
	vector_list_y = ee.vectorize(dataframe[measure2])

	mutual_information = ee.mi(vector_list_x, vector_list_y)
	
	report_line = 'Informacion Mutua %s: %s\n'%(name, mutual_information)
 	
 	report.write(report_line)
 	report.flush()
Ejemplo n.º 2
0
def mutualInformation(ImageStack,TimeRef,FlagROI,ROI):

        MutualInfo = []

        for z in range(TimeRef[0]+1,TimeRef[1]):

            if FlagROI:
                image1 = ImageStack[z-1,ROI[0]:ROI[1],ROI[2]:ROI[3]]
                image2 = ImageStack[z,ROI[0]:ROI[1],ROI[2]:ROI[3]]
            else:
                image1 = ImageStack[z-1,:,:]
                image2 = ImageStack[z,:,:]

            c=ee.vectorize(image1.flatten())
            d=ee.vectorize(image2.flatten())

            mi=ee.mi(c,d)
            MutualInfo.append(mi)
            
        return MutualInfo
Ejemplo n.º 3
0
    ax[0].set_xlabel('Percent White')


    plt.tight_layout()

    fig.savefig('figures/MN_GA_density.pdf')

    plt.close('all')

    sns.set_style('white')
    fig, ax = plt.subplots(1, 2, figsize=(6, 2))
    # bins=np.arange(-.1,1.1,.05)



    mn = EE.kldiv(EE.vectorize(np.random.normal(.82, np.sqrt(.82 * (1 - .82) / 100), 1000)), EE.vectorize(MN_values),
                  k=20)
    ga = EE.kldiv(EE.vectorize(np.random.normal(.55, np.sqrt(.55 * (1 - .55) / 100), 1000)), EE.vectorize(GA_values),
                  k=20)
    objects = [mn, ga]
    y_pos = np.arange(len(objects))

    ax[0].bar(y_pos * 2 + 1, objects, align='center', color=['darkturquoise', 'magenta'])
    # plt.xticks(y_pos, objects)
    # plt.ylabel('Usage')
    # plt.title('Programming language usage')
    ax[0].set_xticks(y_pos * 2 + 1)
    ax[0].set_xticklabels(['Minnesota', 'Georgia'])
    ax[0].set_xlim([0, 4])

    ax[1].bar(y_pos * 2 + 1, [9.2, 13.3], align='center', color=['darkturquoise', 'magenta'])
Ejemplo n.º 4
0
            spearman = sp.spearmanr(
                color_mat[:, 7, t][np.where(~np.isnan(color_mat[:, 5, t]))],
                color_mat[:, 9, t][np.where(~np.isnan(color_mat[:, 5, t]))])[0]
            if n < 2:
                if n == 0:
                    if t == t_len - 1:
                        total_x_wt = np.append(total_x_wt, x.ravel())
                        total_y_wt = np.append(total_y_wt, y.ravel())
                        total_z_wt = np.append(total_z_wt, z.ravel())
                if n == 1:
                    if t == t_len - 1:
                        total_x_c = np.append(total_x_c, x.ravel())
                        total_y_c = np.append(total_y_c, y.ravel())
                        total_z_c = np.append(total_z_c, z.ravel())
            try:
                info = ee.mi(ee.vectorize(y), ee.vectorize(z), k=3)
            except:
                info = 0

            n_cells = len(np.where(~np.isnan(color_mat[:, 5, t]))[0])
            df2 = pd.DataFrame({
                'X': [np.std(x) / np.mean(x)],
                'Y': [np.std(y) / np.mean(y)],
                'Z': [np.std(z) / np.mean(z)],
                'Information': [info],
                'Correlation': [spearman],
                'nCells': [n_cells],
                'label': [tags[n]]
            })
            frames = [df, df2]
            df = pd.concat(frames)
def main():
    sns.set_style('white')
    folder1 = 'Fig3_SourceData_1'
    names1 = listdir(folder1)

    if '.DS_Store' in names1:
        names1.remove('.DS_Store')
    names1 = sorted(names1, key=lambda x: int(x.split('.')[0]))
    names1 = [folder1 + '/' + name for name in names1]

    folder2 = 'Fig3_SourceData_2'
    names2 = listdir(folder2)

    if '.DS_Store' in names2:
        names2.remove('.DS_Store')
    names2 = sorted(names2, key=lambda x: int(x.split('.')[0]))
    names2 = [folder2 + '/' + name for name in names2]

    names = names1 + names2

    df_mar = pd.DataFrame({
        'X': [],
        'Y': [],
        'Z': [],
        'Information': [],
        'Correlation': [],
        'nCells': [],
        'label': []
    })
    tags = ['TX', 'TL']
    n = 0
    num_samps_each = 5
    total_x_wt = np.array([])
    total_x_c = np.array([])

    total_y_wt = np.array([])
    total_z_wt = np.array([])
    total_y_c = np.array([])
    total_z_c = np.array([])

    for j, name in enumerate(names):
        print(name)
        mat_contents = sio.loadmat(name)
        color_mat = mat_contents['data3D']
        t_len = mat_contents['data3D'].shape[2]

        for t in range(t_len):
            x = color_mat[:, 5, t][np.where(~np.isnan(color_mat[:, 5, t]))]
            y = color_mat[:, 7, t][np.where(~np.isnan(color_mat[:, 5, t]))]

            z = color_mat[:, 9, t][np.where(~np.isnan(color_mat[:, 5, t]))]
            spearman = sp.spearmanr(
                color_mat[:, 7, t][np.where(~np.isnan(color_mat[:, 5, t]))],
                color_mat[:, 9, t][np.where(~np.isnan(color_mat[:, 5, t]))])[0]

            if n < 2:
                if n == 0:
                    if t == t_len - 1:
                        total_x_wt = np.append(total_x_wt, x.ravel())
                        total_y_wt = np.append(total_y_wt, y.ravel())
                        total_z_wt = np.append(total_z_wt, z.ravel())
                if n == 1:
                    if t == t_len - 1:
                        total_x_c = np.append(total_x_c, x.ravel())
                        total_y_c = np.append(total_y_c, y.ravel())
                        total_z_c = np.append(total_z_c, z.ravel())

            try:
                info = ee.mi(ee.vectorize(y), ee.vectorize(z), k=3)

            except:
                info = 0

            n_cells = len(np.where(~np.isnan(color_mat[:, 5, t]))[0])
            df2 = pd.DataFrame({
                'X': [np.std(x) / np.mean(x)],
                'Y': [np.std(y) / np.mean(y)],
                'Z': [np.std(z) / np.mean(z)],
                'Information': [info],
                'Correlation': [spearman],
                'nCells': [n_cells],
                'label': [tags[n]]
            })
            frames = [df_mar, df2]
            df_mar = pd.concat(frames)
        if (j + 1) % num_samps_each == 0:
            n += 1

    f3, ax3 = plt.subplots(1, 2, figsize=(10, 3))

    ax3[0].set_xlim([-10, 300])
    sns.set_style('white')
    colors = ['salmon', 'darkblue']
    tags = ['TX', 'TL']
    tvect = np.linspace(0, 400, 1000)
    recs = []
    ax30 = ax3[0].twinx()
    for j, color in enumerate(colors):
        x, y = df_mar.loc[df_mar.label == tags[j]].nCells, df_mar.loc[
            df_mar.label == tags[j]].X
        x, y2 = df_mar.loc[df_mar.label == tags[j]].nCells, df_mar.loc[
            df_mar.label == tags[j]].Information
        ys = df_mar.loc[df_mar.label == tags[j]].Y
        zs = df_mar.loc[df_mar.label == tags[j]].Z

        nbins = 15
        bins = np.linspace(0, 275, nbins)
        idx = np.digitize(x, bins)
        means = [0]
        errors = [0]
        means2 = []
        errors2 = []
        for i in range(nbins):
            if j == 0:
                ax3[0].errorbar(bins[i] + (200 / (2 * nbins)),
                                np.mean(y[idx == i + 1]),
                                fmt='o',
                                color=color)

                ax3[1].errorbar(bins[i] + (200 / (2 * nbins)),
                                np.mean(y2[idx == i + 1]),
                                fmt='o',
                                color=color)
            else:
                ax30.errorbar(bins[i] + (200 / (2 * nbins)),
                              np.mean(y[idx == i + 1]),
                              fmt='o',
                              color=color)

                ax3[1].errorbar(bins[i] + (200 / (2 * nbins)),
                                np.mean(y2[idx == i + 1]),
                                fmt='o',
                                color=color)

                #           ax.errorbar(bins[i]+(200/(2*nbins)),np.mean(y[idx==i+1]),yerr=np.std(y[idx==i+1]),fmt='o',color=color)
            means.append(np.mean(y[idx == i + 1]))
            errors.append(sp.sem(y[idx == i + 1]))
            means2.append(np.mean(y2[idx == i + 1]))
            errors2.append(sp.sem(y2[idx == i + 1]))

        means = np.asarray(means)
        errors = np.asarray(errors)

        xvect = bins + (200 / (2 * nbins))
        xvect = np.insert(xvect, 0, 0)

        if j == 0:
            ax3[0].fill_between(xvect,
                                means - errors,
                                means + errors,
                                color=color,
                                alpha=0.5)
        else:
            ax30.fill_between(xvect,
                              means - errors,
                              means + errors,
                              color=color,
                              alpha=0.5)

        means2 = np.asarray(means2)
        errors2 = np.asarray(errors2)
        ax3[1].fill_between(bins + (200 / (2 * nbins)),
                            means2 - errors2,
                            means2 + errors2,
                            color=color,
                            alpha=0.5)
        recs.append(mpatches.Rectangle((0, 0), 1, 1, fc=colors[j]))

    ax3[0].legend(recs[::-1], ['MarA Fusion', 'WT MarA'],
                  title='Strain',
                  loc=4)
    ax3[1].legend(recs[::-1], ['MarA Fusion', 'WT MarA'],
                  title='Strain',
                  loc=4)

    ax3[0].set_ylabel('Coefficient of Variation')
    ax3[0].set_title('Activator Variance over Time')
    ax3[0].set_xlabel('Number of Cells in Microcolony')
    ax3[1].set_xlabel('Number of Cells in Microcolony')

    ax3[1].set_title('Downstream coordination over time')
    ax3[1].set_ylabel('Infromation (bits)')
    ax3[0].set_ylim([0, 0.25])
    plt.tight_layout()
    f3.savefig('figures/modified_marA_TS.pdf', bbox_inches='tight')
Ejemplo n.º 6
0
			#        = H(T)
			# In this case, I use the average entropy
			# over the training examples
			iXT1.append(t1_ent / h_cnt)
			print(iXT1)
			iXT2.append(t2_ent / h_cnt)
			print(iXT2)
			iXT3.append(t3_ent / h_cnt)
			print(iXT3)
			iXT4.append(t4_ent / h_cnt)
			print(iXT4)

			# Estimate the continuous mutual information using the
			# k-nearst neighbors estimator
			# https://github.com/gregversteeg/NPEET
			ys = ee.vectorize(ys)
			iTY1.append(ee.mi(t1s, ys))
			print(iTY1)
			iTY2.append(ee.mi(t2s, ys))
			print(iTY2)
			iTY3.append(ee.mi(t3s, ys))
			print(iTY3)
			iTY4.append(ee.mi(t4s, ys))
			print(iTY4)

			xs = []
			ys = []
			t1s = []
			t2s = []
			t3s = []
			t4s = []
Ejemplo n.º 7
0
def scoreDependence(X, Y):
    dep = ee.mi(ee.vectorize(X), ee.vectorize(Y))
    return dep