Ejemplo n.º 1
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 10 10:58:09 2018

@author: SCUTCYF

demos for ch03
"""
import sys
sys.path.append("../../chapter01")
from linRnd import linRnd
from linRegEm import linRegEm
from linRegPred import linRegPred
from plotCurveBar import plotCurveBar
import matplotlib.pyplot as plt

d = 1
n = 200
x, t = linRnd(d, n)

# Empirical Bayesian linear regression via EM
model, llh = linRegEm(x, t)
plt.plot(llh)
y, sigma = linRegPred(model, x, t)
plt.Figure
plotCurveBar(x, y, sigma)

mycolor = [255 / 255, 228 / 255, 225 / 255]  # pink
plt.hold(True)
plt.plot(x, t, 'o', markerfacecolor='none', markeredgecolor=mycolor)
plt.hold(False)
Ejemplo n.º 2
0
@author: SCUTCYF

regression

"""
import numpy as np
from rvmRegFp import rvmRegFp
from linRegPred import linRegPred
import sys
sys.path.append("..\..\common")
from plotCurveBar import plotCurveBar
import matplotlib.pyplot as plt

d = 100
beta = 1e-1
X = np.random.rand(1, d)
w = np.random.randn()
b = np.random.randn()
t = w * X + beta * np.random.randn(1, d)
x = np.linspace(np.min(X), np.max(X), num=d)  # test data

# RVM regression by Mackay fix point update
model, llh = rvmRegFp(X, t)
plt.plot(llh)
y, sigma = linRegPred(model, x, t)
plt.figure()
plotCurveBar(x.reshape(y.shape), y, sigma.reshape(y.shape))
mycolor = [255 / 255, 228 / 255, 225 / 255]  # pink
plt.hold(True)
plt.plot(X, t, 'o')
plt.hold(False)