Beispiel #1
0
def gp_ex_fig_22():
    """Similar to figure 2.2 in `Gaussian Processes for Machine Learning`__ by Rasmussen and Williams. 

    __ http://www.amazon.co.uk/Gaussian-Processes-Learning-Adaptive-Computation/dp/026218253X/
    """
    X = [
            [ -4.0 ],
            [ -3.0 ],
            [ -1.0 ],
            [  0.0 ],
            [  2.0 ],
    ]
    y = numpy.array( [
            -2.0,
            0.0,
            1.0,
            2.0,
            -1.0
    ] )
    LN = infpy.LogNormalDistribution
    Gamma = infpy.GammaDistribution
    k = (
            infpy.noise_kernel( .2, Gamma( 1.0, 1.0 ) )
            + infpy.ConstantKernel( )
            * infpy.SquaredExponentialKernel( [ 1.0 ], [ LN() ] )
    )
    gp = infpy.GaussianProcess( X, y, k )
    #infpy.gp_1D_predict( gp, 100, x_min = -5.0, x_max = 5.0 )
    infpy.gp_learn_hyperparameters( gp )
    infpy.gp_1D_predict( gp, 100, x_min = -5.0, x_max = 5.0 )
Beispiel #2
0
def gp_ex_output_scale():
    """Examine how kernel parameters should change for scaled outputs"""
    start, end = 0.0, 1.0
    X = infpy.gp_1D_X_range( start, end, 0.04 )

    noise_level = 0.1
    small_y = infpy.gp_zero_mean(
            numpy.asarray(
                    [ x[0]**2 + noise_level * scipy.stats.norm().rvs()[0] for x in X ]
            )
    )
    # big_y = small_y * 100.0

    LN = infpy.LogNormalDistribution
    k = (
            infpy.noise_kernel( noise_level, LN( math.log( math.sqrt( noise_level ) ) ) )
            + infpy.ConstantSquaredKernel( 1.0, LN( math.log( 1.0 ) ) )
            * infpy.SquaredExponentialKernel( [ 1.0 ], [ LN() ] )
    )
    gp = infpy.GaussianProcess( X, small_y, k )

    infpy.gp_1D_predict( gp, 100 )

    infpy.gp_learn_hyperparameters( gp )
    infpy.gp_1D_predict( gp, 100 )
Beispiel #3
0
def gp_on_nhtemp_ex():
    y = numpy.array( rpy.r.nhtemp )
    y -= numpy.mean( y )
    X = [ [ i ] for i in range( len( y ) ) ]
    # import pylab
    # pylab.plot( y )
    # pylab.show()
    # print X
    # print y
    K = (
            infpy.SquaredExponentialKernel( dimensions = 1 )
            + infpy.noise_kernel( 0.4 )
    )
    gp = infpy.GaussianProcess( X, y, K )
    infpy.gp_1D_predict( gp, num_steps = 120 )
Beispiel #4
0
def gp_ex_fixed_period_1():
    """Example of the fixed period kernel"""
    start, end = 0.0, 4.0
    X = infpy.gp_1D_X_range( start, end, 0.4 )
    y = numpy.asarray( [ math.sin( 2.0 * math.pi * x[0] ) for x in X ] )
    # pylab.plot( [ x[0] for x in X ], [ y1 for y1 in y ] )
    # pylab.show()
    # return
    LN = infpy.LogNormalDistribution
    Gamma = infpy.GammaDistribution
    k = (
            infpy.noise_kernel( 0.1, LN(  ) )
            + infpy.ConstantKernel( 1.0, Gamma(  ) )
            * infpy.FixedPeriod1DKernel( 1.0 )
    )
    gp = infpy.GaussianProcess( X, y, k )
    infpy.gp_learn_hyperparameters( gp )
    infpy.gp_1D_predict( gp )