In [1]:
import sys
# Add the symgp folder path to the sys.path list
module_path = r'/Users/jaduol/Documents/Uni (original)/Part II/IIB/MEng Project/'
if module_path not in sys.path:
sys.path.append(module_path)
from symgp import SuperMatSymbol, utils, MVG, Variable
from sympy import symbols, ZeroMatrix, Identity
from IPython.display import display, Math, Latex
In [2]:
# Define some symbols
D, N, Ns = symbols('D N Ns')
sig_y = symbols('\u03c3_y')
In [3]:
# Prior
w = Variable('w',D,1)
p_w = MVG([w],mean=ZeroMatrix(D,1),cov=Identity(D))
print("p_w:")
display(Latex(utils.matLatex(p_w)))
In [4]:
# Likelihood of w given X
X, y = utils.variables('X y',[(D,N), N])
p_y = MVG([y], mean=X.T*w,
cov=sig_y**2*Identity(N),
cond_vars=[w,X])
print("p_y:")
display(Latex(utils.matLatex(p_y)))
In [5]:
# Joint of w and y
p_w_y = p_w*p_y
print("p_w_y:")
display(Latex(utils.matLatex(p_w_y)))
In [6]:
# Inference: posterior over w
p_w_post = p_w_y.condition([y])
print("p_w_post:")
display(Latex(utils.matLatex(p_w_post)))
In [7]:
#Prediction
# Likelihood of w given Xs
Xs, ys = utils.variables('X_{*} y_{*}',[(D,Ns), Ns])
p_ys = MVG([ys], mean=Xs.T*w,
cov=sig_y**2*Identity(Ns),
cond_vars=[w,Xs])
print("p_ys:")
display(Latex(utils.matLatex(p_ys)))
In [8]:
# Joint of w and ys
p_w_ys = p_w_post*p_ys
print("p_w_ys:")
display(Latex(utils.matLatex(p_w_ys)))
In [9]:
# Predictive distribution of ys
p_ys_post = p_w_ys.marginalise([w])
print("p_ys_post:")
display(Latex(utils.matLatex(p_ys_post)))
In [ ]: