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.experiment.results;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import p3j.misc.math.Matrix2D;
22  
23  /**
24   * Computes the old age dependency ratio for certain sub-populations.
25   * 
26   * @author Christina Bohk
27   * @author Roland Ewald
28   * 
29   */
30  public class MergeSubPopOldAgeDependencyRatioSelector extends
31      MergeSubPopSumOverAgesSelector {
32  
33  	/** The lower border for the summation. */
34  	static final int LOWER_BORDER = 15;
35  
36  	/** The upper border for the summation. */
37  	static final int UPPER_BORDER = 65;
38  
39  	/**
40  	 * Instantiates a new merge sub-population for old age dependency ratios
41  	 * selector.
42  	 * 
43  	 * @param selectorsForAddition
44  	 *          the selectors for addition
45  	 * @param selectorsForSubtraction
46  	 *          the selectors for subtraction
47  	 * @param customFileName
48  	 *          the custom file name
49  	 */
50  	public MergeSubPopOldAgeDependencyRatioSelector(
51  	    AbstractAggregationSelector[] selectorsForAddition,
52  	    AbstractAggregationSelector[] selectorsForSubtraction,
53  	    String customFileName) {
54  		super(selectorsForAddition, selectorsForSubtraction, customFileName);
55  	}
56  
57  	/**
58  	 * Instantiates a new merge sub-populations for old age dependency ratio
59  	 * selector.
60  	 * 
61  	 * @param selectorsForAddition
62  	 *          the selectors for addition
63  	 * @param selectorsForSubtraction
64  	 *          the selectors for subtraction
65  	 * @param customFileName
66  	 *          the custom file name
67  	 */
68  	public MergeSubPopOldAgeDependencyRatioSelector(
69  	    List<AbstractAggregationSelector> selectorsForAddition,
70  	    List<AbstractAggregationSelector> selectorsForSubtraction,
71  	    String customFileName) {
72  		super(selectorsForAddition, selectorsForSubtraction, customFileName);
73  	}
74  
75  	@Override
76  	public void consider(int trialCount, ResultsOfTrial result) {
77  
78  		List<double[]> additionArraysYoungPop = new ArrayList<double[]>();
79  		List<double[]> additionArraysOldPop = new ArrayList<double[]>();
80  		List<double[]> subtractionArraysYoungPop = new ArrayList<double[]>();
81  		List<double[]> subtractionArraysOldPop = new ArrayList<double[]>();
82  
83  		for (AbstractAggregationSelector selector : getAddAggregationSelectors()) {
84  			additionArraysYoungPop.add(Matrix2D.sumRows(selector.select(result),
85  			    LOWER_BORDER, UPPER_BORDER).toArray()[0]);
86  			additionArraysOldPop.add(Matrix2D.sumRows(selector.select(result),
87  			    UPPER_BORDER, null).toArray()[0]);
88  		}
89  
90  		for (AbstractAggregationSelector selector : getSubtractAggregationSelectors()) {
91  			subtractionArraysYoungPop.add(Matrix2D.sumRows(selector.select(result),
92  			    LOWER_BORDER, UPPER_BORDER).toArray()[0]);
93  			subtractionArraysYoungPop.add(Matrix2D.sumRows(selector.select(result),
94  			    UPPER_BORDER, null).toArray()[0]);
95  		}
96  
97  		double[] rowSumYoungPop = sumPerElement(additionArraysYoungPop,
98  		    subtractionArraysYoungPop);
99  		double[] rowSumOldPop = sumPerElement(additionArraysOldPop,
100 		    subtractionArraysOldPop);
101 
102 		double[] rowQuotients = new double[rowSumYoungPop.length];
103 		for (int i = 0; i < rowQuotients.length; i++) {
104 			rowQuotients[i] = rowSumOldPop[i] / rowSumYoungPop[i];
105 		}
106 
107 		System.arraycopy(rowQuotients, 0, aggregation[trialCount], 0,
108 		    rowQuotients.length);
109 	}
110 
111 }