View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.simulation.calculation.deterministic;
17  
18  import p3j.experiment.results.BasicResults;
19  import p3j.misc.math.Matrix2D;
20  import p3j.simulation.calculation.deterministic.parameters.MigChildParameters;
21  
22  /**
23   * Calculation of the population containing children of migrants. One function
24   * does not conform to ESCA-JAVA0138 (9 parameters are required for
25   * calculation).
26   * 
27   * Created on July 22, 2006
28   * 
29   * @author Christina Bohk
30   * @author Roland Ewald
31   * 
32   */
33  public class MigChildPopulation extends
34      AbstractPopulation<MigChildParameters, BasicResults> {
35  
36    @Override
37    public BasicResults calculatePopulation(MigChildParameters parameters) {
38  
39      BasicResults results = new BasicResults(parameters.getNumOfYears(),
40          parameters.getMaxAge());
41  
42      calculateSurvivalProbabilities(parameters, results);
43  
44      // Calculate rest
45  
46      // ...for females
47      calculateMeanAndEndPopulation(parameters.getOldMeanXf(), parameters
48          .getOldFertX(), parameters.getFemalePropLiveBirth(), results
49          .getMeanXf(), results.getEndXf(), parameters.getSurviveProbO100f(),
50          results.getP1f(), results.getP2f(), parameters.getNumOfYears(),
51          parameters.getMaxAge());
52  
53      // ...for males
54      calculateMeanAndEndPopulation(parameters.getOldMeanXf(), parameters
55          .getOldFertX(), parameters.getMalePropLiveBirth(), results.getMeanXm(),
56          results.getEndXm(), parameters.getSurviveProbO100m(), results.getP1m(),
57          results.getP2m(), parameters.getNumOfYears(), parameters.getMaxAge());
58  
59      return results;
60    }
61  
62    /**
63     * Calculates mean and end populations.
64     * 
65     * @param oldMeanXf
66     *          old mean population of females
67     * @param oldFertX
68     *          old fertility
69     * @param propLiveBirth
70     *          proportion of live birth of this sex
71     * @param meanPopulation
72     *          mean population (filled by this method)
73     * @param endPopulation
74     *          end population (filled by this method)
75     * @param surviveProbO100
76     *          survival probability of the over-100-years-olds
77     * @param p1
78     *          P_1 matrix (infant survival probability first 6 months)
79     * @param p2
80     *          P_2 matrix (infant survival probability second half year)
81     * @param numberOfYears
82     *          number of years to be predicted
83     * @param maximumAge
84     *          the maximum age
85     */
86    protected static void calculateMeanAndEndPopulation(Matrix2D oldMeanXf,
87        Matrix2D oldFertX, Matrix2D propLiveBirth, Matrix2D meanPopulation,
88        Matrix2D endPopulation, Matrix2D surviveProbO100, Matrix2D p1,
89        Matrix2D p2, int numberOfYears, int maximumAge) {
90  
91      for (int year = 1; year < numberOfYears; year++) {
92  
93        double numOfChilds = AbstractPopulation.getNumOfChilds(oldMeanXf,
94            oldFertX, year);
95  
96        for (int age = 0; age < maximumAge + 1; age++) {
97  
98          // Calculate mean population
99          if (age == maximumAge) {
100           meanPopulation.setQuick(age, year, endPopulation.getQuick(age - 1,
101               year - 1)
102               * p2.getQuick(age - 1, year - 1)
103               + endPopulation.getQuick(age, year - 1)
104               * surviveProbO100.getQuick(year, 0));
105         } else {
106 	        switch (age) {
107           case 0:
108             meanPopulation.setQuick(age, year, numOfChilds
109                 * propLiveBirth.getQuick(year, 0));
110             break;
111           default:
112             meanPopulation.setQuick(age, year, endPopulation.getQuick(age - 1,
113                 year - 1)
114                 * p2.getQuick(age - 1, year - 1));
115             break;
116           }
117 				}
118 
119         // Calculate end population
120         if (age == maximumAge) {
121 	        endPopulation.setQuick(age, year, meanPopulation.getQuick(age, year)
122               * surviveProbO100.getQuick(year, 0));
123         } else {
124 	        endPopulation.setQuick(age, year, meanPopulation.getQuick(age, year)
125               * p1.getQuick(age, year));
126         }
127 
128       }
129     }
130   }
131 }