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

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

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 229.052512 257.012437 284.525022 310.122547 336.067227 336.067227
std 47.385234 43.090207 39.056941 38.810100 39.188350 39.188350
min 68.460243 116.666672 166.666672 216.666656 266.666656 266.666656
25% 199.025513 231.043968 268.152649 287.692963 309.048500 309.048500
50% 236.270004 261.788712 287.552231 307.462631 325.690994 325.690994
75% 266.407578 284.765038 305.627663 333.634926 358.819801 358.819801
max 328.001068 422.521454 503.497803 495.202881 517.336548 517.336548

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 196.484935 226.754176 257.969109 284.458726 313.343149 313.343149
std 53.273132 48.918822 43.238324 38.017761 31.893123 31.893123
min 66.666664 116.666664 166.666672 216.666656 266.666656 266.666656
25% 161.216377 199.360958 229.236111 257.796883 293.224785 293.224785
50% 198.681610 230.367378 266.217484 285.718018 307.758240 307.758240
75% 235.598625 260.512543 288.135971 307.883972 328.318169 328.318169
max 315.612274 394.641418 443.915314 441.297272 480.170135 480.170135

In [ ]: