ExamJan2024
- Due No Due Date
- Points 50
- Submitting a file upload
Solutions: exam2024Jan_solutions.pdf (updated) Download exam2024Jan_solutions.pdf (updated)
Instructions:
Name files handed in to Canvas using your anonymization code, such as NR.zip or NR-problem1.pdf etc. We prefer that all solutions are handed in via Canvas (photos of handwritten solutions are fine) but if you really prefer to hand in some handwritten solutions on papers at the exam that is ok.Any handwritten solutions should then be marked with both your anonymization code and a personal identifier chosen by you.
All solutions must be well motivated. Code should be understandable, extensive commenting will help.
Preliminary limits for grades: 3: 25, 4:33, 5: 42.
Good luck !
------------------------------------------------------------------------------------------------------------------------
1 Linear Regression [5p]
Consider the linear system
x(t)=a1x(t−1)+a2x(t−2)+bu(t)+e(t)
for which you have collected some data x(t),u(t),t=1,…,N.
a) Describe how you can write this on the form Y=Xθ+E and use linear regression to estimate the parameters
a1,a2,b.
b) Describe a set of conditions (on u and
e) that is enough to guarantee that the parameter estimates
ˆa1,ˆa2,ˆb will converge to their correct values when
N becomes large if you use the procedure in a). The conditions do not have to be the most general, any conditions that works will suffice.
2 Supervised Learning [12p]
The following google colab file Links to an external site. describes an attempt to estimate the age of crabs (output, given in the last column) using observed features of the crabs, such as weight and length etc (inputs, given in the first 8 columns). The goal is to minimize the error in the age prediction (measured as root mean square deviation).
a) There are several drawbacks with the code. Describe these and correct the code so that it follows good practice when doing supervised learning and evaluating performance.
b) Also choose one additional method, such as kNNregressor, RandomForestRegressor, SVM or another suitable method of your choice, and try to minimize the rms error. Your code should follow good practice.
Hint: Don't spend too much time optimizing hyper-parameters, it is more important that your methodology is appropriate.
3 System Identification - Hands-on [12p]
The file sysid03.mat Download sysid03.mat contains some data from a linear system with one input u and one output y sampled at the rate Ts=0.01.
The code sysid03.m Download sysid03.m contains an initial investigation of the data and some not so successful identification of ARX models.
Identify a discrete time linear model of the system. Aim for using few model parameters. Be sure to describe your methodology, including outlier analysis, choice of suitable model structure and model order, and include model validation with residual analysis. Also hand in your matlab code.
(Hint: Useful commands might include help ident, systemIdentification, arx,oe,armax,bj, present, compare, resid, bodeplot,pzmap, pwelch, ...)
4 Causal Inference [7p]
We want to determine the causal effect of X on Y , i.e. ∂∂xE[Y∣do(X:=x)], for the three examples in the figures a, b and c below. Assuming these figures correspond to standard linear structural causal models, which of the following ordinary least square estimations will give the correct result?
Alternative 1: y ~ x
Alternative 2: y ~ x + m
a)
b)
c)
d) Since 1960 data on newborns showed consistently that low-birth-weight babies of smoking mothers had a better survival rate than those of non-smokers. This paradox was discussed for 40 years. An article in 2014 finally explains the observation using this causal diagram:
and the google colab code below generates data that can be used to illustrate and explain the effect.
The variables stand for
S = Smoking (a high number indicating more smoking)
W = Weight loss (a high number indicating a LOWER child weight, considered a high risk situation)
D = Defect (an unobservable health defect, resulting in observable weight loss and increased risk of death)
Y = Mortality outcome (a high number indicating higher risk of child death)
According to medical knowledge, coefficients c1-c5 (see code) should all be expected to be positive.
Explain why a linear regression of the form
Y ~ S + W
would fail to correctly identify the impact of smoking S on child mortality Y and could result in an estimated negative coefficient for S.
e) Choose parameters c1-c5 and use the code above to illustrate the paradox. Hand in your code, with explanations of what you did.
5 Model Reduction [7p]
The code modred.m Download modred.m describes a 1D model of a L=1 meter long metal rod, being heated in the left end. A high order model G has been obtained as an approximate model with N=100 compartments. It is a discrete time model with 100 states and a sample time of h=0.01 sec. The rod is heated by an input signal u(t) at the left end (corresponding to state index 1), and heat leaks out at the other end where (corresponding to state index 100).
At the start there is only one temperature sensor, located near the middle, measuring state 50, resulting in the signal y(t). The code illustrates a model reduction investigation, studying how the required accuracy (chosen by the value "level") impacts the model order for the reduced system Ghat. It indicates that a 2nd order model gives good accuracy up to 0.1 rad/s and an acceptable approximation of the step response, except possibly for the initial 30 seconds where there are some deviations.
a) Study what happens if the location of the sensor is changed, try out some different locations in the range of 0.05 to 0.95. Determine if 2nd order models are still able to give good approximation accuracy up to 0.1 rad/s, or if higher order models are needed to reach similar approximation performance as before depending on sensor position.
b) Now study the configuration with 3 simultaneous sensors, mounted at 20, 50 and 80 percent of the length of the rod. This means that the system has 1 input and 3 outputs. The code is prepared for this investigation, but you need to change some lines. What approximation order is needed to get similar approximation accuracy up to 0.1 rad/s as before. (Study the amplitude and phase in the Bode diagram.) Can you get it to work with model order 2, 3, 4, 5 or 6? (Lower order is better, since it simplifies the design of a controller)
6. System Identification Theory [7p]
Consider the same linear system as in problem 1
x(t)=a1x(t−1)+a2x(t−2)+bu(t)+e(t).
Assume the signals u and
e are Gaussian with zero mean and with
E(u(t)u(s))=E(e(t)e(s))=E(u(t)e(s))=0 when
t≠s.
Assume furthermore that
E(u2(t))=E(e2(t))=1 and E(e(t)u(t))=ρ, where |ρ|≤1.
This means that u(t) and
e(t) are correlated with correlation coefficient
ρ.
Determine what the parameter estimates ˆa1,ˆa2,ˆb will converge to when N becomes large. Which of the parameter estimates will be bias-free? Prove your answer.
Hint: The matlab code systheory.m Download systheory.m generates data according to the model. You do not have to use it if you don't want to.