예제 #1
0
파일: IEMD.py 프로젝트: peterhob/image_emd
def create_spline_v2(x, y, z, rbase=5.0, nlayers=5, lambdaNS=0.0):
    xy = np.zeros((x.shape[0], 3))
    xy[:, 0] = x
    xy[:, 1] = y
    xy[:, 2] = z
    xy = xy.tolist()
    model = xal.rbfcreate(2, 1)
    xal.rbfsetpoints(model, xy)
    xal.rbfsetalgohierarchical(model, rbase, nlayers, lambdaNS)
    xal.rbfbuildmodel(model)
    return model
예제 #2
0
def get_interpolated_alglib(nx, ny, xc, yc, v,
                            nsample=16,
                            radius=100, nlayer=1, par=1.e0):
    import xalglib
    model = xalglib.rbfcreate(2, 1)
    #xy = [[-1,0,2],[+1,0,3]]
    #xy = np.array([xc, yc, v]).T
    xy = map(list, zip(xc, yc, v))
    xalglib.rbfsetpoints(model, xy)
    #xalglib.rbfsetalgoqnn(model)

    # check the meaning of par
    xalglib.rbfsetalgomultilayer(model, radius, nlayer, par)

    rep = xalglib.rbfbuildmodel(model)
    tx = list(np.arange(0, nx, nsample)+nsample*.5)
    ty = list(np.arange(0, ny, nsample)+nsample*.5)
    #xti1 = xalglib.x_vector(512)
    #xalglib.x_from_list(xti1, ti, xalglib.DT_REAL, xalglib.X_CREATE)
    #xti2 = xalglib.x_vector(512)
    #xalglib.x_from_list(xti2, ti, xalglib.DT_REAL, xalglib.X_CREATE)
    vv1 = xalglib.rbfgridcalc2(model, tx, len(tx), ty, len(ty))
    vv4 = ni.zoom(np.array(vv1).T, nsample)

    return vv4
예제 #3
0
def get_interpolated_alglib(nx, ny, xc, yc, v,
                            nsample=16,
                            radius=100, nlayer=1, par=1.e0):
    import xalglib
    model = xalglib.rbfcreate(2, 1)
    #xy = [[-1,0,2],[+1,0,3]]
    #xy = np.array([xc, yc, v]).T
    xy = map(list, zip(xc, yc, v))
    xalglib.rbfsetpoints(model, xy)
    #xalglib.rbfsetalgoqnn(model)

    # check the meaning of par
    xalglib.rbfsetalgomultilayer(model, radius, nlayer, par)

    rep = xalglib.rbfbuildmodel(model)
    tx = list(np.arange(0, nx, nsample)+nsample*.5)
    ty = list(np.arange(0, ny, nsample)+nsample*.5)
    #xti1 = xalglib.x_vector(512)
    #xalglib.x_from_list(xti1, ti, xalglib.DT_REAL, xalglib.X_CREATE)
    #xti2 = xalglib.x_vector(512)
    #xalglib.x_from_list(xti2, ti, xalglib.DT_REAL, xalglib.X_CREATE)
    vv1 = xalglib.rbfgridcalc2(model, tx, len(tx), ty, len(ty))
    vv4 = ni.zoom(np.array(vv1).T, nsample)

    return vv4
예제 #4
0
    def _generate_rbf_potential(self, nstate, dimension, rbase, nlayers, lambdav):

        #this function reads in the filename containing
        #the 1 to 3-d data and generates a multilayer-rbf model

        self.data = np.loadtxt(filename).tolist()


        #initialize model
        self.model = xa.rbfcreate(dimension,1)
        xa.rbfsetpoints(self.model, self.data)
        xa.rbfsetalgomultilayer(self.model, rbase, nlayers, lambdav)
        self.potential = xa.rbfbuildmodel(self.model)
