Modeling: Difference between revisions

From wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Mostly based on [http://greenteapress.com/ModSimPy/ModSimPy.pdf this paper] that comes with its own modsim library.
[[Category:AI]]
Mostly based on an older version of [http://greenteapress.com/modsimpy/ModSimPy3.pdf this paper] that comes with its own modsim library.


=Eyeopeners=
* A model depicts a system.
* Store results in a [[Python:DataTypes#List|list]]
* The state of the system attributes is stored in a [[Pandas#Series]]
<syntaxhighlight lang=python>
* Results of how the system attributes change over time are stored in Pandas Series too (1 Series per attribute).
for a in range(100):
* Parameters that determine how the system attributes change are also stored in a pandas series.
    funcAresults[a] = functionAcall(bla,bla)
* The functions that change the system attributes take the system parameters as parameter. This way you can play with the parameter values to get the best result.
    funcBresults[a] = functionBcall(bla,bla)
** [[Numpy#linspace]] provides an equally distributed range of values so you can play easily between the limits you set.  
</syntaxhighlight>
* The quality of the model can be judged by calculating the relative error of the [[Approximation]] 
: ModSimPy is using Series from [[Pandas]] to store results. This adds handy functions like.
 
* The state of the model is stored in a Pandas Series too.
=Other remarks=
* Put other interesting metrics in the state object too.
* If you use randomness in a function, get the mean values of several runs.
* If you use randomness in a function, get the mean values of several runs.
* Check the effect of different parameter values using [[Numpy]] [[Numpy#linspace | linspace]].
 
=Example code=
[[Numpy]] [[Numpy#linspace | linspace]]
<syntaxhighlight lang=python>
<syntaxhighlight lang=python>
funcAresults = pd.Series([])
funcAresults = pd.Series([])
Line 21: Line 23:
     print(funcAresults)
     print(funcAresults)
</syntaxhighlight>
</syntaxhighlight>
* The [https://en.wikipedia.org/wiki/Approximation_error Approximation error] ([https://nl.wikipedia.org/wiki/Benaderingsfout benaderingsfout]) is the difference between a calculated value and the real value. By dividing it by the real value you get the relative error. A bit relative error indicates bad calculation.
 
The largest relative error between two arrays as percentage:
Store results in a [[Pandas]] [[Pandas#Series|Series]]
<syntaxhighlight lang=python>
<syntaxhighlight lang=python>
max(abs(calculated - real) / real ) * 100
for a in range(100):
    funcAresults[a] = functionAcall(bla,bla)
    funcBresults[a] = functionBcall(bla,bla)
</syntaxhighlight>
</syntaxhighlight>
=Naming conventions=
;system
:[[Pandas#Series]] to store parameters of how the model behaves
;system.alpha
:Variable to store the net change.
;system.t_0
:First time-stamp
;system.p_0
:State of the system at t_0 (a Pandas series)
;system.t_end
:Last time-stamp

Latest revision as of 12:35, 24 January 2020

Mostly based on an older version of this paper that comes with its own modsim library.

  • A model depicts a system.
  • The state of the system attributes is stored in a Pandas#Series
  • Results of how the system attributes change over time are stored in Pandas Series too (1 Series per attribute).
  • Parameters that determine how the system attributes change are also stored in a pandas series.
  • The functions that change the system attributes take the system parameters as parameter. This way you can play with the parameter values to get the best result.
    • Numpy#linspace provides an equally distributed range of values so you can play easily between the limits you set.
  • The quality of the model can be judged by calculating the relative error of the Approximation

Other remarks

  • If you use randomness in a function, get the mean values of several runs.

Example code

Numpy linspace

funcAresults = pd.Series([])
p1_array = np.linspace(0,1,12)
for p1 in p1_array:
    for a in range(50):
        funcAresults[a] = functionAcall(p1,p2)
    print(funcAresults)

Store results in a Pandas Series

for a in range(100):
    funcAresults[a] = functionAcall(bla,bla)
    funcBresults[a] = functionBcall(bla,bla)

Naming conventions

system
Pandas#Series to store parameters of how the model behaves
system.alpha
Variable to store the net change.
system.t_0
First time-stamp
system.p_0
State of the system at t_0 (a Pandas series)
system.t_end
Last time-stamp