Exemple #1
0
def print_obs(gram,
              specs,
              nullify=False,
              isplot=False,
              perm=True,
              fontsize=14):
    ''' Plot a rescale of the observability properties'''
    if nullify is False: nullify = []
    W = np.sum(gram, axis=1)
    #
    W = np.log(W)
    W = W - np.median(W)
    for i_n in nullify:
        W[i_n] = 0
    W = W / np.sum(W)
    W += -np.min(W)
    W = W / np.sum(W)
    for i_n in nullify:
        W[i_n] = 0
    s = np.std(W)
    m = smart_mean(W)
    W2 = np.zeros(W.shape)
    for iw, w in enumerate(W):
        if w < m + 2 * s: W2[iw] = w
    W2 = W2 / np.sum(W2)
    print(W2)
    wm = np.max(W2)
    wM = np.max(W)
    for iw, w in enumerate(W):
        if w > m + 2 * s:
            W2[iw] = wm * 2 * w / wM
    wm = np.min(W2[W2 > 0])
    for iw, w in enumerate(W2):
        if w < wm:
            if iw not in nullify: W2[iw] = 0.5 * wm
    W = W2 / np.sum(W2)

    if perm is False:
        perm = np.arange(len(specs))
    else:
        try:
            if len(perm) != len(specs):
                perm = np.argsort(W)[::-1]
        except:
            perm = np.argsort(W)[::-1]
    #
    if isplot is True:
        pt.plot1(
            np.array([W[pi] for pi in perm]),
            pt.Paradraw(x_tick_label=[specs[pi] for pi in perm],
                        x_label='species',
                        y_label='W',
                        stem=True,
                        ticksize=fontsize,
                        thickness=['3']))
    return W
Exemple #2
0
 def plot(self, style='z'):
     import plot_tools as pt
     pd = pt.Paradraw()
     pd.colors = pt.get_colors(self.n_species)
     pd.x_scale = 'symlog'
     pd.y_scale = 'symlog'
     pd.x_label = 't'
     if style == 'rates':
         pd.y_label = 'rates'
         zs = [self.ts_rates(i)[1:] for i in range(self.n_species)]
     else:
         pd.y_label = 'z'
         zs = [self.ts_Z(i)[1:] for i in range(self.n_species)]
     time = (self.time[1:], ) * self.n_species
     figs = pt.multiplot2(time, zs, pd)
     return figs
Exemple #3
0
def p_explore(dd):
    ''' plot the results of f_explore'''
    nt = dd.shape[0]
    nx = dd.shape[1]
    xx = ()
    yy = ()
    for i in range(nx):
        xx = xx + (dd[:, 0, i, 0], )
        yy = yy + (dd[:, 1, i, 0], )
        xx = xx + (dd[:, 0, i, 1], )
        yy = yy + (dd[:, 1, i, 1], )
    pd = pt.Paradraw()
    pd.x_label = '$x_1$'
    pd.y_label = '$x_2$'
    pd.marks = ['k']
    pt.multiplot2(xx, yy, pd)
    return xx, yy
Exemple #4
0
def plot_mech(inputs,reaction=None,xlim=None):
	ploc = inputs['ploc']
	outputs = inputs['outputs']
	#
	if reaction is None:
		if 'main_reaction' not in outputs.keys():order_observability(inputs)
		reaction = outputs['main_reaction']
	#time
	tmin,tmax = ploc['tmin'],ploc['tmax']
	n_s = reaction.n_species
	tmini = int(np.floor(np.log10(tmin)))
	tmaxi = int(np.ceil(np.log10(tmax)))
	#main parameters
	pd = pt.Paradraw()
	if n_s<10:pd.legend = [reaction.list[i] for i in xrange(n_s)]
	pd.x_scale = 'log'
	if xlim is None:
		pd.xlim = [tmin,tmax]
		pd.x_tick_label = [1.*10**i for i in xrange(tmini+1,tmaxi+1,2)]
	else: pd.xlim = xlim
	pd.x_label = 'time'
	import matplotlib.colors as colors
	pd.colors = []
	for ic,c in enumerate(colors.cnames):
		if ic<n_s:pd.colors.append(str(c))		
#	pd.colors = ['tan','g','r','b','k','y','magenta','aqua']
		
	cc = [reaction.time_series('concentrations',i) for i in xrange(n_s)]
	tt = (reaction.time,)*n_s
	pd.y_label = 'n'
	pd.ylim = [np.min(cc),np.max(cc)]
	pt.multiplot2(tt,cc,pd)
#
	zz = [reaction.time_series('z',i) for i in xrange(n_s)]
	pd.y_scale = 'log'
	pd.y_label = 'z'
	pd.ylim = [np.min(zz),np.max(zz)]
	pt.multiplot2(tt,zz,pd)