def RBFinterpolate(x, y, z, zIndex, gridData):
    # ---- INTERPOLATION PARAMETERS ----
    interpolationDimension = 2  # 2 for plane interpolation, 3 for volume interpolation
    interpolationDataDimension = 1  # 1 for interplating scalar values, vector interpolation also possible

    radiusFactorQ = 1.3  # default = 1.0, Coefficient for multiplying automatically determined interpolation radius, [0.75, 1.50], bigger factor gives greater smoothness
    radiusMedianFactorZ = 5.0  # default = 5.0, each radius cannot be bigger than factorZ*median_radius, so it does not influences to many points
    # ---- INTERPOLATION PARAMETERS END ----

    # Printing info
    name = mp.current_process().name
    print ' ', name, 'interpolating plane number', zIndex + 1

    xyz = np.vstack((x, y, z)).T  # Arrange in matrix
    xyzList = xyz.tolist()  # Convert from array to normal list for xalglib

    # Create interpolation object
    plane = xl.rbfcreate(interpolationDimension, interpolationDataDimension)
    xl.rbfsetpoints(plane, xyzList)

    # Calculate weights
    xl.rbfsetalgoqnn(plane, radiusFactorQ, radiusMedianFactorZ)
    xl.rbfbuildmodel(plane)

    xAxis = gridData[0]
    xAxisLen = gridData[1]
    yAxis = xAxis
    yAxisLen = xAxisLen

    interpolatedPlaneList = xl.rbfgridcalc2(plane, xAxis, xAxisLen, yAxis,
                                            yAxisLen)

    interpolatedPlane = np.asarray(interpolatedPlaneList,
                                   dtype=np.float64)  # Convert to numpy array
    #interpolatedPlane = np.absolute(interpolatedPlane) # Absolute value of all datapoints

    return [zIndex, interpolatedPlane]
예제 #6
0
# creates 2D model (2) with scalar 
# function values (1)
model = alg.rbfcreate(2, 1)

# include obs into the model
alg.rbfsetpoints(model, xyz0)

# sets the model
radius=5.0
nlayers=3
lamb=1.0e-3
alg.rbfsetalgomultilayer(model,radius,nlayers,lamb)

# build the model and return a report
rep = alg.rbfbuildmodel(model)

xg=np.arange(velocsub.shape[0],dtype='float32')
yg=np.arange(velocsub.shape[1],dtype='float32')
XG, YG = np.meshgrid(xg, yg)

xi=np.reshape(XG,np.size(XG))
yi=np.reshape(YG,np.size(YG))
x0=xi.tolist()
x1=yi.tolist()
zi=alg.rbfgridcalc2(model,x0,xi.size,x1,yi.size)



plt.figure
plt.subplot(1,2,1)
예제 #7
0
    print sz
    print data_cart
    print len(data_cart[:,0].tolist())
    splinefit = xalglib.spline3dbuildtrilinearv(data_cart[:,0].tolist(), sz, 
                                                data_cart[:,1].tolist(), sz, 
                                                data_cart[:,2].tolist(), sz, 
                                                data_cart[:,3].tolist(), 1)
    print "...done"
  else:
    print "creating interpolant for cartesian data... "
    data_cart = np.loadtxt("./U_0allf_cart.dat",skiprows=2)
    # make an empty 3 dimensional scalar interpolation model
    model_cart = xalglib.rbfcreate(3, 1)
    xalglib.rbfsetpoints(model_cart, data_cart.tolist())
    xalglib.rbfsetalgomultilayer(model_cart, 0.03, 4, 1.0e-3)
    rep = xalglib.rbfbuildmodel(model_cart)
    print " ...finished."
  
  
  
if integrateit:
  data = np.loadtxt("./U_0allf_rad.dat",skiprows=2)
  print "preview of data sampling... "
  from mayavi import mlab
  xs = data[:,0]*np.sin(data[:,1])*np.cos(data[:,2])
  ys = data[:,0]*np.sin(data[:,1])*np.sin(data[:,2])
  zs = data[:,0]*np.cos(data[:,1])
  mlab.points3d(xs, ys, np.zeros(np.shape(xs)),mode='point')
  mlab.show()
  
  
예제 #8
0
model = xalglib.rbfcreate(2, 1)
xy0 = [[-2,0,1],[-1,0,0],[0,0,1],[+1,0,-1],[+2,0,1]]
xalglib.rbfsetpoints(model, xy0)

# First, we try to use R=5.0 with single layer (NLayers=1) and moderate amount
# of regularization.... but results are disappointing: Model(x=0,y=0)=-0.02,
# and we need 1.0 at (x,y)=(0,0). Why?
#
# Because first layer gives very smooth and imprecise approximation of the
# function. Average distance between points is 1.0, and R=5.0 is too large
# to give us flexible model. It can give smoothness, but can't give precision.
# So we need more layers with smaller radii.
xalglib.rbfsetalgomultilayer(model, 5.0, 1, 1.0e-3)
rep = xalglib.rbfbuildmodelnp(model)
print(rep.terminationtype) # expected 1
v = xalglib.rbfcalc2(model, 0.0, 0.0)
print(v) # expected -0.021690

