Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdde01-ht24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mehce338-felra653-sigjo290
tdde01-ht24
Commits
3571d338
Commit
3571d338
authored
3 months ago
by
Felix Ramnelöv
Browse files
Options
Downloads
Patches
Plain Diff
Lab 2: Fixed figure for assignment 3
parent
ea966921
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lab2/assignment3.R
+20
-43
20 additions, 43 deletions
lab2/assignment3.R
lab2/figures/assignment3-4.eps
+65653
-40283
65653 additions, 40283 deletions
lab2/figures/assignment3-4.eps
lab2/figures/assignment3-4.png
+0
-0
0 additions, 0 deletions
lab2/figures/assignment3-4.png
with
65673 additions
and
40326 deletions
lab2/assignment3.R
+
20
−
43
View file @
3571d338
...
...
@@ -98,47 +98,22 @@ test_errors <- c()
cost_function
<-
function
(
theta
)
{
train_error
<-
MSE
(
y_train
,
as.matrix
(
X_train
)
%*%
theta
)
return
(
train_error
)
}
theta
<-
rep
(
0
,
ncol
(
X_train
))
# res <- optim(
# par = theta,
# fn = cost_function,
# method = "BFGS",
# control = list(trace = 1, maxit = 200, REPORT = 1),
# )
for
(
i
in
1
:
5000
)
{
print
(
i
)
res
<-
optim
(
par
=
theta
,
fn
=
cost_function
,
method
=
"BFGS"
,
control
=
list
(
maxit
=
1
),
)
print
(
res
$
value
)
theta
<-
res
$
par
test_error
<-
MSE
(
y_test
,
as.matrix
(
X_test
)
%*%
theta
)
train_errors
<<-
c
(
train_errors
,
res
$
value
)
test_errors
<<-
c
(
test_errors
,
test_error
)
if
(
res
$
convergence
==
0
)
{
break
}
return
(
train_error
)
}
res
$
counts
theta
<-
rep
(
0
,
ncol
(
X_train
))
range
<-
c
(
train_errors
[
501
:
length
(
train_errors
)],
test_errors
[
501
:
length
(
test_errors
)])
res
<-
optim
(
par
=
theta
,
fn
=
cost_function
,
method
=
"BFGS"
,
control
=
list
(
trace
=
1
,
maxit
=
200
),
)
plot
(
train_errors
,
...
...
@@ -147,21 +122,18 @@ plot(
ylab
=
"Error"
,
xlab
=
"Iteration"
,
main
=
"Training and Test Errors over Iterations"
,
lty
=
1
,
ylim
=
c
(
min
(
range
),
max
(
range
)),
xlim
=
c
(
501
,
length
(
train_errors
)),
ylim
=
c
(
0.25
,
0.75
),
xlim
=
c
(
501
,
10000
),
)
points
(
test_errors
,
type
=
"l"
,
col
=
"red"
,
lty
=
2
)
points
(
test_errors
,
type
=
"l"
,
col
=
"red"
,
)
legend
(
"topright"
,
legend
=
c
(
"Training Error"
,
"Test Error"
),
col
=
c
(
"blue"
,
"red"
),
lty
=
c
(
1
,
2
)
legend
=
c
(
"Training Error"
,
"Test Error"
,
"Optimal Test Error"
),
lty
=
c
(
1
,
1
,
0
),
col
=
c
(
"blue"
,
"red"
,
"green"
),
pch
=
c
(
NA
,
NA
,
19
),
)
early_stopping
<-
which.min
(
test_errors
)
...
...
@@ -169,6 +141,11 @@ early_stopping
test_errors
[
early_stopping
]
points
(
early_stopping
,
test_errors
[
early_stopping
],
col
=
"green"
,
pch
=
19
)
optimal_theta
<-
res
$
par
optimal_train_mse
<-
res
$
value
optimal_train_mse
...
...
This diff is collapsed.
Click to expand it.
lab2/figures/assignment3-4.eps
+
65653
−
40283
View file @
3571d338
This diff is collapsed.
Click to expand it.
lab2/figures/assignment3-4.png
+
0
−
0
View replaced file @
ea966921
View file @
3571d338
4.78 KiB
|
W:
|
H:
4.79 KiB
|
W:
|
H:
2-up
Swipe
Onion skin
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