예제 #1
0
파일: kriging.py 프로젝트: VACUMM/vacumm
def gauss3(x, y,
    x0=-1, y0=0.5, dx0=1, dy0=1, f0=1.,
    x1=1, y1=1, dx1=2, dy1=0.5, f1=-1,
    x2=0, y2=-1.5, dx2=.5, dy2=.5, f2=-.3,
    **kwargs):
    """Create data sample as function position and 3-gaussian function"""
    g = P.bivariate_normal(x, y, dx0, dy0, x0, y0)*f0
    g+= P.bivariate_normal(x, y, dx1, dy1, x1, y1)*f1
    g+= P.bivariate_normal(x, y, dx2, dy2, x2, y2)*f2
    g *= 10.
    return g
예제 #2
0
def gauss3(x, y,
    x0=-1, y0=0.5, dx0=1, dy0=1, f0=1.,
    x1=1, y1=1, dx1=2, dy1=0.5, f1=-1,
    x2=0, y2=-1.5, dx2=.5, dy2=.5, f2=-.3,
    **kwargs):
    """Create data sample as function position and 3-gaussian function"""
    g = P.bivariate_normal(x, y, dx0, dy0, x0, y0)*f0
    g+= P.bivariate_normal(x, y, dx1, dy1, x1, y1)*f1
    g+= P.bivariate_normal(x, y, dx2, dy2, x2, y2)*f2
    g *= 10.
    return g
예제 #3
0
def test():
    import pylab as p

    x = np.linspace(-5, 5, 200)
    y = np.linspace(-5, 5, 150)

    X, Y = p.meshgrid(x, y)
    Z = p.bivariate_normal(X, Y)

    # mainWin = pplt.figure()
    print X, Y, Z
    print X.shape
    print Y.shape
    print Z.shape
    surface_plot(Z)

    pplt.show()
예제 #4
0
def test():
	import pylab as p

	x = np.linspace(-5, 5, 200)
	y = np.linspace(-5, 5, 150)

	X,Y = p.meshgrid(x, y)
	Z = p.bivariate_normal(X, Y)

	# mainWin = pplt.figure()
	print X, Y, Z
	print X.shape
	print Y.shape
	print Z.shape
	surface_plot(Z)

	pplt.show()
예제 #5
0
from numpy import *
import pylab as p
#import matplotlib.axes3d as p3
import mpl_toolkits.mplot3d.axes3d as p3
# u and v are parametric variables.
# u is an array from 0 to 2*pi, with 100 elements
u=r_[0:2*pi:100j]
# v is an array from 0 to 2*pi, with 100 elements
v=r_[0:pi:100j]
# x, y, and z are the coordinates of the points for plotting
# each is arranged in a 100x100 array
delta = 0.025
x = arange(-3.0, 3.0, delta)
y = arange(-2.0, 2.0, delta)
X, Y = p.meshgrid(x, y)
Z1 = p.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = p.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
fig=p.figure()
ax = p3.Axes3D(fig)
ax.plot_surface(X,Y,Z)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
p.show()
fig=p.figure()
ax = p3.Axes3D(fig)
ax.contourf3D(X,Y,Z)
ax.set_xlabel('X')
ax.set_ylabel('Y')
예제 #6
0
## testing for plots

from numpy import *
import pylab as p
#import matplotlib.axes3d as p3
import mpl_toolkits.mplot3d.axes3d as p3

delta = 0.025
x = arange(-3.0, 3.0, delta)
y = arange(-2.0, 2.0, delta)
X, Y = p.meshgrid(x, y)
Z1 = p.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = p.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
fig = p.figure()
ax = p3.Axes3D(fig)
ax.contour3D(X, Y, Z)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
p.show()
예제 #7
0
        for i in range(col):
            data2x2[:, i] = (data2x2[:, i] - mean[i]) / std[i]
        return data2x2

    K = 2
    n_prob_var = 2
    X = regularize(np.genfromtxt("./data/faithful.txt")[:, 0:n_prob_var])

    # fit model
    mu, sigma, pi = fit_gmm(X)

    # print mu
    for k in range(K):
        pl.scatter(mu[k, 0], mu[k, 1], c='r', marker='o')

    # print contour
    x_list = np.linspace(-2.5, 2.5, 50)
    y_list = np.linspace(-2.5, 2.5, 50)
    x, y = np.meshgrid(x_list, y_list)
    for k in range(K):
        z = pl.bivariate_normal(x, y, np.sqrt(sigma[k, 0, 0]),
                                np.sqrt(sigma[k, 1, 1]), mu[k, 0], mu[k, 1],
                                sigma[k, 0, 1])
        pl.contour(x, y, z, 3, colors='k', linewidths=1)

    # print train data
    pl.plot(X[:, 0], X[:, 1], 'gx')
    pl.xlim(-2.5, 2.5)
    pl.ylim(-2.5, 2.5)
    pl.show()
예제 #8
0
    cell.set_height(0.8 / ny)
    cell.set_width(0.8 / nx)

# hide spines and ticks
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])

ax = fig.add_subplot(1, 2, 2, projection='3d')
X = np.arange(-5, 5, 0.1)
Y = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(X, Y)
Z = pylab.bivariate_normal(X, Y)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=0)
ax.set_xticklabels([])  # hide axis labels
ax.set_yticklabels([])
ax.set_zticklabels([])
# fig.colorbar(surf, shrink=0.5, aspect=5)

#####
# Parameter space and Hough space
#####
mpl.rcParams['font.size'] = 18
mpl.rcParams['lines.linewidth'] = 3.0

fig = plt.figure('Hough Space')

x = np.arange(-0.5, 2.5, 0.01)
예제 #9
0
import pylab as pl

statsfile = 'bmrb_ascii.shift'

amino_acids = read_preset(statsfile)
labels = [aa.three_let for aa in amino_acids] 
ca = [aa['CA'] for aa in amino_acids if aa.one_let != 'G']
cb = [aa['CB'] for aa in amino_acids if aa.one_let != 'G']

N = 100
x = pl.linspace(40., 80, N)
y = pl.linspace(0., 80., N)
X, Y = pl.meshgrid(x, y)
Z = []

z = pl.bivariate_normal(x, y, ca[0][1], cb[0][1], ca[0][0], cb[0][0])

#for i in range(0, len(ca)):
#    mu_a = ca[i][0]
#    sig_a = ca[i][1]
#    mu_b = cb[i][0]
#    sig_b = cb[i][1]
#    Z.append(pl.bivariate_normal(X, Y, sig_a, sig_b, mu_a, mu_b))
#Z = array(Z)
#
#print Z

axContour = pl.subplot(1,1,1)
pl.title(r'Verteilungen der $C_\alpha$ und $C_\beta$ Verschiebungen')
pl.xlabel(r'$C_\alpha$ (in ppm)')
pl.ylabel(r'$C_\beta$ (in ppm)')
예제 #10
0
파일: pcolor.py 프로젝트: cliburn/flow
import numpy
import pylab

delta = 0.025
x = numpy.arange(-3.0, 3.0, delta)
y = numpy.arange(-2.0, 2.0, delta)
X, Y = pylab.meshgrid(x, y)
Z1 = pylab.bivariate_normal(X, Y, 0.2, 0.2, 0.0, 0.0)
Z2 = pylab.bivariate_normal(X, Y, 0.35, 0.5, 1, 1)
Z3 = pylab.bivariate_normal(X, Y, 0.135, 0.35, 1.5, 1)
Z4 = pylab.bivariate_normal(X, Y, 0.5, 0.5, 2.1, -1)
Z5 = pylab.bivariate_normal(X, Y, 0.35, 0.55, -1, -1)
# difference of Gaussians
Z = 10.0 * (Z2 + Z1 + Z3 + Z4 + Z5)

# interpolate values 
fig=pylab.figure()
ax = pylab.subplot(111)
xpts = numpy.random.uniform(-3, 3, 10000)
ypts = numpy.random.uniform(-2, 2, 10000)
xint = map(int, (xpts + 3)/delta)
yint = map(int, (ypts + 2)/delta)
zvals = [Z[_y, _x] for _x, _y in zip(xint, yint)]

ax.scatter(xpts, ypts, s=1, c=zvals, edgecolors='none')
ax.set_xlabel('X')
ax.set_ylabel('Y')
pylab.show()
예제 #11
0
파일: EM.py 프로젝트: mlskit/astromlskit
def plot(clusterst, data, title='', gaussians=[], separate_plots=False):
    if clusterst.has_key('name'):
        title = clusterst['name']
    if clusterst.has_key('params'):
        gaussians = clusterst['params']
    clusters = clusterst['clusters']
    if separate_plots:
        ax = pl.subplot(212)
    else:
        ax = pl.subplot(111)
    colors = 'brgcymk'
    for k in range(len(clusters)):
        print ">>>> drawing ", k
        if len(clusters[k]):
            xy = [[data[i,j] for i in clusters[k]]\
                    for j in range(len(data[0]))]
            if len(data[0]) < 3:
                ax.scatter(xy[0], xy[len(data[0])-1],s=20,\
                        c=colors[k % len(colors)],\
                        marker='s', edgecolors='none')
            else:
                # [len(data[0]) * (len(data[0])+1)] / 2 plots
                total = math.sqrt(len(data[0])*(len(data[0])+1.0)/2.0)
                w = int(math.floor(total))
                h = int(math.floor(total+1))
                plotno = 0 
                for i in range(len(data[0])):
                    r = range(i+1, len(data[0]))
                    for j in r:
                        plotno += 1
                        ax = pl.subplot(h, w, plotno)
                        ax.scatter(xy[i], xy[j],s=20,\
                                c=colors[k % len(colors)], marker='s',\
                                edgecolors='none')
                        
    ranges = [min([data[:,i].min() for i in range(data.shape[1])]),\
            max([data[:,i].max() for i in range(data.shape[1])]),\
            min([data[i,:].min() for i in range(data.shape[0])]),\
            max([data[i,:].max() for i in range(data.shape[0])])]
    ax.axis(ranges)
    pl.title(title)

    ### Plot gaussians
    if len(gaussians):
        Z = []
        for g in gaussians:
            delta = (max(ranges) - min(ranges))/1000
            x = pl.arange(ranges[0], ranges[1], delta)
            y = pl.arange(ranges[2], ranges[3], delta)
            X,Y = pl.meshgrid(x, y)
            for i in range(len(g['sigma'])):
                if not g['sigma'][i,i]:                  # to put uncertainty on
                    g['sigma'][i,i] += 1.0/data.shape[0] # perfectly aligned data
            if len(g['sigma']) == 1:
                Z.append(pl.bivariate_normal(X, Y, g['sigma'][0,0],\
                        g['sigma'][0,0], g['mu'][0], g['mu'][0]))
            else:
                Z.append(pl.bivariate_normal(X, Y, g['sigma'][0,0],\
                        g['sigma'][1,1], g['mu'][0], g['mu'][1]))
        if separate_plots: # only supports 2 clusters currently, TODO
            cmap = pl.cm.get_cmap('jet', 10)    # 10 discrete colors
            ay = pl.subplot(221)
            ay.imshow(Z[0], cmap=cmap, interpolation='bilinear',\
                    origin='lower', extent=ranges)
            az = pl.subplot(222)
            az.imshow(Z[1], cmap=cmap, interpolation='bilinear',\
                    origin='lower', extent=ranges)
        else:
            #ZZ = sum(Z)
            if len(data[0]) < 3:
                for i in range(len(Z)):
                    ax.contour(X, Y, Z[i], 1, colors='k')# colors=colors[i%len(colors)])
    ### /Plot gaussians 

    pl.grid(True)
    pl.show()
예제 #12
0
    fig = p.figure()
    ax = p3.Axes3D(fig)
    ax.plot_surface(x, y, z)
    ax.set_xlabel("X")
    ax.set_ylabel("Y")
    ax.set_zlabel("Z")
    p.show()


# ========================================================================================

delta = 0.025
x2 = arange(-3.0, 3.0, delta)
y2 = arange(-2.0, 2.0, delta)
X2, Y2 = p.meshgrid(x2, y2)
Z1 = p.bivariate_normal(X2, Y2, 1.0, 1.0, 0.0, 0.0)
Z2 = p.bivariate_normal(X2, Y2, 1.5, 0.5, 1.0, 1.0)
Z3 = 10.0 * (Z2 - Z1)


def draw_contour():
    fig = p.figure()
    ax = p3.Axes3D(fig)
    ax.contour3D(X2, Y2, Z3)
    ax.set_xlabel("X")
    ax.set_ylabel("Y")
    ax.set_zlabel("Z")
    p.show()


def draw_contour_2():