#
	pd.y_scale = 'symlog'
	pd.y_label = 'p rate'
	pp = [reaction.time_series('rates',i) for i in xrange(n_s)]
	pd.ylim = [np.min(pp),np.max(pp)]
	pt.multiplot2(tt,pp,pd)
Exemple #5
0
def plot_clusters(w1, w2):
    ind0 = np.where(labels == 0)[0]
    ind1 = np.where(labels == 1)[0]
    ind2 = np.where(labels == 2)[0]
    vocab_list = tfidf_vocab.tolist()
    try:
        w1 = int(w1)
        indword1 = w1
    except:
        #w1 is a string, not an integerer
        index1 = vocab_list.index(w1)
        indword1 = np.where(tfidf_index_sorted_weights == index1)[0][0]
    #
    try:
        w2 = int(w2)
        indword2 = w2
    except:
        #w2 is a string, not an integerer
        index2 = vocab_list.index(w2)
        indword2 = np.where(tfidf_index_sorted_weights == index2)[0][0]
    print(indword1, indword2)
    #
    pd = pt.Paradraw()
    pd.title = tfidf_vocab[tfidf_index_sorted_weights[
        indword1]] + '  ' + tfidf_vocab[tfidf_index_sorted_weights[indword2]]
    pd.x_label = tfidf_vocab[tfidf_index_sorted_weights[indword1]]
    pd.y_label = tfidf_vocab[tfidf_index_sorted_weights[indword2]]
    pd.colors = ['r', 'g', 'b']
    pd.markers = ['.', '.', '.']
    pd.marks = ['', '', '']
    pd.markeredge = True
    pd.markerssize = [8, 8, 8]
    pd.thickness = [18, 18, 18]
    pd.legend = ['cluster 1', 'cluster 2', 'cluster 3']

    datax = [
        most_sig_array[:, indword1][ind0], most_sig_array[:, indword1][ind1],
        most_sig_array[:, indword1][ind2]
    ]
    datay = [
        most_sig_array[:, indword2][ind0], most_sig_array[:, indword2][ind1],
        most_sig_array[:, indword2][ind2]
    ]
    pt.multiplot2(datax, datay, pd)
Exemple #6
0
def graph_distrib(graph, plot=False, kmax=None):
    if kmax is None:
        k = np.arange(np.max(graph) + 1)
    else:
        k = np.arange(kmax + 1)
    pk = np.zeros(len(k))
    for g in graph:
        if kmax is None:
            pk[g] += 1
        else:
            if g < kmax + 1:
                pk[g] += 1

    k = k[1:]
    pk = pk[1:]

    pk = 1. * pk / np.sum(pk)
    pk[pk == 0.] = np.min(pk[np.nonzero(pk)]) / 10.

    A = np.ones((len(k) - 2, 2))
    A[:, 1] = k[1:-1]
    logpk = np.log(pk[1:-1])
    mloga, lambda_ = -np.linalg.lstsq(A, logpk)[0][:]
    a = np.exp(-mloga)
    print('lambda approx', lambda_)
    if plot is True:
        import plot_tools
        plot_tools.multiplot2(
            (k, k), (pk, a * np.exp(-lambda_ * k)),
            plot_tools.Paradraw(
                marks=['-', '--'],
                markers=['o', ''],
                y_scale='log',
                x_label='k',
                y_label='P(k)',
                ax_x_format='%.0f',
                legend=['', '$\lambda = ' + '{0:.2f}'.format(lambda_) + '$']))
    return k, pk, lambda_
Exemple #7
0
    datax = [
        most_sig_array[:, indword1][ind0], most_sig_array[:, indword1][ind1],
        most_sig_array[:, indword1][ind2]
    ]
    datay = [
        most_sig_array[:, indword2][ind0], most_sig_array[:, indword2][ind1],
        most_sig_array[:, indword2][ind2]
    ]
    pt.multiplot2(datax, datay, pd)


indword1 = 0
indword2 = 1
indword3 = 2

pd = pt.Paradraw()
pd.colors = ['r', 'g', 'b']
pd.markers = ['.', '.', '.']
pd.marks = ['', '', '']
pd.markeredge = True
pd.markerssize = [8, 8, 8]
pd.thickness = [18, 18, 18]
pd.legend = ['cluster 1', 'cluster 2', 'cluster 3']
pd.title = tfidf_vocab[tfidf_index_sorted_weights[
    indword1]] + '  ' + tfidf_vocab[tfidf_index_sorted_weights[indword2]]
pd.x_label = tfidf_vocab[tfidf_index_sorted_weights[indword1]]
pd.y_label = tfidf_vocab[tfidf_index_sorted_weights[indword2]]

datax = [
    most_sig_array[:, indword1][ind0], most_sig_array[:, indword1][ind1],
    most_sig_array[:, indword1][ind2]