# Now we know that single layer is not enough. We still want to start with
# R=5.0 because it has good smoothness properties, but we will add more layers,
# each with R[i+1]=R[i]/2. We think that 4 layers is enough, because last layer
# will have R = 5.0/2^3 = 5/8 ~ 0.63, which is smaller than the average distance
# between points. And it works!
xalglib.rbfsetalgomultilayer(model, 5.0, 5, 1.0e-3)
rep = xalglib.rbfbuildmodel(model)
print(rep.terminationtype) # expected 1
v = xalglib.rbfcalc2(model, 0.0, 0.0)
print(v) # expected 1.000000

# BTW, if you look at v, you will see that it is equal to 0.9999999997, not to 1.
# This small error can be fixed by adding one more layer.
예제 #9
0
# -*- coding: utf-8 -*-
# kate: indent-pasted-text false; indent-width 4;

"""
Test of RBF-ML algorithm (multilayer algorithm)
"""

import xalglib as xl

model = xl.rbfcreate(2, 1)
xy0 = [[-2,0,1],[-1,0,0],[0,0,1],[+1,0,-1],[+2,0,1]]
xl.rbfsetpoints(model, xy0)

xl.rbfsetalgomultilayer(model, 5.0, 4, 1.0e-3)
rep = xl.rbfbuildmodel(model)
xAxis = [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]
v = xl.rbfgridcalc2(model, xAxis, 9, [0.0], 1)

print v
예제 #10
0
    def __init__(self, indices ,datafiles, rbase, nlayers, lambdav, C_min=0.0001, C_max=0.55, C_chi=0.65, **kwargs):


        ALGLIBCalculator.__init__(self,datafiles, rbase, nlayers, lambdav, **kwargs)

        #construct energy potentials

        self.model = []

        zz = np.loadtxt(datafiles[0])

        x = zz[:,0]
        y = zz[:,1]
        z = zz[:,2]
        s0 = zz[:,3]
        s1 = zz[:,4]
        s2 = zz[:,5]

        S0_min = s0.min()

        x_max = x.max()
        x_min = x.min()
        y_max = y.max()
        y_min = y.min()
        z_max = z.max()
        z_min = z.min()

        data_s0 = np.column_stack([x,y,z,s0-S0_min]).tolist()
        data_s1 = np.column_stack([x,y,z,s1-S0_min]).tolist()
        data_s2 = np.column_stack([x,y,z,s2-S0_min]).tolist()
        #        RBF FITTING        #
        #Dimensionality of the space and of the function (scalar)
        model_s0 = xa.rbfcreate(3,1)
        model_s1 = xa.rbfcreate(3,1)
        model_s2 = xa.rbfcreate(3,1)
        #Set data
        xa.rbfsetpoints(model_s0, data_s0)
        xa.rbfsetpoints(model_s1, data_s1)
        xa.rbfsetpoints(model_s2, data_s2)
        #QNN set method and build model - q = 1.0, z = 5.0
        #xa.rbfsetalgoqnn(model, 1.8, 5.0)

        #Multilayer algorithm
        #rbfsetalgomultilayer(model, rbase, nlayers, lambdav)
        # lambda best from 0.001 to 0.1, 0.01 is default
        xa.rbfsetalgomultilayer(model_s0, rbase, nlayers)#, lambdav)
        xa.rbfsetalgomultilayer(model_s1, rbase, nlayers)#, lambdav)
        xa.rbfsetalgomultilayer(model_s2, rbase, nlayers)#, lambdav)
        rep_s0 = xa.rbfbuildmodel(model_s0)
        rep_s1 = xa.rbfbuildmodel(model_s1)
        rep_s2 = xa.rbfbuildmodel(model_s2)

        self.model = [model_s0, model_s1, model_s2]

        self.energy = None
        self._forces = None
        self._couplings = None
        self.positions = None
        self.current_state = None

        if indices is None:
            self.indices1 = [0,1,2,3]
        else:
            self.indices1 = indices
        self.indices2 = [indices[2],indices[1],indices[0]]
        self.indices3 = [indices[1],indices[2],indices[3]]

        #DIABATIC COUPLING parameters
        self.C_min = C_min
        self.C_max = C_max
        self.C_chi = C_chi