Skip to content

Instantly share code, notes, and snippets.

@seckcoder
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seckcoder/727fa1b8b8a6d7edc810 to your computer and use it in GitHub Desktop.
Save seckcoder/727fa1b8b8a6d7edc810 to your computer and use it in GitHub Desktop.
sp
import numpy as np
import numpy.linalg as linalg
import matplotlib.pyplot as plt
import math
def p4():
A = np.array([[1, 3, 2],
[-1, 2, -5],
[2, -4, 3]])
Sigma = np.array([[5, 2, 1],
[2, 8, -3],
[1, -3, 9]])
print np.dot(np.dot(A.T, Sigma), A)
#print A.T * Sigma * A
def p5():
ux = np.array([2, 1, 1, 0])
sigmax = np.array([[6, 3, 2, 1],
[3, 4, 3, 2],
[2, 3, 4, 3],
[1, 2, 3, 3]])
ux1 = ux[0:2]
ux2 = ux[2:4]
sigma11 = sigmax[0:2, 0:2]
sigma12 = sigmax[0:2, 2:4]
sigma21 = sigmax[2:4, 0:2]
sigma22 = sigmax[2:4, 2:4]
print np.dot(sigma12, linalg.inv(sigma22))
print sigma11 - np.dot(np.dot(sigma12, linalg.inv(sigma22)), sigma21)
def p9(s2):
A = np.random.normal(0, 1, (100,))
X_vec = [0]*100
s = math.sqrt(s2)
for i in xrange(0, 100):
X_vec[i] = np.random.normal(A[i], s, (1,))[0]
X = np.array(X_vec)
coeff = 1.0 / (s2+1)
A_est_vec = [0] * 100
for i in xrange(0, 100):
A_est_vec[i] = coeff * X_vec[i]
A_est = np.array(A_est_vec)
xc = np.linspace(0, 100, num=100, endpoint=False)
plt.plot(xc, A, 'r', xc, X, 'g', xc, A_est, 'b')
def demo():
plt.figure(1)
plt.subplot(211)
p9(0.01)
plt.subplot(212)
p9(2)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment