Skip to content
Snippets Groups Projects
Supervised regression.ipynb 495 KiB
Newer Older
3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000
      "Epoch 294/500  total: 3.70312, -LL: 3.62281, prior: 0.83122, aleatoric unc.: 9.76033\n",
      "Epoch 295/500  total: 3.70929, -LL: 3.64419, prior: 0.83021, aleatoric unc.: 9.76300\n",
      "Epoch 296/500  total: 3.70208, -LL: 3.64338, prior: 0.83049, aleatoric unc.: 9.76104\n",
      "Epoch 297/500  total: 3.70218, -LL: 3.61723, prior: 0.83026, aleatoric unc.: 9.75453\n",
      "Epoch 298/500  total: 3.70252, -LL: 3.64148, prior: 0.83147, aleatoric unc.: 9.74977\n",
      "Epoch 299/500  total: 3.70108, -LL: 3.68672, prior: 0.83107, aleatoric unc.: 9.74179\n",
      "Epoch 300/500  total: 3.70634, -LL: 3.67040, prior: 0.82994, aleatoric unc.: 9.75107\n",
      "Epoch 301/500  total: 3.69355, -LL: 3.60485, prior: 0.82971, aleatoric unc.: 9.73195\n",
      "Epoch 302/500  total: 3.70322, -LL: 3.63580, prior: 0.83051, aleatoric unc.: 9.73157\n",
      "Epoch 303/500  total: 3.70026, -LL: 3.70596, prior: 0.82929, aleatoric unc.: 9.72599\n",
      "Epoch 304/500  total: 3.70397, -LL: 3.65822, prior: 0.83103, aleatoric unc.: 9.72934\n",
      "Epoch 305/500  total: 3.70864, -LL: 3.56731, prior: 0.83211, aleatoric unc.: 9.74369\n",
      "Epoch 306/500  total: 3.70876, -LL: 3.59099, prior: 0.83176, aleatoric unc.: 9.75274\n",
      "Epoch 307/500  total: 3.70129, -LL: 3.63883, prior: 0.82881, aleatoric unc.: 9.74951\n",
      "Epoch 308/500  total: 3.70983, -LL: 3.63237, prior: 0.82886, aleatoric unc.: 9.75686\n",
      "Epoch 309/500  total: 3.70741, -LL: 3.60030, prior: 0.83055, aleatoric unc.: 9.76448\n",
      "Epoch 310/500  total: 3.70709, -LL: 3.59931, prior: 0.83434, aleatoric unc.: 9.76765\n",
      "Epoch 311/500  total: 3.69747, -LL: 3.63639, prior: 0.83337, aleatoric unc.: 9.74833\n",
      "Epoch 312/500  total: 3.71152, -LL: 3.62594, prior: 0.83660, aleatoric unc.: 9.76304\n",
      "Epoch 313/500  total: 3.70416, -LL: 3.64673, prior: 0.83517, aleatoric unc.: 9.76183\n",
      "Epoch 314/500  total: 3.69919, -LL: 3.58278, prior: 0.83536, aleatoric unc.: 9.75043\n",
      "Epoch 315/500  total: 3.70675, -LL: 3.60159, prior: 0.83583, aleatoric unc.: 9.75515\n",
      "Epoch 316/500  total: 3.70445, -LL: 3.64417, prior: 0.83832, aleatoric unc.: 9.75135\n",
      "Epoch 317/500  total: 3.70155, -LL: 3.64957, prior: 0.83247, aleatoric unc.: 9.74824\n",
      "Epoch 318/500  total: 3.70251, -LL: 3.61336, prior: 0.83256, aleatoric unc.: 9.74411\n",
      "Epoch 319/500  total: 3.70864, -LL: 3.61781, prior: 0.83391, aleatoric unc.: 9.75591\n",
      "Epoch 320/500  total: 3.69483, -LL: 3.62589, prior: 0.83023, aleatoric unc.: 9.73673\n",
      "Epoch 321/500  total: 3.70477, -LL: 3.65918, prior: 0.83147, aleatoric unc.: 9.73801\n",
      "Epoch 322/500  total: 3.71006, -LL: 3.68025, prior: 0.83056, aleatoric unc.: 9.75054\n",
      "Epoch 323/500  total: 3.70612, -LL: 3.63204, prior: 0.82882, aleatoric unc.: 9.75776\n",
      "Epoch 324/500  total: 3.70220, -LL: 3.63502, prior: 0.82885, aleatoric unc.: 9.75287\n",
      "Epoch 325/500  total: 3.70991, -LL: 3.67634, prior: 0.82949, aleatoric unc.: 9.75935\n",
      "Epoch 326/500  total: 3.70031, -LL: 3.67920, prior: 0.83210, aleatoric unc.: 9.74968\n",
      "Epoch 327/500  total: 3.71157, -LL: 3.65393, prior: 0.83033, aleatoric unc.: 9.76567\n",
      "Epoch 328/500  total: 3.70492, -LL: 3.64040, prior: 0.82936, aleatoric unc.: 9.76520\n",
      "Epoch 329/500  total: 3.70176, -LL: 3.60859, prior: 0.83023, aleatoric unc.: 9.75874\n",
      "Epoch 330/500  total: 3.70091, -LL: 3.61544, prior: 0.83437, aleatoric unc.: 9.74670\n",
      "Epoch 331/500  total: 3.70303, -LL: 3.65750, prior: 0.83323, aleatoric unc.: 9.74530\n",
      "Epoch 332/500  total: 3.70879, -LL: 3.59750, prior: 0.82948, aleatoric unc.: 9.75656\n",
      "Epoch 333/500  total: 3.70656, -LL: 3.65474, prior: 0.82868, aleatoric unc.: 9.76092\n",
      "Epoch 334/500  total: 3.69965, -LL: 3.63443, prior: 0.83218, aleatoric unc.: 9.74758\n",
      "Epoch 335/500  total: 3.70277, -LL: 3.63288, prior: 0.83110, aleatoric unc.: 9.74762\n",
      "Epoch 336/500  total: 3.70189, -LL: 3.66539, prior: 0.83201, aleatoric unc.: 9.74239\n",
      "Epoch 337/500  total: 3.69537, -LL: 3.65592, prior: 0.82954, aleatoric unc.: 9.72731\n",
      "Epoch 338/500  total: 3.69802, -LL: 3.60642, prior: 0.82822, aleatoric unc.: 9.72182\n",
      "Epoch 339/500  total: 3.71005, -LL: 3.67063, prior: 0.82849, aleatoric unc.: 9.73660\n",
      "Epoch 340/500  total: 3.70104, -LL: 3.60019, prior: 0.83237, aleatoric unc.: 9.73406\n",
      "Epoch 341/500  total: 3.70567, -LL: 3.62259, prior: 0.83000, aleatoric unc.: 9.74208\n",
      "Epoch 342/500  total: 3.70195, -LL: 3.65865, prior: 0.82917, aleatoric unc.: 9.73657\n",
      "Epoch 343/500  total: 3.70123, -LL: 3.62708, prior: 0.83080, aleatoric unc.: 9.73533\n",
      "Epoch 344/500  total: 3.70437, -LL: 3.61342, prior: 0.82911, aleatoric unc.: 9.73596\n",
      "Epoch 345/500  total: 3.70366, -LL: 3.60328, prior: 0.83045, aleatoric unc.: 9.74204\n",
      "Epoch 346/500  total: 3.70356, -LL: 3.62689, prior: 0.83147, aleatoric unc.: 9.73873\n",
      "Epoch 347/500  total: 3.69629, -LL: 3.64269, prior: 0.82647, aleatoric unc.: 9.72898\n",
      "Epoch 348/500  total: 3.69996, -LL: 3.65626, prior: 0.82871, aleatoric unc.: 9.72221\n",
      "Epoch 349/500  total: 3.70417, -LL: 3.63705, prior: 0.82662, aleatoric unc.: 9.72849\n",
      "Epoch 350/500  total: 3.70177, -LL: 3.65497, prior: 0.82323, aleatoric unc.: 9.72953\n",
      "Epoch 351/500  total: 3.70254, -LL: 3.67832, prior: 0.82772, aleatoric unc.: 9.73065\n",
      "Epoch 352/500  total: 3.70162, -LL: 3.63990, prior: 0.83119, aleatoric unc.: 9.72532\n",
      "Epoch 353/500  total: 3.70578, -LL: 3.60402, prior: 0.83188, aleatoric unc.: 9.73709\n",
      "Epoch 354/500  total: 3.70272, -LL: 3.62950, prior: 0.82930, aleatoric unc.: 9.73685\n",
      "Epoch 355/500  total: 3.70043, -LL: 3.62746, prior: 0.82995, aleatoric unc.: 9.73355\n",
      "Epoch 356/500  total: 3.69946, -LL: 3.61545, prior: 0.83072, aleatoric unc.: 9.72545\n",
      "Epoch 357/500  total: 3.70071, -LL: 3.67021, prior: 0.83015, aleatoric unc.: 9.72398\n",
      "Epoch 358/500  total: 3.70548, -LL: 3.63582, prior: 0.82771, aleatoric unc.: 9.73216\n",
      "Epoch 359/500  total: 3.69811, -LL: 3.60202, prior: 0.82758, aleatoric unc.: 9.72475\n",
      "Epoch 360/500  total: 3.69686, -LL: 3.64973, prior: 0.82581, aleatoric unc.: 9.71591\n",
      "Epoch 361/500  total: 3.70717, -LL: 3.65881, prior: 0.82941, aleatoric unc.: 9.72619\n",
      "Epoch 362/500  total: 3.70385, -LL: 3.65302, prior: 0.82832, aleatoric unc.: 9.73025\n",
      "Epoch 363/500  total: 3.70743, -LL: 3.64934, prior: 0.82749, aleatoric unc.: 9.74160\n",
      "Epoch 364/500  total: 3.70326, -LL: 3.58934, prior: 0.82753, aleatoric unc.: 9.74316\n",
      "Epoch 365/500  total: 3.70402, -LL: 3.62665, prior: 0.82742, aleatoric unc.: 9.74414\n",
      "Epoch 366/500  total: 3.70585, -LL: 3.68176, prior: 0.82632, aleatoric unc.: 9.74891\n",
      "Epoch 367/500  total: 3.70568, -LL: 3.62934, prior: 0.82647, aleatoric unc.: 9.75294\n",
      "Epoch 368/500  total: 3.69735, -LL: 3.63394, prior: 0.82584, aleatoric unc.: 9.73833\n",
      "Epoch 369/500  total: 3.70665, -LL: 3.60627, prior: 0.82508, aleatoric unc.: 9.74506\n",
      "Epoch 370/500  total: 3.70283, -LL: 3.64191, prior: 0.82496, aleatoric unc.: 9.74463\n",
      "Epoch 371/500  total: 3.69990, -LL: 3.63656, prior: 0.82942, aleatoric unc.: 9.73714\n",
      "Epoch 372/500  total: 3.70170, -LL: 3.65815, prior: 0.82560, aleatoric unc.: 9.73377\n",
      "Epoch 373/500  total: 3.70135, -LL: 3.66173, prior: 0.82487, aleatoric unc.: 9.73149\n",
      "Epoch 374/500  total: 3.70539, -LL: 3.60903, prior: 0.82451, aleatoric unc.: 9.74010\n",
      "Epoch 375/500  total: 3.69980, -LL: 3.63325, prior: 0.82713, aleatoric unc.: 9.73296\n",
      "Epoch 376/500  total: 3.69921, -LL: 3.60023, prior: 0.82868, aleatoric unc.: 9.72724\n",
      "Epoch 377/500  total: 3.69869, -LL: 3.66106, prior: 0.82731, aleatoric unc.: 9.72021\n",
      "Epoch 378/500  total: 3.69702, -LL: 3.62505, prior: 0.82719, aleatoric unc.: 9.71488\n",
      "Epoch 379/500  total: 3.69819, -LL: 3.60678, prior: 0.82717, aleatoric unc.: 9.71085\n",
      "Epoch 380/500  total: 3.69677, -LL: 3.62688, prior: 0.82746, aleatoric unc.: 9.70245\n",
      "Epoch 381/500  total: 3.70501, -LL: 3.60229, prior: 0.82751, aleatoric unc.: 9.71364\n",
      "Epoch 382/500  total: 3.69922, -LL: 3.57855, prior: 0.83100, aleatoric unc.: 9.71044\n",
      "Epoch 383/500  total: 3.69865, -LL: 3.63590, prior: 0.82836, aleatoric unc.: 9.70802\n",
      "Epoch 384/500  total: 3.70344, -LL: 3.59795, prior: 0.82755, aleatoric unc.: 9.71421\n",
      "Epoch 385/500  total: 3.70533, -LL: 3.64661, prior: 0.82573, aleatoric unc.: 9.72334\n",
      "Epoch 386/500  total: 3.70198, -LL: 3.61014, prior: 0.82611, aleatoric unc.: 9.72450\n",
      "Epoch 387/500  total: 3.70406, -LL: 3.64215, prior: 0.82555, aleatoric unc.: 9.73054\n",
      "Epoch 388/500  total: 3.70490, -LL: 3.63847, prior: 0.82456, aleatoric unc.: 9.73703\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 389/500  total: 3.69739, -LL: 3.60615, prior: 0.82374, aleatoric unc.: 9.72495\n",
      "Epoch 390/500  total: 3.70646, -LL: 3.59768, prior: 0.82653, aleatoric unc.: 9.73402\n",
      "Epoch 391/500  total: 3.69914, -LL: 3.65293, prior: 0.82449, aleatoric unc.: 9.72576\n",
      "Epoch 392/500  total: 3.70214, -LL: 3.62112, prior: 0.82444, aleatoric unc.: 9.72820\n",
      "Epoch 393/500  total: 3.70022, -LL: 3.57499, prior: 0.82906, aleatoric unc.: 9.72694\n",
      "Epoch 394/500  total: 3.69050, -LL: 3.60771, prior: 0.82554, aleatoric unc.: 9.70561\n",
      "Epoch 395/500  total: 3.69285, -LL: 3.68116, prior: 0.82755, aleatoric unc.: 9.69149\n",
      "Epoch 396/500  total: 3.70537, -LL: 3.61828, prior: 0.82465, aleatoric unc.: 9.70394\n",
      "Epoch 397/500  total: 3.69655, -LL: 3.61455, prior: 0.82317, aleatoric unc.: 9.70052\n",
      "Epoch 398/500  total: 3.70530, -LL: 3.62109, prior: 0.82612, aleatoric unc.: 9.71183\n",
      "Epoch 399/500  total: 3.70086, -LL: 3.61040, prior: 0.82481, aleatoric unc.: 9.71438\n",
      "Epoch 400/500  total: 3.70211, -LL: 3.64791, prior: 0.82474, aleatoric unc.: 9.71751\n",
      "Epoch 401/500  total: 3.70449, -LL: 3.66220, prior: 0.82469, aleatoric unc.: 9.72471\n",
      "Epoch 402/500  total: 3.69559, -LL: 3.68538, prior: 0.82521, aleatoric unc.: 9.71284\n",
      "Epoch 403/500  total: 3.70262, -LL: 3.61727, prior: 0.82641, aleatoric unc.: 9.71845\n",
      "Epoch 404/500  total: 3.70541, -LL: 3.65800, prior: 0.82866, aleatoric unc.: 9.72628\n",
      "Epoch 405/500  total: 3.70215, -LL: 3.66135, prior: 0.82954, aleatoric unc.: 9.72948\n",
      "Epoch 406/500  total: 3.69729, -LL: 3.64724, prior: 0.82800, aleatoric unc.: 9.72026\n",
      "Epoch 407/500  total: 3.69719, -LL: 3.63176, prior: 0.82775, aleatoric unc.: 9.71121\n",
      "Epoch 408/500  total: 3.70596, -LL: 3.66872, prior: 0.82940, aleatoric unc.: 9.72126\n",
      "Epoch 409/500  total: 3.70204, -LL: 3.63414, prior: 0.83020, aleatoric unc.: 9.72397\n",
      "Epoch 410/500  total: 3.70021, -LL: 3.64946, prior: 0.83012, aleatoric unc.: 9.72245\n",
      "Epoch 411/500  total: 3.69402, -LL: 3.61718, prior: 0.82774, aleatoric unc.: 9.70823\n",
      "Epoch 412/500  total: 3.70567, -LL: 3.61743, prior: 0.82851, aleatoric unc.: 9.71849\n",
      "Epoch 413/500  total: 3.70361, -LL: 3.64554, prior: 0.82617, aleatoric unc.: 9.72331\n",
      "Epoch 414/500  total: 3.69468, -LL: 3.60278, prior: 0.82620, aleatoric unc.: 9.71184\n",
      "Epoch 415/500  total: 3.70510, -LL: 3.64241, prior: 0.82747, aleatoric unc.: 9.72071\n",
      "Epoch 416/500  total: 3.70178, -LL: 3.59014, prior: 0.83144, aleatoric unc.: 9.72354\n",
      "Epoch 417/500  total: 3.69967, -LL: 3.63795, prior: 0.83206, aleatoric unc.: 9.71923\n",
      "Epoch 418/500  total: 3.69828, -LL: 3.60308, prior: 0.82796, aleatoric unc.: 9.71243\n",
      "Epoch 419/500  total: 3.70307, -LL: 3.66544, prior: 0.82524, aleatoric unc.: 9.71768\n",
      "Epoch 420/500  total: 3.70183, -LL: 3.61180, prior: 0.82254, aleatoric unc.: 9.72192\n",
      "Epoch 421/500  total: 3.69221, -LL: 3.63945, prior: 0.82239, aleatoric unc.: 9.70423\n",
      "Epoch 422/500  total: 3.69980, -LL: 3.61604, prior: 0.82302, aleatoric unc.: 9.70583\n",
      "Epoch 423/500  total: 3.69928, -LL: 3.63499, prior: 0.81947, aleatoric unc.: 9.70428\n",
      "Epoch 424/500  total: 3.70064, -LL: 3.64438, prior: 0.82250, aleatoric unc.: 9.70499\n",
      "Epoch 425/500  total: 3.69506, -LL: 3.61971, prior: 0.82166, aleatoric unc.: 9.69757\n",
      "Epoch 426/500  total: 3.70398, -LL: 3.62597, prior: 0.82278, aleatoric unc.: 9.70802\n",
      "Epoch 427/500  total: 3.70216, -LL: 3.65498, prior: 0.81911, aleatoric unc.: 9.71137\n",
      "Epoch 428/500  total: 3.70190, -LL: 3.64064, prior: 0.81833, aleatoric unc.: 9.71579\n",
      "Epoch 429/500  total: 3.70573, -LL: 3.66083, prior: 0.81893, aleatoric unc.: 9.72434\n",
      "Epoch 430/500  total: 3.69885, -LL: 3.65177, prior: 0.82123, aleatoric unc.: 9.72031\n",
      "Epoch 431/500  total: 3.70198, -LL: 3.67658, prior: 0.81868, aleatoric unc.: 9.72134\n",
      "Epoch 432/500  total: 3.70692, -LL: 3.63311, prior: 0.81943, aleatoric unc.: 9.73138\n",
      "Epoch 433/500  total: 3.70009, -LL: 3.59875, prior: 0.81951, aleatoric unc.: 9.72938\n",
      "Epoch 434/500  total: 3.69864, -LL: 3.63859, prior: 0.82302, aleatoric unc.: 9.72290\n",
      "Epoch 435/500  total: 3.69655, -LL: 3.66607, prior: 0.82137, aleatoric unc.: 9.71333\n",
      "Epoch 436/500  total: 3.69973, -LL: 3.65163, prior: 0.81886, aleatoric unc.: 9.71366\n",
      "Epoch 437/500  total: 3.69769, -LL: 3.68498, prior: 0.81805, aleatoric unc.: 9.70730\n",
      "Epoch 438/500  total: 3.69672, -LL: 3.64131, prior: 0.81733, aleatoric unc.: 9.70155\n",
      "Epoch 439/500  total: 3.69554, -LL: 3.62049, prior: 0.82319, aleatoric unc.: 9.69490\n",
      "Epoch 440/500  total: 3.69749, -LL: 3.62081, prior: 0.82234, aleatoric unc.: 9.69433\n",
      "Epoch 441/500  total: 3.70329, -LL: 3.59532, prior: 0.82169, aleatoric unc.: 9.70249\n",
      "Epoch 442/500  total: 3.69808, -LL: 3.62759, prior: 0.82254, aleatoric unc.: 9.70274\n",
      "Epoch 443/500  total: 3.70494, -LL: 3.65422, prior: 0.82270, aleatoric unc.: 9.71221\n",
      "Epoch 444/500  total: 3.69976, -LL: 3.65673, prior: 0.82426, aleatoric unc.: 9.71188\n",
      "Epoch 445/500  total: 3.70325, -LL: 3.64046, prior: 0.82422, aleatoric unc.: 9.71596\n",
      "Epoch 446/500  total: 3.70594, -LL: 3.65127, prior: 0.82255, aleatoric unc.: 9.72795\n",
      "Epoch 447/500  total: 3.70256, -LL: 3.65205, prior: 0.82299, aleatoric unc.: 9.72941\n",
      "Epoch 448/500  total: 3.70255, -LL: 3.66160, prior: 0.82127, aleatoric unc.: 9.73019\n",
      "Epoch 449/500  total: 3.70477, -LL: 3.65332, prior: 0.82186, aleatoric unc.: 9.73749\n",
      "Epoch 450/500  total: 3.69821, -LL: 3.62343, prior: 0.82277, aleatoric unc.: 9.72872\n",
      "Epoch 451/500  total: 3.69862, -LL: 3.61988, prior: 0.81971, aleatoric unc.: 9.72094\n",
      "Epoch 452/500  total: 3.69956, -LL: 3.64692, prior: 0.82058, aleatoric unc.: 9.71754\n",
      "Epoch 453/500  total: 3.68746, -LL: 3.61281, prior: 0.81960, aleatoric unc.: 9.69424\n",
      "Epoch 454/500  total: 3.69136, -LL: 3.61534, prior: 0.82130, aleatoric unc.: 9.67839\n",
      "Epoch 455/500  total: 3.70947, -LL: 3.63629, prior: 0.82276, aleatoric unc.: 9.70095\n",
      "Epoch 456/500  total: 3.70455, -LL: 3.62145, prior: 0.82456, aleatoric unc.: 9.71287\n",
      "Epoch 457/500  total: 3.69434, -LL: 3.64094, prior: 0.82408, aleatoric unc.: 9.70524\n",
      "Epoch 458/500  total: 3.69588, -LL: 3.62607, prior: 0.82356, aleatoric unc.: 9.69614\n",
      "Epoch 459/500  total: 3.69965, -LL: 3.67129, prior: 0.82353, aleatoric unc.: 9.69692\n",
      "Epoch 460/500  total: 3.69278, -LL: 3.64340, prior: 0.82238, aleatoric unc.: 9.68522\n",
      "Epoch 461/500  total: 3.69769, -LL: 3.66663, prior: 0.82365, aleatoric unc.: 9.68477\n",
      "Epoch 462/500  total: 3.70174, -LL: 3.64461, prior: 0.82374, aleatoric unc.: 9.69469\n",
      "Epoch 463/500  total: 3.69422, -LL: 3.62371, prior: 0.82634, aleatoric unc.: 9.68775\n",
      "Epoch 464/500  total: 3.70086, -LL: 3.65318, prior: 0.82430, aleatoric unc.: 9.69298\n",
      "Epoch 465/500  total: 3.69787, -LL: 3.66150, prior: 0.81959, aleatoric unc.: 9.69327\n",
      "Epoch 466/500  total: 3.69348, -LL: 3.64051, prior: 0.81754, aleatoric unc.: 9.68517\n",
      "Epoch 467/500  total: 3.70298, -LL: 3.65390, prior: 0.81789, aleatoric unc.: 9.69441\n",
      "Epoch 468/500  total: 3.69817, -LL: 3.65901, prior: 0.81541, aleatoric unc.: 9.69768\n",
      "Epoch 469/500  total: 3.69301, -LL: 3.63411, prior: 0.81612, aleatoric unc.: 9.68669\n",
      "Epoch 470/500  total: 3.70037, -LL: 3.61972, prior: 0.81542, aleatoric unc.: 9.69086\n",
      "Epoch 471/500  total: 3.70139, -LL: 3.60899, prior: 0.81560, aleatoric unc.: 9.69815\n",
      "Epoch 472/500  total: 3.70118, -LL: 3.68662, prior: 0.81407, aleatoric unc.: 9.70126\n",
      "Epoch 473/500  total: 3.70042, -LL: 3.64964, prior: 0.81481, aleatoric unc.: 9.70599\n",
      "Epoch 474/500  total: 3.70516, -LL: 3.62561, prior: 0.81684, aleatoric unc.: 9.71484\n",
      "Epoch 475/500  total: 3.69569, -LL: 3.62760, prior: 0.81538, aleatoric unc.: 9.70852\n",
      "Epoch 476/500  total: 3.69344, -LL: 3.63575, prior: 0.81317, aleatoric unc.: 9.69601\n",
      "Epoch 477/500  total: 3.69725, -LL: 3.66014, prior: 0.81203, aleatoric unc.: 9.69300\n",
      "Epoch 478/500  total: 3.70594, -LL: 3.65619, prior: 0.81437, aleatoric unc.: 9.70621\n",
      "Epoch 479/500  total: 3.69992, -LL: 3.61516, prior: 0.81284, aleatoric unc.: 9.70868\n",
      "Epoch 480/500  total: 3.69582, -LL: 3.64135, prior: 0.81684, aleatoric unc.: 9.70021\n",
      "Epoch 481/500  total: 3.69739, -LL: 3.60619, prior: 0.81517, aleatoric unc.: 9.70025\n",
      "Epoch 482/500  total: 3.70488, -LL: 3.63401, prior: 0.81520, aleatoric unc.: 9.70766\n",
      "Epoch 483/500  total: 3.69736, -LL: 3.61727, prior: 0.81478, aleatoric unc.: 9.70594\n",
      "Epoch 484/500  total: 3.70235, -LL: 3.63803, prior: 0.81578, aleatoric unc.: 9.71074\n",
      "Epoch 485/500  total: 3.70031, -LL: 3.64106, prior: 0.81726, aleatoric unc.: 9.71344\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 486/500  total: 3.70281, -LL: 3.65334, prior: 0.81765, aleatoric unc.: 9.71675\n",
      "Epoch 487/500  total: 3.69665, -LL: 3.62427, prior: 0.81798, aleatoric unc.: 9.71068\n",
      "Epoch 488/500  total: 3.69354, -LL: 3.60938, prior: 0.81778, aleatoric unc.: 9.69865\n",
      "Epoch 489/500  total: 3.69664, -LL: 3.66371, prior: 0.81562, aleatoric unc.: 9.69401\n",
      "Epoch 490/500  total: 3.70017, -LL: 3.61261, prior: 0.81859, aleatoric unc.: 9.69709\n",
      "Epoch 491/500  total: 3.70181, -LL: 3.64116, prior: 0.81858, aleatoric unc.: 9.70037\n",
      "Epoch 492/500  total: 3.69507, -LL: 3.62122, prior: 0.81482, aleatoric unc.: 9.69759\n",
      "Epoch 493/500  total: 3.69890, -LL: 3.65301, prior: 0.81908, aleatoric unc.: 9.69581\n",
      "Epoch 494/500  total: 3.70058, -LL: 3.65166, prior: 0.81909, aleatoric unc.: 9.69850\n",
      "Epoch 495/500  total: 3.69788, -LL: 3.62267, prior: 0.81817, aleatoric unc.: 9.70015\n",
      "Epoch 496/500  total: 3.69267, -LL: 3.64171, prior: 0.81855, aleatoric unc.: 9.68762\n",
      "Epoch 497/500  total: 3.70465, -LL: 3.66362, prior: 0.81682, aleatoric unc.: 9.70045\n",
      "Epoch 498/500  total: 3.70106, -LL: 3.66015, prior: 0.81733, aleatoric unc.: 9.70227\n",
      "Epoch 499/500  total: 3.69741, -LL: 3.64281, prior: 0.81737, aleatoric unc.: 9.70153\n"
     ]
    }
   ],
   "source": [
    "epochs = 500\n",
    "# for each epoch\n",
    "for epoch in range(epochs):\n",
    "    losses = list()\n",
    "    # for each mini-batch given by the loader:\n",
    "    for batch in loader:\n",
    "        # get the input in the mini-batch\n",
    "        # this has size (B, C)\n",
    "        # where B is the mini-batch size\n",
    "        # C is the number of features (1 in this case)\n",
    "        features = batch[\"data\"]\n",
    "        # get the targets in the mini-batch (there shall be B of them)\n",
    "        target = batch[\"target\"]\n",
    "        # get the output of the neural network:\n",
    "        prediction = b_network(features)\n",
    "        \n",
    "        # calculate the loss function being minimized\n",
    "        # in this case, it is the mean-squared error between the prediction and the target values added\n",
    "        # to the Kullback-Leibler divergence between the current weight Gaussian and\n",
    "        # the prior Gaussian, set to the unit Normal distribution\n",
    "        nll = b_network.nll(prediction, target)\n",
    "        prior = kl_loss(b_network)\n",
    "        loss = nll + weight_kl * prior\n",
    "\n",
    "        # clean the optimizer temporary gradient storage\n",
    "        optimizer.zero_grad()\n",
    "        # calculate the gradient of the loss function as a function of the gradients\n",
    "        loss.backward()\n",
    "        # ask the Adam optimizer to change the parameters in the direction of - gradient\n",
    "        # Adam scales the gradient by a constant which is adaptively tuned\n",
    "        # take a look at the Adam paper for more details: https://arxiv.org/abs/1412.6980\n",
    "        optimizer.step()\n",
    "        \n",
    "        ale = b_network.aleatoric_uncertainty().detach().numpy()\n",
    "\n",
    "        losses.append(loss.detach().cpu().item())\n",
    "    avg_loss = np.mean(np.array(losses))\n",
    "    print(f\"Epoch {epoch}/{epochs}  total: {avg_loss:.5f}, -LL: {nll.item():.5f}, prior: {prior.item():.5f}, aleatoric unc.: {ale:.5f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15f3f633",
   "metadata": {},
   "source": [
    "To evaluate the effect of the uncertainty, we perform the prediction many times for the same data and take the average and root-mean-squared-error of the predictions, since each prediction performed with the Bayesian Neural Network leads to a different results, using a different weight, selected from the final Gaussian."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a3d244e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "b_predicted = list()\n",
    "for k in range(10):\n",
    "    p = b_network(torch.from_numpy(test_data[:,0:1])).detach().numpy()\n",
    "    b_predicted.append(p[:,0])\n",
    "b_predicted = np.stack(b_predicted, axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85fed034",
   "metadata": {},
   "source": [
    "We can now take the average result for each sample, and their root-mean-squared-error as an estimate of the mean and epistemic uncertainty for the results.\n",
    "\n",
    "The aleatoric uncertainty is fitted as an independent parameter. Since we assume the aleatoric uncertainty is independent, we can calculate the total uncertainty as the sum of squares of the epistemic and aleatoric uncertainty."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4a56960d",
   "metadata": {},
   "outputs": [],
   "source": [
    "b_mean = np.mean(b_predicted, axis=1)\n",
    "b_sigma = np.std(b_predicted, axis=1)\n",
    "aleatoric_uncertainty = b_network.aleatoric_uncertainty().detach().numpy()\n",
    "\n",
    "total_uncertainty = (b_sigma**2 + aleatoric_uncertainty**2)**0.5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ef3d430",
   "metadata": {},
   "source": [
    "Let's check how big are those uncertainties found:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4d01c41f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average epistemic uncertainty:  0.83653456\n"
     ]
    }
   ],
   "source": [
    "print(\"Average epistemic uncertainty: \", np.mean(b_sigma))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "67d456a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Aleatoric uncertainty:  9.7015295\n"
     ]
    }
   ],
   "source": [
    "print(\"Aleatoric uncertainty: \", aleatoric_uncertainty)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "364bdcd7",
   "metadata": {},
   "source": [
    "Note that the aleatoric uncertainty is very close to the standard deviation of the $\\epsilon$ component of the model we created in the beginning! Clearly the model could fit the uncertainty coming from that component of the noise.\n",
    "\n",
    "It is not easy to estimate the effect of the epistemic uncertainty, as it is different for every data point (as it is scaled by $x^2$), but we can plot it to take a look at its effect.\n",
    "\n",
    "Note that the uncertainties are the standard deviations of Gaussian models and therefore they correspond to a $1\\sigma$ quantile band, which is a 67% confidence band. The quantile corresponding to $2\\sigma$ corresponds to a 95% confidence band in a Gaussian model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8b9142e8",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "/* global mpl */\n",
       "window.mpl = {};\n",
       "\n",
       "mpl.get_websocket_type = function () {\n",
       "    if (typeof WebSocket !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof MozWebSocket !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert(\n",
       "            'Your browser does not have WebSocket support. ' +\n",
       "                'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "                'Firefox 4 and 5 are also supported but you ' +\n",
       "                'have to enable WebSockets in about:config.'\n",
       "        );\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = this.ws.binaryType !== undefined;\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById('mpl-warnings');\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent =\n",
       "                'This browser does not support binary websocket messages. ' +\n",
       "                'Performance may be slow.';\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = document.createElement('div');\n",
       "    this.root.setAttribute('style', 'display: inline-block');\n",
       "    this._root_extra_style(this.root);\n",
       "\n",
       "    parent_element.appendChild(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen = function () {\n",
       "        fig.send_message('supports_binary', { value: fig.supports_binary });\n",
       "        fig.send_message('send_image_mode', {});\n",
       "        if (fig.ratio !== 1) {\n",
       "            fig.send_message('set_dpi_ratio', { dpi_ratio: fig.ratio });\n",
       "        }\n",
       "        fig.send_message('refresh', {});\n",
       "    };\n",
       "\n",
       "    this.imageObj.onload = function () {\n",
       "        if (fig.image_mode === 'full') {\n",
       "            // Full images could contain transparency (where diff images\n",
       "            // almost always do), so we need to clear the canvas so that\n",
       "            // there is no ghosting.\n",
       "            fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "        }\n",
       "        fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "    };\n",
       "\n",
       "    this.imageObj.onunload = function () {\n",
       "        fig.ws.close();\n",
       "    };\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._init_header = function () {\n",
       "    var titlebar = document.createElement('div');\n",
       "    titlebar.classList =\n",
       "        'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
       "    var titletext = document.createElement('div');\n",
       "    titletext.classList = 'ui-dialog-title';\n",
       "    titletext.setAttribute(\n",
       "        'style',\n",
       "        'width: 100%; text-align: center; padding: 3px;'\n",
       "    );\n",
       "    titlebar.appendChild(titletext);\n",
       "    this.root.appendChild(titlebar);\n",
       "    this.header = titletext;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function () {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = (this.canvas_div = document.createElement('div'));\n",
       "    canvas_div.setAttribute(\n",
       "        'style',\n",
       "        'border: 1px solid #ddd;' +\n",
       "            'box-sizing: content-box;' +\n",
       "            'clear: both;' +\n",
       "            'min-height: 1px;' +\n",
       "            'min-width: 1px;' +\n",
       "            'outline: 0;' +\n",
       "            'overflow: hidden;' +\n",
       "            'position: relative;' +\n",
       "            'resize: both;'\n",
       "    );\n",
       "\n",
       "    function on_keyboard_event_closure(name) {\n",
       "        return function (event) {\n",
       "            return fig.key_event(event, name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    canvas_div.addEventListener(\n",
       "        'keydown',\n",
       "        on_keyboard_event_closure('key_press')\n",
       "    );\n",
       "    canvas_div.addEventListener(\n",
       "        'keyup',\n",
       "        on_keyboard_event_closure('key_release')\n",
       "    );\n",
       "\n",
       "    this._canvas_extra_style(canvas_div);\n",
       "    this.root.appendChild(canvas_div);\n",
       "\n",
       "    var canvas = (this.canvas = document.createElement('canvas'));\n",
       "    canvas.classList.add('mpl-canvas');\n",
       "    canvas.setAttribute('style', 'box-sizing: content-box;');\n",
       "\n",
       "    this.context = canvas.getContext('2d');\n",
       "\n",
       "    var backingStore =\n",
       "        this.context.backingStorePixelRatio ||\n",
       "        this.context.webkitBackingStorePixelRatio ||\n",
       "        this.context.mozBackingStorePixelRatio ||\n",
       "        this.context.msBackingStorePixelRatio ||\n",
       "        this.context.oBackingStorePixelRatio ||\n",
       "        this.context.backingStorePixelRatio ||\n",
       "        1;\n",
       "\n",
       "    this.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
       "        'canvas'\n",
       "    ));\n",
       "    rubberband_canvas.setAttribute(\n",
       "        'style',\n",
       "        'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
       "    );\n",
       "\n",
       "    // Apply a ponyfill if ResizeObserver is not implemented by browser.\n",
       "    if (this.ResizeObserver === undefined) {\n",
       "        if (window.ResizeObserver !== undefined) {\n",
       "            this.ResizeObserver = window.ResizeObserver;\n",
       "        } else {\n",
       "            var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n",
       "            this.ResizeObserver = obs.ResizeObserver;\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n",
       "        var nentries = entries.length;\n",
       "        for (var i = 0; i < nentries; i++) {\n",
       "            var entry = entries[i];\n",
       "            var width, height;\n",
       "            if (entry.contentBoxSize) {\n",
       "                if (entry.contentBoxSize instanceof Array) {\n",
       "                    // Chrome 84 implements new version of spec.\n",
       "                    width = entry.contentBoxSize[0].inlineSize;\n",
       "                    height = entry.contentBoxSize[0].blockSize;\n",
       "                } else {\n",
       "                    // Firefox implements old version of spec.\n",
       "                    width = entry.contentBoxSize.inlineSize;\n",
       "                    height = entry.contentBoxSize.blockSize;\n",
       "                }\n",
       "            } else {\n",
       "                // Chrome <84 implements even older version of spec.\n",
       "                width = entry.contentRect.width;\n",
       "                height = entry.contentRect.height;\n",
       "            }\n",
       "\n",
       "            // Keep the size of the canvas and rubber band canvas in sync with\n",
       "            // the canvas container.\n",
       "            if (entry.devicePixelContentBoxSize) {\n",
       "                // Chrome 84 implements new version of spec.\n",
       "                canvas.setAttribute(\n",
       "                    'width',\n",
       "                    entry.devicePixelContentBoxSize[0].inlineSize\n",
       "                );\n",
       "                canvas.setAttribute(\n",
       "                    'height',\n",
       "                    entry.devicePixelContentBoxSize[0].blockSize\n",
       "                );\n",
       "            } else {\n",
       "                canvas.setAttribute('width', width * fig.ratio);\n",
       "                canvas.setAttribute('height', height * fig.ratio);\n",
       "            }\n",
       "            canvas.setAttribute(\n",
       "                'style',\n",
       "                'width: ' + width + 'px; height: ' + height + 'px;'\n",
       "            );\n",
       "\n",
       "            rubberband_canvas.setAttribute('width', width);\n",
       "            rubberband_canvas.setAttribute('height', height);\n",
       "\n",
       "            // And update the size in Python. We ignore the initial 0/0 size\n",
       "            // that occurs as the element is placed into the DOM, which should\n",
       "            // otherwise not happen due to the minimum size styling.\n",
       "            if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n",
       "                fig.request_resize(width, height);\n",
       "            }\n",
       "        }\n",
       "    });\n",
       "    this.resizeObserverInstance.observe(canvas_div);\n",
       "\n",
       "    function on_mouse_event_closure(name) {\n",
       "        return function (event) {\n",
       "            return fig.mouse_event(event, name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mousedown',\n",
       "        on_mouse_event_closure('button_press')\n",
       "    );\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseup',\n",
       "        on_mouse_event_closure('button_release')\n",
       "    );\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'dblclick',\n",
       "        on_mouse_event_closure('dblclick')\n",
       "    );\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mousemove',\n",
       "        on_mouse_event_closure('motion_notify')\n",
       "    );\n",
       "\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseenter',\n",
       "        on_mouse_event_closure('figure_enter')\n",
       "    );\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseleave',\n",
       "        on_mouse_event_closure('figure_leave')\n",
       "    );\n",
       "\n",
       "    canvas_div.addEventListener('wheel', function (event) {\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        on_mouse_event_closure('scroll')(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.appendChild(canvas);\n",
       "    canvas_div.appendChild(rubberband_canvas);\n",
       "\n",
       "    this.rubberband_context = rubberband_canvas.getContext('2d');\n",
       "    this.rubberband_context.strokeStyle = '#000000';\n",
       "\n",
       "    this._resize_canvas = function (width, height, forward) {\n",
       "        if (forward) {\n",
       "            canvas_div.style.width = width + 'px';\n",
       "            canvas_div.style.height = height + 'px';\n",
       "        }\n",
       "    };\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
       "        event.preventDefault();\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus() {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function () {\n",
       "    var fig = this;\n",
       "\n",
       "    var toolbar = document.createElement('div');\n",
       "    toolbar.classList = 'mpl-toolbar';\n",
       "    this.root.appendChild(toolbar);\n",
       "\n",
       "    function on_click_closure(name) {\n",
       "        return function (_event) {\n",
       "            return fig.toolbar_button_onclick(name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    function on_mouseover_closure(tooltip) {\n",
       "        return function (event) {\n",
       "            if (!event.currentTarget.disabled) {\n",
       "                return fig.toolbar_button_onmouseover(tooltip);\n",
       "            }\n",
       "        };\n",
       "    }\n",
       "\n",
       "    fig.buttons = {};\n",
       "    var buttonGroup = document.createElement('div');\n",
       "    buttonGroup.classList = 'mpl-button-group';\n",
       "    for (var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            /* Instead of a spacer, we start a new button group. */\n",
       "            if (buttonGroup.hasChildNodes()) {\n",
       "                toolbar.appendChild(buttonGroup);\n",
       "            }\n",
       "            buttonGroup = document.createElement('div');\n",
       "            buttonGroup.classList = 'mpl-button-group';\n",
       "            continue;\n",
       "        }\n",
       "\n",
       "        var button = (fig.buttons[name] = document.createElement('button'));\n",
       "        button.classList = 'mpl-widget';\n",
       "        button.setAttribute('role', 'button');\n",
       "        button.setAttribute('aria-disabled', 'false');\n",
       "        button.addEventListener('click', on_click_closure(method_name));\n",
       "        button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
       "\n",
       "        var icon_img = document.createElement('img');\n",
       "        icon_img.src = '_images/' + image + '.png';\n",
       "        icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
       "        icon_img.alt = tooltip;\n",
       "        button.appendChild(icon_img);\n",
       "\n",
       "        buttonGroup.appendChild(button);\n",
       "    }\n",
       "\n",
       "    if (buttonGroup.hasChildNodes()) {\n",
       "        toolbar.appendChild(buttonGroup);\n",
       "    }\n",
       "\n",
       "    var fmt_picker = document.createElement('select');\n",
       "    fmt_picker.classList = 'mpl-widget';\n",
       "    toolbar.appendChild(fmt_picker);\n",
       "    this.format_dropdown = fmt_picker;\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = document.createElement('option');\n",
       "        option.selected = fmt === mpl.default_extension;\n",
       "        option.innerHTML = fmt;\n",
       "        fmt_picker.appendChild(option);\n",
       "    }\n",
       "\n",
       "    var status_bar = document.createElement('span');\n",
       "    status_bar.classList = 'mpl-message';\n",
       "    toolbar.appendChild(status_bar);\n",
       "    this.message = status_bar;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.send_message = function (type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function () {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1], msg['forward']);\n",
       "        fig.send_message('refresh', {});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
       "    var x0 = msg['x0'] / fig.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n",
       "    var x1 = msg['x1'] / fig.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0,\n",
       "        0,\n",
       "        fig.canvas.width / fig.ratio,\n",
       "        fig.canvas.height / fig.ratio\n",
       "    );\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch (cursor) {\n",
       "        case 0:\n",
       "            cursor = 'pointer';\n",
       "            break;\n",
       "        case 1:\n",
       "            cursor = 'default';\n",
       "            break;\n",
       "        case 2:\n",
       "            cursor = 'crosshair';\n",
       "            break;\n",
       "        case 3:\n",
       "            cursor = 'move';\n",
       "            break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_message = function (fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
       "    for (var key in msg) {\n",
       "        if (!(key in fig.buttons)) {\n",
       "            continue;\n",
       "        }\n",
       "        fig.buttons[key].disabled = !msg[key];\n",
       "        fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
       "    if (msg['mode'] === 'PAN') {\n",
       "        fig.buttons['Pan'].classList.add('active');\n",
       "        fig.buttons['Zoom'].classList.remove('active');\n",
       "    } else if (msg['mode'] === 'ZOOM') {\n",
       "        fig.buttons['Pan'].classList.remove('active');\n",
       "        fig.buttons['Zoom'].classList.add('active');\n",
       "    } else {\n",
       "        fig.buttons['Pan'].classList.remove('active');\n",
       "        fig.buttons['Zoom'].classList.remove('active');\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function () {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message('ack', {});\n",
       "};\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function (fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            var img = evt.data;\n",
       "            if (img.type !== 'image/png') {\n",
       "                /* FIXME: We get \"Resource interpreted as Image but\n",
       "                 * transferred with MIME type text/plain:\" errors on\n",
       "                 * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "                 * to be part of the websocket stream */\n",
       "                img.type = 'image/png';\n",
       "            }\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src\n",
       "                );\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                img\n",
       "            );\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        } else if (\n",
       "            typeof evt.data === 'string' &&\n",
       "            evt.data.slice(0, 21) === 'data:image/png;base64'\n",
       "        ) {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig['handle_' + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\n",
       "                \"No handler for the '\" + msg_type + \"' message type: \",\n",
       "                msg\n",
       "            );\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\n",
       "                    \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
       "                    e,\n",
       "                    e.stack,\n",
       "                    msg\n",
       "                );\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "};\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function (e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e) {\n",
       "        e = window.event;\n",
       "    }\n",
       "    if (e.target) {\n",
       "        targ = e.target;\n",
       "    } else if (e.srcElement) {\n",
       "        targ = e.srcElement;\n",
       "    }\n",
       "    if (targ.nodeType === 3) {\n",
       "        // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "    }\n",
       "\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    var boundingRect = targ.getBoundingClientRect();\n",
       "    var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
       "    var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
       "\n",
       "    return { x: x, y: y };\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys(original) {\n",
       "    return Object.keys(original).reduce(function (obj, key) {\n",
       "        if (typeof original[key] !== 'object') {\n",
       "            obj[key] = original[key];\n",
       "        }\n",
       "        return obj;\n",
       "    }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function (event, name) {\n",
       "    var canvas_pos = mpl.findpos(event);\n",
       "\n",
       "    if (name === 'button_press') {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * this.ratio;\n",
       "    var y = canvas_pos.y * this.ratio;\n",
       "\n",
       "    this.send_message(name, {\n",
       "        x: x,\n",
       "        y: y,\n",
       "        button: event.button,\n",