Presentation is loading. Please wait.

Presentation is loading. Please wait.

Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 Playing with Objects.

Similar presentations


Presentation on theme: "Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 Playing with Objects."— Presentation transcript:

1 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 Playing with Objects

2 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 2 Topics 1.Lifecycle functions new() remove() Exercises (demo04.yml) 2.Linking objects many2one one2many links: Getting information through links Exercises (demo05.yml)

3 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 3 Creating and Removing Objects

4 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 4  New persons (instances of entities) can be added to the simulated population through birth, cloning, immigration => let’s concentrate first on births  Example (demo04+), while considering an « adult » (a possible « mother ») : new('person', filter=to_give_birth, age = 0, agegroup = 0, mother_id = id, gender = child_gender)  A new object of the type person is created if the filter condition is True  The Function “new” returns an identifier for this new object (its “id” value)  Fields are either specified or will receive “missing” value (e.g. “-1” if an integer)  Of course, to_give_birth and child_gender must be given values ex ante invoking “new” and creating the object  The right part of expressions are referring to the object which is presently considered (the “mother” in our case) => “ id ” is mother’s id Creating a new person (giving birth)

5 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 5  Cloning an instance of entity (e.g. a person) is duplicating an existing object  Cloning can e.g. be used when implementing immigration (coming back to that later)  The syntax in LIAM2 is similar as for the the NEW () function clone( filter=to_be_replicated, nationality = False)  A new object of the same type as original is created if the filter condition is True  The Function “ CLONE () ” returns an identifier for this new object (its “ id ” value)  The value of Fields in the new object are either specified (e.g; in this case, False = “Foreigner” / “not Luxembourgish”) or will be inherited from original (“parental”) values (contrarily to NEW which initializes by default with “ MISSINGS ”) Creating a new person (cloning)

6 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 6  The counterpart of births is death event  If a person dies, it can be removed from the dataset  Example (demo04) : remove(dead) Of course, the field “dead” must be initialized first dead: if(ISMALE, age >= 90, age >= 95)  « new » and « remove » are called lifecycle functions Getting rid of an Object

7 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 7 Linking Objects

8 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 8  Objects are easily linked in LIAM2, and information can be derived in an efficient way through links  2 types of Links : « many2one » …  Child => Mother  Wife => Husband  Person => Household  … and « one2many »  Mother => Children  Household => Members  We can link objects of the same entity / from different entities Linking Objects in LIAM2

9 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 9  Within the entity which is the SOURCE of link, add a “ links: ” section (cf. “ fields: ” section)  Example (Household => Members) entities: household: links: persons: {type: one2many, target: person, field: hh_id}  A link gets a name and a type, specifies the TARGET entity and the field which will make the link operational (which is in the present example a person’s field)  In this example, several persons can be linked to the same household  Other example (Child => Mother), to be declared in entity « person » mother: {type: many2one, target: person, field: mother_id} Specifying the links in LIAM2

10 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 10  « many2one » links  Most simple syntax :.  Example (mother’s age) : mother.age (Question : what about mother.mother.age ?)  Advanced syntax :.get( ) Example (income tax of the mother): mother.get(income * tax_percent) Getting information through links (1)

11 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 11  « one2many » links  We need to use aggregate functions :. ( )  Example (assuming « persons » is a link from a household to its members) persons.avg(age)  Available functions : count([filter]) sum(expr[, filter]) min, max(expr[, filter]) avg(expr[, filter]) Getting information through links (2)

12 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 12  To change object links, update the underlying field  Example (remove the link to a dead person) - mother_id: if(mother.dead, -1, mother_id)  Example (move young adults to another household) - new_hh_id: … - hh_id: if(age >= 24 and not alone, new_hh_id, hh_id) Modifying links

13 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 13 Exercises (demo04.yml)

14 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 14 1. Open demo04.yml in the editor 2. Go through contents : general structure, entities, processes (list & contents) 3. How many newly born persons in 2016 ? 4. Is this about 6% of the “target” population ?  ISFEMALE and (age >= 15) and (age <= 50) 5. How many dying persons in 2017 ? 6. Simulate over 10 years. What are the changed in "agegroup" thorugh time ? 7. Try modelling twins  Since we have no stochastic functions yet, lets just say all women who give birth at 35 have twins Exercises – About new objects

15 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 15 Exercises (demo05.yml)

16 Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 16 1. Open demo05.yml in the editor 2. Go through contents : general structure, entities, processes (list & contents) 3. Concentrate on year 2016  What are contents of CSV outputs for households in 2016 ?  How many persons with a mother (resp. a grand-mother) among the first 10 individuals ?  For the same group, what do you expect if comparing hh_id with household.id ? Check  Among persons with id between 90 and 99, how many persons in their respective households ? Check, for hh_id = 2010 And how many adults ( age >= 18 ) ?  How could I get the average age of persons living alone ? Exercises – Linking Objects


Download ppt "Autumn School Dynamic MSM16-18 November 2015 | L-Esch-sur-Alzette Slide 1 Playing with Objects."

Similar presentations


Ads by Google