Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

M8_pac_learning.ipynb 11.4 KB
Newer Older
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Let us start by looking again at the Prey-Predator model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
16
    "load(library:examples/lotka_volterra/LVi.bc).\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    "list_model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SSA means Stochastic Simulation Algorithm (from Gillespie)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "numerical_simulation(method: ssa).\n",
    "plot."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SPN is a Stochastic Petri Net, i.e., SSA without time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "numerical_simulation(method: spn).\n",
    "plot."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SBN is a Stochastic Boolean Net, i.e., a stochastic boolean simulation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "numerical_simulation(method: sbn).\n",
    "plot."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "Now let us look at different ways to approach PAC learning for this model.\n",
    "\n",
    "First, the biocham command: `pac_learning(Model, #Initial_states, Time_horizon)`\n",
    "it will read the file `Model` and generate `#Initial_states` random initial states from which it will run simulations for `Time_horizon`.\n",
    "\n",
    "You can add options for the simulation, notably: `boolean_simulation: yes` to go from default `ssa` to `sbn` method,\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
83
    "and `cnf_clause_size: 2` to change the size of the clauses considered from the default `3`."
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 1\n",
    "\n",
    "Compare the results of trying to learn a model from traces of the above `library:examples/lotka_volterra/LVi.bc` model in the 3 following conditions:\n",
    "\n",
    "1. A single boolean simulation of length 50\n",
    "2. 25 boolean simulations of length 2\n",
    "3. 50 stochastic simulations of length 1\n",
    "\n",
    "Explain what you observe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 2\n",
    "\n",
    "In the output, the `h` corresponds to Valiant's precision parameter. What we know (see François' slides) is that with $L(h, s)$ samples we have probability higher than $1 - h^{-1}$ to find our approximation, and its total amount of false negatives has measure $< h^{-1}$\n",
    "\n",
    "How did we turn this into an estimate of the number of samples needed for a given $h$?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 3\n",
    "\n",
    "Why do we have to provide a `cnf_clause_size` to learn CNF formulae of size less than `K`?\n",
    "\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
155
    "What does it represent \"biologically\"? Where can you see that in the model?\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    "\n",
    "Could we have used the DNF learning algorithm here? why?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
174
175
176
177
178
179
180
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
181
182
183
184
185
186
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    "Let us now look at a slightly bigger model of the Circadian Clock by J.-P. Comet and G. Bernot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "load(library:examples/circadian_cycle/bernot_comet.bc).\n",
    "list_model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 4\n",
    "\n",
    "Using Biocham commands of your choice, what do you observe as the behavior of this model?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question 5\n",
    "\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
236
237
238
    "Now try PAC learning on that model, choosing yourself the number of initial states and simulation lenght, so that you are satisfied with the result.\n",
    "\n",
    "What happens if you impose `cnf_clause_size: 1`? How would you expect that to be reflected in the behavior of the model?"
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "Let us now consider an even bigger model coming from L. Mendoza (Biosystems 2006), and made Boolean by the same author with Remy et al. (Dynamical Roles and Functionality of Feedback Circuits, Springer 2006).\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
269
270
271
    "\n",
    "![Th Lymphocite differentiation](RemyEtAl06.png)\n",
    "\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
272
273
274
    "The model is about the control and differentiation of Th (lymphocite) cells.\n",
    "\n",
    "Before \"learning\" it, we will try to understand it a bit…"
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
275
276
277
278
   ]
  },
  {
   "cell_type": "code",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
279
280
281
   "execution_count": null,
   "metadata": {},
   "outputs": [],
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
282
283
284
285
286
   "source": [
    "load(library:examples/Th_lymphocytes/lympho.bc).\n",
    "list_model."
   ]
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_influences."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Basically Th0 cells differentiate either into\n",
    "\n",
    "Th1 cells (marked by the activity of the TBet transcription factor) under the effect of IFNγ\n",
    "\n",
    "or\n",
    "\n",
    "Th2 cells under the effect of IL4 that binds to its receptor to activate STAT6 and GATA3…"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_stable_states."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
322
    "## Question 6\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
323
324
325
326
327
328
329
330
331
332
333
334
335
    "\n",
    "Why do we have 6 stable states instead of 3?\n",
    "\n",
    "Hint: the picture of the graph might help…"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
336
337
338
339
340
341
342
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
343
344
345
346
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
347
    "## Question 7\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    "\n",
    "If one hopes for traces that would present all events with equal probability, what would be the approximate total number of samples needed to learn our 12-species model for $h = 0.1$?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For time reasons, we will only use 10000 samples total.\n",
    "\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
372
    "## Question 8\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    "\n",
    "Compare the three following models, and especially the last two ones:\n",
    "\n",
    "- the model learnt with a single (stochastic) simulation of length 10000\n",
    "- the model learnt with 10000 simulations of length 1 (with random initial states)\n",
    "- the original model\n",
    "\n",
    "What do you observe? Can you explain why?\n",
    "\n",
    "If there are inconsistencies, can you propose a possible solution?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
410
    "## Question 9\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
411
412
413
414
415
416
417
418
419
420
421
    "\n",
    "Keeping the total number of samples at 10000, can you find a threshold after which models learnt are of better quality?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
436
437
438
439
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
440
    "## Question 8\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
441
442
443
444
445
446
447
448
449
450
451
    "\n",
    "Could we have used the DNF learning algorithm? Why?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
452
453
454
455
456
457
458
459
460
461
462
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
463
    "## Question 10\n",
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
    "\n",
    "In order to reduce the number of samples needed for a given $h$, one solution is to use some prior knowledge.\n",
    "\n",
    "Say we provide to the PAC learning algorithm the influence graph obtained by `draw_influences`.\n",
    "\n",
    "How and why would that reduce the number of samples?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Biocham",
   "language": "",
   "name": "biocham"
  },
  "language_info": {
   "codemirror_mode": "biocham",
   "file_extension": ".bc",
   "mimetype": "text/plain",
   "name": "biocham",
   "pygments_lexer": "prolog"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}