Docsity

Schema riassuntivo Mida1 e Mida2, Schemi e mappe concettuali di Modelli Stocastici E Analisi Dei Dati

Toggle sidebar
bg1
Model Identification and Data Analysis
__________________________________________ Statistical Learning for Automation Systems
__________________________________________
Learning
feasibility
x
=
[
x
1
, x
2
, … , x n
]
T
input variable
y
output variable
f
:
X → Y
target function
h ∈ H
generic model
g
:
X → Y
candidate model (with tuned parameters)
DN
=
{
(
x
(
1
)
, y
(
1
)
)
,
(
x
(
2
)
, y
(
2
)
)
, … ,
(
x
(
N
)
, y
(
N
)
)
}
dataset
Learning is impossible from a deterministic point of view
because we there is no assumption on how data is
generated and we cannot hypothesize how the model
performs outside the datapoints
It becomes possible in a probabilistic framework assuming
that data is i.i.d. from a certain distribution.
Learning is meaningful if:
A pattern exists
The pattern cannot be derived mathematically
We have data
E
¿
(
g
)
=1
N
∑
i
=1
N
⟦
g
(
x
(
i
)
)
≠ f
(
x
(
i
)
)
⟧
in-sample error
Eout
(
g
)
=
P
(
g
(
x
)
≠ f
(
x
)
)
out-of-sample error
Hoeffding’s inequality provides a probabilistic bound on
how much the empirical error deviates from the true error
→ P
(
|
E
¿
(
g
)
−
Eout
(
g
)
|
>
ε
)
≤
2
M e
−2
ε
2
N
Objectives of learning
Fitting (minimizing
E
¿(
g
)
)
Generalization (minimizing
|
E
¿
(
g
)
−
Eout
(
g
)
|
)
Linear
regression
y
=∑
i
=0
n
wixi
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Anteprima parziale del testo

Scarica Schema riassuntivo Mida1 e Mida2 e più Schemi e mappe concettuali in PDF di Modelli Stocastici E Analisi Dei Dati solo su Docsity!

Model Identification and Data Analysis

__________________________________________ (^) Statistical Learning for Automation Systems __________________________________________ Learning feasibility

x =[ x 1 , x 2 ,… , x n ]

T input variable y output variable f : X → Y target function h ∈ H generic model g : X → Y candidate model (with tuned parameters) D (^) N ={( x ( 1 ) , y

, ( x

( 2 ) , y

,… , ( x

( N ) , y

( N ) )

} dataset Learning is impossible from a deterministic point of view because we there is no assumption on how data is generated and we cannot hypothesize how the model performs outside the datapoints It becomes possible in a probabilistic framework assuming that data is i.i.d. from a certain distribution. Learning is meaningful if:  A pattern exists  The pattern cannot be derived mathematically  We have data E (^) ¿ ( g )= 1 N ∑ i = 1 N ⟦ g ( x

( i ) )

≠ f ( x

( i ) )

⟧ ∈ [ 0 , 1 ] in-sample error

E out ( g )= P ( g ( x ) ≠ f ( x ) ) out-of-sample error

Hoeffding’s inequality provides a probabilistic bound on how much the empirical error deviates from the true error → P (^) (| E (^) ¿ ( g )− E (^) out ( g )|> ε (^) ) ≤ 2 M e − 2 ε 2 N Objectives of learning  Fitting (minimizing E (^) ¿ ( g ))  Generalization (minimizing (^) |^ E^ ¿ (^ g^ )−^ E^ out (^ g^ )|) Linear regression^ y^ =∑ i = 0 n w (^) i x (^) i

E (^) out ( w )= E [( y −∑ i = 0 ¿ n w (^) i x (^) i ) 2 ] The goal of OLS (Ordinary Least Squares) is to minimize the sum of the squared errors between predicted output and actual output E (^) ¿ ( w )= 1 N ∑ j = 0 N

( y

( j ) − ^ y ( j )

2 = 1 N ∑ j = 0 N ( y ( j ) −∑ i = 0 n w (^) i x (^) i ( j ) ) 2 w^ ^ = argmin w E (^) ¿ ( w )= argmin w 1 N

|| Y − Xw ||

2

=( X

T

X )

− 1 X T Y Learning a linear model equals to fitting the values of w (^) i that minimize E (^) ¿ ( w ) Necessary and sufficient conditions for w^ to be a minimum:

 ∇ E ¿ ( w^ )= 0 → w^ =( X T^ X )

− 1 X T Y null gradient 

2 E (^) ¿ ( w ) ∂ w (^2) | ^ w > 0 hessian of E (^) ¿ is a positive definite Generalization → E (^) out ( w )= E (^) ¿ ( w ) + O ( n N ) Linear classification ^^ y^ ( j ) = sign ( i∑ = 0 n w (^) i x (^) i ( j ) ) = sign ( w T x ) → perceptron E (^) ¿ ( g )= 1 N ∑ j = 0 N

( y

( j )

− g ( x

( j )

2 g ( x )= w T x Learning a perceptron is equal to finding the values of w (^) i that minimize the number of missclassified points. The idea is to move the hyperplane to correctly classify every point PLA update rule:  w ( 0 ) can be a random guess of values  w ( k + 1 )= w ( k ) + y (^ j^ )^ ( k ) x (^ j^ )^ ( k ) Generalization → E (^) out ( w )= E (^) ¿ ( w ) + O (√ n N ln N (^) ) Logistic regression^ h^ (^ s^ )= e s 1 + e s ^^ y^ ∈^ [^0 ,^1 ]

Logistic model: P ( y =+ 1 | x )= h ( ys )= h ( y w T^ x ) ≈ f ( x )

 Bias measures the error of the model due to simplifying assumptions between the average model and the target function  Variance rapresents the sensitivity to fluctuation in the training data measuring the deviation of the model from the average model A model with high variance depends to much on the given data and might perform poorly on new unseen data leading to overfitting, while a model with high bias does not capture the underlying trend of the data well and might lead to underfitting When we find ourselves in an overfitting scenario, to improve model performance we can:  Reduce the number of features of our model  Use regularization techniques to penalize large coefficients  Use cross-validation to find the right complexity for the model  Increase the size of the training dataset to generalize better Model selection Regularization When working in optimality conditions, regularization adds a penalty term to the linear regression cost function E (^) ¿ to discourage the model from being too complex λ Penalità Effetto su w Effetto sul modello 0 nessuna liberi di crescere massima flessibilità (overfitting) medio moderata più contenuti modello più regolare grand e forte vicini a zero modello molto semplice (underfitting) E (^) aug ( w )= E (^) ¿ ( w ) + λ N w T w Cross-validation Cross-validation helps measure how complex a model should be by computing E (^) cv , which is an estimate of E (^) out , and compairing it with the ones of other model families With cross-validation we can tune hyperparameters that control complexity We partition D (^) N into a training dataset D (^) train (size N − k ), which will be used to train the model, and a validation

dataset D (^) val (size k ), which will give us a proxy of the out- of-sample performance E (^) val ≈ E (^) out ( ^ w ) as k increases

-^ E^ val is an unbiased estimation of^ E^ out →

E D val [ E val ]= E out

  • The variance of the error between^ E^ val and^ E^ out decreases with increasing size of^ D^ val

→ var [ E val − E out ]= O

( 1 k ) Rule of thumb:^ k^ =

N

5 Leave-one-out cross validation ( k = 1 ) → there are N ways to partition D (^) N into a training set and a validation set Each of the N times we partition the dataset, we compute a new model based on N − 1 points and test it on the remaining one E (^) cv = 1 N ∑ j = 1 N E (^) val ( j )

( h

−( j )

( x ) )

E D [ E cv ]=

1 N ∑ j = 1 N E (^) D [ E (^) val ( j )

( h

−( j ) ( x ) ) (^) ]= 1 N

N E out ( h

−( j )

( x )) ≈

N large

E out ( h^ ( x ) )

Nonlinear models

^ y = h ( z )= h ( Φ ( x ) ) → change of coordinates to linearize

the separating surface Neural networks Neural networks are a biologically inspired tool that deals with complexity by combining many elements MLP Neural Networks To implement simple functions we use perceptrons, and we connect them with logical operations that are also modeled by perceptrons Increasing the number of perceptrons, we can obtain separating sufaces (=functions) of arbitrary complexity The activation function must be the same for all nodes MLP-NN are FF-NN that have at least one hidden layer

¿ ( x 1 , x 2 ) → sign ( w

T

x )= sign ( x 1 + x 2 + 1 )

¿ ( x 1 , x 2 ) → sign ( w

T

x )= sign ( x 1 + x 2 − 1 )

Volnoi tessalletion of the input space K nearest neighbor → assigns the label of the majority of the closest points ^ y = sign ( i∑ = 1 k y ( x ( i ) ) )

Rule of thumb: k = ⌊ √ N ⌋

If N , k → ∞ but k N → (^0) , E (^) ¿ ( h ) → E (^) out ( h ) (^) and E (^) out ( h ) (^) is the minimun available error Classifier qualificators  Missclassification error ( E (^) ¿ for training set, E (^) cv for validation set)  Confusion matrix [ true p false p false n true n ] Accuracy:^ A^ = true p + true n true p + true n + false p + false n Precision: PPV = true p true p + false p Recall:^ TPR^ = true p true p + false n F1-score: F 1 =

2 ∙ PPV ∙ TPR
PPV + TPR

Precision and recall are very useful when we want to know how good a model works in a situation where there is a significant size difference between the classes Clustering (unsupervised learning) The goal is to partition the input space in k clusters to easily predict the label of any new point x ¿ → k sets S with corresponding centroids μ Lloyd’s algorithm ( k means)  Initialize the controids^ μ^1 ,…^ ,^ μ^ k  Set S (^) j is the set of all points closer to μ (^) j ∀ j  Update che position of the centroids → μ (^) j = 1 n (^) j ∑ j ∈ S (^) j x ( j )  Repeat the previous two steps until E (^) ¿ stops decreasing

How to select k if it’s not given a priori? In the E (^) ¿− k graph, we can observe that the optimal value of k is in the “knee” of the graph → the error function does not decrease significally anymore Hierarchical clustering In this approach E (^) ¿ is computed for each k (starting at zero error when the number of clusters is equal to the number of points) Data preprocessing

  1. Input centering → remove any bias in x by translating the origin x = 1 N ∑ i x ( i ) z ( i ) = x ( i ) − x
  2. Input normalization → scale the input x σ (^) j 2 = 1 N ∑ i x (^) j ( i ) 2 z ( i ) = [ z (^1) ( i ) ⋮ z (^) n ( i )] = [ x (^1) ( i ) σ (^1) ⋮ x (^) n ( i ) σ (^) n ]
  3. Input whitening → decorrelate the input samples A = 1 N ∑ i x ( i ) x ( i ) T z ( i ) = A − 1 2 x ( i ) A : covariance matrix
  4. Data cleaning → remove the outliers in the data (manually)
  5. Dimesionality reduction → reduce the number of inputs Principal component analysis (method for automatic feature extraction) → we can work in a lower dimensional space by observing that input points might have a correlation along axes: doing a change of coordinates we can

White noise → e ( s , t ) wn ( μ , λ 2 )^ γ^ e (^ τ^ )=^0 ∀^ τ^ ≠^0 Spectral density function Γ ( ω )= (^) ∑ τ =− ∞

  • ∞ γ ( τ ) e − jωτ  Realness

Imm ( Γ ( ω ) )= 0 ∀ ω ∈ R

 Non negativity Γ ( ω ) ≥ 0 ∀ ω ∈ R  Symmetry Γ ( ω )= Γ (− ω ) ∀ ω ∈ R  Periodicity Γ ( ω )= Γ ( ω + 2 kπ ) ∀ ω ∈ R , k ∈ Z Inverse transform: γ ( τ )= 1 2 π ∫ − π π Γ ( ω ) e jωτ dω Learning with SP The out-of-sample error of an estimator can be written as E (^) out [ ^ Q (^) N ]= E [ ( Q − Q ¿ ) 2 ] + E (^) [( Q^ (^) N − Q ¿ ) 2 ]  Correctness → E (^) [ ^ Q (^) N ]= Q ¿= Q  Consistency → E (^) [( Q ¿− ^ Q (^) N ) 2 ]^ →^0 as^ N^ →^ ∞

  1. Sample mean → ^ m (^) N = 1 N ∑ t = 1 N x ( s , t )
  2. Sample covariance function → ^ γ (^) N ' ( τ )= 1 N −¿ τ ∨¿ (^) ∑ t = 1 N −¿ τ ∨¿ x ( s , t ) x ( s , t +¿ τ ∨)¿ ¿ ¿

m^ ^ N and ^ γ N ( τ ) are consistent if γ ( τ ) → 0 as | τ | → ∞ and

correct

  1. Sample spectral density → Γ^ (^) N ( ω )= (^) ∑ −( N − 1 ) N − 1 ^ γ (^) N^ '^ ( τ ) e −^ jωτ^ (asymptotically correct but not consistent) → Averaging: we infer on subparts of the dataset and compute the average between estimators (if k is too big the estimators are biased) Γ^ ^ N ¿ ( ω )= 1 k ∑ i = 1 k Γ^ ^ N ' ' ( ω ) [ k ] = 1 k ∑ i = 1 k Γ^ ^ N ' ' ( ω ) [ k ] Γ^ ^ N ' ' ( ω )= (^) ∑ −( N − 1 ) N − 1 ^ γ (^) N^ '^ '^ ( τ ) e −^ jωτ^ = (^) ∑ −( N − 1 ) N − 1 ( 1 N ∑ t = 1 N −| τ |

x ( s , t ) x ( s , t +| τ |)

) e − jωτ Linear trends x ( s , t )= x (^) SSP ( t ) + linear trend

v ( t )= kt + q → v^ ( t )= argmin k , q E (^) [ ( x ( t )−( kt + q ) ) 2 ] Seasonality x ( s , t )= x (^) SSP ( t ) + seasonal behaviour v ( t )= v ( t + kT ) → v^ ( t )= 1 M ∑ h = 0 M − 1 x ( t + hT ) Supervised learning = learn from labeled data to predict outcomes (perceptrons, linear/logistic regression,k-NN) Unsupervised learning = learn from unlabeled data to discover hidden structure (k means) Parametric classification Nonparametric classification Pros Cons Pros Cons  Computationally cheap  Low storage  Fast prediction of the output  Good generalization  Limited flexibility  Requires correct model assumption  Very flexible  Few assumptions  High memory usage  Computationally expensive  Sensitive to noise Advantages Disadvantages Linear Regression Continuous output, fast prediction Cannot adjust to nonlinear behaviours of data Perceptron Rapid class prediction Rigid binary output Logistic Regression Interpretable, threshold to divide classes can be suitably tuned, coefficient indicate the relative importance of a feature, converges to a global optimum (convex f) Computationally expensive (GD), assumes a linear relationship between inputs and log- odds of the target variable Neural Networks Useful when dealing with complex multilayer patterns, layers help the model in learning and generalizing, efficient on large datasets, adapts to changing data distributions A lot of layers can lead to overfitting and also require more computational capacity Linear regression with nonlinear input Enhances the performance of linear regression significantly, approximate nonlinear relationships with a simple model, physical interpretability Limited to interactions specified by the features (cannot learn new patterns) k-Nearest Neighbour No assumptions about data distribution, can Computationally expensive, sensitive to the

 Division of the leading terms  Mutiplication  Subtraction Example: W ( z )= z − 1 1 − 1 2 z − 1 z − 1 1 − 1 2 z − 1 − z − 1

1 2 z − 2 0000 + 1 2 z − 2 0000 − 1 2 z − 2

1 4 z − 3 00000000 + 1 4 z − 3 z − 1

1 2 z − 2  Transformation from IR to TF W ( z )= Z ( ω ( t ) )=∑ t = 0 ∞ ω ( t ) z − t → useless because we would neeed a noise-free dataset and all the infinite values of the IR  Transformation from SS to IR ω ( t )= { 0 t ≤ 0 H F t − 1 G t > 0 Observability and controllabilit y The system is fully controllable from output y ( t ) iff the observability matrix O (^) n = [

H
HF
H F

n − 1 ]^ is full rank Rank ( O )= n The system is fully controllable from input u ( t ) iff the

controllability matrix R n =[ G FG ⋯ F n^ −^1 G ] is full rank

Rank ( R )= n BB identification in a non- parametric way using SS representatio The key task of subspace-based SS identification is moving from a measured experimental IR to a SS model 4-SID algorithm (noise-free IR dataset)

  1. Build Henkel matrix in increasing order and check the rank

n in time domain H (^) n = [ ω (^1 ) ω (^2 ) ω ( 2 ) ω ( 3 ) ⋯ ω ( n ) ⋯ ω ( n + 1 ) ⋯ i ω ( n ) ω ( n − 1 ) i i ⋯ ω ( 2 n − 1 ) ]

  1. Take^ H^ n + 1 and factorize it into two rectangular matrices O (^) n + 1 and R (^) n + 1
  2. Estimate (^) F^ , G^ and (^) H^ 4-SID algorithm (noisy IR dataset) ~ ω ( t )= ω ( t ) + η ( t )
  3. Build “one-shot” the Henkel matrix using the full dataset ~ H (^) qd = [ ~ ω ( 1 ) ~ ω ( 2 ) ~ ω ( 2 ) ~ ω ( 3 ) ⋯ ~ ω ( d ) ⋯ ~ ω ( d + 1 ) ⋯ ~ ω ( j − 1 ) ~ ω ( q ) ~ ω ( q + 1 ) i i ⋯ ~ ω ( q + d − 1 ) ] N = q + d − 1
  4. SVD of ~ H (^) qd → ~ H (^) qd = ~ U ~ S ~ V T
  5. Divide the singular values between system and noise → the decision must be made by tuning n and testing various cases
  6. Build the clean Henkel matrix H^ ^ qd H^ ^ qd =^
U^ S^ ^ V T

We did a huge rank reduction

  1. Estimate (^) F^ , G^ and (^) H^ O^ ^ = U^ S^ 1 (^2) ^ R = S^ 1 (^2) ^ V
T → H^ = O^ ( 1 ,:) G^ = R^ ( 1 ,:)

F^ ^ =( O 1 T O (^1) ) − 1 O (^1) T O (^2) 4-SID is optimal because it makes the best possible rank reduction of ~ H (^) qd BB identification in a parametric way using TF representatio n in time domain Prediction theory for DT dynamic linear system

e ( t ) wn ( 0 , λ

2

ARMA models y ( t )= a 1 y ( t − 1 ) + a 2 y ( t − 2 ) + …+ a (^) n y ( t − n ) + c 0 e ( t ) + c 1 e ( t − 1 ) + p …+ c (^) m e

ESR =

var [ y ( t )− ^ y ( t / t − k ) ]

var [ y ( t ) ]

error to signal ratio Estimation of ARMA models from data

  1. Data collection and cleaning (^) { y ( 1 ) , y ( 2 ) ,… , y ( N ) }
  2. Select a parametric class of models m ( ϑ ) m ( ϑ ) : y ( t )= 1 + c 1 z − 1 + …+ c (^) m z − m 1 + a 1 z − 1
  • …+ a (^) n z − n e^ (^ t^ )^ ϑ^ = [ a (^1) ⋮ a (^) n c (^1) ⋮ c (^) m ] Optimal selection of model class: the best model must be able to compromise error minimization and generalization capabilities → cross-validation If the model is optimal ε ( t ) is a white noise (whiteness test)
  1. Select a performance index (PEM – prediction error method) J (^) n ( ϑ )= 1 N ∑ i = 1 N

( y ( t )− ^ y ( t / t − 1 ) )

2 sample variance of 1 step ahead prediction

  1. Optimization^ →^ ϑ^ N =^ argmin ϑ J (^) N ( ϑ )  J (^) N ( ϑ ) is a quadratic function → explicit formula for ϑ^ ^ N ,^1!^ solution For AR ( n ) models:^ y^ (^ t^ )=^ 1 1 + a 1 z − 1
  • …+ a (^) n z − n e^ (^ t^ ) ^ y ( t / t − 1 )= C ( z )− A ( z ) C ( z ) =− a 1 y ( t − 1 )− …− a (^) n z − n = φ T ( t ) ∙ ϑ ∂ J (^) N ∂ ϑ |^ ϑ (^) N = 0 = 2 N ∑ t = 1 N

(− φ ( t )^ ) ( y ( t )− φ

T (

t ) ϑ )

ϑ^ ^ N =[ ∑ t = 1 N φ ( t ) φ T ( t ) ] − 1 [ (^) t∑ = 1 N φ ( t ) y ( t ) ]  J (^) N ( ϑ ) is a convex function → iterative method, (^1)! solution  J (^) N ( ϑ ) is not convex → iterative method with multiple random initializations (can get stuck in local minima) For ARMA ( n , m ) and MA ( m ) models:

J (^) N ( ϑ )= 1 N ∑ i = 1 N ( A ( z , ϑ ) C ( z , ϑ ) y ( t ) ) 2 → to minime this function an iterative mthod with local quadratic approximation is used (Newton’s method or even better quasi-Newton’s method, that guarantees a positive second order approximation)

  1. Validation → final check that m ( ϑ ) is optimal (whiteness test) ARMAX models → ARMAX ( n , m , p + k ) : y ( t )= B ( z ) A ( z ) u ( t − k ) + C ( z ) A ( z ) e ( t ) Optimal predictor from data: ^ y ( t / t − k )= B ( z ) E ( z ) C ( z ) u ( t − k ) + ~ R ( z ) C ( z ) y ( t − k ) ε ( t )= y ( t )− ^ y ( t / t − k )= E ( z ) e ( t ) prediction error Estimation of ARMAX models from data

1. Dataset { u ( 1 ) , u ( 2 ) ,… , u ( N )} { y ( 1 ) , y ( 2 ) ,… , y ( N )}

  1. Model class m ( ϑ ): y ( t )= B ( z ) A ( z ) u ( t − k ) + C ( z ) A ( z ) e ( t ) ϑ =

[

a (^1) ⋮ a (^) n b (^0) ⋮ b (^) p c (^1) ⋮ c (^) m

]

  1. Performance index: J (^) N ( ϑ )= 1 N ∑ t = 1 N ( A ( z ) C ( z ) y ( t )− B ( z ) C ( z ) u ( t − 1 ) ) 2
  2. Optimization^ →^ ^ ϑ N =^ argmin ϑ J (^) N ( ϑ )  For ARX models we use quadratic optimization  For ARMAX or MAX models we use iterative and randomized methods
  3. Validation → whiteness test on ε ( t ) BB Two steps to find the system model given I/O data: