def run_test1():
    f = Forrester()
    x = np.linspace(0,1,100)
    
    yh = f.high_fidelity(x)
    yl = f.low_fidelity(x)
    
    # case 1
    xs1 = np.array([0.1, 0.3, 0.5, 0.7, 0.9])
    yh1 = f.high_fidelity(xs1)
    yl1 = f.low_fidelity(xs1)
    gs1 = yh1 - yl1
    fg1 = RbfMod(xs1,gs1)
    yv1 = yl + np.array([fg1(xi) for xi in x])
    
    # case 2
    xs2 = np.array([0.15, 0.2, 0.25, 0.75, 0.8,0.85])
    yh2 = f.high_fidelity(xs2)
    yl2 = f.low_fidelity(xs2)
    gs2 = yh2 - yl2
    fg2 = RbfMod(xs2,gs2)
    yv2 = yl + np.array([fg2(xi) for xi in x])
    
    frbf = RbfMod(xs2, yh2)
    yrbf2 = np.array([frbf(xi) for xi in x])
    
    # case 3
    xs3 = np.array([0.15, 0.2, 0.25])
    yh3 = f.high_fidelity(xs3)
    yl3 = f.low_fidelity(xs3)
    gs3 = yh3 - yl3
    p = sigmoid_fit(xs3,gs3)
    yv3 = yl + sigmoid(x,p)
    
    frbf3 = RbfMod(xs3, yh3)
    yrbf3 = np.array([frbf3(xi) for xi in x])
    
    # case 4
    xs4 = np.linspace(0,1,8)
    yh4 = f.high_fidelity(xs4)
    f4 = RbfMod(xs4,yh4)
    yv4 = np.array([f4(xi) for xi in x])
    
    # case 5
    bp1 = 0.5
    gap = 0.05
    x5l = np.linspace(0.0,bp1)
    x5r = np.linspace(bp1,1.0)
    y5l = f.low_fidelity(x5l)
    y5r = f.high_fidelity(x5r)
    xs5l = np.linspace(0.0,bp1-gap,8)
    xs5r = np.linspace(bp1+gap,1.0,8)
    ys5l = f.low_fidelity(xs5l)
    ys5r = f.high_fidelity(xs5r)
    d = y5l[-1] - y5r[0]
    xs5 = np.hstack([xs5l, xs5r])
    ys5 = np.hstack([ys5l, ys5r])
    f5 = RbfMod(xs5,ys5)
    yv5 = np.array([f5(xi) for xi in x])
    
    
    
    plt.figure(1)
    plt.hold(True)
    plt.plot(x,yh,'k--',lw=2)
    plt.plot(x,yl,'k:',lw=2)
    plt.plot(x, yv1, 'r-',lw=2)
    plt.plot(xs1, yh1, 'bo', markersize=9)
    plt.legend(['High fidelity function','Low fidelity function','Data fusion','High fidelity samples'],loc='upper left')
    
    plt.figure(2)
    plt.hold(True)
    plt.plot(x,yh,'k--',lw=2)
    plt.plot(x,yl,'k:',lw=2)
    plt.plot(x, yv2, 'r-',lw=2)
    plt.plot(xs2, yh2, 'bo', markersize=9)
    plt.plot(x,yrbf2,'g.-',markevery=2)
    plt.legend(['High fidelity function','Low fidelity function','Data fusion (VF interpolation)','High fidelity samples','Conventional Interpolation (RBF)'],loc='upper left')
    
    
    plt.figure(3)
    plt.hold(True)
    plt.plot(x,yh,'k--',lw=2)
    plt.plot(x,yl,'k:',lw=2)
    plt.plot(x, yv3, 'r-',lw=2)
    plt.plot(xs3, yh3, 'bo', markersize=9)
    plt.plot(x,yrbf3,'g.-',markevery=2)
    plt.legend(['High fidelity function','Low fidelity function','Data fusion (VF extrapolation)','High fidelity samples','Conventional Extrapolation (RBF)'],loc='upper left')
    
    plt.figure(4)
    plt.hold(True)
    plt.plot(x,yh,'k--',lw=2)
    #plt.plot(x,yl,'k:',lw=2)
    plt.plot(x, yv4, 'r-',lw=2)
    plt.plot(xs4, yh4, 'bo', markersize=9)
    plt.legend(['High fidelity function','Data fusion','High fidelity samples'],loc='upper left')
    
    plt.figure(5)
    plt.hold(True)
    plt.plot(x5l,y5l,'k--',lw=2)
    plt.plot(x5r,y5r,'k:',lw=2)
    plt.plot(x, yv5, 'r-',lw=2)
    
    
    
    
    plt.legend(['Low fidelity function','High fidelity function','Data fusion','High fidelity samples',],loc='upper left')
    plt.axis([0,1,-10,20])
    plt.show()
