<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.aardrock.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DurkKingma</id>
	<title>AardRock Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.aardrock.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DurkKingma"/>
	<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/Special:Contributions/DurkKingma"/>
	<updated>2026-05-05T12:04:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2572</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2572"/>
		<updated>2006-07-17T14:21:48Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level and activities like driving, work, exercise, sleep&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. The posterior function should approximate the measured samples as good as possible.&lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2571</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2571"/>
		<updated>2006-07-17T12:50:29Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Preface ==&lt;br /&gt;
&lt;br /&gt;
In the second semester of the academic year 2005/2006 I participated in the course Software Project. The subject of my group was Cheetah - Artificial Pancreas. I choose this project since it came close to my interests, a mixture of computer science and biology. The 'Cheetah' project fitted nicely into this great mixture, since it software that is targeted at diabetics and their sickness, in all its social and physiological aspects.&lt;br /&gt;
The goal of the Cheetah software was clear: improve life quality of diabetics, make them deal with their sickness, and even have fun in the process.&lt;br /&gt;
The means to achieve this goal were more or less open: if had to be Open Source software, but we had to chose the language ourselves. We chose Java since we were quite familiar with the language, it is multi-platform.&lt;br /&gt;
The functionality of the software was specified by the &amp;quot;User Manual&amp;quot;, which was literally a user manual, descriptions of how the user should interact with the software including descriptions of system output.&lt;br /&gt;
One of these described functionalities was a 'Self-learning system', which was just vaguely talked about since the project manager was not an expert in the field. Talks with the manager revealed a description like &amp;quot;the learning system should learn about the user, and return advice about food or insulin intake&amp;quot;. The theory, design, and implemenation was completely left to the resosponsible 'self-learning system' subteam of the development team. At that time, the beginning of the project, this subteam actually consisted of one person, namely Just Boerlage. Halfway the project, three months later, this person left the team with hardly any progress on the learning system. This left a huge amount of work left to be done. I decided to try to attack the problem, eventually resulting in this paper.&lt;br /&gt;
&lt;br /&gt;
This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level and activities like driving, work, exercise, sleep&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. The posterior function should approximate the measured samples as good as possible.&lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Cheetah_Slim&amp;diff=2323</id>
		<title>Cheetah Slim</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Cheetah_Slim&amp;diff=2323"/>
		<updated>2006-06-13T21:42:39Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Als diabeticus ben je elke dag bezig met je glucosespiegel. Een te hoge glucosespiegel veroorzaakt beschadigingen aan het zenuwstelsel, terwijl een te lage glucosespiegel een persoon in coma kan brengen. Bijna alles in je dagelijkse leven heeft invloed op je suikerspiegel: voeding, sport, activiteiten, stress, en medicijngebruik.&lt;br /&gt;
