M7777 Applied Functional Data Analysis 5. From Data to Functions — Constrained Functions Jan Koláček (kolacek@math.muni.cz) Dept. of Mathematics and Statistics, Faculty of Science, Masaryk University, Brno n Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 1/17 Constrained Functions Constrained Functions There are some situations in which we want to include known restrictions about x(t). • x(t) is always positive • x(t) is always increasing (or decreasing) • x(t) is a density Idea: Enforce these conditions by transforming x(t). Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 2 / 17 Constrained Functions Angular Acceleration for Handwrite Data -0.04 -0.02 0.00 0.02 0 500 1000 1500 2000 Position [mm] Time [ms] We know that angular acceleration a2(t) = [D2x(t)}2 + [D2y(t)}2 must be positive. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 3 / 17 Constrained Functions Positive Smoothing of Angular Acceleration for Handwrite Data 1.0e-10 CD o 2.5e-11 < 0.0e+00 1000 1500 Time [ms] Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 4 / 17 Constrained Functions Positive Smoothing • We want to ensure that x(t) > 0. • Set W(t) = 0*(t)c • Let us consider the transformation x(t) = ewW Now we need to minimize N 2 r PENSSEX(W) = J] (y; - e^^) + A / [LW(t)]2dt, i=l ' This does not have an explicit formula. It is convex there is only one minimum. Requires numerical optimization, but this is generally fast. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 5 / 17 Constrained Functions Monotone Smoothing Growth of baby's tibia Baby's tibia Baby's tibia Growth process is increasing =4> the derivative should be positive! Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 6 / 17 Constrained Functions Monotone Smoothing • We need x(t) always increasing, i.e. Dx(t) > 0 • Set again W(t) = 4>*(t)c. • Let us consider the transformation r Dx(t) = ew^ x(t) = a + J ew&ds. to We want to minimize PENSSEX{W) = £[y/-a- ^ e^c/s ) +XJ [LW(t)]2dt. i=i to Still convex problem, numerics work fairly quickly /_!/!/(£) = D2l/l/(t) suggests that any x(t) = a + e/3t is smooth Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 7 / 17 Constrained Functions Monotone Smoothing Estimation with the constraint of monotonity Baby's tibia Baby's tibia Jan Koláček (SCI MUNI) M7777 Applied FDA Constrained Functions Density Estimation St. Johns 10.0- •; Days Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 9 / 17 Constrained Functions Density Estimation • The function x(t) is a density =4> we need x(t) > 0 and Jx(t)dt = 1. Set again W(t) = 4>*(t)c. Let us consider the transformation x(t) = W(t) feeds' But we observe only yi,..., y/v (correspond to ii,..., t/v) What would we to minimize? Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 10 / 17 Constrained Functions Penalized Likelihood • Likelihood of W(t) is probability of seeing ti, • We maximize the likelihood function N N L(W\tu...,tN) = [[x(ti) = e-i i=i • Easier to work with log-likelihood N ., tisi if W is true. — A/ /(l/l/|ti,..., t/v) = ^ l/l/(t/) - A/In / ew(s)cfe. /=i ' Minimize the penalized negative log-likelihood PENLOGUK^W) = -£ W(«)) + Wl„/.«'C)* + A/[UV(0P*. / = 1 Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 11 / 17 Constrained Functions Thinking about Smoothness • What is an appropriate measure of smoothness for densities? x(t) = Cew^ Compare to Normal density m = -(t-M)2/2a2 V2 TTd Then W(t) — t2 should be smooth ^> roughness penalty LW(t) = D3W(t). Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 12 / 17 Constrained Functions Density Estimation for St. Johns Precipitation St. Johns 0.2 0.1 0.0 I / 2.5 5.0 7.5 10.0 Precipitation Used: B-spline basis of order 6 with 29 knots, log A = Jan Koláček (SCI MUNI) M7777 Applied FDA -2 Fall 2019 13 / 17 Problems to solve O Absorbance Data • Load the variable absorb from the absorb.RData file and plot it. • Fit the data using a B-spline basis and a curvature penalty. Try some values of A, do not consider any constraint. • Consider the monotonicity constraint and fit the data using the same basis. Try some values of A and observe how the "optimal" value changes with the monotonicity constraint. Plot both final fits (see Figure 1). © Turany Precipitation Data • Load the variable df .turany.monthly from the turany.RData file. The dataset contains monthly precipitation amounts in Brno-Turany in years 2016 - 2018. • Fit the temperature density with Fourier bases and the third derivative rougness penalties at a number of values of A (see Figure 2 for A = 100). • Use the generic function density to get the density estimate, plot it (see Figure 3) and compare with the previous step result. 0 (optional) Program the CV procedure for monotone smoothing. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 14 / 17 Problems to solve Classic 0.4- o 0.3-o -Q o C/5 _Q < 0.2- 0.1 Monotone Plate B1 ■ C1 D1 E1 0 5 10 15 20 25 0 5 10 15 20 25 Time [hrs] Figure 1. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 15 / 17 Problems to solve Tu rany 0.03 4 0.02 4 C/5 Q 0.01 4 0.00 4- 25 50 75 100 Precipitation Figure 2. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 16 / 17 Problems to solve Tu rany 0.020 0.015 .-ST 0.010 0.005 0.000 / \ \ 1 \ 7 1 • • • • • • • _ _ _ m» _______ • • • • - - 7---. • • • • 0 50 100 Precipitation Figure 3. Jan Koláček (SCI MUNI) M7777 Applied FDA Fall 2019 17 / 17