def run_test1():
    f = Forrester()
    xs = np.array([0.1, 0.3, 0.5, 0.7, 0.9])
    x0 = 0.75
    dx = 0.01
    x = np.linspace(0,1,100)
    
    yh = f.high_fidelity(x)
    yl = f.low_fidelity(x)
    
    yhs = f.high_fidelity(xs)
    yls = f.low_fidelity(xs)
    # constant
    
    def objective(k):
        yscaled = yls + k[1]
        err = (yhs - yscaled)**2.0
        return np.sum(err)
    
    kopt = minimize(objective, [1.0,1.0]).x
    yConst = kopt[0]*yl + kopt[1]
    print kopt
        
    # local
    gamma0 = f.high_fidelity(x0) - f.low_fidelity(x0)
    gamma1 = f.high_fidelity(x0+dx) - f.low_fidelity(x0+dx)
    dGamma = (gamma1 - gamma0)/dx
    
    yLocal = yl + gamma0 + dGamma*(x-x0)
    
    # global
    
    gamma = yhs - yls
    model = RbfMod(xs,gamma)
    yScaled = np.array([model(_x) for _x in x])
    yGlobal = yl + yScaled
    
    # rbf
    model2 = RbfMod(xs,yhs)
    yRbf = np.array([model2(_x) for _x in x])
    
    plt.figure(1)
    plt.hold(True)
    plt.plot(x,yh,'gs-',markersize=3,markevery=2)
    plt.plot(x,yl,'bo-',markersize=3,markevery=2)
    plt.plot(xs,yhs,'rs',markersize=8)
    plt.plot(x,yConst,'r-',linewidth=1.5)
    plt.legend(['high-fidelity','low-fidelity','sample points','constant scaled function'],'upper left')
    
    
    
    plt.figure(2)
    plt.hold(True)
    plt.plot(x,yh,'gs-',markersize=3,markevery=2)
    plt.plot(x,yl,'bo-',markersize=3,markevery=2)
    plt.plot(x0,f.high_fidelity(x0),'rs',markersize=8)
    plt.plot(x,yLocal,'r-',linewidth=1.5)
    plt.legend(['high-fidelity','low-fidelity','sample points','local scaled function'],'upper left')
    
    plt.figure(3)
    plt.hold(True)
    plt.plot(x,yh,'gs-',markersize=3,markevery=2)
    plt.plot(x,yl,'bo-',markersize=3,markevery=2)
    plt.plot(xs,yhs,'rs',markersize=8)
    plt.plot(x,yGlobal,'r-',linewidth=1.5)
    plt.plot(x,yRbf,'k--',linewidth=1.5)
    plt.legend(['high-fidelity','low-fidelity','sample points','global scaled function','RBF interpolation'],'upper left')
    
    plt.figure(4)
    plt.hold(True)
    plt.plot(x,yh,'gs',markersize=3,markevery=2)
    plt.plot(xs,yhs,'rs',markersize=8)
    plt.plot(x,yRbf,'r-',linewidth=1.5)
    
    plt.show()