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
14a62e57
Commit
14a62e57
authored
Apr 17, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Solved merge conflicts.
parents
c1a1a0c1
60348742
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
63 additions
and
25 deletions
+63
-25
modsim/ass3/.gitignore
modsim/ass3/.gitignore
+1
-0
modsim/ass3/Makefile
modsim/ass3/Makefile
+1
-1
modsim/ass3/compare_osc.sh
modsim/ass3/compare_osc.sh
+4
-4
modsim/ass3/main.c
modsim/ass3/main.c
+12
-0
modsim/ass3/report/osc_euler.pdf
modsim/ass3/report/osc_euler.pdf
+0
-0
modsim/ass3/report/osc_rk2.pdf
modsim/ass3/report/osc_rk2.pdf
+0
-0
modsim/ass3/report/osc_rk4.pdf
modsim/ass3/report/osc_rk4.pdf
+0
-0
statred/ass1/Makefile
statred/ass1/Makefile
+6
-0
statred/ass1/q21_multivariate.py
statred/ass1/q21_multivariate.py
+10
-3
statred/ass1/q22_estimate.py
statred/ass1/q22_estimate.py
+15
-5
statred/ass1/q23_iris.py
statred/ass1/q23_iris.py
+14
-12
No files found.
modsim/ass3/.gitignore
View file @
14a62e57
...
@@ -2,3 +2,4 @@ test
...
@@ -2,3 +2,4 @@ test
main
main
*.sgv
*.sgv
*.png
*.png
*.data
modsim/ass3/Makefile
View file @
14a62e57
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-D_GNU_SOURCE
-g
-O0
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-D_GNU_SOURCE
-g
-
ggdb
-
O0
LDFLAGS
=
-lm
LDFLAGS
=
-lm
PROGS
=
test
main
PROGS
=
test
main
...
...
modsim/ass3/compare_osc.sh
View file @
14a62e57
./main 0
./main 0
cat
report/osc_euler
| ./plot.py report/osc_euler.pdf
cat
osc_euler.data
| ./plot.py report/osc_euler.pdf
cat
report/osc_rk2
| ./plot.py report/osc_rk2.pdf
cat
osc_rk2.data
| ./plot.py report/osc_rk2.pdf
cat
report/osc_rk4
| ./plot.py report/osc_rk4.pdf
cat
osc_rk4.data
| ./plot.py report/osc_rk4.pdf
#rm report/osc_euler report/osc_rk2 report/osc_rk4
rm
*
.data
modsim/ass3/main.c
View file @
14a62e57
...
@@ -35,6 +35,7 @@ int main(int argc, char **argv) {
...
@@ -35,6 +35,7 @@ int main(int argc, char **argv) {
case
0
:
case
0
:
y0
[
0
]
=
10
.
0
;
y0
[
0
]
=
10
.
0
;
y0
[
1
]
=
20
.
0
;
y0
[
1
]
=
20
.
0
;
<<<<<<<
HEAD
logger_open
(
"report/osc_euler"
);
logger_open
(
"report/osc_euler"
);
puts
(
"Integrating Euler method..."
);
puts
(
"Integrating Euler method..."
);
INTEGRATE
(
Euler
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
INTEGRATE
(
Euler
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
...
@@ -44,6 +45,17 @@ int main(int argc, char **argv) {
...
@@ -44,6 +45,17 @@ int main(int argc, char **argv) {
INTEGRATE
(
RungeKutta2
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
INTEGRATE
(
RungeKutta2
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
logger_close
();
logger_close
();
logger_open
(
"report/osc_rk4"
);
logger_open
(
"report/osc_rk4"
);
=======
logfile
=
fopen
(
"osc_euler.data"
,
"w"
);
puts
(
"Integrating Euler method..."
);
INTEGRATE
(
Euler
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
logger_close
();
logfile
=
fopen
(
"osc_rk2.data"
,
"w"
);
puts
(
"Integrating Runge-Kutta 2 method..."
);
INTEGRATE
(
RungeKutta2
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
logger_close
();
logfile
=
fopen
(
"osc_rk4.data"
,
"w"
);
>>>>>>>
6034874266
b42027b60f69f6ee27e8add52cd8be
puts
(
"Integrating Runge-Kutta 4 method..."
);
puts
(
"Integrating Runge-Kutta 4 method..."
);
INTEGRATE
(
RungeKutta4
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
INTEGRATE
(
RungeKutta4
,
.
0
,
100
.
0
,
COMPARE_DT
,
2
,
osc
);
break
;
break
;
...
...
modsim/ass3/report/osc_euler.pdf
View file @
14a62e57
No preview for this file type
modsim/ass3/report/osc_rk2.pdf
View file @
14a62e57
No preview for this file type
modsim/ass3/report/osc_rk4.pdf
View file @
14a62e57
No preview for this file type
statred/ass1/Makefile
0 → 100644
View file @
14a62e57
.PHONY
:
all clean
all
:
clean
:
rm
-vf
*
.pyc q
*
.pdf
statred/ass1/q21_multivariate.py
View file @
14a62e57
from
pylab
import
array
,
eig
,
diagflat
,
dot
,
sqrt
,
randn
,
tile
,
\
from
pylab
import
array
,
eig
,
diagflat
,
dot
,
sqrt
,
randn
,
tile
,
\
plot
,
subplot
,
axis
,
figure
,
clf
,
savefig
plot
,
subplot
,
axis
,
figure
,
clf
,
savefig
# The used mu (mean vector) and cov (covariance matrix).
mu
=
array
([[
3
],
mu
=
array
([[
3
],
[
4
],
[
4
],
[
5
],
[
5
],
...
@@ -12,10 +13,14 @@ cov = array(
...
@@ -12,10 +13,14 @@ cov = array(
[
-
3.60224613
,
-
3.98616664
,
13.04508284
,
-
1.59255406
],
[
-
3.60224613
,
-
3.98616664
,
13.04508284
,
-
1.59255406
],
[
-
2.08792829
,
0.48723704
,
-
1.59255406
,
8.28742469
]])
[
-
2.08792829
,
0.48723704
,
-
1.59255406
,
8.28742469
]])
# Samples is the constant `N' which is the total amount of numbers to generate
# according to the normal distribution.
samples
=
1000
samples
=
1000
vector_size
=
4
vector_size
=
4
def
dataset
():
def
dataset
():
# The covariance matrix is used to transform the generated dataset into a
# multivariant normal distribution dataset.
d
,
U
=
eig
(
cov
)
d
,
U
=
eig
(
cov
)
L
=
diagflat
(
d
)
L
=
diagflat
(
d
)
A
=
dot
(
U
,
sqrt
(
L
))
A
=
dot
(
U
,
sqrt
(
L
))
...
@@ -23,11 +28,13 @@ def dataset():
...
@@ -23,11 +28,13 @@ def dataset():
return
dot
(
A
,
X
)
+
tile
(
mu
,
samples
)
return
dot
(
A
,
X
)
+
tile
(
mu
,
samples
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
# Create a n*n grid of subplots and generate a new dataset.
figure
(
vector_size
**
2
)
figure
(
vector_size
**
2
)
clf
()
clf
()
Y
=
dataset
()
Y
=
dataset
()
for
i
in
range
(
vector_size
):
for
i
in
range
(
vector_size
):
for
j
in
range
(
vector_size
):
for
j
in
range
(
vector_size
):
# Skip the diagonal subplots since those are irrelevant.
if
i
!=
j
:
if
i
!=
j
:
subplot
(
vector_size
,
vector_size
,
(
i
+
1
)
+
j
*
vector_size
)
subplot
(
vector_size
,
vector_size
,
(
i
+
1
)
+
j
*
vector_size
)
plot
(
Y
[
i
],
Y
[
j
],
'x'
)
plot
(
Y
[
i
],
Y
[
j
],
'x'
)
...
...
statred/ass1/q22_estimate.py
View file @
14a62e57
from
q21_multivariate
import
dataset
from
q21_multivariate
import
dataset
from
numpy
import
array
,
mean
,
tile
,
newaxis
,
dot
from
pylab
import
array
,
mean
,
tile
,
newaxis
,
dot
,
eigvals
,
\
from
pylab
import
eigvals
,
diagflat
,
axis
,
figure
,
clf
,
show
,
plot
,
sub
plot
axis
,
figure
,
clf
,
show
,
plot
def
eigenvalues
(
n
):
def
eigenvalues
(
n
):
"""Return eigenvalues of unbiased estimators for the covariance matrix
Sigma (based on a pseudo-random generated dataset)."""
Y
=
array
([
mean
(
dataset
(),
1
)
for
i
in
range
(
n
)]).
T
Y
=
array
([
mean
(
dataset
(),
1
)
for
i
in
range
(
n
)]).
T
# Sigma = 1 / (n - 1) * Sum for i=1 to n: (x_i - x_mean) T(x_i - x_mean),
# where T(x) is the transpose of `x'. Mu = x_mean and
# Yzm = Sum for i=1 to n: x_i - x_mean.
mu
=
mean
(
Y
,
1
)
mu
=
mean
(
Y
,
1
)
Yzm
=
Y
-
tile
(
mu
[:,
newaxis
],
n
)
Yzm
=
Y
-
tile
(
mu
[:,
newaxis
],
n
)
S
=
dot
(
Yzm
,
Yzm
.
T
)
/
(
n
-
1
)
S
=
dot
(
Yzm
,
Yzm
.
T
)
/
(
n
-
1
)
...
@@ -11,14 +18,17 @@ def eigenvalues(n):
...
@@ -11,14 +18,17 @@ def eigenvalues(n):
figure
(
1
)
figure
(
1
)
clf
()
clf
()
samples
=
range
(
2
,
10000
,
500
)
max_range
=
10000
samples
=
range
(
2
,
max_range
,
500
)
data
=
[[]
for
i
in
range
(
4
)]
data
=
[[]
for
i
in
range
(
4
)]
for
n
in
samples
:
for
n
in
samples
:
e
=
eigenvalues
(
n
)
e
=
eigenvalues
(
n
)
for
i
in
range
(
4
):
for
i
in
range
(
4
):
data
[
i
].
append
(
e
[
i
])
data
[
i
].
append
(
e
[
i
])
for
i
in
range
(
4
):
for
i
in
range
(
4
):
#subplot(2, 2, i+1)
plot
(
samples
,
data
[
i
],
'x'
)
plot
(
samples
,
data
[
i
],
'x'
)
axis
([
0
,
10000
,
0.
,
0.025
])
axis
([
0
,
max_range
,
0.
,
0.025
])
show
()
show
()
statred/ass1/q23_iris.py
View file @
14a62e57
from
numpy
import
loadtxt
from
pylab
import
loadtxt
,
figure
,
plot
,
subplot
,
axis
,
clf
,
savefig
from
pylab
import
figure
,
plot
,
subplot
,
show
,
axis
,
clf
def
cnvt
(
s
):
# The last column of the data sets is a label, which is used to distinguish the
try
:
# three groups of data in the data sets. This label should be translated to a
return
{
'Iris-setosa'
:
0.0
,
'Iris-versicolor'
:
1.0
,
\
# floating point, or a conversion error will occur (since ``dtype=float'').
'Iris-virginica'
:
2.0
}[
s
]
cnvt_dict
=
{
'Iris-setosa'
:
0.0
,
'Iris-versicolor'
:
1.0
,
'Iris-virginica'
:
2.0
}
except
KeyError
:
data
=
loadtxt
(
'iris.data'
,
delimiter
=
','
,
dtype
=
float
,
\
ireturn
-
1.0
converters
=
{
4
:
lambda
s
:
not
s
in
cnvt_dict
and
-
1.0
or
cnvt_dict
[
s
]})
data
=
loadtxt
(
'iris.data'
,
delimiter
=
','
,
dtype
=
float
,
converters
=
{
4
:
cnvt
})
# Transform the data set into plottable graph data
graph_data
=
[[[]
for
i
in
range
(
3
)]
for
j
in
range
(
16
)]
graph_data
=
[[[]
for
i
in
range
(
3
)]
for
j
in
range
(
16
)]
colors
=
[
'r'
,
'g'
,
'b'
]
figure
(
16
)
clf
()
for
i
in
range
(
4
):
for
i
in
range
(
4
):
for
j
in
range
(
4
):
for
j
in
range
(
4
):
if
i
!=
j
:
if
i
!=
j
:
for
d
in
data
:
for
d
in
data
:
graph_data
[
i
+
j
*
4
][
int
(
d
[
4
])].
append
((
d
[
i
],
d
[
j
]));
graph_data
[
i
+
j
*
4
][
int
(
d
[
4
])].
append
((
d
[
i
],
d
[
j
]));
# Different colors for different data types (map these colors to cnvt_dict).
colors
=
[
'r'
,
'g'
,
'b'
]
figure
(
16
)
clf
()
for
i
in
range
(
4
):
for
i
in
range
(
4
):
for
j
in
range
(
4
):
for
j
in
range
(
4
):
if
i
!=
j
:
if
i
!=
j
:
subplot
(
4
,
4
,
(
i
+
1
)
+
j
*
4
)
subplot
(
4
,
4
,
(
i
+
1
)
+
j
*
4
)
axis
(
'equal'
)
axis
(
'equal'
)
# Plot the three data sets.
for
c
in
range
(
3
):
for
c
in
range
(
3
):
tmp
=
zip
(
*
graph_data
[
i
+
j
*
4
][
c
])
tmp
=
zip
(
*
graph_data
[
i
+
j
*
4
][
c
])
plot
(
tmp
[
0
],
tmp
[
1
],
'x'
+
colors
[
c
])
plot
(
tmp
[
0
],
tmp
[
1
],
'x'
+
colors
[
c
])
...
...
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