&lt;br /&gt;
===De huidige situatie voor diabetici===&lt;br /&gt;
Om grip op de suikerspiegel te krijgen, houden diabetici elke dag een diabetesdagboek bij. Vervolgens kunnen ze patronen proberen te vinden in de relatie tussen ‘events’ als voedselinname, insulineinname, activiteiten enzovoorts en stijging of daling van je glucosespiegel. De arts helpt bij het vinden van patronen in het diabetesdagboek. Negatieve of positieve gevolgen van events kunnen dan vaak worden geschat.&lt;br /&gt;
Dit ‘klassieke’ systeem laten echter te wensen over. Diabetici kunnen, uit financiële en praktische overwegingen, niet op dagelijkse basis naar de arts voor consultatie. Als diabeticus ben je dan op jezelf aangewezen om bepaalde situaties goed in te schatten.  Vooral als ‘beginnende’ diabeticus is dit nog erg lastig.&lt;br /&gt;
&lt;br /&gt;
===De hulp van Cheetah===&lt;br /&gt;
Cheetah kan door zijn unieke kracht, een automatische leer- en adviessysteem, diabetici helpen om hun glucosespiegel binnen de grenzen te houden.&lt;br /&gt;
Het Cheetah leersysteem…&lt;br /&gt;
* Analyseert continu je digitale diabetesdagboek;&lt;br /&gt;
* Trekt hieruit conclusies over effect van voeding, activiteiten, etc.&lt;br /&gt;
Het Cheetah adviessysteem…&lt;br /&gt;
* Kan je toekomstige bloedsuikerspiegel voorspellen;&lt;br /&gt;
* Geeft je adviezen om je bloedsuikerspiegel binnen de grenzen te houden.&lt;br /&gt;
&lt;br /&gt;
===Tekst martien===&lt;br /&gt;
Diabetici en verzorgers ontdekken redelijk makkelijk en snel patronen in de effecten van voeding, stress, insulinedosering en sport op bloedsuikerspiegel&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;p style=&amp;quot;background: #fff6cc;&amp;quot;&amp;gt;De toekomst kan vaak voorspeld worden vanuit het verleden. Software heeft vaak moeite met het voorspellen van bloedsuikerwaardes op basis van de vele en continu veranderende gegevens. En omdat het systeem niet meegroeit met haar gebruiker veroudert het snel en wordt waardeloos.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Maak daarom gebruik van incrementele zelflerende en evoluerende deelsystemen die elkaar en ook de gebruiker scherp houden. De evolutionaire aspecten zorgen voor een continue aanpassing aan veranderende omstandigheden. Het systeem groeit zo mee met haar gebruikers.&lt;br /&gt;
&lt;br /&gt;
===Groei mee tijdens de Cheetah Zomer 2006-lancering===&lt;br /&gt;
Ervaar de eerste werkende zelflerende prototype van Cheetah op 4 juli 2006 wordt tijdens de [[Cheetah Zomer 2006]]-lancering. Betere bloedsuikerspiegels en een gezonder langer leven.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2317</id>
		<title>LogboekDurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2317"/>
		<updated>2006-06-13T15:42:53Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; Datum           Tijd           Duur            Cumulatief    Activiteit&lt;br /&gt;
 --------------- -------------- --------------- ------------- ----------------------------------------&lt;br /&gt;
 8 februari      13-17          4               4             Eerste overleg en taakverdeling&lt;br /&gt;
 11 februari      9-11          2               6             Inlezen op Agile Development&lt;br /&gt;
 13 februari     12-14          2               8             Cruise Control onderzocht, nu pas door ziekte.&lt;br /&gt;
                 15-17          2               10            Vergadering&lt;br /&gt;
 14 februari     15-17          2               12            XP Game&lt;br /&gt;
 16 februari      9-12          3               15            WiredReach fundamenten uitgezocht&lt;br /&gt;
 20 februari     15-17          2               17            vergadering&lt;br /&gt;
                 20-22          2               19            Notulen uitgewerkt / Op het web gezet&lt;br /&gt;
 21 februari      9-15          6               25            WiredReach/Eclipse platform onderzoeken (met Martijn)&lt;br /&gt;
 22 februari      9-10          1               26            Wiki logboek gebouwd&lt;br /&gt;
                 10-14          4               30            WiredReach/Eclipse platform onderzoeken&lt;br /&gt;
 25 februari     12-18          6               36            Implementatie WiredReach proef&lt;br /&gt;
 27 februari      9-15          6               42            JXTA/Andere protocollen vergeleken&lt;br /&gt;
                 15-17          2               44            Vergadering&lt;br /&gt;
 28 februari     15-17          4               45            AardRock vergadering&lt;br /&gt;
 5 maart          9-15          6               51            Onderzoek WiredReach/JXTA&lt;br /&gt;
                 15-17          2               53            Vergadering&lt;br /&gt;
 6 maart         15-17          2               55            Vergadering AardRock&lt;br /&gt;
                 12-16          4               59            Lunch, vergaderd over implementatie P2P gedeelte         &lt;br /&gt;
 13 maart        15-17          2               61            Vergadering&lt;br /&gt;
 16 maart        9-13           4               64            Uitwerking/Uitdenken P2P communicatie datamodel&lt;br /&gt;
 21 maart        15-17          2               67            Vergadering AardRock&lt;br /&gt;
 23 maart        9-15           6               73            De-Eclipsed WiredReach, aan RDF Black Box gewerkt, Jena uitgezocht.&lt;br /&gt;
 27 maart        10-17          3               76            RDF Black Box uitgewerkt, vergadering &lt;br /&gt;
 28 maart        15-17          2               78            Vergadering AardRock&lt;br /&gt;
 18 april        14-17          3               81            Vergadering Aardrock / Proefpresentatie&lt;br /&gt;
 19 april        15-17          2               83            Overleg adviessysteem met Just&lt;br /&gt;
 25 april        9-15           6               89            Neuraal Netwerk vergadering / Adviessysteem cheetah&lt;br /&gt;
                 15-17          2               91            Vergadering Cheetah&lt;br /&gt;
 27 april        9-17           8               99            Bayesiaans netwerk / neuraal netwerk / onderzoek algoritmes&lt;br /&gt;
 28 april        9-11           2               101           Uitzoeken andere adviessoftware / dagboeken / mailen Harold de Valk&lt;br /&gt;
 28 april        11-12          1               102           Update logboek&lt;br /&gt;
 29 april        12-14          2               104           Adviessysteem (AIDA, Neural Networks, Kernel Machines)&lt;br /&gt;
 30 april        12-15          3               107           Adviessysteem (AIDA bestudeerd, alternatieven, schetsen)&lt;br /&gt;
 1 mei           12-14          2               109           Adviessysteem (AIDA, kernel machines)&lt;br /&gt;
 2 mei           10-19          9               118           Adviessysteem (Op wiki gezet, schema's gemaakt, besproken met diverse mensen)&lt;br /&gt;
 3 mei           12-13          2               120           Mailtjes, AI boek doorgespit over fuzzy logic&lt;br /&gt;
 4 mei           11-14          3               123           AI boek doorgespit, gelezen: http://www.fao.org/docrep/w8079e/w8079e00.htm&lt;br /&gt;
                 14-17          3               126           Verder literatuuronderzoek over effect van voeding/insuline/activities&lt;br /&gt;
 6 mei           11-5           6               132           [[Condition Effect Learning]]&lt;br /&gt;
 7 mei           5-6            1               133           Solved major condition effect learning problem.&lt;br /&gt;
                 11-15          4               136           Worked out the formula (&amp;quot;Kingma's Theorem&amp;quot;) and put it on the wiki.&lt;br /&gt;
                                                              Thought about better solutions to the condition effect learning problem.&lt;br /&gt;
 8 mei           20-24          4               140           Received usefull information about a patient (logbooks, medical dossier etc)&lt;br /&gt;
 9 mei           10-16          6               146           Worked at statistical problem, talked Giel about GUI and Peter de Waal about Bayesian Learning&lt;br /&gt;
 10 mei          15-17          2               148           Aardrock meeting. Explained some theories.&lt;br /&gt;
 11 mei          20-22          2               150           Formulated advisory limitations&lt;br /&gt;
 16 mei          15-18          3               153           Aardrock meeting / Advisory System&lt;br /&gt;
 19 mei &lt;br /&gt;
 20 mei          12-17          5               158           Brushing up on statistics.&lt;br /&gt;
 21 mei          14-20          6               164           Idem. reviewed (Biased) Estimators, marginalization, maximum likelihood functions, and bayesian inference (further)&lt;br /&gt;
 22 mei          14-15          1               165           Statistiek onderzocht.&lt;br /&gt;
 23 mei          14-17+21-01    7               172           Statistisch probleem opgelost! Zie [Condition Effect Learning], meer info volgt&lt;br /&gt;
 24 mei          10-11          1               173           Aantal kleine dingen opgezocht&lt;br /&gt;
 27 mei          12-18          6               179           Bayesiaanse inferentie.&lt;br /&gt;
 30 mei          13-18          5               184           Aardrock vergadering + Adviessyst.&lt;br /&gt;
 31 mei          16-24          8               192           Gemaild, formules uitgewerkt, aanpassingen aan wiki&lt;br /&gt;
 1 juni          13-17          4               196           Idem&lt;br /&gt;
 2 juni          14-17          3               199           Worked on Learning System wiki page, mailed etc&lt;br /&gt;
 3 juni          21-01          4               203           Finish Learning System wiki page and compiled an explanatory image&lt;br /&gt;
 11 juni         11-14          3               206           Programmeren&lt;br /&gt;
 12 juni         12-16          4               210           Programmeren&lt;br /&gt;
 13 juni         16-1730        1.5             211.5         Programmeren&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=LogboekSjoerdVanKreel&amp;diff=2316</id>
		<title>LogboekSjoerdVanKreel</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=LogboekSjoerdVanKreel&amp;diff=2316"/>
		<updated>2006-06-13T15:39:37Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:left;&amp;quot; border=&amp;quot;1px solid grey&amp;quot; cellspacing=0 &lt;br /&gt;
|- &lt;br /&gt;
||'''Datum'''||'''Activiteit'''||'''Van'''||'''Tot'''||'''Duur'''||'''Cumulatief'''&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-08||Vergadering||13:00||16:00||03:00||03:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-13||Vergadering||15:00||17:00||02:00||05:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-14||Vergadering||15:00||17:00||02:00||07:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-20||Vergadering||15:00||17:00||02:00||09:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-20||Installeren/testen Eclipse + SVN||20:00||20:45||00:45||09:45&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-20||Doornemen java codeconventies||20:45||21:30||00:45||10:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-21||Werken aan story update check||09:00||13:00||04:00||14:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-21||Werken aan story update check||13:30||15:00||01:30||16:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-21||Vergadering||15:00||17:00||02:00||18:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-21||Werken aan story update check||12:30||17:30||05:00||21:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-21||Werken aan story update check||20:00||21:00||01:00||22:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-24||Toevoegen design thought en agenda, bewerken notulen||17:30||18:30||01:00||23:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-26||Werken aan story update check||22:00||00:00||02:00||25:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-27||Werken aan story update check||12:00||15:00||03:00||28:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-27||Vergadering||15:00||17:00||02:00||30:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-27||Werken aan story installatie||21:30||23:30||02:00||32:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-28||Werken aan story installatie||13:00||15:00||02:00||34:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-02-28||Vergadering||15:00||17:00||02:00||36:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-01||Werken aan story update demo||11:00||17:30||06:30||42:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-02||Werken aan story update demo||19:30||22:30||03:00||45:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-03||Werken aan story update demo||11:00||19:00||08:00||53:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-06||Testen story update demo||13:00||15:00||02:00||55:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-06||Vergadering||15:00||17:00||02:00||57:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-13||Lezen usermanual 1.0, nadenken over rdf ontwerp||14:00||15:00||01:00||58:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-13||Vergadering||15:00||17:00||02:00||60:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-20||Vergadering &amp;amp; stories uitzoeken||15:15||16:30||01:15||61:45&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-20||Story 25: tabel maken van story overview||17:45||18:15||00:30||62:15&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-21||Installeren subversion en functioneringsgesprek||12:00||15:15||3:15||65:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-21||Vergadering||15:15||17:15||02:00||67:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-21||Installeren subversion||20:00||22:30||02:30||70:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-22||Installeren subversion||16:00||18:00||02:00||72:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-22||Installeren subversion||19:00||20:00||01:00||73:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-27||Doornemen Platonos||14:00||15:00||01:00||74:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-27||Vergadering||15:00||16:15||01:15||75:15&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-27||Updates via platonos||10:00||16:00||06:00||81:15&lt;br /&gt;
|- &lt;br /&gt;
||2006-03-27||Vergadering||16:00||17:00||01:00||82:15&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-03||Updates via platonos||12:00||15:00||03:00||85:15&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-03||Vergadering||15:00||16:15||01:15||86:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-04||Updates via platonos||10:00||15:30||05:30||92:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-04||Vergadering||15:30||16:30||01:00||93:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-05||Updates via platonos||11:00||17:00||06:00||99:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-07||Updates via platonos||11:00||14:00||03:00||102:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-10||Updates via platonos||10:30||15:30||05:00||107:00&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-10||Vergadering||15:30||16:00||00:30||107:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-10||Updates via platonos||16:00||17:00||01:00||108:30&lt;br /&gt;
|- &lt;br /&gt;
||2006-04-11||Updates via platonos||9:00||17:00||08:00||116:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-18||Vergadering + story installatie||14:00||17:00||03:00||119:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-19||story installatie||16:00||19:30||03:30||123:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-24||story updates + tussentijdse presentaties||11:00||17:00||06:00||129:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-25||story updates + vergadering||10:30||17:00||06:30||135:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-26||meenemen browser launcher in  ant build||09:00||11:00||02:00||137:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-04-26||werken aan updates||13:00||15:00||02:00||139:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-01||installer publishen voor v0.0.3||20:00||22:00||02:00||141:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-02||performance + presentatie giel||10:30||17:30||07:00||148:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-03||performance + structuur||13:00||18:00||05:00||153:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-08||performance + structuur||13:00||14:00||01:00||154:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-08||UI||11:00||17:30||06:30||161:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-11||UI||14:00||18:00||04:00||165:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-16||UI||11:30||17:30||06:00||172:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-22||UI/FilteredComboBox||16:00||20:00||04:00||176:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-23||UI/FilteredComboBox||11:00||18:00||07:00||183:00&lt;br /&gt;
|-&lt;br /&gt;
||2006-05-30||UI/FilteredComboBox, vergadering||13:15||17:45||04:30||187:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-06-06||UI / presentatie / vergadering||11:30||17:30||06:00||193:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-06-12||UI||13:00||22:00||09:00||202:30&lt;br /&gt;
|-&lt;br /&gt;
||2006-06-13||UI||11:30||17:30||06:00||208:30&lt;br /&gt;
|- }&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2200</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2200"/>
		<updated>2006-06-05T11:17:43Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Glucose level estimation */ added activities like driving, work, exercise, sleep&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level and activities like driving, work, exercise, sleep&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. The posterior function should approximate the measured samples as good as possible.&lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2199</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2199"/>
		<updated>2006-06-04T11:48:52Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* 2c. Update posterior values */ correction of formula&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_{\theta, prior}^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. The posterior function should approximate the measured samples as good as possible.&lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2198</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2198"/>
		<updated>2006-06-04T10:06:49Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* 2d. Update posterior f(x) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. The posterior function should approximate the measured samples as good as possible.&lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2197</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2197"/>
		<updated>2006-06-04T09:55:49Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Learning System, ignite your engine! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Update posterior f(x) ====&lt;br /&gt;
&lt;br /&gt;
Now the function f(x), or its parameters, can be updated similar to the methods in &amp;quot;Generating of a fprior(t) or its prior parameters&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
==== 2e. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2196</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2196"/>
		<updated>2006-06-03T23:17:07Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* The function f(t) */  new event type: progress into pregnancy&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* For pregnancy diabetes: progress of pregnancy. Its hormone decreases insulin sensivity.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2195</id>
		<title>LogboekDurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2195"/>
		<updated>2006-06-03T22:37:46Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; Datum           Tijd           Duur            Cumulatief    Activiteit&lt;br /&gt;
 --------------- -------------- --------------- ------------- ----------------------------------------&lt;br /&gt;
 8 februari      13-17          4               4             Eerste overleg en taakverdeling&lt;br /&gt;
 11 februari      9-11          2               6             Inlezen op Agile Development&lt;br /&gt;
 13 februari     12-14          2               8             Cruise Control onderzocht, nu pas door ziekte.&lt;br /&gt;
                 15-17          2               10            Vergadering&lt;br /&gt;
 14 februari     15-17          2               12            XP Game&lt;br /&gt;
 16 februari      9-12          3               15            WiredReach fundamenten uitgezocht&lt;br /&gt;
 20 februari     15-17          2               17            vergadering&lt;br /&gt;
                 20-22          2               19            Notulen uitgewerkt / Op het web gezet&lt;br /&gt;
 21 februari      9-15          6               25            WiredReach/Eclipse platform onderzoeken (met Martijn)&lt;br /&gt;
 22 februari      9-10          1               26            Wiki logboek gebouwd&lt;br /&gt;
                 10-14          4               30            WiredReach/Eclipse platform onderzoeken&lt;br /&gt;
 25 februari     12-18          6               36            Implementatie WiredReach proef&lt;br /&gt;
 27 februari      9-15          6               42            JXTA/Andere protocollen vergeleken&lt;br /&gt;
                 15-17          2               44            Vergadering&lt;br /&gt;
 28 februari     15-17          4               45            AardRock vergadering&lt;br /&gt;
 5 maart          9-15          6               51            Onderzoek WiredReach/JXTA&lt;br /&gt;
                 15-17          2               53            Vergadering&lt;br /&gt;
 6 maart         15-17          2               55            Vergadering AardRock&lt;br /&gt;
                 12-16          4               59            Lunch, vergaderd over implementatie P2P gedeelte         &lt;br /&gt;
 13 maart        15-17          2               61            Vergadering&lt;br /&gt;
 16 maart        9-13           4               64            Uitwerking/Uitdenken P2P communicatie datamodel&lt;br /&gt;
 21 maart        15-17          2               67            Vergadering AardRock&lt;br /&gt;
 23 maart        9-15           6               73            De-Eclipsed WiredReach, aan RDF Black Box gewerkt, Jena uitgezocht.&lt;br /&gt;
 27 maart        10-17          3               76            RDF Black Box uitgewerkt, vergadering &lt;br /&gt;
 28 maart        15-17          2               78            Vergadering AardRock&lt;br /&gt;
 18 april        14-17          3               81            Vergadering Aardrock / Proefpresentatie&lt;br /&gt;
 19 april        15-17          2               83            Overleg adviessysteem met Just&lt;br /&gt;
 25 april        9-15           6               89            Neuraal Netwerk vergadering / Adviessysteem cheetah&lt;br /&gt;
                 15-17          2               91            Vergadering Cheetah&lt;br /&gt;
 27 april        9-17           8               99            Bayesiaans netwerk / neuraal netwerk / onderzoek algoritmes&lt;br /&gt;
 28 april        9-11           2               101           Uitzoeken andere adviessoftware / dagboeken / mailen Harold de Valk&lt;br /&gt;
 28 april        11-12          1               102           Update logboek&lt;br /&gt;
 29 april        12-14          2               104           Adviessysteem (AIDA, Neural Networks, Kernel Machines)&lt;br /&gt;
 30 april        12-15          3               107           Adviessysteem (AIDA bestudeerd, alternatieven, schetsen)&lt;br /&gt;
 1 mei           12-14          2               109           Adviessysteem (AIDA, kernel machines)&lt;br /&gt;
 2 mei           10-19          9               118           Adviessysteem (Op wiki gezet, schema's gemaakt, besproken met diverse mensen)&lt;br /&gt;
 3 mei           12-13          2               120           Mailtjes, AI boek doorgespit over fuzzy logic&lt;br /&gt;
 4 mei           11-14          3               123           AI boek doorgespit, gelezen: http://www.fao.org/docrep/w8079e/w8079e00.htm&lt;br /&gt;
                 14-17          3               126           Verder literatuuronderzoek over effect van voeding/insuline/activities&lt;br /&gt;
 6 mei           11-5           6               132           [[Condition Effect Learning]]&lt;br /&gt;
 7 mei           5-6            1               133           Solved major condition effect learning problem.&lt;br /&gt;
                 11-15          4               136           Worked out the formula (&amp;quot;Kingma's Theorem&amp;quot;) and put it on the wiki.&lt;br /&gt;
                                                              Thought about better solutions to the condition effect learning problem.&lt;br /&gt;
 8 mei           20-24          4               140           Received usefull information about a patient (logbooks, medical dossier etc)&lt;br /&gt;
 9 mei           10-16          6               146           Worked at statistical problem, talked Giel about GUI and Peter de Waal about Bayesian Learning&lt;br /&gt;
 10 mei          15-17          2               148           Aardrock meeting. Explained some theories.&lt;br /&gt;
 11 mei          20-22          2               150           Formulated advisory limitations&lt;br /&gt;
 16 mei          15-18          3               153           Aardrock meeting / Advisory System&lt;br /&gt;
 19 mei &lt;br /&gt;
 20 mei          12-17          5               158           Brushing up on statistics.&lt;br /&gt;
 21 mei          14-20          6               164           Idem. reviewed (Biased) Estimators, marginalization, maximum likelihood functions, and bayesian inference (further)&lt;br /&gt;
 22 mei          14-15          1               165           Statistiek onderzocht.&lt;br /&gt;
 23 mei          14-17+21-01    7               172           Statistisch probleem opgelost! Zie [Condition Effect Learning], meer info volgt&lt;br /&gt;
 24 mei          10-11          1               173           Aantal kleine dingen opgezocht&lt;br /&gt;
 27 mei          12-18          6               179           Bayesiaanse inferentie.&lt;br /&gt;
 30 mei          13-18          5               184           Aardrock vergadering + Adviessyst.&lt;br /&gt;
 31 mei          16-24          8               192           Gemaild, formules uitgewerkt, aanpassingen aan wiki&lt;br /&gt;
 1 juni          13-17          4               196           Idem&lt;br /&gt;
 2 juni          14-17          3               199           Worked on Learning System wiki page, mailed etc&lt;br /&gt;
 3 juni          21-01          4               203           Finish Learning System wiki page and compiled an explanatory image&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=User:DurkKingma&amp;diff=2194</id>
		<title>User:DurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=User:DurkKingma&amp;diff=2194"/>
		<updated>2006-06-03T22:34:58Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Logboek: [[LogboekDurkKingma]]&lt;br /&gt;
&lt;br /&gt;
==Personal Data==&lt;br /&gt;
&lt;br /&gt;
* Born May 30, 1983&lt;br /&gt;
* Adress: Weerdsingel Oostzijde 1bis, 3514AA, Utrecht, The Netherlands&lt;br /&gt;
* Contact phone: +31641511577 &lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* September 2002 until ...: Computer science at Utrecht University. Minors: Medical Technical Science &lt;br /&gt;
&lt;br /&gt;
==Extracurricular Interests==&lt;br /&gt;
&lt;br /&gt;
* 2006: Organizer of the 123th Varsity (national student rowing championships)&lt;br /&gt;
* 2006: Organizer of the 1st Nacht van de Fooi (3rd world fundraising)&lt;br /&gt;
* Sports (Rowing, Hockey, Golf, Hiking)&lt;br /&gt;
* Student life (USC/going out)&lt;br /&gt;
* Traveling&lt;br /&gt;
&lt;br /&gt;
==Practical Computing Skills==&lt;br /&gt;
&lt;br /&gt;
* Java&lt;br /&gt;
* (X)HTML, CSS&lt;br /&gt;
* PHP, SQL&lt;br /&gt;
* Haskell, Z80 Assembly, other 'educational' languages &lt;br /&gt;
&lt;br /&gt;
==Work Experience==&lt;br /&gt;
&lt;br /&gt;
* (2004) KPN ADSL&lt;br /&gt;
* (2005-...) Operator Groep Delft&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2193</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2193"/>
		<updated>2006-06-03T22:31:30Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: added glycemic response estimation image&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
[[Image:Summing_events.png|thumb|right|Example of glucose level estimation.]]&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=File:Summing_events.png&amp;diff=2192</id>
		<title>File:Summing events.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=File:Summing_events.png&amp;diff=2192"/>
		<updated>2006-06-03T22:29:25Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: Example of summing events using the bayesian learning system.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Example of summing events using the bayesian learning system.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=User:DurkKingma&amp;diff=2191</id>
		<title>User:DurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=User:DurkKingma&amp;diff=2191"/>
		<updated>2006-06-03T21:26:00Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Logboek: [[LogboekDurkKingma]]&lt;br /&gt;
&lt;br /&gt;
==Personal Data==&lt;br /&gt;
&lt;br /&gt;
* Born May 30, 1983&lt;br /&gt;
* Adress: Weerdsingel Oostzijde 1bis, 3514AA, Utrecht&lt;br /&gt;
* Contact phone: +31641511577 &lt;br /&gt;
&lt;br /&gt;
==Education==&lt;br /&gt;
&lt;br /&gt;
* September 2002 until ...: Computer science at Utrecht University. Minors: Medical Technical Science &lt;br /&gt;
&lt;br /&gt;
==Hobbies / Extracurricular stuff==&lt;br /&gt;
&lt;br /&gt;
* 2006: Organizer of the 123th Varsity (national student rowing championships)&lt;br /&gt;
* 2006: Organizer of the 1st Nacht van de Fooi (3rd world fundraising)&lt;br /&gt;
* Sports (Rowing, Hockey, Golf, Hiking)&lt;br /&gt;
* Student life (USC/going out)&lt;br /&gt;
* Traveling&lt;br /&gt;
&lt;br /&gt;
==Skills==&lt;br /&gt;
&lt;br /&gt;
* Java&lt;br /&gt;
* (X)HTML, CSS&lt;br /&gt;
* PHP, SQL&lt;br /&gt;
* Haskell, Z80 Assembly, other 'educational' languages &lt;br /&gt;
&lt;br /&gt;
==Work Experience==&lt;br /&gt;
&lt;br /&gt;
* (2004) KPN ADSL&lt;br /&gt;
* (2005-...) Operator Groep Delft&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2190</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2190"/>
		<updated>2006-06-03T21:16:26Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Bayesian Inference */ more corrections on posterior formula&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar s&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar s}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2189</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2189"/>
		<updated>2006-06-03T21:06:44Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; = */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \times \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; ti &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar x_n&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar x_n}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2188</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2188"/>
		<updated>2006-06-03T21:04:30Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Bayesian Inference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\}\!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; ti &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar x_n&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar x_n}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2187</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2187"/>
		<updated>2006-06-03T21:03:33Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Learning System, ignite your engine! */ corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n\\!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\\!}&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i\!&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}\!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;\{e_1,e_2,...,e_n\}\!&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \sigma_i \!&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}\!&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i\!&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2\!&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; ti &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar x_n&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;\{s_1 s_2,...,s_n,s_i\}\!&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar x_n}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== 2d. Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2186</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2186"/>
		<updated>2006-06-03T20:56:05Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Bayesian Inference */ concluded last text.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. The variance &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is a static value, and we assign some reasonable value to it, defined by the event type (like 3 for food or something). The mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;{s_1 s_2,...,s_n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event i has a &amp;lt;math&amp;gt;f_i(t_{g2}-t_{ei}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_i \pm \sigma_i&amp;lt;/math&amp;gt; are (synonyms of) these posterior mean and variance values for event i, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
&lt;br /&gt;
This step is looped trough all events i in &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;s_i = \mu_i + a \sigma_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, ask me.&lt;br /&gt;
&lt;br /&gt;
While &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; is the most likely subsample of &amp;lt;math&amp;gt;s_{tot}&amp;lt;/math&amp;gt;, it is still an estimation. How well it comes close to the 'real' value of &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; depends on the precision of the posterior variables &amp;lt;math&amp;gt;\mu_{\theta,post} \pm \sigma_{\theta,post}^2&amp;lt;/math&amp;gt;. Like written above, the initial values of these 'a posteriori' variables are close to the 'a prior' variables, so it can't be pressed enough that these prior variables are important.&lt;br /&gt;
&lt;br /&gt;
(Maybe an improvement would be to store the supersample in combination with the event types somewhere. Old supersamples can then be used again to compute even more likely posterior distributions. This whole routine can then be iterated of all glucose measurements)&lt;br /&gt;
&lt;br /&gt;
==== 2b. Add &amp;lt;math&amp;gt;s_i&amp;lt;/math&amp;gt; ti &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt;'s sample set ====&lt;br /&gt;
&lt;br /&gt;
Now that we have a new subsample, we can add it to its sample set: &amp;lt;math&amp;gt;{s_1 s_2,...,s_n,s_i}&amp;lt;/math&amp;gt;. Now this is used to update the posterior values of i.&lt;br /&gt;
&lt;br /&gt;
==== 2c. Update posterior values ====&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\sigma_t^2&amp;lt;/math&amp;gt; is the static event variance, and &amp;lt;math&amp;gt;\bar x_n&amp;lt;/math&amp;gt; is the mean value of &amp;lt;math&amp;gt;{s_1 s_2,...,s_n,s_i}&amp;lt;/math&amp;gt;, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, post}=\frac{\sigma_t^2\mu_{\theta, prior}+n\sigma_t^2 \bar x_n}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_t^2\sigma_{\theta, prior}^2}{\sigma_t^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For proof, see &amp;quot;Morris H.DeGroot and Mark J.Schervish. ''Probability and Statistics, third edition'': blz 330&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Repeat ====&lt;br /&gt;
&lt;br /&gt;
Repeat 2a-2c for each i, and all worthfull composites.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2185</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2185"/>
		<updated>2006-06-03T20:15:38Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. We say that the variance is a static, and the mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;{s_1 s_2,...,s_n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event k has a , &amp;lt;math&amp;gt;f_k(t_{g2}-t_{ek}) \to \mu_{\theta,post} \pm \sigma_{\theta,post}^2&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mu_k \pm \sigma_k&amp;lt;/math&amp;gt; are these posterior mean and variance values for event k, and (g2-g1) is the measured glucose rise/fall, then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{(g2-g1)-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
This step is looped trough all events k in &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Furthermore this loops through composite events &amp;lt;math&amp;gt;{e_a+e_b+e_c,e_d+e_e,...}&amp;lt;/math&amp;gt; which are combinations events that happen at the same time. Time t is measured in intervals, so the chance that events happen at the same t is quite big. &lt;br /&gt;
&lt;br /&gt;
==== 2a. Calculate subsample for event k =====&lt;br /&gt;
Now we can calculate the subsample &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; for event k. What is this? The user did a new glucose measurement, and the system sees the difference in glucose level (g2-g1): in statistical terms, (g2-g1) is our new composite sample &amp;lt;math&amp;gt;x_{tot}&amp;lt;/math&amp;gt;. This sample is actually a composite sample, because it is caused by the sum of all events &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. So to add a sample to each single event, the system needs to divide this composite sample into subsamples, one for each event. Using our calculated helper variable ''a'', we do this using this simple formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_k = \mu_k + a * &lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2184</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2184"/>
		<updated>2006-06-03T19:53:46Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Bayesian Inference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;f(t) = \mu_t \pm \sigma_t^2&amp;lt;/math&amp;gt;. We say that the variance is a static, and the mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;. This unkonwn paramter &amp;amp;theta; is exactly (and only) thing we need to learn for each t. &amp;amp;theta; is where its all about. And each event type has a whole line of &amp;amp;theta;'s because it has one &amp;amp;theta; for each ''t''. To be able to compute &amp;amp;theta;, we need to see it as a normal distribution too: &amp;lt;math&amp;gt;\theta = \mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And now we can use our prior and posterior functions. The f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type. Through bayesian inference, which functions we will soon explain, we will compute the &amp;lt;math&amp;gt;\mu_\theta \pm \sigma_\theta^2&amp;lt;/math&amp;gt; for each t for each event type: the &amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function.&lt;br /&gt;
&lt;br /&gt;
Using samples, we can use Bayesian inference to compute &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t. This will be explained in the following section.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;{s_1 s_2,...,s_n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Each event e&amp;lt;sub&amp;gt;k&amp;lt;/sub&amp;gt; has an event type with attributes described above, a timestamp t&amp;lt;sub&amp;gt;ek&amp;lt;/sub&amp;gt;, and a multiplicity indicator. &lt;br /&gt;
&lt;br /&gt;
==== 1. Calculate helper variable a ====&lt;br /&gt;
The first thing we calculate is the helper variable ''a''. Each event k has a , &amp;lt;math&amp;gt;f_k(t_{g2}-t_{ek}) \to \mu_{ek} \pm \sigma_{ek}^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{g2-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 2. Update event knowledge ====&lt;br /&gt;
This step is looped trough all events &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt;. Furthermore this loops through composites, which are events that happen at the same time. Time is measured in intervals, so this chance is rather big.&lt;br /&gt;
&lt;br /&gt;
===== 2a. ======&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2183</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2183"/>
		<updated>2006-06-03T10:59:36Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Glucose level estimation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycemic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each the function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;\mu \pm \sigma^2&amp;lt;/math&amp;gt;. We say that the variance is a static, and the mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;.&lt;br /&gt;
&lt;br /&gt;
This unknown parameter &amp;amp;theta; is exactly the thing we need to know for each f(t). This is the parameter where we define the prior function for, and each to&lt;br /&gt;
&lt;br /&gt;
 o be clear: the f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values for an effect. Likewise, The f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function defines the posterior mean values of an effect, initially equal to f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
This way, using samples, we can use Bayesian inference to calculate a &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;{s_1 s_2,...,s_n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt; each having an event type with attributes described above plus a multiplicity indicator. So e1 has a &amp;amp;mu;&amp;lt;sub&amp;gt;e1&amp;lt;/sub&amp;gt; and a &lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{g2-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2178</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2178"/>
		<updated>2006-06-02T15:24:10Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we must describe the problem in terms of statistics. Following this viewpoint, one could say at t, there is a ''mean'' estimated value and variance value indicating the mean error. This way we describe each the function in terms of a normal (Gaussian) distribution. So each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;\mu \pm \sigma^2&amp;lt;/math&amp;gt;. We say that the variance is a static, and the mean value &amp;amp;mu; is the to be estimated variable, or the unknown parameter &amp;amp;theta;.&lt;br /&gt;
&lt;br /&gt;
This unknown parameter &amp;amp;theta; is exactly the thing we need to know for each f(t). This is the parameter where we define the prior function for, and each to&lt;br /&gt;
&lt;br /&gt;
 o be clear: the f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) function defines the prior mean values for an effect. Likewise, The f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) function defines the posterior mean values of an effect, initially equal to f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
This way, using samples, we can use Bayesian inference to calculate a &amp;amp;mu;&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt; for each t.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described in above sections, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples &amp;lt;math&amp;gt;{s_1 s_2,...,s_n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was g1 at t&amp;lt;sub&amp;gt;g1&amp;lt;/sub&amp;gt; with value g1. Now we do a new glucose measurement g2 at t&amp;lt;sub&amp;gt;g2&amp;lt;/sub&amp;gt; with value g2. The set of events that have impact on glucose level g2 is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt; each having an event type with attributes described above plus a multiplicity indicator. So e1 has a &amp;amp;mu;&amp;lt;sub&amp;gt;e1&amp;lt;/sub&amp;gt; and a &lt;br /&gt;
&lt;br /&gt;
The first thing we calculate is the helper variable ''a'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{g2-(\mu_e1+\mu_e2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2176</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2176"/>
		<updated>2006-06-02T14:25:35Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: \\Statistical nature of the function f(t) intermediate save&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
=== The function f(t) ===&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
=== g2 Estimation ===&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) or its prior parameters ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
=== Attributes of event types ===&lt;br /&gt;
&lt;br /&gt;
Summarizing what we have said above, each event type has the following attributes:&lt;br /&gt;
* An a priori function f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A (initially empty) set of samples, each a tuple {t,dg} with t=time and dg=delta-g, the glycemic response.&lt;br /&gt;
* An a posteriori function f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
&lt;br /&gt;
The following section will describe the process of computation of f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Statistical nature of the function f(t) ===&lt;br /&gt;
&lt;br /&gt;
In the texts above, we wrote about the glycemic response functions f(t), like f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) and f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions. For inference reasons, because we are using bayesian inference, we describe. Each point ''t'' doesnt map to just one value, but to two: mean &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; and squared variance &amp;lt;math&amp;gt;\sigma^2&amp;lt;/math&amp;gt;, written as &amp;lt;math&amp;gt;\mu \pm \sigma^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine! ===&lt;br /&gt;
&lt;br /&gt;
Assume that with formula's described above, we are given a group of event types, each event type has a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t). Additionally, each event type has an initially empty set of samples.&lt;br /&gt;
&lt;br /&gt;
Assume the last glucose measurement was ''n'', and the measuring instrument gave a value of g&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;. Assume we have some time in the near future &amp;lt;i&amp;gt;t&amp;lt;/i&amp;gt;, and the system or user wants to estimate the glucose level which we will call g&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt;. The set of events that have impact on glucose level at &amp;lt;i&amp;gt;t&amp;lt;/i&amp;gt; is &amp;lt;math&amp;gt;{e_1,e_2,...,e_n}&amp;lt;/math&amp;gt; with each an event type with attributes described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2175</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2175"/>
		<updated>2006-06-02T13:22:40Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: added Learning System, ignite your engine!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
&lt;br /&gt;
* Stress level.&lt;br /&gt;
&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
&lt;br /&gt;
* Health status.&lt;br /&gt;
&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty about the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Generating of a f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) (/or its initial parameters) ===&lt;br /&gt;
So what are the steps of creating f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) for certain event types? For...&lt;br /&gt;
&lt;br /&gt;
* Food intake, calculate the ''a'' and ''b'' paramaters (for information about these parameters, see above). [Mapping of Carbonhydrate count to ''a'' and ''b'' parameters to be added]&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. [To do]&lt;br /&gt;
&lt;br /&gt;
* Stress level. [To do]&lt;br /&gt;
&lt;br /&gt;
* Time of the day. [To do]&lt;br /&gt;
&lt;br /&gt;
* Health status. [To do]&lt;br /&gt;
&lt;br /&gt;
* Other event types. [To do]&lt;br /&gt;
&lt;br /&gt;
The following section will explain how to compute an a posteriori function using glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
So how does the system calculate f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x)? And how are the samples created?&lt;br /&gt;
&lt;br /&gt;
=== Learning System, ignite your engine!&lt;br /&gt;
&lt;br /&gt;
Assume we functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2164</id>
		<title>LogboekDurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2164"/>
		<updated>2006-06-02T10:30:14Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; Datum           Tijd           Duur            Cumulatief    Activiteit&lt;br /&gt;
 --------------- -------------- --------------- ------------- ----------------------------------------&lt;br /&gt;
 8 februari      13-17          4               4             Eerste overleg en taakverdeling&lt;br /&gt;
 11 februari      9-11          2               6             Inlezen op Agile Development&lt;br /&gt;
 13 februari     12-14          2               8             Cruise Control onderzocht, nu pas door ziekte.&lt;br /&gt;
                 15-17          2               10            Vergadering&lt;br /&gt;
 14 februari     15-17          2               12            XP Game&lt;br /&gt;
 16 februari      9-12          3               15            WiredReach fundamenten uitgezocht&lt;br /&gt;
 20 februari     15-17          2               17            vergadering&lt;br /&gt;
                 20-22          2               19            Notulen uitgewerkt / Op het web gezet&lt;br /&gt;
 21 februari      9-15          6               25            WiredReach/Eclipse platform onderzoeken (met Martijn)&lt;br /&gt;
 22 februari      9-10          1               26            Wiki logboek gebouwd&lt;br /&gt;
                 10-14          4               30            WiredReach/Eclipse platform onderzoeken&lt;br /&gt;
 25 februari     12-18          6               36            Implementatie WiredReach proef&lt;br /&gt;
 27 februari      9-15          6               42            JXTA/Andere protocollen vergeleken&lt;br /&gt;
                 15-17          2               44            Vergadering&lt;br /&gt;
 28 februari     15-17          4               45            AardRock vergadering&lt;br /&gt;
 5 maart          9-15          6               51            Onderzoek WiredReach/JXTA&lt;br /&gt;
                 15-17          2               53            Vergadering&lt;br /&gt;
 6 maart         15-17          2               55            Vergadering AardRock&lt;br /&gt;
                 12-16          4               59            Lunch, vergaderd over implementatie P2P gedeelte         &lt;br /&gt;
 13 maart        15-17          2               61            Vergadering&lt;br /&gt;
 16 maart        9-13           4               64            Uitwerking/Uitdenken P2P communicatie datamodel&lt;br /&gt;
 21 maart        15-17          2               67            Vergadering AardRock&lt;br /&gt;
 23 maart        9-15           6               73            De-Eclipsed WiredReach, aan RDF Black Box gewerkt, Jena uitgezocht.&lt;br /&gt;
 27 maart        10-17          3               76            RDF Black Box uitgewerkt, vergadering &lt;br /&gt;
 28 maart        15-17          2               78            Vergadering AardRock&lt;br /&gt;
 18 april        14-17          3               81            Vergadering Aardrock / Proefpresentatie&lt;br /&gt;
 19 april        15-17          2               83            Overleg adviessysteem met Just&lt;br /&gt;
 25 april        9-15           6               89            Neuraal Netwerk vergadering / Adviessysteem cheetah&lt;br /&gt;
                 15-17          2               91            Vergadering Cheetah&lt;br /&gt;
 27 april        9-17           8               99            Bayesiaans netwerk / neuraal netwerk / onderzoek algoritmes&lt;br /&gt;
 28 april        9-11           2               101           Uitzoeken andere adviessoftware / dagboeken / mailen Harold de Valk&lt;br /&gt;
 28 april        11-12          1               102           Update logboek&lt;br /&gt;
 29 april        12-14          2               104           Adviessysteem (AIDA, Neural Networks, Kernel Machines)&lt;br /&gt;
 30 april        12-15          3               107           Adviessysteem (AIDA bestudeerd, alternatieven, schetsen)&lt;br /&gt;
 1 mei           12-14          2               109           Adviessysteem (AIDA, kernel machines)&lt;br /&gt;
 2 mei           10-19          9               118           Adviessysteem (Op wiki gezet, schema's gemaakt, besproken met diverse mensen)&lt;br /&gt;
 3 mei           12-13          2               120           Mailtjes, AI boek doorgespit over fuzzy logic&lt;br /&gt;
 4 mei           11-14          3               123           AI boek doorgespit, gelezen: http://www.fao.org/docrep/w8079e/w8079e00.htm&lt;br /&gt;
                 14-17          3               126           Verder literatuuronderzoek over effect van voeding/insuline/activities&lt;br /&gt;
 6 mei           11-5           6               132           [[Condition Effect Learning]]&lt;br /&gt;
 7 mei           5-6            1               133           Solved major condition effect learning problem.&lt;br /&gt;
                 11-15          4               136           Worked out the formula (&amp;quot;Kingma's Theorem&amp;quot;) and put it on the wiki.&lt;br /&gt;
                                                              Thought about better solutions to the condition effect learning problem.&lt;br /&gt;
 8 mei           20-24          4               140           Received usefull information about a patient (logbooks, medical dossier etc)&lt;br /&gt;
 9 mei           10-16          6               146           Worked at statistical problem, talked Giel about GUI and Peter de Waal about Bayesian Learning&lt;br /&gt;
 10 mei          15-17          2               148           Aardrock meeting. Explained some theories.&lt;br /&gt;
 11 mei          20-22          2               150           Formulated advisory limitations&lt;br /&gt;
 16 mei          15-18          3               153           Aardrock meeting / Advisory System&lt;br /&gt;
 19 mei &lt;br /&gt;
 20 mei          12-17          5               158           Brushing up on statistics.&lt;br /&gt;
 21 mei          14-20          6               164           Idem. reviewed (Biased) Estimators, marginalization, maximum likelihood functions, and bayesian inference (further)&lt;br /&gt;
 22 mei          14-15          1               165           Statistiek onderzocht.&lt;br /&gt;
 23 mei          14-17+21-01    7               172           Statistisch probleem opgelost! Zie [Condition Effect Learning], meer info volgt&lt;br /&gt;
 24 mei          10-11          1               173           Aantal kleine dingen opgezocht&lt;br /&gt;
 27 mei          12-18          6               179           Bayesiaanse inferentie.&lt;br /&gt;
 30 mei          13-18          5               184           Aardrock vergadering + Adviessyst.&lt;br /&gt;
 31 mei          16-24          8               192           Gemaild, formules uitgewerkt, aanpassingen aan wiki&lt;br /&gt;
 1 juni          13-17          4               196           Idem&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2163</id>
		<title>LogboekDurkKingma</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=LogboekDurkKingma&amp;diff=2163"/>
		<updated>2006-06-02T10:29:44Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; Datum           Tijd           Duur            Cumulatief    Activiteit&lt;br /&gt;
 --------------- -------------- --------------- ------------- ----------------------------------------&lt;br /&gt;
 8 februari      13-17          4               4             Eerste overleg en taakverdeling&lt;br /&gt;
 11 februari      9-11          2               6             Inlezen op Agile Development&lt;br /&gt;
 13 februari     12-14          2               8             Cruise Control onderzocht, nu pas door ziekte.&lt;br /&gt;
                 15-17          2               10            Vergadering&lt;br /&gt;
 14 februari     15-17          2               12            XP Game&lt;br /&gt;
 16 februari      9-12          3               15            WiredReach fundamenten uitgezocht&lt;br /&gt;
 20 februari     15-17          2               17            vergadering&lt;br /&gt;
                 20-22          2               19            Notulen uitgewerkt / Op het web gezet&lt;br /&gt;
 21 februari      9-15          6               25            WiredReach/Eclipse platform onderzoeken (met Martijn)&lt;br /&gt;
 22 februari      9-10          1               26            Wiki logboek gebouwd&lt;br /&gt;
                 10-14          4               30            WiredReach/Eclipse platform onderzoeken&lt;br /&gt;
 25 februari     12-18          6               36            Implementatie WiredReach proef&lt;br /&gt;
 27 februari      9-15          6               42            JXTA/Andere protocollen vergeleken&lt;br /&gt;
                 15-17          2               44            Vergadering&lt;br /&gt;
 28 februari     15-17          4               45            AardRock vergadering&lt;br /&gt;
 5 maart          9-15          6               51            Onderzoek WiredReach/JXTA&lt;br /&gt;
                 15-17          2               53            Vergadering&lt;br /&gt;
 6 maart         15-17          2               55            Vergadering AardRock&lt;br /&gt;
                 12-16          4               59            Lunch, vergaderd over implementatie P2P gedeelte         &lt;br /&gt;
 13 maart        15-17          2               61            Vergadering&lt;br /&gt;
 16 maart        9-13           4               64            Uitwerking/Uitdenken P2P communicatie datamodel&lt;br /&gt;
 21 maart        15-17          2               67            Vergadering AardRock&lt;br /&gt;
 23 maart        9-15           6               73            De-Eclipsed WiredReach, aan RDF Black Box gewerkt, Jena uitgezocht.&lt;br /&gt;
 27 maart        10-17          3               76            RDF Black Box uitgewerkt, vergadering &lt;br /&gt;
 28 maart        15-17          2               78            Vergadering AardRock&lt;br /&gt;
 18 april        14-17          3               81            Vergadering Aardrock / Proefpresentatie&lt;br /&gt;
 19 april        15-17          2               83            Overleg adviessysteem met Just&lt;br /&gt;
 25 april        9-15           6               89            Neuraal Netwerk vergadering / Adviessysteem cheetah&lt;br /&gt;
                 15-17          2               91            Vergadering Cheetah&lt;br /&gt;
 27 april        9-17           8               99            Bayesiaans netwerk / neuraal netwerk / onderzoek algoritmes&lt;br /&gt;
 28 april        9-11           2               101           Uitzoeken andere adviessoftware / dagboeken / mailen Harold de Valk&lt;br /&gt;
 28 april        11-12          1               102           Update logboek&lt;br /&gt;
 29 april        12-14          2               104           Adviessysteem (AIDA, Neural Networks, Kernel Machines)&lt;br /&gt;
 30 april        12-15          3               107           Adviessysteem (AIDA bestudeerd, alternatieven, schetsen)&lt;br /&gt;
 1 mei           12-14          2               109           Adviessysteem (AIDA, kernel machines)&lt;br /&gt;
 2 mei           10-19          9               118           Adviessysteem (Op wiki gezet, schema's gemaakt, besproken met diverse mensen)&lt;br /&gt;
 3 mei           12-13          2               120           Mailtjes, AI boek doorgespit over fuzzy logic&lt;br /&gt;
 4 mei           11-14          3               123           AI boek doorgespit, gelezen: http://www.fao.org/docrep/w8079e/w8079e00.htm&lt;br /&gt;
                 14-17          3               126           Verder literatuuronderzoek over effect van voeding/insuline/activities&lt;br /&gt;
 6 mei           11-5           6               132           [[Condition Effect Learning]]&lt;br /&gt;
 7 mei           5-6            1               133           Solved major condition effect learning problem.&lt;br /&gt;
                 11-15          4               136           Worked out the formula (&amp;quot;Kingma's Theorem&amp;quot;) and put it on the wiki.&lt;br /&gt;
                                                              Thought about better solutions to the condition effect learning problem.&lt;br /&gt;
 8 mei           20-24          4               140           Received usefull information about a patient (logbooks, medical dossier etc)&lt;br /&gt;
 9 mei           10-16          6               146           Worked at statistical problem, talked Giel about GUI and Peter de Waal about Bayesian Learning&lt;br /&gt;
 10 mei          15-17          2               148           Aardrock meeting. Explained some theories.&lt;br /&gt;
 11 mei          20-22          2               150           Formulated advisory limitations&lt;br /&gt;
 16 mei          15-18          3               153           Aardrock meeting / Advisory System&lt;br /&gt;
 19 mei &lt;br /&gt;
 20 mei          12-17          5               158           Brushing up on statistics.&lt;br /&gt;
 21 mei          14-20          6               164           Idem. reviewed (Biased) Estimators, marginalization, maximum likelihood functions, and bayesian inference (further)&lt;br /&gt;
 22 mei          14-15          1               165           Statistiek onderzocht.&lt;br /&gt;
 23 mei          14-17+21-01    7               172           Statistisch probleem opgelost! Zie [Condition Effect Learning], meer info volgt&lt;br /&gt;
 24 mei          10-11          1               173           Aantal kleine dingen opgezocht&lt;br /&gt;
 27 mei          12-18          6               179           Bayesiaanse inferentie.&lt;br /&gt;
 30 mei          13-18          5               184        Aardrock vergadering + Adviessyst.&lt;br /&gt;
 31 mei          16-24          8               192        Gemaild, formules uitgewerkt, aanpassingen aan wiki&lt;br /&gt;
 1 juni          13-17          4               196        Idem&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2162</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2162"/>
		<updated>2006-06-02T10:02:08Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Significance of good a priori functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty of the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good a priori functions ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly, maybe from months to just weeks or days&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following section will explain how to form an a posteriori function using glucose glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2161</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2161"/>
		<updated>2006-06-02T10:01:16Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Creation of a new event type */ added &amp;quot;Significance of good a priori functions&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty of the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
=== Significance of good a priori functions ===&lt;br /&gt;
In our case, we will see that the samples are estimations too. Later on, we will conclude that better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly.&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following section will explain how to form an a posteriori function using glucose glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2159</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2159"/>
		<updated>2006-06-02T09:59:21Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Creation of a new event type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty of the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). A sample is an observation value of f(t) at some t. More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t).&lt;br /&gt;
&lt;br /&gt;
In other words:&lt;br /&gt;
* Better prior knowledge (carbonhydrate count etc) leads to a better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A better f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* More samples leads to a better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)&lt;br /&gt;
* A good f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) means it is close to the real f(t)&lt;br /&gt;
&lt;br /&gt;
(&amp;lt;b&amp;gt;important!&amp;lt;/b&amp;gt;) In our case, we will see that the samples are estimations too. Later on, we will conclude that:&lt;br /&gt;
* Better f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) functions lead to better estimations of samples. In the 'bigger picture', this means that bad-quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s implicates inititally bad-quality f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t)'s, which in turn implicate intially bad-quality samples, leading to initially slow progression of inference. &amp;lt;i&amp;gt;This is important to know, because quality f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t)'s are VITAL to fast initial inference. Concretely said, good a priori functions will decrease the startup time significantly.&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following section will explain how to form an a posteriori function using glucose glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2155</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2155"/>
		<updated>2006-06-02T09:28:27Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Creation of a new event type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty of the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(t). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(t) means the system needs less training time to estimate the real function f(t). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t) is formed that esimates the real function f(t). More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(t). The following section will explain how to form an a posteriori function using glucose glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2154</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2154"/>
		<updated>2006-06-02T09:27:31Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* On events */  add &amp;quot;Creation of a new event type&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating certain food types nullify the effect of other foods.&lt;br /&gt;
Another positive thing about compositive events is that it decreases the amount of events in the sum of g2_estimate (see above). Less summation means less uncertainty of the estimate.&lt;br /&gt;
&lt;br /&gt;
=== Creation of a new event type ===&lt;br /&gt;
What needs to be done when a new event type is created, for example when a user eats something new or gets new insulin therapy? The first the system needs to create is an ''a priori'' estimate of f(x). This is called the ''a priori'' function. For food, this would be based on carbonhydrate count. For insulin, this would be done by entering medicine information. A better ''a priori'' f&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;(x) means the system needs less training time to estimate the real function f(x). When evidence arrives in the form of a ''sample'', an ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x) is formed that esimates the real function f(x). More evidence/samples means a better ''a posteriori'' f&amp;lt;sub&amp;gt;post&amp;lt;/sub&amp;gt;(x). The following section will explain how to form an a posteriori function using glucose glucose measurements.&lt;br /&gt;
&lt;br /&gt;
== Bayesian inference ==&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2153</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2153"/>
		<updated>2006-06-02T09:06:41Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* On events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. A composite event is a set or cominbation or multiple single events. Why use composite events? Because, for example, eating different food types combined leads to a different glycemic response then the sum of individual foods. Eating food types nullify the effect of other foods.&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2149</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2149"/>
		<updated>2006-06-01T15:05:42Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: /* Glucose level estimation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give near future glucose level estimation. The current glucose level estimation is done by (1) taking the last glucose measurement, and then (2) adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose levels structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== On events ==&lt;br /&gt;
&lt;br /&gt;
Like told above, the term 'event' can be things like apple intake. Our definition is broader then that: events can also be composite. -incomplete-&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2135</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2135"/>
		<updated>2006-06-01T09:53:32Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose level structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by taking the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to be continued...&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2134</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2134"/>
		<updated>2006-06-01T09:52:21Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b} \right )^2 \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b} \right )^2 \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose level structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by takken the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to be continued...&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2132</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2132"/>
		<updated>2006-06-01T09:49:07Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: correction on the prediction formula&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b}^2 \right ) \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose level structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by takken the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/math&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;(e_1,e_2,...,e_n)&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. &amp;lt;math&amp;gt;(f_1,f_2,...,f_n)&amp;lt;/math&amp;gt; are the estimated functions of the events. &amp;lt;math&amp;gt;(t_1,t_2,...,t_n)&amp;lt;/math&amp;gt; are the (start) times of each events. Then the glucose prediction g2 at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate}(t_{g2}) = g1 + \sum_{k = 1}^n \left ( f_k(t_{g2}-t_k)-f_k(t_{g1}-t_k) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to be continued...&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2131</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2131"/>
		<updated>2006-06-01T09:34:16Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: added &amp;lt;math&amp;gt;g2_{estimate} = g1 + \sum_{k = 0}^n{f_(e1}(t_{g2}-t_{e1})-f_(e1}(t_{g1}-t_{e1})}&amp;lt;/math&amp;gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b}^2 \right ) \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose level structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
As told above, the estimate for future moments in time is done by takken the last glucose measurement and adding the sum of glycemic responses of events. If &amp;lt;i&amp;gt;g1&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g1}&amp;lt;/sub&amp;gt; is the last glucose measurement, &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt; at &amp;lt;math&amp;gt;t_{g2}&amp;lt;/math&amp;gt; is the glucose level to be estimated, and &amp;lt;math&amp;gt;e_1,e_2,...,e_n&amp;lt;/math&amp;gt; events that have influence on &amp;lt;i&amp;gt;g2&amp;lt;/i&amp;gt;. Then:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g2_{estimate} = g1 + \sum_{k = 0}^n \left ( f_{e1}(t_{g2}-t_{e1})-f_{e1}(t_{g1}-t_{e1}) \right )&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...to be continued...&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2130</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2130"/>
		<updated>2006-06-01T08:57:24Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: New page to make stuff clearer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the typical glycamic response (''glucose rise/fall'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic response of each event is modelled in terms of a glucose rise/fall in function of time: f(t). Time real time t is mapped to discrete intervals of 15 minutes. Event types are split into distinct categories (see below). For computational conveniance, each event type category ''c'' is modelled by a function &amp;lt;i&amp;gt;f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(t)&amp;lt;/i&amp;gt;, and each concrete individual event type is modelled as transformation of that function using parameters a and b: &amp;lt;i&amp;gt;a*f&amp;lt;sub&amp;gt;c&amp;lt;/sub&amp;gt;(b*t)&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect. It appears to be modelled as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f(t) =&lt;br /&gt;
 a    * exp \left [ \left ( \frac{t-b }{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/2) * exp \left [ \left ( \frac{t-2b}{0,667*b}^2 \right ) \right ] +&lt;br /&gt;
(a/4) * exp \left [ \left ( \frac{t-3b}{0,667*b}^2 \right ) \right ]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Stress level.&lt;br /&gt;
* Time of the day, because glucose level structurally differ during the day.&lt;br /&gt;
* Health status.&lt;br /&gt;
* Other event types.&lt;br /&gt;
&lt;br /&gt;
[Add picture here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2129</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2129"/>
		<updated>2006-06-01T08:05:58Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system. It consists of a few interdependent systems for functions of estimation, inference and storage.&lt;br /&gt;
&lt;br /&gt;
== Glucose level estimation ==&lt;br /&gt;
&lt;br /&gt;
The most top-level functioning of the learning system is to give glucose level predictions. The current glucose level estimation is done using the last glucose measurement, and adding up the glycamic effect (/''glucose respons'') of all events since the last measurement.&lt;br /&gt;
&lt;br /&gt;
The glycemic effect of each event is modelled in terms of a glucose rise/fall in function of time: ''f(t)''.&lt;br /&gt;
&lt;br /&gt;
* Food intake. Usually has a positive glycemic effect.&lt;br /&gt;
* Insulin intake. Usually has a negative glycemic effect.&lt;br /&gt;
* Insulin&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2128</id>
		<title>Learning System</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Learning_System&amp;diff=2128"/>
		<updated>2006-06-01T07:53:01Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page reflects my/our idea about the Learning system.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2123</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2123"/>
		<updated>2006-05-30T19:00:45Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt; is now correct&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1^2+\sigma_2^2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2122</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2122"/>
		<updated>2006-05-30T18:57:30Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt; is now correct&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_i^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2043</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2043"/>
		<updated>2006-05-24T18:35:09Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2042</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2042"/>
		<updated>2006-05-24T18:32:53Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta; = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2041</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2041"/>
		<updated>2006-05-24T18:32:20Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta; = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but it has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prior means used here are derived from the estimated curve. The prior variances is also derived from this. Alternativly, when there are enough evidences on that particular moment, the system can use just these values.&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2040</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2040"/>
		<updated>2006-05-24T18:30:43Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta; = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but is assigned has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,post&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;a = \frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prior means used here are derived from the estimated curve. The prior variances is also derived from this. Alternativly, when there are enough evidences on that particular moment, the system can use just these values.&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2039</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2039"/>
		<updated>2006-05-24T18:26:29Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta; = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but is assigned has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\triangle t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,secondior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each interval has an a priori distribution as explained above. Some intervals have &amp;gt;0 collected samples: for these the sample mean is computed.&lt;br /&gt;
(unfinished)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How does it do that? Suppose it gets 'evidence' that at &amp;amp;Delta;T, the effect is &amp;amp;Delta;BG. It then adds that evidence to its set of all evidences. These evidences are then mapped to certain time intevals, e.g. 15 minutes. Some intervals then have a couple of evidences, some only one or none. At each interval, the a posteriori effect is computed. The math is as follows.&lt;br /&gt;
&lt;br /&gt;
The esimated effect has a normal distribution with mean=M and variance=V. The set of evidence values are e&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;, ..., e&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A posteriori mean[further explanation to be added]: &lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{post}=\frac{\sigma^2\mu+nv^2\bar x_n}{\sigma^2+nv^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A posteriori variance:&lt;br /&gt;
&amp;lt;math&amp;gt;v_{post}^2=\frac{\sigma^2v^2}{\sigma^2+nv^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\bar x&amp;lt;/math&amp;gt; means the mean of all evidences.&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do: &lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''a'' is &lt;br /&gt;
&amp;lt;math&amp;gt;\frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prior means used here are derived from the estimated curve. The prior variances is also derived from this. Alternativly, when there are enough evidences on that particular moment, the system can use just these values.&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
	<entry>
		<id>http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2038</id>
		<title>Condition Effect Learning</title>
		<link rel="alternate" type="text/html" href="http://wiki.aardrock.com/index.php?title=Condition_Effect_Learning&amp;diff=2038"/>
		<updated>2006-05-24T18:24:10Z</updated>

		<summary type="html">&lt;p&gt;DurkKingma: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
# Certain conditions: the effect is known and fixed. The effect is fixed, so the learning system will see the effect as certain.&lt;br /&gt;
# 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
I solved the first one, but not yet the second.&lt;br /&gt;
# Learning a condition's effect by assigning it a minimal and maximal effect value. For example, a minimum and maximum BG effect.&lt;br /&gt;
# Learning a condition's effect by seeing it as a normally distributed random variable.&lt;br /&gt;
&lt;br /&gt;
== 1. Learning a condition's effect by assigning it a minimal and maximal effect value ==&lt;br /&gt;
With this system, all conditions X have a X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; variables which tells the system the hard minimum and maximum of effect. For example, [http://www.ajcn.org/cgi/content/full/76/1/5/T1 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 CocaCola&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;=14 and CocaCola&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;=16. So, CocaCola could be a type 1 condition because it has a certain effect.&lt;br /&gt;
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 X&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and X&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, all conditions have a minimum and a maximum effect.&amp;lt;br/&amp;gt;&lt;br /&gt;
Suppose c is a condition, then:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min}, c_{max} \in \mathbb{R}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;c_{min} \le c_{max}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also, conditions can be contained in a group (set) of conditions S:&amp;lt;br/&amp;gt;&lt;br /&gt;
S = {c1, c2, ...}&amp;lt;br/&amp;gt;&lt;br /&gt;
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:&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = c1&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + c2&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; + ...&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br/&amp;gt;&lt;br /&gt;
If condition c is part of set S (''and (S-c) is set S minus condition c')&amp;lt;br/&amp;gt;&lt;br /&gt;
and S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; and S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
and c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; are known&amp;lt;br/&amp;gt;&lt;br /&gt;
then can be said:&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
(S-c)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = S&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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). &lt;br /&gt;
Then, cheetah calculates the difference (min and max) between the BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; and predicted CE group effect. This difference should equal the UE group effect. So:&amp;lt;br&amp;gt;&lt;br /&gt;
BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt; + CE&amp;lt;sub&amp;gt;real&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
So:&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
UE is the range of the sum of the to be learned conditions. These conditions all have their own effect range, c&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; and c&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt;. 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.&lt;br /&gt;
&lt;br /&gt;
'''Example 1.1'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The system knows a priori (from its database):&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 5&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 9&lt;br /&gt;
&lt;br /&gt;
The system calculates the effect range these two items must have had:&lt;br /&gt;
&lt;br /&gt;
UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 20 - 13 = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = BG&amp;lt;sub&amp;gt;measurement&amp;lt;/sub&amp;gt; - CE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 20 - 9 = 11&lt;br /&gt;
&lt;br /&gt;
Using Kingma's Theorem, The system then calculates the current A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt;, B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; values:&lt;br /&gt;
&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 5 = 2 (this is under B's hardmin, so) =&amp;gt; 7&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - A&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 2 = 9 (not above B's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmax&amp;lt;/sub&amp;gt; = 7 - 9 = -2 (this is under A's hardmin, so) =&amp;gt; 2&amp;lt;br/&amp;gt;&lt;br /&gt;
(UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = UE&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; - B&amp;lt;sub&amp;gt;hardmin&amp;lt;/sub&amp;gt; = 11 - 7 = 4 (not above A's hardmax, so keep it)&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, (UE-A) is B, and (UE-B) is A, is the system already calculated everything it needed:&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 2&amp;lt;br/&amp;gt;&lt;br /&gt;
A&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-B)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 4&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;min&amp;lt;/sub&amp;gt; = 7&amp;lt;br/&amp;gt;&lt;br /&gt;
B&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = (UE-A)&amp;lt;sub&amp;gt;max&amp;lt;/sub&amp;gt; = 9&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== 2. Bayesian Inference way ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Lets describe these events, their effects and their computations, in terms of a statistics problem.&lt;br /&gt;
&lt;br /&gt;
=== About events ===&lt;br /&gt;
Each single event &amp;lt;math&amp;gt;e_i&amp;lt;/math&amp;gt; has three things.&lt;br /&gt;
&lt;br /&gt;
1) Firstly: A set of samples. Each sample is a tuple &amp;lt;b&amp;gt;(&amp;amp;Delta;t, &amp;amp;Delta;g)&amp;lt;/b&amp;gt; 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].&lt;br /&gt;
&lt;br /&gt;
2) A prior (''a priori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,prior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta; = &amp;amp;mu;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;lt;/b&amp;gt;. 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 &amp;amp;sigma;&amp;lt;sub&amp;gt;prior&amp;lt;/sub&amp;gt;&amp;amp;sup2;. Spoken in statistic terms, the event effect at each moment in time has a normal distribution with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_e^2 = \mbox{some-static-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_e = \theta \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This parameter &amp;amp;theta; is unknown, but is assigned has a prior distribution with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta ,prior}^2 = \mbox{some-a-priori-value} \,&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{\theta, prior} = f_{e,prior}(\delta t) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) A posterior (''a posteriori'') function &amp;lt;b&amp;gt;f&amp;lt;sub&amp;gt;e,secondior&amp;lt;/sub&amp;gt;(&amp;amp;Delta;t) &amp;amp;rarr; &amp;amp;Delta;g&amp;lt;/b&amp;gt;. 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&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; with i=(1, ..., n), and each interval representing 15 minutes. Each of these intervals t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; have a distribution &amp;amp;theta; with a prior distribution as explained above. The posterior distribution of t&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\sigma_{\theta, post}^2=\frac{\sigma_{\theta, prior}^2\sigma_{\theta, prior}^2}{\sigma_e^2+n\sigma_{\theta, prior}^2}&amp;lt;/math&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\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}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each interval has an a priori distribution as explained above. Some intervals have &amp;gt;0 collected samples: for these the sample mean is computed.&lt;br /&gt;
(unfinished)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How does it do that? Suppose it gets 'evidence' that at &amp;amp;Delta;T, the effect is &amp;amp;Delta;BG. It then adds that evidence to its set of all evidences. These evidences are then mapped to certain time intevals, e.g. 15 minutes. Some intervals then have a couple of evidences, some only one or none. At each interval, the a posteriori effect is computed. The math is as follows.&lt;br /&gt;
&lt;br /&gt;
The esimated effect has a normal distribution with mean=M and variance=V. The set of evidence values are e&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;, ..., e&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A posteriori mean[further explanation to be added]: &lt;br /&gt;
&amp;lt;math&amp;gt;\mu_{post}=\frac{\sigma^2\mu+nv^2\bar x_n}{\sigma^2+nv^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A posteriori variance:&lt;br /&gt;
&amp;lt;math&amp;gt;v_{post}^2=\frac{\sigma^2v^2}{\sigma^2+nv^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\bar x&amp;lt;/math&amp;gt; means the mean of all evidences.&lt;br /&gt;
&lt;br /&gt;
To assign an evidence x&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; to each individual events e&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; you do: &lt;br /&gt;
&amp;lt;math&amp;gt;x_i=\mu_{prior}+a*\sigma_1^2&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''a'' is &lt;br /&gt;
&amp;lt;math&amp;gt;\frac{x_{tot}-(\mu_1+\mu_2+...)}{\sigma_1+\sigma_2+...}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The prior means used here are derived from the estimated curve. The prior variances is also derived from this. Alternativly, when there are enough evidences on that particular moment, the system can use just these values.&lt;br /&gt;
&lt;br /&gt;
So it comes down to some quite simple math. I'll make my explanation better when I have more time.&lt;/div&gt;</summary>
		<author><name>DurkKingma</name></author>
	</entry>
</feed>