def student_t_approx(optimize=True, plot=True):
real_std = <NUM_LIT:0.1><EOL>X = np.linspace(<NUM_LIT:0.0>, np.pi*<NUM_LIT:2>, <NUM_LIT:100>)[:, None]<EOL>Y = np.sin(X) + np.random.randn(*X.shape)*real_std<EOL>Y = Y/Y.max()<EOL>Yc = Y.copy()<EOL>X_full = np.linspace(<NUM_LIT:0.0>, np.pi*<NUM_LIT:2>, <NUM_LIT>)[:, None]<EOL>Y_full = np.sin(X_full)<EOL>Y_full = Y_full/Y_full.max()<EOL>Yc[<NUM_LIT>:<NUM_LIT>] += <NUM_LIT:1><EOL>deg_free = <NUM_LIT:1><EOL>print("<STR_LIT>", real_std)<EOL>initial_var_guess = <NUM_LIT:0.5><EOL>edited_real_sd = initial_var_guess<EOL>kernel1 = GPy.kern.RBF(X.shape[<NUM_LIT:1>]) + GPy.kern.White(X.shape[<NUM_LIT:1>])<EOL>kernel2 = GPy.kern.RBF(X.shape[<NUM_LIT:1>]) + GPy.kern.White(X.shape[<NUM_LIT:1>])<EOL>kernel3 = GPy.kern.RBF(X.shape[<NUM_LIT:1>]) + GPy.kern.White(X.shape[<NUM_LIT:1>])<EOL>kernel4 = GPy.kern.RBF(X.shape[<NUM_LIT:1>]) + GPy.kern.White(X.shape[<NUM_LIT:1>])<EOL>m1 = GPy.models.GPRegression(X, Y.copy(), kernel=kernel1)<EOL>m1['<STR_LIT>'].constrain_fixed(<NUM_LIT>)<EOL>m1.randomize()<EOL>m2 = GPy.models.GPRegression(X, Yc.copy(), kernel=kernel2)<EOL>m2['<STR_LIT>'].constrain_fixed(<NUM_LIT>)<EOL>m2.randomize()<EOL>t_distribution = GPy.likelihoods.StudentT(deg_free=deg_free, sigma2=edited_real_sd)<EOL>laplace_inf = GPy.inference.latent_function_inference.Laplace()<EOL>m3 = GPy.core.GP(X, Y.copy(), kernel3, likelihood=t_distribution, inference_method=laplace_inf)<EOL>m3['<STR_LIT>'].constrain_bounded(<NUM_LIT>, <NUM_LIT>)<EOL>m3['<STR_LIT>'].constrain_fixed(<NUM_LIT>)<EOL>m3.randomize()<EOL>t_distribution = GPy.likelihoods.StudentT(deg_free=deg_free, sigma2=edited_real_sd)<EOL>laplace_inf = GPy.inference.latent_function_inference.Laplace()<EOL>m4 = GPy.core.GP(X, Yc.copy(), kernel4, likelihood=t_distribution, inference_method=laplace_inf)<EOL>m4['<STR_LIT>'].constrain_bounded(<NUM_LIT>, <NUM_LIT>)<EOL>m4['<STR_LIT>'].constrain_fixed(<NUM_LIT>)<EOL>m4.randomize()<EOL>print(m4)<EOL>debug=True<EOL>if debug:<EOL><INDENT>m4.optimize(messages=<NUM_LIT:1>)<EOL>from matplotlib import pyplot as pb<EOL>pb.plot(m4.X, m4.inference_method.f_hat)<EOL>pb.plot(m4.X, m4.Y, '<STR_LIT>')<EOL>m4.plot()<EOL>print(m4)<EOL>return m4<EOL><DEDENT>if optimize:<EOL><INDENT>optimizer='<STR_LIT>'<EOL>print("<STR_LIT>")<EOL>m1.optimize(optimizer, messages=<NUM_LIT:1>)<EOL>print("<STR_LIT>")<EOL>m2.optimize(optimizer, messages=<NUM_LIT:1>)<EOL>print("<STR_LIT>")<EOL>m3.optimize(optimizer, messages=<NUM_LIT:1>)<EOL>print("<STR_LIT>")<EOL>m4.optimize(optimizer, messages=<NUM_LIT:1>)<EOL><DEDENT>if plot:<EOL><INDENT>plt.figure(<NUM_LIT:1>)<EOL>plt.suptitle('<STR_LIT>')<EOL>ax = plt.subplot(<NUM_LIT>)<EOL>m1.plot(ax=ax)<EOL>plt.plot(X_full, Y_full)<EOL>plt.ylim(-<NUM_LIT>, <NUM_LIT>)<EOL>plt.title('<STR_LIT>')<EOL>ax = plt.subplot(<NUM_LIT>)<EOL>m2.plot(ax=ax)<EOL>plt.plot(X_full, Y_full)<EOL>plt.ylim(-<NUM_LIT>, <NUM_LIT>)<EOL>plt.title('<STR_LIT>')<EOL>plt.figure(<NUM_LIT:2>)<EOL>plt.suptitle('<STR_LIT>')<EOL>ax = plt.subplot(<NUM_LIT>)<EOL>m3.plot(ax=ax)<EOL>plt.plot(X_full, Y_full)<EOL>plt.ylim(-<NUM_LIT>, <NUM_LIT>)<EOL>plt.title('<STR_LIT>')<EOL>ax = plt.subplot(<NUM_LIT>)<EOL>m4.plot(ax=ax)<EOL>plt.plot(X_full, Y_full)<EOL>plt.ylim(-<NUM_LIT>, <NUM_LIT>)<EOL>plt.title('<STR_LIT>')<EOL><DEDENT>return m1, m2, m3, m4<EOL>
Example of regressing with a student t likelihood using Laplace