Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
337aed09
Commit
337aed09
authored
Apr 05, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/home/git/repos/uva
parents
3f0c473f
f3c4b14d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
0 deletions
+59
-0
statred/ass1/ex21.py
statred/ass1/ex21.py
+22
-0
statred/multivariate.py
statred/multivariate.py
+10
-0
statred/mvnd.py
statred/mvnd.py
+23
-0
statred/urls.txt
statred/urls.txt
+4
-0
No files found.
statred/ass1/ex21.py
View file @
337aed09
#from math import mean
#import matplotlib.pyplot as plt
from
numpy.random
import
multivariate_normal
def
mu_est
(
x
):
return
sum
(
x
)
/
float
(
len
(
x
))
def
cov_est
(
x
):
avg
=
mean
(
x
)
n
=
len
(
x
)
# TODO: transpose the second "(i - avg)"
return
sum
([(
i
-
avg
)
*
(
i
-
avg
)
for
i
in
x
])
/
float
(
n
-
1
)
mean
=
[
0
,
0
]
cov
=
[[
1
,
0
],[
0
,
100
]]
# diagonal covariance, points lie on x or y-axis
N
=
512
# Samples to use.
x
,
y
=
multivariate_normal
(
mean
,
cov
,
N
).
T
print
'x:'
,
x
print
'y:'
,
y
print
'mu_est(x):'
,
mu_est
(
x
)
print
'mu_est(y):'
,
mu_est
(
y
)
statred/multivariate.py
0 → 100644
View file @
337aed09
mean
=
[
0
,
0
]
cov
=
[[
1
,
0
],[
0
,
100
]]
# diagonal covariance, points lie on x or y-axis
import
matplotlib.pyplot
as
plt
import
numpy
as
np
x
,
y
=
np
.
random
.
multivariate_normal
(
mean
,
cov
,
5000
).
T
print
'x:'
,
x
print
'y:'
,
y
plt
.
plot
(
x
,
y
,
'x'
);
plt
.
axis
(
'equal'
);
plt
.
show
()
statred/mvnd.py
0 → 100644
View file @
337aed09
from
numpy
import
pi
,
exp
,
power
,
dot
,
rank
from
numpy.linalg
import
inv
,
det
def
mvnd
(
x
,
mu
,
S
):
"""
Calculate multivariate normal distribution of vector X, given mu (mean of
elements in vector X) and S (covariance matrix).
Based on the following formula:
http://upload.wikimedia.org/math/a/0/a/a0ad9db46854c4a616ce6959095cf21d.png
"""
return
exp
((
2
*
pi
)
**
rank
(
x
))
*
power
(
det
(
S
),
-
.
5
)
\
*
exp
(
-
.
5
*
dot
(
dot
((
x
-
mu
).
T
,
inv
(
S
)),
(
x
-
mu
)))
#mean = [0,0]
#cov = [[1,0],[0,100]] # diagonal covariance, points lie on x or y-axis
#
#import matplotlib.pyplot as plt
#import numpy as np
#x,y = np.random.multivariate_normal(mean,cov,5000).T
##mvnd(x, mean, cov)
#plt.plot(x,y,'x'); plt.axis('equal'); plt.show()
statred/urls.txt
0 → 100644
View file @
337aed09
http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.multivariate_normal.html
http://packages.python.org/algopy/examples/covariance_matrix_computation.html
http://en.wikipedia.org/wiki/Multivariate_normal_distribution
http://lmf-ramblings.blogspot.com/2009/07/multivariate-normal-distribution-in.html
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment