Difference between revisions of "Condition Effect Learning"
DurkKingma (talk | contribs) |
DurkKingma (talk | contribs) m (<math>a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}</math> is now correct) |
||
(22 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This page reflects my idea about the Condition Effect Learning system. If you have comments, please dont delete text but add comments so I can reflect. See this as a first draft, which can be used as a basis for the Cheetah condition effect learning system. | This page reflects my idea about the Condition Effect Learning system. If you have comments, please dont delete text but add comments so I can reflect. See this as a first draft, which can be used as a basis for the Cheetah condition effect learning system. | ||
As said in [[Advisory System]], Cheetah needs a system that learns about the effect of certain conditions. As you can read in [[Advisory System]], | As said in [[Advisory System]], Cheetah needs a system that learns about the effect of certain conditions. Condtions are variables that have effect on blood glucose levels. As you can read in [[Advisory System]], conditions can be classified as follows: | ||
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain. | # Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain. | ||
# Uncertain conditions: the effect is not certain or not known yet. So, the effect is a prediction done by the system. The learning system tries to approve the prediction by looking at the past. | # Uncertain conditions: the effect is not certain or not known yet. So, the effect is a prediction done by the system. The learning system tries to approve the prediction by looking at the past. | ||
There are some | There are some complications regarding learning about condition (e.g. food) effects. Since each human and each body is different, conditions dont always have a fixed certain effect. Food for instance has a GL (Glycamic Load) that tells about the effect of the food on BG (Blood Glucose) levels. Food effect (response) varies between individuals and between days as much as 20%. Likewise, effect of insulin and activities varies between people and temporally. Therefore, to account for intra-individual and temporal differences, I think it is a good thing to generally express condition effect by a range instead of a simple number. Such a range could be a probability distribution, or expressed as (minimum,maximum) tuple. For Cheetah, 'Learning' about conditions means assigning a range or distribution to it. There are several levels of expressing such variation in terms of a range or distribution. | ||
I solved the first one, but not yet the second. | I solved the first one, but not yet the second. | ||
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect. | # Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect. | ||
Line 28: | Line 28: | ||
Using | Using intuition, I came up with the following theorem. I have to give it a name so lets call it ''Kingma's Theorem'' :). It's not formally proved yet, but the following seems to be true for all cases. Its actually quite logical.<br/> | ||
If condition c is part of set S (''and (S-c) is set S minus condition c')<br/> | |||
and S<sub>min</sub> and S<sub>max</sub> are known<br/> | and S<sub>min</sub> and S<sub>max</sub> are known<br/> | ||
and c<sub>hardmin</sub> and c<sub>hardmax</sub> are known<br/> | and c<sub>hardmin</sub> and c<sub>hardmax</sub> are known<br/> | ||
then can be said:<br/> | then can be said:<br/> | ||
S-c<sub>min</sub> = S<sub>min</sub> - c<sub>hardmax</sub><br/> | (S-c)<sub>min</sub> = S<sub>min</sub> - c<sub>hardmax</sub><br/> | ||
S-c<sub>max</sub> = S<sub>max</sub> - c<sub>hardmin</sub><br/> | (S-c)<sub>max</sub> = S<sub>max</sub> - c<sub>hardmin</sub><br/> | ||
Line 48: | Line 48: | ||
'''Example 1.1''' | '''Example 1.1''' | ||
Lets look at | Lets look at a simple example of how a system would learn. Say, the user adds a glucose mearurement entry and the system starts its learning system. The user has taken a glass of applejuice A and a bread B. The user fills in a blood glucose measurement of 15. | ||
The system knows a priori (from its database): | |||
A<sub>hardmin</sub> = 2<br/> | |||
A<sub>hardmax</sub> = 5<br/> | |||
B<sub>hardmin</sub> = 7<br/> | |||
B<sub>hardmax</sub> = 9 | |||
The system calculates the effect range these two items must have had: | |||
UE<sub>min</sub> = BG<sub>measurement</sub> - CE<sub>max</sub> = 20 - 13 = 7<br/> | |||
UE<sub>max</sub> = BG<sub>measurement</sub> - CE<sub>min</sub> = 20 - 9 = 11 | |||
Using Kingma's Theorem, The system then calculates the current A<sub>min</sub>, A<sub>max</sub>, B<sub>min</sub>, B<sub>max</sub> values: | |||
(UE-A)<sub>min</sub> = UE<sub>min</sub> - A<sub>hardmax</sub> = 7 - 5 = 2 (this is under B's hardmin, so) => 7<br/> | |||
(UE-A)<sub>max</sub> = UE<sub>max</sub> - A<sub>hardmin</sub> = 11 - 2 = 9 (not above B's hardmax, so keep it)<br/> | |||
(UE-B)<sub>min</sub> = UE<sub>min</sub> - B<sub>hardmax</sub> = 7 - 9 = -2 (this is under A's hardmin, so) => 2<br/> | |||
(UE-B)<sub>max</sub> = UE<sub>max</sub> - B<sub>hardmin</sub> = 11 - 7 = 4 (not above A's hardmax, so keep it)<br/> | |||
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed: | |||
A<sub>min</sub> = (UE-B)<sub>min</sub> = 2<br/> | |||
A<sub>max</sub> = (UE-B)<sub>max</sub> = 4<br/> | |||
B<sub>min</sub> = (UE-A)<sub>min</sub> = 7<br/> | |||
B<sub>max</sub> = (UE-A)<sub>max</sub> = 9<br/> | |||
Above values indicate the possible current effect range of A and B. The system can use this to tweak its knowledge about the overall effect range of this values. This could be done by giving a condition a list of these calculated effect ranges. An algorithm then a mean (or something) of this list to use in effect prediction. | |||
In other cases, when there are more then 2 conditions, the system iterates down a few levels to calculate the individual possible condition effect ranges. I will add such an example when I have time. | |||
:<math> | == 2. Bayesian Inference way == | ||
Lets forget the term 'condition' but the more intuitive term 'event' instead. So events are things like food intake (eg one glass of lemonade), insuline intake (one unit of type X), sports (half an hour of running), but also current health status and stress level etc. Before the system learns anything, each event is assigned an 'a priori' estimating curve, which tells us how, in time, the estimated effect on the blood glucose level 'g'. This a priori curve is assigned before any measurements have been made (example: the a priori curve for food could be based on known carbonhydrate). Quickly said, the learning system uses the blood glucose measurements to update and improve the estimating curve. | |||
Lets describe these events, their effects and their computations, in terms of a statistics problem. | |||
=== About events === | |||
Each single event <math>e_i</math> has three things. | |||
1) Firstly: A set of samples. Each sample is a tuple <b>(Δt, Δg)</b> So the set of samples could be represented on a 2-dimensional area. The sample set is initially empty, and samples are added through bayesian inference (explained below). [For extra clarity, image to be added here]. | |||
2) A prior (''a priori'') function <b>f<sub>e,prior</sub>(Δt) → Δg = μ<sub>prior</sub></b>. This is the estimated mean effect of the event, for each determined before any samples have arrived. For food, it could be determined by looking at carbonhydrate amount. For insuline, it could be determined by medicine information. If no prior function can be made, an effect is assigned a default prior function. The prior function also has a pre-determined variance σ<sub>prior</sub>². Spoken in statistic terms, the event effect at each moment in time has a normal distribution with: | |||
<math>\sigma_e^2 = \mbox{some-static-value} \,</math><br/> | |||
<math>\mu_e = \theta \,</math> | |||
This parameter θ is unknown, but it has a prior distribution with | |||
<math>\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,</math><br/> | |||
<math>\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,</math> | |||
3) A posterior (''a posteriori'') function <b>f<sub>e,post</sub>(Δt) → Δg</b>. This is the esimated effect of the event after looking at the samples. It is determined as follows. The samples are divived into give time intervals, for example 15 minutes. So we have intervals t<sub>i</sub> with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t<sub>i</sub> have a distribution θ with a prior distribution as explained above. The posterior distribution of t<sub>i</sub> is calculated as follows: | |||
<math>\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}</math><br/> | |||
<math>\mu_{\theta, post}=\frac{\sigma_{\theta, prior}^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2\bar x_n}{\sigma_e^2+n\sigma_{\theta, prior}^2}</math> | |||
To assign an evidence x<sub>i</sub> to each individual events e<sub>i</sub> you do: | |||
<math>x_i=\mu_{prior}+a*\sigma_i^2</math><br> | |||
where | |||
<math>a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}</math> | |||
So it comes down to some quite simple math. I'll make my explanation better when I have more time. |
Latest revision as of 19:00, 30 May 2006
This page reflects my idea about the Condition Effect Learning system. If you have comments, please dont delete text but add comments so I can reflect. See this as a first draft, which can be used as a basis for the Cheetah condition effect learning system.
As said in Advisory System, Cheetah needs a system that learns about the effect of certain conditions. Condtions are variables that have effect on blood glucose levels. As you can read in Advisory System, conditions can be classified as follows:
- Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.
- Uncertain conditions: the effect is not certain or not known yet. So, the effect is a prediction done by the system. The learning system tries to approve the prediction by looking at the past.
There are some complications regarding learning about condition (e.g. food) effects. Since each human and each body is different, conditions dont always have a fixed certain effect. Food for instance has a GL (Glycamic Load) that tells about the effect of the food on BG (Blood Glucose) levels. Food effect (response) varies between individuals and between days as much as 20%. Likewise, effect of insulin and activities varies between people and temporally. Therefore, to account for intra-individual and temporal differences, I think it is a good thing to generally express condition effect by a range instead of a simple number. Such a range could be a probability distribution, or expressed as (minimum,maximum) tuple. For Cheetah, 'Learning' about conditions means assigning a range or distribution to it. There are several levels of expressing such variation in terms of a range or distribution. I solved the first one, but not yet the second.
- Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.
- Learning a condition's effect by seeing it as a normally distributed random variable.
1. Learning a condition's effect by assigning it a minimal and maximal effect value
With this system, all conditions X have a Xhardmin and Xhardmax variables which tells the system the hard minimum and maximum of effect. For example, research has pointed out that a can of Coca-Cola has a Glycemic Load (GL) of minimally 14 and maximally 16. If we see the GL as the foods effect, we can assign CocaColahardmin=14 and CocaColahardmax=16. So, CocaCola could be a type 1 condition because it has a certain effect. When a user adds a new food type X to the database, it can add information like carbonhydrate(%), GI and such, to help the system determine Xhardmin and Xhardmax.
So, all conditions have a minimum and a maximum effect.
Suppose c is a condition, then:
<math>c_{min}, c_{max} \in \mathbb{R}</math>
<math>c_{min} \le c_{max}</math>
Also, conditions can be contained in a group (set) of conditions S:
S = {c1, c2, ...}
Like conditions, such group of conditions S also has minimum and maxmimum cumulative effect. Such effect is the sum of all of the effects of its contained conditions:
Smin = c1min + c2min + ...
Smax = c1max + c2max + ...
Using intuition, I came up with the following theorem. I have to give it a name so lets call it Kingma's Theorem :). It's not formally proved yet, but the following seems to be true for all cases. Its actually quite logical.
If condition c is part of set S (and (S-c) is set S minus condition c')
and Smin and Smax are known
and chardmin and chardmax are known
then can be said:
(S-c)min = Smin - chardmax
(S-c)max = Smax - chardmin
Lets assume that at each blood glucose (BG) measurement, Cheetah starts its learning system. Cheetah looks at all conditions that could have an effect, and puts all type 1 conditions into group CE (certain effect) and all type 2 into group UE (uncertain effect).
Then, cheetah calculates the difference (min and max) between the BGmeasurement and predicted CE group effect. This difference should equal the UE group effect. So:
BGmeasurement = UEreal + CEreal
So:
UEmin = BGmeasurement - CEmax
UEmax = BGmeasurement - CEmin
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, chardmin and chardmax. But because the sum of effects (UE) is restricted , each individual effect for each condition must be somewhat more restricted. The possible effect range for each effect can be deduced from the total effect and the hardmin and hardmax value of the other effects. Using Kingma's Theorem, one can deduce the effect range of each individual condition.
Example 1.1
Lets look at a simple example of how a system would learn. Say, the user adds a glucose mearurement entry and the system starts its learning system. The user has taken a glass of applejuice A and a bread B. The user fills in a blood glucose measurement of 15.
The system knows a priori (from its database):
Ahardmin = 2
Ahardmax = 5
Bhardmin = 7
Bhardmax = 9
The system calculates the effect range these two items must have had:
UEmin = BGmeasurement - CEmax = 20 - 13 = 7
UEmax = BGmeasurement - CEmin = 20 - 9 = 11
Using Kingma's Theorem, The system then calculates the current Amin, Amax, Bmin, Bmax values:
(UE-A)min = UEmin - Ahardmax = 7 - 5 = 2 (this is under B's hardmin, so) => 7
(UE-A)max = UEmax - Ahardmin = 11 - 2 = 9 (not above B's hardmax, so keep it)
(UE-B)min = UEmin - Bhardmax = 7 - 9 = -2 (this is under A's hardmin, so) => 2
(UE-B)max = UEmax - Bhardmin = 11 - 7 = 4 (not above A's hardmax, so keep it)
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:
Amin = (UE-B)min = 2
Amax = (UE-B)max = 4
Bmin = (UE-A)min = 7
Bmax = (UE-A)max = 9
Above values indicate the possible current effect range of A and B. The system can use this to tweak its knowledge about the overall effect range of this values. This could be done by giving a condition a list of these calculated effect ranges. An algorithm then a mean (or something) of this list to use in effect prediction.
In other cases, when there are more then 2 conditions, the system iterates down a few levels to calculate the individual possible condition effect ranges. I will add such an example when I have time.
2. Bayesian Inference way
Lets forget the term 'condition' but the more intuitive term 'event' instead. So events are things like food intake (eg one glass of lemonade), insuline intake (one unit of type X), sports (half an hour of running), but also current health status and stress level etc. Before the system learns anything, each event is assigned an 'a priori' estimating curve, which tells us how, in time, the estimated effect on the blood glucose level 'g'. This a priori curve is assigned before any measurements have been made (example: the a priori curve for food could be based on known carbonhydrate). Quickly said, the learning system uses the blood glucose measurements to update and improve the estimating curve.
Lets describe these events, their effects and their computations, in terms of a statistics problem.
About events
Each single event <math>e_i</math> has three things.
1) Firstly: A set of samples. Each sample is a tuple (Δt, Δg) So the set of samples could be represented on a 2-dimensional area. The sample set is initially empty, and samples are added through bayesian inference (explained below). [For extra clarity, image to be added here].
2) A prior (a priori) function fe,prior(Δt) → Δg = μprior. This is the estimated mean effect of the event, for each determined before any samples have arrived. For food, it could be determined by looking at carbonhydrate amount. For insuline, it could be determined by medicine information. If no prior function can be made, an effect is assigned a default prior function. The prior function also has a pre-determined variance σprior². Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:
<math>\sigma_e^2 = \mbox{some-static-value} \,</math>
<math>\mu_e = \theta \,</math>
This parameter θ is unknown, but it has a prior distribution with
<math>\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,</math>
<math>\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,</math>
3) A posterior (a posteriori) function fe,post(Δt) → Δg. This is the esimated effect of the event after looking at the samples. It is determined as follows. The samples are divived into give time intervals, for example 15 minutes. So we have intervals ti with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals ti have a distribution θ with a prior distribution as explained above. The posterior distribution of ti is calculated as follows:
<math>\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}</math>
<math>\mu_{\theta, post}=\frac{\sigma_{\theta, prior}^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2\bar x_n}{\sigma_e^2+n\sigma_{\theta, prior}^2}</math>
To assign an evidence xi to each individual events ei you do:
<math>x_i=\mu_{prior}+a*\sigma_i^2</math>
where
<math>a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}</math>
So it comes down to some quite simple math. I'll make my explanation better when I have more time.