Download presentation
Presentation is loading. Please wait.
Published byEllen O’Connor’ Modified over 9 years ago
1
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 Advanced topics
2
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 2 Topics 1.Advanced globals 2.Import other models 3.Functions with arguments 4.Loops
3
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 3 Advanced globals
4
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 4 Globals - in csv file globals: periodic: path: param\globals.csv fields: # PERIOD is implicit - WEMRA: float No need to reimport dataset when globals change Different globals with same dataset (variants) Usage is the same
5
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 5 globals: othertable: path: param\othertable.csv fields: # PERIOD is NOT implicit - PERIOD: int - INTFIELD: int - FLOATFIELD: float […] processes : test_globals : - result : othertable.INTFIELD - result : othertable.INTFIELD[period] Globals - other tables with PERIOD field
6
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 6 globals: othertable2: fields: - INTFIELD: int […] processes: test_globals: # explicit index - result: othertable2.INTFIELD[0] # expr index - row_number: trunc((period - 1980) / 10) - result: othertable2.INTFIELD[row_number] Globals - other tables without PERIOD field Row 0
7
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 7 globals: ARRAY: type: float MIG: path: param\mig.csv type: float […] processes: test_globals: - result: MIG * 2.5 Globals - (multi dimensional) arrays
8
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 8 Import other models (demo09.yml)
9
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 9 Re-use other model(s) inside a model/file Usage Split large model files Variants How? Merge ! "importing model" items replaces "imported model" items with the same name new fields can be added, existing fields definitions are replaced if present functions can be added, existing functions can be (completely) replaced (simulation) processes lists: replaced if present each file does not need to be a valid model (only the merged result)! Imports
10
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 10 import: imported.yml # Or import: - imported1.yml - imported2.yml entities: [everything that changes] simulation: [everything that changes] Imports - format
11
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 11 import: demo08.yml entities: person: fields: # additional field not present in the base model # (nor in the input in this case) - study_years_failed: {type: int, initialdata: False} processes: # we override the ineducation process ineducation: - … Imports - small example
12
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 12 Functions with arguments
13
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 13 function_name(arg1, arg2): - code - return result other_func: - result: function_name(value1, value2) Functions with arguments
14
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 14 myaverage(a, b): - c: a + b - return c / 2 other_func: # 1.5 (scalar) - result1: myaverage(1, 2) # one value per person - result2: myaverage(age, partner.age) Functions with arguments - example
15
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 15 While loops
16
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 16 - while scalar_condition : - the_code_to_repeat condition must be a scalar expression single value for all individuals number of iterations is always the same for all individuals count_to_5: - i: 1 - while i <= 5: - show(i) - i: i + 1 while loops
17
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 17 while loops repeat_while_below_1: - score: age / max(age) - while score < 1: # <-- this line is WRONG ! - score: score + 0.1 - show(score) ValueError: The truth value of an array with more than one element is ambiguous.Use a.any() or a.all()
18
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 18 while loops repeat_while_below_1: - score: age / max(age) - while any(score < 1): - score: score + 0.1 - show(score) repeat_while_below_1: - score: age / max(age) - while any(score < 1): - score: if(score < 1, score + 0.1, score) - show(score) Or
19
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 19 Exercises (demo05.yml)
20
Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 20 1. Split "demo05.yml" into "demo05fields.yml" containing fields definition and "demo05rest.yml" and run "demo05rest.yml" to check it works 2. Create "demo05variant.yml" reuse (import -- do NOT modify it in place) demo05.yml change agegroup to be groups of 5 years including for people 50+ put all output in a directory called "output_variant" Exercises - imports
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.