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
6c3c45fc
Commit
6c3c45fc
authored
Apr 07, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StatRed: Implemented Lab Excercises 21 and 22.
parent
495fa7cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
23 deletions
+46
-23
statred/ass1/ex21.py
statred/ass1/ex21.py
+0
-23
statred/ass1/q21_multivariate.py
statred/ass1/q21_multivariate.py
+35
-0
statred/ass1/q22_estimate.py
statred/ass1/q22_estimate.py
+11
-0
No files found.
statred/ass1/ex21.py
deleted
100644 → 0
View file @
495fa7cb
#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/ass1/q21
-
multivariate.py
→
statred/ass1/q21
_
multivariate.py
View file @
6c3c45fc
from
pylab
import
array
,
eig
,
diagflat
,
dot
,
sqrt
,
randn
,
tile
,
\
plot
,
subplot
,
axis
,
show
,
figure
,
clf
plot
,
subplot
,
axis
,
figure
,
clf
,
savefig
m
ean
=
array
([[
3
],
m
u
=
array
([[
3
],
[
4
],
[
5
],
[
6
]])
...
...
@@ -15,20 +15,21 @@ cov = array(
samples
=
1000
vector_size
=
4
figure
(
16
)
clf
()
def
dataset
():
d
,
U
=
eig
(
cov
)
L
=
diagflat
(
d
)
A
=
dot
(
U
,
sqrt
(
L
))
X
=
randn
(
vector_size
,
samples
)
return
dot
(
A
,
X
)
+
tile
(
mu
,
samples
)
d
,
U
=
eig
(
cov
)
L
=
diagflat
(
d
)
A
=
dot
(
U
,
sqrt
(
L
))
X
=
randn
(
vector_size
,
samples
)
Y
=
dot
(
A
,
X
)
+
tile
(
mean
,
samples
)
for
i
in
range
(
1
,
5
):
for
j
in
range
(
1
,
5
):
if
i
!=
j
:
subplot
(
4
,
4
,
i
+
(
j
-
1
)
*
4
)
plot
(
Y
[
i
-
1
],
Y
[
j
-
1
],
'x'
)
axis
(
'equal'
)
show
()
if
__name__
==
'__main__'
:
figure
(
vector_size
**
2
)
clf
()
Y
=
dataset
()
for
i
in
range
(
vector_size
):
for
j
in
range
(
vector_size
):
if
i
!=
j
:
subplot
(
vector_size
,
vector_size
,
(
i
+
1
)
+
j
*
vector_size
)
plot
(
Y
[
i
],
Y
[
j
],
'x'
)
axis
(
'equal'
)
savefig
(
'figures/q21.pdf'
)
statred/ass1/q22_estimate.py
0 → 100644
View file @
6c3c45fc
from
q21_multivariate
import
dataset
,
samples
from
numpy
import
array
,
mean
,
tile
,
newaxis
,
dot
n
=
1000
Y
=
array
([
mean
(
dataset
(),
1
)
for
i
in
range
(
n
)]).
T
mu
=
mean
(
Y
,
1
)
Yzm
=
Y
-
tile
(
mu
[:,
newaxis
],
n
)
S
=
dot
(
Yzm
,
Yzm
.
T
)
/
(
n
-
1
)
print
'S:'
,
S
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