In [ ]:
#diff eq: y' = -15y for t:[0,1.5] and y(0)=1 https://en.wikipedia.org/wiki/Stiff_equation

Machine Learning Solution To A Stiff Differential Equation

By Per Lindholm 2018 aug 1

In [185]:
import numpy as np
import chainer
from chainer import Function, gradient_check, report, training, utils, Variable
from chainer import datasets, iterators, optimizers, serializers
from chainer import Link, Chain, ChainList
import chainer.functions as F
import chainer.links as L
from chainer.training import extensions
from chainer.dataset import concat_examples

from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import pylab as plt
from skimage.restoration import denoise_tv_chambolle
In [186]:
import pandas as pd
In [187]:
def nearest_rectangle(limit):
    b = 0
    for a in range(int(limit**0.5),1,-1):
        b = limit//a
        if a*b != limit:
            continue
        else:
            break
            
    return (a,b)
In [188]:
class Model(chainer.Chain):

    def __init__(self, n_hidden,n_out):
        super(Model, self).__init__()
        with self.init_scope():
            self.l1 = L.Linear(None, n_hidden)
            self.l2 = L.Linear(None, n_hidden)
            self.l3 = L.Linear(None, n_out) 
    def __call__(self, x,xprev=-1):
        x = F.relu(self.l1(x))
        x = -F.relu(self.l2(-x))
        x = self.l3(x)
        return x
In [189]:
hidden = 5

model0 = Model(hidden,1)
optimizer0 = chainer.optimizers.Adam()
optimizer0.setup(model0)

model1 = Model(hidden,1)
optimizer1 = chainer.optimizers.Adam()
optimizer1.setup(model1)

modelt = Model(hidden,1)
optimizert = chainer.optimizers.Adam()
optimizert.setup(modelt)
Out[189]:
<chainer.optimizers.adam.Adam at 0x7f5fa260e7f0>
In [190]:
def rng():
    return 1e-15*np.random.rand(1,1).astype(np.float32)
In [191]:
steps = np.linspace(0,1.5,151)
iterations = 1000
init = np.array([1]).reshape(1,1).astype(np.float32)
y_pred = np.zeros(152)
y_pred[0] = init[0]
dt = 0.01
tol = 1e-5
for j, t in enumerate(steps):
    loss = Variable(np.array([1]))
    i = 0 
    while loss.data > tol:
        if t == 0:
            i = i + 1 
            y0 = model0(rng()) 
            y1 = model1(rng())
            yp = (y1-y0)/dt
            loss_eq = F.mean_squared_error(yp,-15*y0)
            loss_initial = F.mean_squared_error(init,y0)
            loss = loss_eq + loss_initial
            model0.cleargrads()
            model1.cleargrads()
            loss.backward()
            optimizer0.update()
            optimizer1.update()
            if i%10==0:print(j,i, loss_eq.data,loss_initial.data)
        else:
            tol = 1e-6
            i = i + 1 
            y1 = model1(rng())
            yp = (y1-y0)/dt
            loss_eq = F.mean_squared_error(yp,-15*y0)
            loss = loss_eq
            model1.cleargrads()
            loss.backward()
            optimizer1.update()
            if i%10==0:print(j,i, loss_eq.data)

    y_pred[j+1] = y1.data
    y0 = y1
    
#     print(loss_eq.data,loss_initial.data)
0 10 0.00836698 0.9970458
0 20 0.004404994 0.9957546
0 30 0.0013977573 0.99417025
0 40 0.00044858025 0.9921713
0 50 0.00023677325 0.9898037
0 60 0.00015891355 0.987155
0 70 8.013442e-05 0.9842767
0 80 2.1227395e-05 0.98117983
0 90 6.836146e-06 0.97784674
0 100 1.5782418e-05 0.9742769
0 110 2.3743298e-05 0.9705096
0 120 1.5311454e-05 0.96656024
0 130 1.6080035e-05 0.9624081
0 140 1.6287688e-05 0.9580656
0 150 1.4460428e-05 0.95353717
0 160 1.44479645e-05 0.948822
0 170 1.3420651e-05 0.94392604
0 180 1.27537705e-05 0.93885124
0 190 1.2193215e-05 0.93360126
0 200 1.1438107e-05 0.92818046
0 210 1.0817025e-05 0.92259234
0 220 1.0234626e-05 0.91684115
0 230 9.65389e-06 0.91093147
0 240 9.098024e-06 0.90486795
0 250 8.572943e-06 0.8986553
0 260 8.0705795e-06 0.89229876
0 270 7.5906064e-06 0.88580304
0 280 7.1415843e-06 0.8791738
0 290 6.719841e-06 0.87241614
0 300 6.310034e-06 0.86553574
0 310 5.938947e-06 0.8585378
0 320 5.59432e-06 0.85142815
0 330 5.2545265e-06 0.8442123
0 340 4.939145e-06 0.83689576
0 350 4.657676e-06 0.829484
0 360 4.3680047e-06 0.8219827
0 370 4.1170897e-06 0.81439734
0 380 3.8778207e-06 0.8067332
0 390 3.6502674e-06 0.7989959
0 400 3.426504e-06 0.79119056
0 410 3.2264982e-06 0.78332245
0 420 3.0445588e-06 0.7753967
0 430 2.8711297e-06 0.7674184
0 440 2.7165224e-06 0.7593924
0 450 2.5509394e-06 0.75132346
0 460 2.4134724e-06 0.7432164
0 470 2.2733375e-06 0.7350758
0 480 2.1646679e-06 0.726906
0 490 2.049775e-06 0.7187115
0 500 1.9274084e-06 0.71049654
0 510 1.860476e-06 0.7022651
0 520 1.7001844e-06 0.6940214
0 530 1.6306522e-06 0.6857692
0 540 1.6367469e-06 0.6775121
0 550 3.3904103e-06 0.66925263
0 560 0.00044471901 0.6609882
0 570 0.00015461635 0.65305036
0 580 6.762258e-05 0.6451738
0 590 3.1346375e-05 0.637323
0 600 1.0398118e-05 0.62948996
0 610 6.362848e-08 0.6216743
0 620 1.6532595e-06 0.6138639
0 630 7.383287e-07 0.606075
0 640 4.125318e-06 0.59830153
0 650 0.00010820582 0.59053415
0 660 0.000164102 0.58302176
0 670 1.441038e-05 0.5756035
0 680 3.4850075e-08 0.56826484
0 690 1.1030175e-05 0.5609683
0 700 1.632933e-05 0.5537096
0 710 5.8608526e-07 0.5464907
0 720 1.1913291e-06 0.5392914
0 730 9.808739e-07 0.5321231
0 740 4.1904623e-06 0.5249831
0 750 3.270362e-05 0.51786983
0 760 0.0006803225 0.5108044
0 770 0.00017336737 0.50406164
0 780 1.4385049e-05 0.49740198
0 790 2.4238545e-06 0.49078393
0 800 4.2768006e-06 0.48419288
0 810 4.6906653e-06 0.47762564
0 820 2.8832621e-06 0.47110608
0 830 1.0315716e-06 0.46462256
0 840 3.7778614e-07 0.45817444
0 850 5.6689737e-07 0.45176226
0 860 3.940515e-06 0.44539532
0 870 0.0011165835 0.43917713
0 880 5.5390425e-05 0.43309453
0 890 7.011251e-06 0.42718202
0 900 3.842615e-09 0.4213374
0 910 5.192951e-06 0.41553771
0 920 1.2789769e-05 0.40977883
0 930 6.718914e-06 0.40406242
0 940 2.4592737e-07 0.39838493
0 950 1.4901161e-06 0.39273697
0 960 1.7483965e-06 0.38712773
0 970 1.581104e-06 0.38155666
0 980 9.3053336e-07 0.37602443
0 990 4.101023e-07 0.37053126
0 1000 1.0781377e-05 0.36508617
0 1010 0.001316215 0.35980007
0 1020 0.00017387001 0.35464197
0 1030 3.0138192e-05 0.34962592
0 1040 1.9814033e-06 0.3446769
0 1050 2.6875214e-06 0.33977315
0 1060 1.1201873e-05 0.33490992
0 1070 7.3951487e-06 0.33008796
0 1080 5.267075e-07 0.32530448
0 1090 6.432683e-07 0.32055143
0 1100 2.3487237e-06 0.31583253
0 1110 7.7650475e-07 0.31115288
0 1120 1.4473537e-06 0.30650735
0 1130 1.7915338e-06 0.30189914
0 1140 3.2867329e-06 0.29732728
0 1150 4.072369e-05 0.2927844
0 1160 0.0015696249 0.28825396
0 1170 7.0832015e-05 0.28409135
0 1180 4.0338236e-06 0.2799721
0 1190 2.2163505e-05 0.27588677
0 1200 1.2296668e-05 0.27183145
0 1210 1.4807688e-07 0.26780462
0 1220 7.842602e-06 0.26381415
0 1230 1.1510792e-06 0.2598655
0 1240 3.6846563e-07 0.2559468
0 1250 1.8977337e-06 0.2520581
0 1260 9.1404786e-07 0.24820502
0 1270 9.667574e-07 0.24438424
0 1280 1.1871691e-06 0.24059671
0 1290 1.4313357e-06 0.23684283
0 1300 5.9488284e-06 0.23312043
0 1310 0.0005185565 0.22939718
0 1320 0.00094452396 0.22600779
0 1330 0.00028403482 0.22264071
0 1340 0.00010748285 0.21935122
0 1350 3.5390844e-05 0.21610487
0 1360 9.790675e-06 0.21289301
0 1370 1.4576981e-06 0.20971127
0 1380 1.2585951e-07 0.20655769
0 1390 2.0737389e-06 0.20343226
0 1400 2.6470261e-06 0.20033585
0 1410 8.36445e-07 0.1972684
0 1420 5.908405e-07 0.19422714
0 1430 1.3826948e-06 0.19121228
0 1440 6.070777e-07 0.18822649
0 1450 1.2728278e-06 0.18526696
0 1460 7.171766e-07 0.18233642
0 1470 6.757946e-07 0.17943324
0 1480 8.9319747e-07 0.17655772
0 1490 1.6921113e-06 0.17370984
0 1500 2.2619286e-05 0.17088448
0 1510 0.0022146448 0.16803321
0 1520 9.255109e-06 0.16553418
0 1530 1.9311905e-05 0.16302817
0 1540 8.21276e-06 0.16055794
0 1550 5.4547863e-06 0.15811808
0 1560 4.4904336e-06 0.15570302
0 1570 1.7851571e-06 0.15330967
0 1580 3.214518e-08 0.15093723
0 1590 1.8030405e-06 0.1485876
0 1600 1.6039703e-06 0.1462622
0 1610 4.940093e-07 0.14395975
0 1620 8.5398005e-07 0.14167812
0 1630 6.7109886e-07 0.13941926
0 1640 7.8662197e-07 0.13718235
0 1650 6.571099e-07 0.13496791
0 1660 7.9170513e-07 0.13277552
0 1670 6.1902483e-07 0.13060579
0 1680 3.541354e-07 0.12845854
0 1690 5.5333658e-09 0.12633443
0 1700 5.6102468e-05 0.12424374
0 1710 0.0015501142 0.122250386
0 1720 0.00028725842 0.12029316
0 1730 7.2429284e-06 0.118397094
0 1740 1.1898636e-05 0.11654226
0 1750 2.8055107e-05 0.11471571
0 1760 1.4132969e-05 0.11291348
0 1770 4.806943e-07 0.111131765
0 1780 1.4771013e-07 0.10936461
0 1790 8.0876725e-07 0.107611455
0 1800 1.0257681e-06 0.10587779
0 1810 2.7913848e-07 0.1041627
0 1820 8.788347e-07 0.1024639
0 1830 4.2551255e-07 0.100783765
0 1840 6.679775e-07 0.09912067
0 1850 5.4485645e-07 0.09747562
0 1860 3.263276e-07 0.09584832
0 1870 1.3759745e-08 0.094239436
0 1880 1.4910621e-05 0.09265255
0 1890 0.0012510279 0.0911297
0 1900 0.00073915184 0.08955802
0 1910 3.8674843e-05 0.08815183
0 1920 4.3779295e-05 0.08675714
0 1930 1.3167687e-05 0.08535766
0 1940 9.9284225e-06 0.08396849
0 1950 2.58226e-06 0.08260565
0 1960 3.3070046e-07 0.08125807
0 1970 2.1569576e-06 0.079919055
0 1980 2.046363e-08 0.07859892
0 1990 9.004225e-07 0.07729013
0 2000 2.4972542e-07 0.07599723
0 2010 2.8216982e-07 0.074717976
0 2020 3.7252903e-07 0.07345284
0 2030 2.4782275e-07 0.072202094
0 2040 4.5634806e-08 0.07096571
0 2050 9.441723e-06 0.06974725
0 2060 0.001829877 0.068594046
0 2070 0.0006414432 0.06739045
0 2080 0.00035702667 0.06632519
0 2090 0.00014343037 0.06528105
0 2100 5.065555e-05 0.06424813
0 2110 1.1584926e-05 0.063225456
0 2120 4.1808016e-07 0.0622125
0 2130 4.380454e-07 0.061208494
0 2140 3.283276e-08 0.060212918
0 2150 7.849312e-07 0.059227273
0 2160 9.222722e-07 0.05825336
0 2170 1.4334455e-07 0.057290714
0 2180 4.292533e-07 0.05633756
0 2190 3.9377846e-07 0.055395238
0 2200 1.9665549e-07 0.05446359
0 2210 3.772002e-07 0.053541996
0 2220 3.985806e-07 0.05263097
0 2230 2.9033345e-07 0.051730473
0 2240 2.6915222e-07 0.050840244
0 2250 3.8900544e-07 0.04996025
0 2260 5.490883e-07 0.049090523
0 2270 4.912159e-06 0.048229694
0 2280 0.0004817086 0.04736073
0 2290 0.00039902708 0.046604216
0 2300 2.6532362e-06 0.04582748
0 2310 1.7720045e-05 0.04508921
0 2320 2.066762e-05 0.044364393
0 2330 1.9496747e-05 0.04364886
0 2340 1.19315555e-05 0.04294221
0 2350 3.7590225e-06 0.0422438
0 2360 2.0693642e-07 0.04155294
0 2370 1.5847036e-08 0.040868666
0 2380 1.2926557e-07 0.04019084
0 2390 4.623589e-07 0.039520644
0 2400 2.8216982e-07 0.038858462
0 2410 1.5438127e-07 0.038203686
0 2420 2.8115755e-07 0.037556097
0 2430 2.3748817e-07 0.0369161
0 2440 2.841998e-07 0.036283422
0 2450 1.7687944e-07 0.03565824
0 2460 3.285104e-07 0.035040163
0 2470 5.184347e-07 0.034429435
0 2480 5.490883e-07 0.033826116
0 2490 1.6039703e-06 0.03322965
0 2500 3.3532328e-05 0.032636896
0 2510 0.0016981213 0.03202744
0 2520 0.00070299505 0.03154558
0 2530 5.5859862e-05 0.03100412
0 2540 4.9374125e-05 0.030476129
0 2550 3.1157113e-05 0.029969323
0 2560 1.6233535e-06 0.029473297
0 2570 1.5276019e-06 0.028977087
0 2580 2.9467628e-06 0.028484102
0 2590 3.6379788e-10 0.028000774
0 2600 1.8499213e-07 0.027521305
0 2610 1.9920117e-07 0.027047759
0 2620 2.0090738e-07 0.02657984
0 2630 1.02678314e-07 0.026117582
0 2640 2.0867537e-07 0.025660679
0 2650 1.6660488e-07 0.025209453
0 2660 5.9604645e-08 0.024763789
0 2670 6.4173946e-09 0.024323752
0 2680 7.125346e-06 0.02389096
0 2690 0.0007035514 0.023480825
0 2700 0.00041200896 0.023039704
0 2710 0.0001509035 0.022677977
0 2720 0.000111635236 0.022297729
0 2730 1.1205884e-08 0.021916246
0 2740 1.9826584e-05 0.02154432
0 2750 8.019206e-07 0.021182723
0 2760 1.4808174e-06 0.020824257
0 2770 1.0471276e-06 0.02046682
0 2780 1.2789769e-07 0.020115688
0 2790 5.0655217e-08 0.019768333
0 2800 2.944589e-07 0.019424818
0 2810 5.5487362e-08 0.01908586
0 2820 3.784953e-08 0.01875085
0 2830 2.3470784e-07 0.018419713
0 2840 7.269009e-07 0.018092614
0 2850 1.0529911e-06 0.017769733
0 2860 5.0056005e-06 0.017450217
0 2870 0.000117762866 0.017129963
0 2880 0.001475489 0.01680583
0 2890 0.00011994621 0.016549353
0 2900 7.1121256e-05 0.016265187
0 2910 5.6002507e-05 0.015976854
0 2920 5.2532414e-09 0.015707437
0 2930 3.1702157e-06 0.015437795
0 2940 4.3064356e-06 0.015167829
0 2950 7.043127e-07 0.014905382
0 2960 9.2961363e-07 0.014643176
0 2970 5.820766e-11 0.014385914
0 2980 5.2386895e-08 0.014131088
0 2990 2.3655957e-07 0.013879423
0 3000 3.63274e-07 0.013630981
0 3010 2.1747928e-07 0.0133858435
0 3020 1.0451768e-06 0.013143422
0 3030 2.9321822e-05 0.012901903
0 3040 0.0017622227 0.0126463035
0 3050 0.0008341715 0.012468516
0 3060 7.6211756e-05 0.012246048
0 3070 3.410912e-05 0.012030891
0 3080 4.14143e-05 0.011826702
0 3090 9.139421e-08 0.011628862
0 3100 4.16123e-06 0.011431301
0 3110 4.7148205e-07 0.011233297
0 3120 8.628158e-07 0.01103904
0 3130 9.964515e-08 0.010847917
0 3140 3.0384763e-07 0.010657996
0 3150 4.0827217e-09 0.010471118
0 3160 2.449824e-07 0.010286074
0 3170 3.1127456e-08 0.010103722
0 3180 7.439303e-08 0.00992344
0 3190 1.0513759e-07 0.009745465
0 3200 3.0279716e-07 0.009569659
0 3210 1.3031322e-06 0.009395927
0 3220 1.6204322e-05 0.009223317
0 3230 0.0005779323 0.009044891
0 3240 1.4719743e-05 0.008898038
0 3250 0.00027907416 0.008733829
0 3260 4.0851595e-05 0.00859402
0 3270 6.6449584e-06 0.008443341
0 3280 1.6450947e-05 0.008293288
0 3290 3.7479367e-06 0.008151092
0 3300 1.5394116e-06 0.008006369
0 3310 1.8335504e-07 0.007865691
0 3320 6.8839654e-07 0.0077254325
0 3330 4.8952643e-08 0.0075879935
0 3340 2.2992936e-08 0.007451654
0 3350 7.596191e-08 0.007317173
0 3360 7.596191e-08 0.0071844715
0 3370 2.9467628e-08 0.0070535457
0 3380 6.1154424e-09 0.0069243987
0 3390 4.8657685e-06 0.0067977426
0 3400 0.00070213556 0.0066824253
0 3410 0.0006000579 0.0065429895
0 3420 2.7572274e-05 0.0064445063
0 3430 0.00010144024 0.0063379784
0 3440 5.902542e-05 0.006230108
0 3450 9.076103e-06 0.006122716
0 3460 7.731469e-07 0.0060169604
0 3470 3.7553255e-06 0.005913629
0 3480 3.1766922e-07 0.0058125197
0 3490 2.5837744e-07 0.0057125078
0 3500 3.248806e-08 0.005613015
0 3510 2.545139e-07 0.0055148834
0 3520 3.7252903e-09 0.005418249
0 3530 7.543713e-08 0.0053225644
0 3540 3.1127456e-08 0.005228215
0 3550 1.5134901e-08 0.005135025
0 3560 8.734787e-09 0.00504302
0 3570 6.435221e-08 0.0049521155
0 3580 3.7111022e-08 0.00486247
0 3590 3.214518e-08 0.0047739646
0 3600 2.6520866e-09 0.0046866555
0 3610 1.8828814e-07 0.004600629
0 3620 1.160441e-05 0.004516618
0 3630 0.00091019797 0.0044423062
0 3640 0.0005436982 0.00434499
0 3650 0.00013670397 0.004282058
0 3660 0.00010637834 0.0042079776
0 3670 1.5276019e-06 0.004131547
0 3680 1.7336748e-05 0.0040590367
0 3690 1.728913e-07 0.0039899466
0 3700 1.0432277e-06 0.003920404
0 3710 1.1429083e-06 0.0038508293
0 3720 8.185452e-08 0.003783256
0 3730 1.0700114e-07 0.0037158956
0 3740 2.6284397e-10 0.0036496734
0 3750 1.4771013e-07 0.0035840892
0 3760 1.8081664e-08 0.003519531
0 3770 4.2433385e-08 0.0034557069
0 3780 2.5669578e-08 0.003392758
0 3790 2.6906491e-08 0.0033307183
0 3800 8.806237e-07 0.0032696328
0 3810 2.7512215e-05 0.0032104363
0 3820 0.0009415953 0.0031585838
0 3830 0.00029137864 0.0030881448
0 3840 0.00023134872 0.0030431896
0 3850 2.209621e-05 0.0029839205
0 3860 4.438044e-06 0.0029320014
0 3870 6.6991524e-06 0.00288137
0 3880 4.6207024e-06 0.0028287126
0 3890 1.194454e-06 0.002778972
0 3900 9.2961363e-07 0.00272839
0 3910 5.2386895e-10 0.002679297
0 3920 6.8281224e-08 0.0026306678
0 3930 2.881643e-08 0.0025824779
0 3940 3.2523894e-07 0.0025349315
0 3950 2.0409097e-06 0.0024878983
0 3960 3.2101052e-05 0.0024406223
0 3970 0.000956933 0.0023887397
0 3980 0.00026878342 0.0023580585
0 3990 0.00023709919 0.0023083086
0 4000 2.6511043e-05 0.0022727705
0 4010 1.0490803e-06 0.002231518
0 4020 6.5811946e-06 0.0021909392
0 4030 2.8557988e-06 0.0021528283
0 4040 1.6184968e-06 0.0021134403
0 4050 1.6350532e-07 0.0020756812
0 4060 4.1262865e-08 0.0020378698
0 4070 1.6894865e-07 0.0020006509
0 4080 3.283276e-10 0.001964071
0 4090 6.571099e-09 0.001927902
0 4100 9.024461e-08 0.0018922401
0 4110 2.728324e-06 0.0018573223
0 4120 0.00015684184 0.0018250612
0 4130 0.0012823899 0.0017968606
0 4140 1.3008979e-05 0.0017581915
0 4150 0.00018117588 0.0017237817
0 4160 6.551869e-06 0.0016961226
0 4170 2.190833e-05 0.0016680297
0 4180 1.3536919e-08 0.0016376862
0 4190 2.8978548e-06 0.0016084242
0 4200 9.630103e-07 0.0015804305
0 4210 2.9342482e-07 0.001551917
0 4220 2.5547706e-09 0.001524203
0 4230 5.9604645e-08 0.0014966648
0 4240 8.913958e-09 0.0014695742
0 4250 2.3283064e-08 0.0014427898
0 4260 3.6097845e-09 0.0014164178
0 4270 7.2041075e-09 0.0013903602
0 4280 1.0027179e-08 0.0013646105
0 4290 7.701692e-08 0.0013392105
0 4300 1.5895093e-06 0.0013140016
0 4310 7.927237e-05 0.0012878642
0 4320 0.0022844814 0.0012565153
0 4330 8.899557e-05 0.0012452034
0 4340 0.00024226669 0.0012247682
0 4350 6.348422e-06 0.0012011201
0 4360 2.4953482e-05 0.001178828
0 4370 3.972764e-06 0.0011587563
0 4380 3.0992996e-06 0.0011390744
0 4390 3.283276e-10 0.0011186558
0 4400 5.879119e-07 0.0010986668
0 4410 1.5438127e-07 0.0010792731
0 4420 1.3064073e-07 0.001059796
0 4430 5.820766e-11 0.0010407538
0 4440 3.283276e-08 0.001021869
0 4450 4.811227e-10 0.0010032894
0 4460 4.980393e-09 0.000984925
0 4470 7.491417e-08 0.00096677843
0 4480 4.456524e-11 0.00094895484
0 4490 2.0090738e-09 0.00093131897
0 4500 8.5718966e-08 0.0009138845
0 4510 1.4994439e-06 0.00089657906
0 4520 0.00010362262 0.00087824103
0 4530 0.002205857 0.000856122
0 4540 4.9347324e-05 0.0008473756
0 4550 0.00010982887 0.0008354838
0 4560 8.802657e-05 0.00082092074
0 4570 6.016475e-06 0.00080565654
0 4580 6.0492684e-06 0.00079090765
0 4590 3.576396e-06 0.00077716884
0 4600 5.7193483e-07 0.0007639095
0 4610 1.3691897e-07 0.000750369
0 4620 3.7020436e-07 0.00073691405
0 4630 1.2663804e-08 0.0007238758
0 4640 3.961759e-09 0.0007108777
0 4650 3.7252903e-09 0.00069806667
0 4660 2.3868779e-08 0.00068541575
0 4670 9.904397e-10 0.0006729672
0 4680 1.0513759e-09 0.00066064793
0 4690 3.4960976e-09 0.0006485002
0 4700 4.4823537e-08 0.0006365013
0 4710 2.0606967e-07 0.0006246442
0 4720 6.478658e-07 0.000612937
0 4730 7.2531984e-06 0.00060118554
0 4740 0.00030481373 0.0005879339
0 4750 0.00034686478 0.0005769755
0 4760 0.00010750262 0.00056780624
0 4770 0.00012689574 0.00056054915
0 4780 1.728913e-07 0.0005492829
0 4790 1.72812e-05 0.0005389609
0 4800 4.657676e-06 0.0005301331
0 4810 3.155228e-07 0.00052030344
0 4820 9.8444616e-08 0.00051096187
0 4830 2.1569576e-08 0.00050176634
0 4840 5.684342e-10 0.0004926146
0 4850 2.0191692e-08 0.00048358898
0 4860 1.5847036e-08 0.00047473516
0 4870 6.435221e-08 0.00046592197
0 4880 1.0951135e-07 0.00045726274
0 4890 1.5288606e-07 0.0004487226
0 4900 1.206994e-06 0.00044022544
0 4910 4.1022446e-05 0.00043133405
0 4920 0.0016197413 0.00041946364
0 4930 0.00073837425 0.00041936355
0 4940 9.677609e-06 0.0004086886
0 4950 8.633474e-05 0.00040081982
0 4960 6.195569e-06 0.00039499628
0 4970 5.151742e-06 0.00038796518
0 4980 4.929083e-06 0.0003805692
0 4990 9.3329527e-07 0.00037407628
0 5000 1.3762565e-07 0.00036719593
0 5010 1.8859282e-08 0.00036059672
0 5020 6.571099e-09 0.00035401023
0 5030 1.6816557e-09 0.00034754447
0 5040 8.6278305e-08 0.0003411185
0 5050 5.0655217e-08 0.0003348637
0 5060 3.3877768e-08 0.0003286387
0 5070 3.8221515e-08 0.00032250208
0 5080 2.9795956e-08 0.00031644874
0 5090 9.969963e-07 0.00031055987
0 5100 6.80664e-05 0.00030535928
0 5110 0.0025131973 0.0003035912
0 5120 6.7830566e-05 0.00029286803
0 5130 0.00026377247 0.00028704634
0 5140 4.2426927e-05 0.00028294293
0 5150 5.3881704e-06 0.00027881135
0 5160 1.2504883e-05 0.00027404274
0 5170 2.4592737e-09 0.00026890458
0 5180 1.8158689e-06 0.00026403586
0 5190 9.139421e-08 0.00025948804
0 5200 1.7572347e-08 0.0002548427
0 5210 4.9375558e-08 0.0002502393
0 5220 4.7148205e-09 0.00024574887
0 5230 8.381903e-09 0.00024128243
0 5240 4.456524e-11 0.00023689365
0 5250 8.381903e-09 0.00023254879
0 5260 8.734787e-09 0.00022826935
0 5270 7.697963e-09 0.00022406
0 5280 5.392394e-09 0.0002198792
0 5290 2.337847e-07 0.00021573779
0 5300 2.4372357e-06 0.00021159933
0 5310 5.445749e-05 0.00020715078
0 5320 0.0014294044 0.0002009069
0 5330 0.000574407 0.00020201349
0 5340 9.572166e-05 0.00019586313
0 5350 7.3873707e-06 0.00019289977
0 5360 2.4858295e-05 0.00019002472
0 5370 1.0115605e-05 0.00018600533
0 5380 1.8598257e-06 0.00018297747
0 5390 5.733782e-07 0.0001794998
0 5400 2.5259305e-07 0.00017631498
0 5410 2.3286339e-07 0.00017300968
0 5420 2.7853275e-08 0.00016986615
0 5430 1.9653271e-08 0.00016671757
0 5440 2.0463631e-10 0.0001636015
0 5450 2.3748817e-07 0.00016057372
0 5460 3.6452584e-06 0.00015765206
0 5470 9.648829e-05 0.00015520985
0 5480 0.0015556763 0.0001543067
0 5490 0.00041270614 0.00014759618
0 5500 1.7775201e-06 0.00014638214
0 5510 4.0450286e-05 0.00014409931
0 5520 2.364668e-05 0.00014079708
0 5530 3.9765664e-06 0.00013869876
0 5540 4.3301043e-07 0.00013602324
0 5550 6.435221e-08 0.00013360656
0 5560 1.8746141e-07 0.00013112144
0 5570 1.4551915e-07 0.00012876108
0 5580 1.3691897e-07 0.00012633772
0 5590 3.248806e-08 0.00012400243
0 5600 2.6284397e-08 0.00012170733
0 5610 3.4735785e-07 0.0001194493
0 5620 5.684342e-06 0.00011730407
0 5630 0.00018271955 0.00011573676
0 5640 0.0010624754 0.0001147054
0 5650 5.8586626e-05 0.00011036297
0 5660 6.0574093e-05 0.000108389424
0 5670 5.315635e-05 0.00010730002
0 5680 5.8261876e-06 0.00010483723
0 5690 1.5847036e-08 0.00010307242
0 5700 4.292533e-07 0.000101248224
0 5710 1.6505146e-07 9.934642e-05
0 5720 7.6488504e-10 9.755211e-05
0 5730 1.9386789e-08 9.576365e-05
0 5740 2.0348034e-07 9.396054e-05
0 5750 8.1854523e-10 9.2236376e-05
0 5760 3.0595402e-09 9.051798e-05
0 5770 1.0027179e-08 8.882135e-05
0 5780 8.9102286e-08 8.7156346e-05
0 5790 3.1906247e-06 8.557987e-05
0 5800 0.00025279913 8.465713e-05
0 5810 0.0004615374 8.339066e-05
0 5820 0.0004599407 8.194695e-05
0 5830 2.4215842e-07 7.9515616e-05
0 5840 5.458424e-05 7.775451e-05
0 5850 1.6668273e-05 7.655036e-05
0 5860 1.8702449e-06 7.5460164e-05
0 5870 2.8140503e-06 7.414049e-05
0 5880 5.3504573e-07 7.271042e-05
0 5890 1.2249893e-07 7.142922e-05
0 5900 1.6894865e-07 7.018038e-05
0 5910 7.232666e-08 6.888318e-05
0 5920 7.6488504e-10 6.764513e-05
0 5930 5.820766e-09 6.640957e-05
0 5940 2.3655957e-09 6.519309e-05
0 5950 3.6379788e-10 6.399644e-05
0 5960 1.2028067e-08 6.2805215e-05
0 5970 1.7607817e-09 6.164295e-05
0 5980 9.313226e-10 6.048784e-05
0 5990 1.114131e-09 5.9352835e-05
0 6000 8.9102286e-08 5.8222213e-05
0 6010 3.4654513e-06 5.705293e-05
0 6020 0.00025307215 5.539486e-05
0 6030 0.0005028671 5.4108805e-05
0 6040 0.00041305495 5.324417e-05
0 6050 2.2618487e-06 5.3180687e-05
0 6060 6.5479275e-05 5.251427e-05
0 6070 8.605435e-06 5.1393825e-05
0 6080 5.401461e-06 5.028377e-05
0 6090 1.5158375e-06 4.9433616e-05
0 6100 1.0103722e-06 4.8637256e-05
0 6110 1.4551915e-11 4.7728692e-05
0 6120 1.397566e-07 4.6854806e-05
0 6130 1.3551107e-07 4.6033467e-05
0 6140 6.6302164e-08 4.517531e-05
0 6150 2.2737368e-09 4.4360953e-05
0 6160 1.2028067e-08 4.3540625e-05
0 6170 3.7252903e-09 4.2743544e-05
0 6180 2.446177e-08 4.195305e-05
0 6190 2.5976078e-08 4.1159994e-05
0 6200 1.9496747e-07 4.037905e-05
0 6210 1.1185703e-06 3.9596584e-05
0 6220 1.7472019e-05 3.8740112e-05
0 6230 0.00060103944 3.7323513e-05
0 6240 5.835399e-06 3.7535014e-05
0 6250 0.0002007802 3.6320936e-05
0 6260 8.4940344e-05 3.6438854e-05
0 6270 1.3603576e-06 3.545186e-05
0 6280 3.904628e-06 3.4787092e-05
0 6290 3.9499864e-06 3.42834e-05
0 6300 2.1541573e-06 3.3550277e-05
0 6310 8.1564303e-07 3.301043e-05
0 6320 2.8115755e-07 3.2358224e-05
0 6330 1.08057066e-08 3.178036e-05
0 6340 2.0005336e-07 3.1202377e-05
0 6350 6.0539605e-08 3.0613868e-05
0 6360 1.3315912e-08 3.0035533e-05
0 6370 1.9328672e-07 2.9478892e-05
0 6380 3.2042672e-06 2.8960807e-05
0 6390 0.00016243257 2.8730317e-05
0 6400 0.0013346861 2.889733e-05
0 6410 3.6744495e-06 2.74029e-05
0 6420 0.00018738984 2.6484044e-05
0 6430 8.986135e-07 2.6371896e-05
0 6440 2.4554916e-05 2.606852e-05
0 6450 8.824145e-07 2.5442972e-05
0 6460 1.5228907e-06 2.4978499e-05
0 6470 1.290101e-06 2.4592146e-05
0 6480 4.1931435e-07 2.4099245e-05
0 6490 9.197174e-08 2.3684956e-05
0 6500 3.6744495e-08 2.3238617e-05
0 6510 3.7252903e-09 2.2817587e-05
0 6520 2.6906491e-08 2.2389688e-05
0 6530 4.980393e-09 2.1975897e-05
0 6540 9.313226e-10 2.1568181e-05
0 6550 2.5364898e-08 2.1159345e-05
0 6560 2.6284397e-08 2.0760941e-05
0 6570 1.1984321e-07 2.036417e-05
0 6580 6.6351286e-06 1.9921714e-05
0 6590 0.00062340836 1.9003019e-05
0 6600 0.0001915379 1.9586332e-05
0 6610 0.00029014275 1.8520754e-05
0 6620 0.00015593544 1.830591e-05
0 6630 4.6906653e-06 1.822643e-05
0 6640 1.2236545e-05 1.8039116e-05
0 6650 5.225601e-06 1.7694461e-05
0 6660 6.2504205e-07 1.7312435e-05
0 6670 6.8523514e-07 1.7003818e-05
0 6680 2.291963e-07 1.6729166e-05
0 6690 1.3833414e-09 1.641712e-05
0 6700 2.9467628e-08 1.6117581e-05
0 6710 1.7070306e-08 1.5832184e-05
0 6720 8.734787e-09 1.5538055e-05
0 6730 7.697963e-09 1.5256926e-05
0 6740 1.114131e-09 1.4973751e-05
0 6750 1.5134901e-08 1.4695056e-05
0 6760 5.867696e-08 1.4418979e-05
0 6770 3.8595317e-08 1.4149556e-05
0 6780 8.1309736e-08 1.3881341e-05
0 6790 1.4715479e-06 1.360074e-05
0 6800 3.666155e-05 1.32461e-05
0 6810 0.0012358949 1.2427017e-05
0 6820 0.0005210787 1.3334321e-05
0 6830 0.0001780573 1.2398038e-05
0 6840 9.574032e-07 1.2413154e-05
0 6850 2.524972e-05 1.2306284e-05
0 6860 1.0489035e-05 1.1929085e-05
0 6870 1.3961844e-06 1.1795648e-05
0 6880 1.3691897e-07 1.1552084e-05
0 6890 7.9148776e-08 1.1352394e-05
0 6900 1.0085296e-07 1.1132558e-05
0 6910 4.8531547e-08 1.0936544e-05
0 6920 8.9102286e-08 1.0724695e-05
0 6930 1.1656448e-07 1.0523424e-05
0 6940 4.3620275e-08 1.0327891e-05
0 6950 3.0806768e-07 1.01269825e-05
0 6960 3.3737488e-06 9.913028e-06
0 6970 0.00013788846 9.555985e-06
0 6980 0.0015202217 8.926605e-06
0 6990 6.1154424e-05 9.541251e-06
0 7000 0.00013439452 9.438792e-06
0 7010 2.9923918e-05 8.991545e-06
1 10 0.250186
1 20 20.262386
1 30 0.03889266
1 40 2.272032
1 50 0.0008053926
1 60 0.281541
1 70 6.443396e-05
1 80 0.034184236
1 90 1.8572255e-06
1 100 0.004178952
1 110 5.72078e-06
1 120 0.00050582265
2 10 12.225546
2 20 8.455853
2 30 4.7974267
2 40 0.062155247
2 50 0.7007173
2 60 0.02865509
2 70 0.058005724
2 80 0.017995078
2 90 0.0018623295
2 100 0.0035777688
2 110 6.4207134e-06
2 120 0.00040729923
2 130 4.4628927e-05
3 10 15.914056
3 20 2.5938065
3 30 4.5694723
3 40 0.20192431
3 50 0.28936407
3 60 0.15582201
3 70 0.00021206951
3 80 0.020919893
3 90 0.003398225
3 100 0.0006419747
3 110 0.0009772779
3 120 1.9446248e-05
4 10 14.669291
4 20 0.7931653
4 30 3.2693799
4 40 0.43227023
4 50 0.081199095
4 60 0.1410989
4 70 0.008312113
4 80 0.0072680335
4 90 0.0056251143
4 100 6.0737497e-05
4 110 0.0005003894
4 120 0.00018923511
5 10 11.979511
5 20 0.27216333
5 30 2.2529206
5 40 0.44068456
5 50 0.023984876
5 60 0.10007822
5 70 0.013617484
6 10 9.134791
6 20 0.08745348
6 30 1.5126173
6 40 0.3849452
6 50 0.0046772426
6 60 0.06557216
6 70 0.014779871
7 10 7.0011554
7 20 0.025653232
7 30 1.0429833
7 40 0.30946827
7 50 0.00069832493
7 60 0.04410462
7 70 0.012739148
8 10 5.2062383
8 20 0.009979773
8 30 0.736685
8 40 0.2315532
8 50 0.00017200137
8 60 0.030985273
8 70 0.009671419
8 80 1.9111263e-05
8 90 0.0013656279
8 100 0.00039093406
9 10 3.8934114
9 20 0.007161674
9 30 0.5477888
9 40 0.16411209
9 50 0.0005224293
9 60 0.023982659
9 70 0.0064839176
9 80 7.07598e-05
9 90 0.0010853834
9 100 0.0002431284
10 10 2.7503788
10 20 0.011524148
10 30 0.41139287
10 40 0.106993034
10 50 0.0015973469
10 60 0.018689083
10 70 0.003801756
10 80 0.000193483
10 90 0.00085237995
10 100 0.00012125535
11 10 1.9244356
11 20 0.016973007
11 30 0.30992442
11 40 0.066789396
11 50 0.0030113067
11 60 0.014349092
11 70 0.0019746409
12 10 1.2844037
12 20 0.022397792
12 30 0.2267545
12 40 0.040081505
12 50 0.0037675225
12 60 0.010394566
12 70 0.0009690816
13 10 0.8989026
13 20 0.022541104
13 30 0.16726573
13 40 0.024642097
13 50 0.0040232074
13 60 0.007528505
13 70 0.00044218858
13 80 0.0003980894
13 90 0.00029470903
13 100 1.9337026e-06
14 10 0.65430695
14 20 0.022164263
14 30 0.12618114
14 40 0.014222737
14 50 0.0045327516
14 60 0.0054046563
14 70 0.00011831201
15 10 0.41972294
15 20 0.025064074
15 30 0.090072654
15 40 0.006881315
15 50 0.0045107394
15 60 0.0035175723
15 70 9.129333e-06
15 80 0.00037683657
15 90 9.209904e-05
16 10 0.30784526
16 20 0.022539206
16 30 0.06702701
16 40 0.0034034946
16 50 0.0043388316
16 60 0.0023000285
17 10 0.19141991
17 20 0.02310413
17 30 0.046273213
17 40 0.0011468729
17 50 0.0038080506
17 60 0.0013111252
17 70 5.5306173e-05
17 80 0.0002417252
17 90 1.1243406e-05
18 10 0.14220594
18 20 0.019540677
18 30 0.033919822
18 40 0.00037027246
18 50 0.0032938418
18 60 0.0007507021
19 10 0.08515651
19 20 0.018654468
19 30 0.022426024
19 40 1.514538e-05
19 50 0.002606365
19 60 0.00034126823
20 10 0.057553638
20 20 0.0155860875
20 30 0.0154567
20 40 1.5592612e-05
20 50 0.0019998564
20 60 0.00015546243
21 10 0.03853625
21 20 0.012885247
21 30 0.010498564
21 40 9.285163e-05
21 50 0.0014907721
21 60 5.7495447e-05
21 70 0.00012962079
21 80 3.344334e-05
22 10 0.029762825
23 10 0.00041771127
23 20 0.014216291
23 30 0.0014198027
24 10 0.023495942
24 20 0.0046795746
24 30 0.0049187383
24 40 5.323808e-05
24 50 0.00068726303
24 60 1.1609284e-05
25 10 0.007931197
25 20 0.0049819034
25 30 0.0021389702
25 40 0.00022504428
25 50 0.00036998122
26 10 0.005149643
26 20 0.0039395615
26 30 0.0013572508
27 10 0.0074491897
28 10 1.4643007e-05
28 20 0.0031270836
28 30 6.142273e-05
28 40 0.0003350306
28 50 3.090941e-05
29 10 0.0015233398
29 20 0.0017159779
29 30 0.0003764352
30 10 0.0025474061
30 20 0.001128444
30 30 0.00047317575
31 10 0.0018235783
31 20 0.00085887016
31 30 0.0003241156
32 10 0.0012495084
32 20 0.0006589301
32 30 0.00021310369
33 10 0.0009086813
33 20 0.0004966388
33 30 0.00014636682
34 10 0.0006224738
35 10 3.708665e-05
35 20 0.00032653988
36 10 0.0003459587
37 10 2.6553105e-05
37 20 0.00016890113
38 10 0.00016795933
39 10 1.5206273e-05
39 20 8.676185e-05
40 10 8.851181e-05
In [195]:
y_true = 1*np.exp(-15*steps)
In [196]:
plt.plot(y_pred)
plt.plot(y_true)
Out[196]:
[<matplotlib.lines.Line2D at 0x7f5f9dda8438>]
In [197]:
y_pred
Out[197]:
array([1.00000000e+00, 8.47462118e-01, 7.20346808e-01, 6.12291873e-01,
       5.20447671e-01, 4.42380488e-01, 3.76024067e-01, 3.19614828e-01,
       2.71677494e-01, 2.30926767e-01, 1.96289748e-01, 1.66844055e-01,
       1.41816050e-01, 1.20533735e-01, 1.02451995e-01, 8.70907009e-02,
       7.40263835e-02, 6.29293919e-02, 5.34900166e-02, 4.54763137e-02,
       3.86482924e-02, 3.28411236e-02, 2.79066041e-02, 2.37305164e-02,
       2.01770216e-02, 1.71428248e-02, 1.45740807e-02, 1.23846307e-02,
       1.05369091e-02, 8.96290690e-03, 7.62195140e-03, 6.47805631e-03,
       5.51381707e-03, 4.67901677e-03, 3.97575647e-03, 3.38734686e-03,
       2.87549943e-03, 2.45043635e-03, 2.08579004e-03, 1.77145749e-03,
       1.50100887e-03, 1.27357244e-03, 1.08863413e-03, 9.17688012e-04,
       7.89090991e-04, 6.72258437e-04, 5.71742654e-04, 4.86023724e-04,
       4.22440469e-04, 3.64139676e-04, 3.13058496e-04, 2.75693834e-04,
       2.41070986e-04, 2.10084021e-04, 1.87955797e-04, 1.67198479e-04,
       1.48206949e-04, 1.35220587e-04, 1.22845173e-04, 1.11237168e-04,
       1.04002655e-04, 9.69916582e-05, 9.02488828e-05, 8.38190317e-05,
       8.07419419e-05, 7.77021050e-05, 7.47144222e-05, 7.17937946e-05,
       6.89327717e-05, 6.61388040e-05, 6.34044409e-05, 6.07445836e-05,
       5.81666827e-05, 5.56558371e-05, 5.32269478e-05, 5.08800149e-05,
       4.86001372e-05, 4.64022160e-05, 4.42862511e-05, 4.22373414e-05,
       4.02778387e-05, 3.83779407e-05, 3.65599990e-05, 3.48091125e-05,
       3.31327319e-05, 3.15159559e-05, 2.99736857e-05, 2.84910202e-05,
       2.70679593e-05, 2.57194042e-05, 2.44155526e-05, 2.31787562e-05,
       2.19866633e-05, 2.08541751e-05, 1.97812915e-05, 1.87605619e-05,
       1.77845359e-05, 1.68457627e-05, 1.59591436e-05, 1.51097775e-05,
       1.43051147e-05, 1.35451555e-05, 1.28224492e-05, 1.21295452e-05,
       1.14664435e-05, 1.08405948e-05, 1.02445483e-05, 9.68575478e-06,
       9.14931297e-06, 8.64267349e-06, 8.15838575e-06, 7.69644976e-06,
       7.26431608e-06, 6.85453415e-06, 6.45965338e-06, 6.09457493e-06,
       5.74439764e-06, 5.41657209e-06, 5.10364771e-06, 4.80562449e-06,
       4.52995300e-06, 4.26918268e-06, 4.01586294e-06, 3.78489494e-06,
       3.56137753e-06, 3.35276127e-06, 3.14414501e-06, 2.95788050e-06,
       2.77161598e-06, 2.60770321e-06, 2.44379044e-06, 2.29477882e-06,
       2.16066837e-06, 2.02655792e-06, 1.90734863e-06, 1.78813934e-06,
       1.67638063e-06, 1.57207251e-06, 1.47521496e-06, 1.38580799e-06,
       1.30385160e-06, 1.22189522e-06, 1.13993883e-06, 1.07288361e-06,
       1.00582838e-06, 9.46223736e-07, 8.86619091e-07, 8.34465027e-07,
       7.82310963e-07, 7.30156898e-07, 6.85453415e-07, 6.40749931e-07])