Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
6c3c45fc
Commit
6c3c45fc
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
StatRed: Implemented Lab Excercises 21 and 22.
parent
495fa7cb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
statred/ass1/ex21.py
+0
-23
0 additions, 23 deletions
statred/ass1/ex21.py
statred/ass1/q21_multivariate.py
+35
-0
35 additions, 0 deletions
statred/ass1/q21_multivariate.py
statred/ass1/q22_estimate.py
+11
-0
11 additions, 0 deletions
statred/ass1/q22_estimate.py
with
46 additions
and
23 deletions
statred/ass1/ex21.py
deleted
100644 → 0
+
0
−
23
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
)
This diff is collapsed.
Click to expand it.
statred/ass1/q21
-
multivariate.py
→
statred/ass1/q21
_
multivariate.py
+
35
−
0
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
'
)
This diff is collapsed.
Click to expand it.
statred/ass1/q22_estimate.py
0 → 100644
+
11
−
0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment