The Kalman filter and other methods Anders Ringgaard

  • Slides: 40
Download presentation
The Kalman filter - and other methods Anders Ringgaard Kristensen Slide 1

The Kalman filter - and other methods Anders Ringgaard Kristensen Slide 1

Outline Filtering techniques applied to monitoring of daily gain in slaughter pigs: • •

Outline Filtering techniques applied to monitoring of daily gain in slaughter pigs: • • Introduction Basic monitoring Shewart control charts DLM and the Kalman filter • Simple case • Seasonality • Online monitoring • Used as input to decision support Slide 2

”E-kontrol”, slaughter pigs Quarterly calculated production results Presented as a table A result for

”E-kontrol”, slaughter pigs Quarterly calculated production results Presented as a table A result for each of the most recent quarters and aggregated Sometimes comparison with expected (target) values Offered by two companies: • • Dansk Landbrugsrådgivning, Landscentret (as shown) Agro. Soft A/S One of the most important key figures: Average daily gain Slide 3

Average daily gain, slaughter pigs We have: • 4 quarterly results • 1 annual

Average daily gain, slaughter pigs We have: • 4 quarterly results • 1 annual result • 1 target value How do we interpret the results? Question 1: How is the figure calculated? Slide 4

How is the figure calculated? The basic principles are: • • • Total (live)

How is the figure calculated? The basic principles are: • • • Total (live) weight of pigs delivered: Total weight of piglets inserted: Valuation weight at end of the quarter: Valuation weight at beginning of the quarter: Total gain during the quarter xxxx −xxxx +xxxx −xxxx yyyy Daily gain = (Total gain)/(Days in feed) Registration sources? • • • Slide 5 * Slaughter house – rather precise ** Scale – very precise *** ? ? ? – anything from very precise to very uncertain * ** ***

First finding: Observation error All measurements are encumbered with uncertainty (error), but it is

First finding: Observation error All measurements are encumbered with uncertainty (error), but it is most prevalent for the valuation weights. We define a (very simple) model: = + eo , where: • • • is the calculated daily gain (as it appears in the report) is the true daily gain (which we wish to estimate) eo is the observation error which we assume is normally distributed N(0, o 2) The structure of the model (qualitative knowledge) is the equation The parameters (quantitative knowledge) is the value of o (the standard deviation of the observation error). It depends on the observation method. Slide 6

Observation error Slide 7 = + eo , eo » N(0, o 2) What

Observation error Slide 7 = + eo , eo » N(0, o 2) What we measure is What we wish to know is The difference between the two variables is undesired noise We wish to filter the noise away, i. e. we wish to estimate from

Second finding: Randomness The true daily gains vary at random. Even if we produce

Second finding: Randomness The true daily gains vary at random. Even if we produce under exactly the same conditions in two successive quarters the results will differ. We shall denote the phenomenon as the “sample error”. We have, = + es, where • • es is the sample error expressing random variation. We assume es » N(0, s 2) is the underlying permanent (and true) value This supplementary qualitative knowledge should be reflected in the stucture of the model: = + eo = + es + eo The parameters of the model are now: og o s Slide 8

Sample error and measurement error Slide 9 What we measure is What we wish

Sample error and measurement error Slide 9 What we measure is What we wish to know is The difference between the two variables is undesired noise: • • Sample noise Observation noise We wish to filter the noise away, i. e. we wish to estimate from

The model in practice: Preconditions The model is necessary for any meaningful interpretation of

The model in practice: Preconditions The model is necessary for any meaningful interpretation of calculated production results. The standard deviation on the sample error, s , depends on the natural individual variation between pigs in a herd and the herd size. The standard deviation of the observation error, o , depends on the measurement method of valuation weights. For the interpretation of the calculated results, it is the total uncertainty, , that matters ( 2 = s 2 + o 2) Competent guesses of the value of using different observation methods (1250 pigs): • Weighing of all pigs: = 3 g • Stratified sample: = 7 g • Random sample: = 20 g • Visual assessment: = 29 g Slide 10

Different observation methods =3 g Slide 11 =7 g = 20 g = 29

Different observation methods =3 g Slide 11 =7 g = 20 g = 29 g

The model in practice: Interpretation Calculated daily gain in a herd was 750 g,

The model in practice: Interpretation Calculated daily gain in a herd was 750 g, whereas the expected target value was 775 g. Shall we be worried? It depends on the observation method! A lower control limit (LCL) is the target minus 2 times the standard deviation, i. e. 775 – 2 Using each of the 4 observation methods, we obtain the following LCLs: • • Slide 12 Weighing of all pigs: 775 g – 2 x 3 g = 769 Stratified sample: 775 g – 2 x 7 g = 761 Random sample: 775 g – 2 x 20 g = 735 Visual assessment: 775 g – 2 x 29 g = 717

Third finding: Dynamics, time Daily gain in a herd over 4 years. Is this

Third finding: Dynamics, time Daily gain in a herd over 4 years. Is this good or bad? Slide 13

Modeling dynamics We extend our model to include time. At time n we model

Modeling dynamics We extend our model to include time. At time n we model the calculated result as follows: n = sn + eon = + esn + eon Only change from before is that we know we have a new result each quarter. We can calculate control limits for each quarter and plot everything in a diagram: A Shewart Control Chart … Slide 14 1 2 3 4 …

A simple Shewart control chart: Weighing all pigs Periode Slide 15

A simple Shewart control chart: Weighing all pigs Periode Slide 15

Simple Shewart control chart: Visual assessment Periode Slide 16

Simple Shewart control chart: Visual assessment Periode Slide 16

Interpretation: Conclusion Something is wrong! Possible explanations: • • Slide 17 The pig farmer

Interpretation: Conclusion Something is wrong! Possible explanations: • • Slide 17 The pig farmer has serious problems with fluctuating daily gains. Something is wrong with the model: • Structure – our qualitative knowledge • Parameters – the quantitative knowledge (standard deviations).

More findings: n = + esn + eon The true underlying daily gain in

More findings: n = + esn + eon The true underlying daily gain in the herd, , may change over time: • • Trend Seasonal variation The sample error esn may be auto correlated • Temporary influences The observation error eon is obviously auto correlated: • Slide 18 Valuation weight at the end of Quarter n is the same as the valuation weight at the start of Quarter n+1

”Dynamisk e-kontrol” Developed and described by Madsen & Ruby (2000). Principles: • • Slide

”Dynamisk e-kontrol” Developed and described by Madsen & Ruby (2000). Principles: • • Slide 19 Avoid labor intensive valuation weighing. Calculate new daily gain every time pigs have been sent to slaughter (typically weekly) Use a simple Dynamic Linear Model to monitor daily gain • n = n + esn + eon = n + vn , where vn » N(0, v 2) • n = n-1 + wn, where wn » N(0, w 2) The calculated results are filtered by the Kalman filter in order to remove random noise (sample error + observation error)

”Dynamisk E-kontrol”, results Raw data to the left – filtered data to the right

”Dynamisk E-kontrol”, results Raw data to the left – filtered data to the right Figures from: • Madsen & Ruby (2000). An application for early detection of growth rate changes in the slaughter pig production unit. Computers and Electronics in Agriculture 25, 261 -270. Still: Results only available after slaughter Slide 20

The Dynamic Linear Model (DLM) Example General, first order Observation equation n = n

The Dynamic Linear Model (DLM) Example General, first order Observation equation n = n + vn , vn » N(0, v 2) Yt = t + vt , vn » N(0, v 2) System equation n = n-1 + wn, wn » N(0, w 2) t = t-1 + wn, wn » N(0, w 2) 1 2 3 4 Y Y 1 2 3 4 1 2 Slide 21 3 4

Extending the model Slide 22 Fn n is the true level described as a

Extending the model Slide 22 Fn n is the true level described as a vector product. A general level, 0 n, and 4 seasonal effects 1 n, 2 n, 3 n and 4 n are included in the model. From the model we are able to predict the expected daily gain for next quarter. As long as the forecast errors are small, production is in control (no large change in true underlying level)!

Observed and predicted Blue: Observed Pink: Predicted Slide 23

Observed and predicted Blue: Observed Pink: Predicted Slide 23

Analysis of prediction errors Slide 24

Analysis of prediction errors Slide 24

The last model Dynamic Linear Model Structure of the model (qualitative knowledge): • •

The last model Dynamic Linear Model Structure of the model (qualitative knowledge): • • Seasonal variation allowed (no assumption about the size). The general level as well as the seasonal pattern may change over time. Are those assumptions correct? Parameters of the model: • The observation and sample variance and the system variance. The model learns as observations are done, and adapts to the observations over time. Seasonal varation may be modeled more sophistically as demonstrated by Thomas Nejsum Madsen in Farm. Watch™ Slide 25

Moral If we wish to analyze the daily gain of a herd you need

Moral If we wish to analyze the daily gain of a herd you need to: • Know exactly how the observations are done (and know the precision). • Know how it may naturally develop over time. Without professional knowledge you may conclude anything. Without a model you may interpret the results inadequately. Through the structure of the model we apply our professional knowledge to the problem. Slide 26

On-line monitoring of slaughter pigs: Pig. Vision Innovation project led by Danish Pig Production:

On-line monitoring of slaughter pigs: Pig. Vision Innovation project led by Danish Pig Production: • • Danish Institute of Agricultural Sciences Videometer (external assistance) Skov A/S LIFE, IPH, Production and Health Continuous monitoring of daily gain while still in herd: • • • Slide 27 Dynamic Linear Models Chance of interference in the fattening period Adaptation of delivery policy

Pig. Vision: Principles A camera is placed above the pen. In case of movements

Pig. Vision: Principles A camera is placed above the pen. In case of movements a series of pictures are recorded and sent to a computer. The computer automatically identifies the pig (by use of a model) and calculates the area (seen from above). If the computer doesn’t belief that a pig has been identified, the picture is ignored. The area is converted to live weight (using a model). Through many pictures, the average weight and the standard deviation are estimated. Figure by Teresia Heiskanen Slide 28

What is online weight assessment used for? Continuous monitoring of gain. Collection of evidence

What is online weight assessment used for? Continuous monitoring of gain. Collection of evidence about growth capacity (learning) Adaptation of delivery policies depending on: • • Whether the pigs grow fast or slowly Whether the uniformity is small or big Whether a new batch of piglets is ready Prices Direct advice about pigs to deliver Slide 29

The decision support model Technique: • A hierarchical Markov Decision Process (dynamic programming) with

The decision support model Technique: • A hierarchical Markov Decision Process (dynamic programming) with a Dynamic Linear Model (DLM) embedded. Every week, the average weight and the standard deviation is observed After each observation the parameters of the DLM are opdated using Kalman filtering: • Permanent growth capacity of pigs, L • Temporary deviation, e(t) • Within-pen standard deviation, (t) Decisions based on (state space): • Number of pigs left • Estimated values of the 3 parameters Decision: Deliver all pigs with live weight bigger than a threshold Uncertainty of knowledge is directly built into the model through the DLM Slide 30

On-line weight assessment Pen with n pigs is monitored. No identification of pigs. At

On-line weight assessment Pen with n pigs is monitored. No identification of pigs. At any time t we have: The precision 1/ 2 is assumed known Slide 31

Objectives Given the on-line weight estimates to assign an optimal delivery policy for the

Objectives Given the on-line weight estimates to assign an optimal delivery policy for the pigs in the pen. Sequential (weekly) decision problem with decisions at two levels: • Slaughtering of individual pigs (the price is highest in a rather narrow interval) • Terminating the batch (slaughter all remaining pigs and insert a new batch of weaners) Slide 32

Dynamic linear models Slide 33

Dynamic linear models Slide 33

A dynamic linear weight model, I Known average herd specific growth curve: True weights

A dynamic linear weight model, I Known average herd specific growth curve: True weights at time t distributed as: Slide 34

The scaling factor L In principle unknown and not directly observable Initial belief: The

The scaling factor L In principle unknown and not directly observable Initial belief: The belief is updated each time we observe a set of live weights from the pen. Let L » N(1, L 2) be the true average weight Then Slide 35

Observation & system equation 1 Full observation equation for mean: Auto-correlated sample error (system

Observation & system equation 1 Full observation equation for mean: Auto-correlated sample error (system eq. ): Slide 36

Observation & system equation 2 Far more information available from the observed live weights

Observation & system equation 2 Far more information available from the observed live weights Sample variance not normally distributed. Use the 0. 16 sample quantile: The symbol (t) is the standard deviation of the observed values. System equation: Slide 37

Full equation set Slide 38

Full equation set Slide 38

Learning, permanent growth capacity Slide 39

Learning, permanent growth capacity Slide 39

Learning: Homogeneity (standard deviation) Slide 40

Learning: Homogeneity (standard deviation) Slide 40