FITC


In [1]:
from sympy import *
import utils as utils
from SuperMatExpr import Variable, SuperDiagMat
from MVG import MVG
import kernels.kernel as kern
from IPython.display import display, Math, Latex

In [2]:
m, n, l = symbols('m n l')
s_y = symbols('\u03c3_y')
K = kern.Kernel()

1. Induding prior


In [3]:
u = Variable('u',m,1)
p_u = MVG([u],mean=ZeroMatrix(m,1),cov=K(u,u))

print("p_u:")
display(Latex(utils.matLatex(p_u)))


p_u:
\begin{align*} p\left(\mathbf{u}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{u}},\mathbf{\Sigma}_{\mathbf{u}}\right)\\ \mathbf{m}_{\mathbf{u}} &= \mathbf{0}\\ \mathbf{\Sigma}_{\mathbf{u}} &= \mathbf{K}_{\mathbf{u},\mathbf{u}}\\ \end{align*}

2. Training and Test Conditionals


In [4]:
f, fs, y = utils.variables("f fs y",[n, l, n])

q_fgu = MVG([f], mean=K(f,u)*K(u,u).I*u,
                 cov=SuperDiagMat(K(f,f)-K(f,u)*K(u,u).I*K(u,f)),
                 cond_vars=[u],
                 prefix='q_{FITC}')

print("q_fgu:")
display(Latex(utils.matLatex(q_fgu)))


q_fgu:
\begin{align*} q_{FITC}\left(\mathbf{f}|\mathbf{u}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{f}|\mathbf{u}},\mathbf{\Sigma}_{\mathbf{f}|\mathbf{u}}\right)\\ \mathbf{m}_{\mathbf{f}|\mathbf{u}} &= \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{u}\\ \mathbf{\Sigma}_{\mathbf{f}|\mathbf{u}} &= \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}]\\ \end{align*}

In [5]:
q_fsgu = MVG([fs], mean=K(fs,u)*K(u,u).I*u,
                   cov=K(fs,fs)-K(fs,u)*K(u,u).I*K(u,fs),
                   cond_vars=[u],
                   prefix='q_{FITC}')

print("q_fgu:")
display(Latex(utils.matLatex(q_fsgu)))


q_fgu:
\begin{align*} q_{FITC}\left(\mathbf{fs}|\mathbf{u}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{fs}|\mathbf{u}},\mathbf{\Sigma}_{\mathbf{fs}|\mathbf{u}}\right)\\ \mathbf{m}_{\mathbf{fs}|\mathbf{u}} &= \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{u}\\ \mathbf{\Sigma}_{\mathbf{fs}|\mathbf{u}} &= \mathbf{K}_{\mathbf{fs},\mathbf{fs}} - \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}\\ \end{align*}

In [6]:
# q(f,fs|u)
q_f_fs_g_u = q_fgu*q_fsgu

print("q_f_fs_g_u:")
display(Latex(utils.matLatex(q_f_fs_g_u)))


q_f_fs_g_u:
\begin{align*} q_{FITC}\left(\mathbf{f},\mathbf{fs}|\mathbf{u}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{f},\mathbf{fs}|\mathbf{u}},\mathbf{\Sigma}_{\mathbf{f},\mathbf{fs}|\mathbf{u}}\right)\\ \mathbf{m}_{\mathbf{f},\mathbf{fs}|\mathbf{u}} &= \left[\begin{smallmatrix}\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{u}\\\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{u}\end{smallmatrix}\right]\\ \mathbf{\Sigma}_{\mathbf{f},\mathbf{fs}|\mathbf{u}} &= \left[\begin{smallmatrix}\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}]&\mathbf{0}\\\mathbf{0}&\mathbf{K}_{\mathbf{fs},\mathbf{fs}} - \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}\end{smallmatrix}\right]\\ \end{align*}

In [7]:
# q(f,fs,u)
q_f_fs_u = q_f_fs_g_u*p_u

print("q_f_fs_u:")
display(Latex(utils.matLatex(q_f_fs_u)))


q_f_fs_u:
\begin{align*} q_{FITC}\left(\mathbf{f},\mathbf{fs},\mathbf{u}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{f},\mathbf{fs},\mathbf{u}},\mathbf{\Sigma}_{\mathbf{f},\mathbf{fs},\mathbf{u}}\right)\\ \mathbf{m}_{\mathbf{f},\mathbf{fs},\mathbf{u}} &= \left[\begin{smallmatrix}\mathbf{0}\\\mathbf{0}\\\mathbf{0}\end{smallmatrix}\right]\\ \mathbf{\Sigma}_{\mathbf{f},\mathbf{fs},\mathbf{u}} &= \left[\begin{smallmatrix}\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}&\mathbf{K}_{\mathbf{f},\mathbf{u}}\\\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{fs},\mathbf{fs}}&\mathbf{K}_{\mathbf{fs},\mathbf{u}}\\\mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{u},\mathbf{fs}}&\mathbf{K}_{\mathbf{u},\mathbf{u}}\end{smallmatrix}\right]\\ \end{align*}

In [8]:
# Effective prior: q(f,fs)
q_f_fs = q_f_fs_u.marginalize([u])

print("q_f_fs:")
display(Latex(utils.matLatex(q_f_fs)))


q_f_fs:
\begin{align*} q_{FITC}\left(\mathbf{f},\mathbf{fs}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{f},\mathbf{fs}},\mathbf{\Sigma}_{\mathbf{f},\mathbf{fs}}\right)\\ \mathbf{m}_{\mathbf{f},\mathbf{fs}} &= \left[\begin{smallmatrix}\mathbf{0}\\\mathbf{0}\end{smallmatrix}\right]\\ \mathbf{\Sigma}_{\mathbf{f},\mathbf{fs}} &= \left[\begin{smallmatrix}\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}\\\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{fs},\mathbf{fs}}\end{smallmatrix}\right]\\ \end{align*}

3. Likelihood


In [9]:
p_ygf = MVG([y],mean=f,cov=s_y**2*Identity(n),cond_vars=[f])

print("p_ygf:")
display(Latex(utils.matLatex(p_ygf)))


p_ygf:
\begin{align*} p\left(\mathbf{y}|\mathbf{f}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{y}|\mathbf{f}},\mathbf{\Sigma}_{\mathbf{y}|\mathbf{f}}\right)\\ \mathbf{m}_{\mathbf{y}|\mathbf{f}} &= \mathbf{f}\\ \mathbf{\Sigma}_{\mathbf{y}|\mathbf{f}} &= \sigma_y^{2} \mathbf{I}\\ \end{align*}

4. Inference


In [10]:
# q(f,fs,y)
q_f_fs_y = p_ygf*q_f_fs

print("q_f_fs_y:")
display(Latex(utils.matLatex(q_f_fs_y)))


q_f_fs_y:
\begin{align*} q_{FITC}\left(\mathbf{y},\mathbf{fs},\mathbf{f}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{y},\mathbf{fs},\mathbf{f}},\mathbf{\Sigma}_{\mathbf{y},\mathbf{fs},\mathbf{f}}\right)\\ \mathbf{m}_{\mathbf{y},\mathbf{fs},\mathbf{f}} &= \left[\begin{smallmatrix}\mathbf{0}\\\mathbf{0}\\\mathbf{0}\end{smallmatrix}\right]\\ \mathbf{\Sigma}_{\mathbf{y},\mathbf{fs},\mathbf{f}} &= \left[\begin{smallmatrix}\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}&\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\\\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{fs},\mathbf{fs}}&\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\\\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}&\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}&\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\end{smallmatrix}\right]\\ \end{align*}

In [11]:
# q(f,fs|y)
q_f_fs_g_y = q_f_fs_y.condition([y])

print("q_f_fs_g_y:")
display(Latex(utils.matLatex(q_f_fs_g_y)))


q_f_fs_g_y:
\begin{align*} q_{FITC}\left(\mathbf{fs},\mathbf{f}|\mathbf{y}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{fs},\mathbf{f}|\mathbf{y}},\mathbf{\Sigma}_{\mathbf{fs},\mathbf{f}|\mathbf{y}}\right)\\ \mathbf{m}_{\mathbf{fs},\mathbf{f}|\mathbf{y}} &= \left[\begin{smallmatrix}\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{y}\\\left(\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right) \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{y}\end{smallmatrix}\right]\\ \mathbf{\Sigma}_{\mathbf{fs},\mathbf{f}|\mathbf{y}} &= \left[\begin{smallmatrix}\mathbf{K}_{\mathbf{fs},\mathbf{fs}} - \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}&\mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} - \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \left(\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)\\\mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}} - \left(\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right) \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}&\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} - \left(\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right) \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \left(\text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)\end{smallmatrix}\right]\\ \end{align*}

In [12]:
# q(fs|y)
q_fs_g_y = q_f_fs_g_y.marginalize([f])

print("q_fs_g_y:")
display(Latex(utils.matLatex(q_fs_g_y)))


q_fs_g_y:
\begin{align*} q_{FITC}\left(\mathbf{fs}|\mathbf{y}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{fs}|\mathbf{y}},\mathbf{\Sigma}_{\mathbf{fs}|\mathbf{y}}\right)\\ \mathbf{m}_{\mathbf{fs}|\mathbf{y}} &= \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{y}\\ \mathbf{\Sigma}_{\mathbf{fs}|\mathbf{y}} &= \mathbf{K}_{\mathbf{fs},\mathbf{fs}} - \mathbf{K}_{\mathbf{fs},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}} \left(\sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}] + \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{f}}\right)^{-1} \mathbf{K}_{\mathbf{f},\mathbf{u}} \mathbf{K}_{\mathbf{u},\mathbf{u}}^{-1} \mathbf{K}_{\mathbf{u},\mathbf{fs}}\\ \end{align*}

In [15]:
Q = kern.Kernel(name='Q')
repl_dict = {K(fs,u)*K(u,u).I*K(u,f): Q(fs,f),
             K(f,u)*K(u,u).I*K(u,f): Q(f,f),
             K(f,u)*K(u,u).I*K(u,fs): Q(f,fs)}

q_fs_g_y.mean.expanded = utils.replace(q_fs_g_y.mean, repl_dict)
q_fs_g_y.covar.expanded = utils.replace(q_fs_g_y.covar, repl_dict)

print("q_fs_g_y (replaced):")
display(Latex(utils.matLatex(q_fs_g_y)))


Q(fs,f)*(Q(f,f) + σ_y**2*I + SuperDiagMat(K(f,f) + (-1)*Q(f,f)))^-1*y
K(fs,fs) + (-1)*Q(fs,f)*(Q(f,f) + σ_y**2*I + SuperDiagMat(K(f,f) + (-1)*Q(f,f)))^-1*Q(f,fs)
q_fs_g_y (replaced):
\begin{align*} q_{FITC}\left(\mathbf{fs}|\mathbf{y}\right)&= \mathcal{N}\left(\mathbf{m}_{\mathbf{fs}|\mathbf{y}},\mathbf{\Sigma}_{\mathbf{fs}|\mathbf{y}}\right)\\ \mathbf{m}_{\mathbf{fs}|\mathbf{y}} &= \mathbf{Q}_{\mathbf{fs},\mathbf{f}} \left(\mathbf{Q}_{\mathbf{f},\mathbf{f}} + \sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{Q}_{\mathbf{f},\mathbf{f}}]\right)^{-1} \mathbf{y}\\ \mathbf{\Sigma}_{\mathbf{fs}|\mathbf{y}} &= \mathbf{K}_{\mathbf{fs},\mathbf{fs}} - \mathbf{Q}_{\mathbf{fs},\mathbf{f}} \left(\mathbf{Q}_{\mathbf{f},\mathbf{f}} + \sigma_y^{2} \mathbf{I} + \text{diag}[\mathbf{K}_{\mathbf{f},\mathbf{f}} - \mathbf{Q}_{\mathbf{f},\mathbf{f}}]\right)^{-1} \mathbf{Q}_{\mathbf{f},\mathbf{fs}}\\ \end{align*}

In [ ]: