Simulation of the Sugar Beet model

Load the modules


In [1]:
import sys
sys.path.append('../src')
import Pyfuzzy as Fuzz
import numpy as np
import pylab as plt
import pandas as pd
%matplotlib inline

Load the model


In [2]:
f1=Fuzz.read_model('zr_simple_t.fis')

Simulation

Define the Simulation


In [3]:
ZR=pd.ExcelFile('ZR_Daten_DDR_1976_1990.xlsx')
df=ZR.parse("Tabelle1")
pd.DataFrame({'NI': df['NI_6']+df['NI_7']+df['NI_8']+df['NI_9']}).describe()


Out[3]:
NI
count 4551.000000
mean 222.603296
std 77.191826
min 67.900000
25% 170.400000
50% 217.300000
75% 269.700000
max 482.900000

8 rows × 1 columns


In [4]:
pd.DataFrame({'LT': df['LT_6']+df['LT_7']+df['LT_8']+df['LT_9']}).describe()


Out[4]:
LT
count 4551.000000
mean 63.189695
std 4.162295
min 50.900000
25% 60.000000
50% 62.700000
75% 65.600000
max 73.400000

8 rows × 1 columns


In [5]:
az=[20,30,40,50,60,70]    # array of soil quality
NI=np.random.normal(222,77,1000)  # generate 1000 normal distributed NIs
LT=np.random.normal(63,4,1000)    # same for the temperature

Make the simulation


In [6]:
x=pd.DataFrame(np.zeros((1000,6)),columns=['20','30','40','50','60','70']) # a data frame to store the res
for k in az:
    res=[]
    for i in range(1000):     # use the 1000 samples
        val=f1.calc3(k,LT[i],NI[i])
        res.append(val)
    res=np.array(res)
    x[str(k)]=res
x.describe()


Out[6]:
20 30 40 50 60 70
count 1000.000000 1000.000000 1000.000000 1000.000000 1000.000000 1000.000000
mean 226.006229 254.832349 285.510223 310.782142 336.613898 336.613898
std 53.552041 47.204226 39.025691 38.656326 39.528472 39.528472
min 25.615227 83.333336 166.666672 216.666656 266.666656 266.666656
25% 195.506557 230.076950 269.975296 288.018883 308.489273 308.489273
50% 235.193016 260.466202 288.357712 308.679550 327.764954 327.764954
75% 268.229836 286.502647 306.514267 335.348427 360.216515 360.216515
max 321.522308 408.161530 470.216034 462.574097 497.900238 497.900238

8 rows × 6 columns

Repeat the simulation with changed NI and LI


In [7]:
NI-=50    # 50 mm less 
LT+=1     # 1 degree more
for k in az:
    res=[]
    for i in range(1000):     # use the 1000 samples
        val=f1.calc3(k,LT[i],NI[i])
        res.append(val)
    res=np.array(res)
    x[str(k)]=res
x.describe()


Out[7]:
20 30 40 50 60 70
count 1000.000000 1000.000000 1000.000000 1000.000000 1000.000000 1000.000000
mean 188.102961 221.664989 259.542005 285.836518 314.152968 314.152968
std 66.446090 57.450530 42.987130 38.073674 32.533395 32.533395
min 0.000000 83.333328 166.666656 216.666656 266.666656 266.666656
25% 148.613792 190.643768 234.348579 261.021111 292.842857 292.842857
50% 196.615891 230.289894 269.492691 288.298538 308.927582 308.927582
75% 239.251034 263.574730 288.270302 309.340729 328.405556 328.405556
max 310.004211 378.673859 417.466461 421.504120 463.345917 463.345917

8 rows × 6 columns


In [7]: