{ "cells": [ { "cell_type": "markdown", "id": "4020d39e", "metadata": {}, "source": [ "## Install" ] }, { "cell_type": "markdown", "id": "2b878ace", "metadata": {}, "source": [ "Install robustgp via pip:\n", "```\n", "pip install robustgp\n", "```" ] }, { "cell_type": "markdown", "id": "24f28e7f", "metadata": {}, "source": [ "## Import libraries" ] }, { "cell_type": "code", "execution_count": 1, "id": "01bc90b6", "metadata": {}, "outputs": [], "source": [ "from robustgp import ITGP\n", "import GPy\n", "from matplotlib import pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "507afe3f", "metadata": {}, "source": [ "## Generate mock data" ] }, { "cell_type": "code", "execution_count": 2, "id": "35f03902", "metadata": {}, "outputs": [], "source": [ "def neal_func(x):\n", " return 0.3 + 0.4 * x + 0.5 * np.sin(2.7 * x) + 1.1 / (1 + x**2)\n", "\n", "np.random.seed(5)\n", "\n", "# generate mock data\n", "n = 200\n", "noise = 0.2\n", "n_outlier = 60\n", "noise_outlier = 1\n", "\n", "x_ob = np.random.rand(n) * 6 - 3\n", "y_ob = neal_func(x_ob) + np.random.randn(n) * noise\n", "y_ob[:n_outlier] = neal_func(x_ob[:n_outlier]) + np.random.randn(n_outlier) * noise_outlier" ] }, { "cell_type": "markdown", "id": "aa4ae2ff", "metadata": {}, "source": [ "## Train ITGP" ] }, { "cell_type": "code", "execution_count": 3, "id": "e799585c", "metadata": {}, "outputs": [], "source": [ "# run ITGP\n", "res = ITGP(x_ob, y_ob,\n", " alpha1=0.5, alpha2=0.975, nsh=2, ncc=2, nrw=1,\n", " optimize_kwargs=dict(optimizer='lbfgsb')\n", " )\n", "gp, consistency = res.gp, res.consistency" ] }, { "cell_type": "code", "execution_count": 4, "id": "f696dea9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.0838720595921671\n" ] } ], "source": [ "# consistency factor\n", "print(consistency**0.5)" ] }, { "cell_type": "code", "execution_count": 5, "id": "67e12d30", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n",
"Model: ITGP regression
\n",
"Objective: 5.8201329768374706
\n",
"Number of Parameters: 3
\n",
"Number of Optimization Parameters: 3
\n",
"Updates: True
\n",
"
ITGP_regression. | value | constraints | priors |
---|---|---|---|
rbf.variance | 1.4888588994471008 | +ve | |
rbf.lengthscale | 0.8875986623320775 | +ve | |
Gaussian_noise.variance | 0.046814645071985676 | +ve |