Exemple #1
0
def run_test2():
    xmin, xmax = -2.0, 2.0
    ymin, ymax = -2.0, 2.0
    func = mt.NormalizedFunction(tf.ackley,[xmin,ymin],[xmax,ymax])
    
    npop = 3
    spread = 0.5
    ndim = 2
    itrMax = 10
    errFilterRatio = 0.0
    
    # --- func evaluation ---
    xLHS = mt.read_tabulated_data_without_header('LHS20.txt')
    xFFD = np.array([[-5.0,-5],[5,5],[-5,5],[5,-5]])
    xDOE = np.vstack([xFFD,xLHS])
    yDOE = np.array([func(xi) for xi in xDOE])
    
    nskip = len(xFFD)
    err, SE, MSE = t.cross_validation(xDOE,yDOE,nskip)
    
    for i in range(itrMax):
        print len(xDOE), MSE, np.max(SE)
        model = mt.RbfMod(xDOE,SE)
        fig = plt.figure(1)
        ax1 = fig.add_subplot(111,projection='3d')
        ax1.hold(True)
        ax1.set_xlabel('X1')
        ax1.set_ylabel('X2')
        x,y,z = t.get_points_for_2d_plot(model,xmin,xmax,ymin,ymax)
        ax1.plot_surface(x,y,z,cmap=cm.jet,rstride=1, cstride=1)
        ax1.plot(xDOE[:,0],xDOE[:,1],SE,'ro')
        
        fig2 = plt.figure(2)
        ax2 = fig2.add_subplot(111,projection='3d')
        ax2.hold(True)
        model2 = mt.RbfMod(xDOE,yDOE)
        x1,y1,z1 = t.get_points_for_2d_plot(func,xmin,xmax,ymin,ymax)
        x2,y2,z2 = t.get_points_for_2d_plot(model2,xmin,xmax,ymin,ymax)
        ax2.plot_wireframe(x1,y1,z1,color='b')
        ax2.plot_wireframe(x2,y2,z2,color='r')
        ax2.plot(xDOE[:,0],xDOE[:,1],yDOE,'go')
        plt.show()

        xDOEadd = get_new_samples(xDOE, SE, npop,spread)
        xDOE = np.vstack([xDOE, xDOEadd])
        yDOE = np.array([stybtang(xi) for xi in xDOE])
        err, SE, MSE = t.cross_validation(xDOE,yDOE,nskip)
Exemple #2
0
def run_test1():
    # styblinski-tang function
    X1 = np.arange(-5,5,0.25)
    X2 = np.arange(-5,5,0.25)
    X1, X2 = np.meshgrid(X1,X2)
    Y = stybtang([X1,X2])
    
    # DOE points
    xLHS = mt.read_tabulated_data_without_header('LHS10.txt')
    xFFD = np.array([[-5.0,-5],[5,5],[-5,5],[5,-5]])
    xDOE = np.vstack([xFFD,xLHS])
    yDOE = np.array([stybtang(xi) for xi in xDOE])
    rbf  = mt.RbfMod(xDOE,yDOE)
    
    X = np.vstack([X1.flatten(),X2.flatten()])
    yRbf = rbf(X)
    Y2 = np.reshape(yRbf,X1.shape)
    err = t.cross_validation(xDOE,yDOE,4)
    err = err*err
    err[0:4] = np.zeros(4)
    rbfErr = mt.RbfMod(xDOE,err)
    errRbf = rbfErr(X)

    
    # plot area
    fig = plt.figure(1)
    ax = fig.add_subplot(111, projection='3d')
    ax.hold = True
    ax.plot_wireframe(X1,X2,Y)
    ax.plot_wireframe(X1,X2,Y2,color='r')
    
    
    fig2 = plt.figure(2)
    ax2 = fig2.add_subplot(111)
    ax2.plot(xDOE[:,0],xDOE[:,1],'ro')
    
    fig3 = plt.figure(3)
    ax3 = fig3.add_subplot(111, projection='3d')
    ax3.plot_surface(X1,X2,np.reshape(errRbf,X1.shape),cmap=cm.jet,rstride=1, cstride=1)
    #ax3.plot_wireframe(X1,X2,(Y-Y2)**2)
    ax3.plot(xDOE[:,0],xDOE[:,1],err,'ro')
    plt.show()