{ From user Lonnie, Model A1_D______2_D_date_t at 16-May-2016 8:13:37 PM } SoftwareVersion 4.6.2 { System Variables with non-default values: } TypeChecking := 1 Checking := 1 SaveOptions := 2 SaveValues := 0 NodeInfo FormNode: 1,0,0,1,0,0,0,,0,0,,0 Model A1_D______2_D_date_t Title: 1-D <==> 2-D date transformations Description: Challenge problems: Transforming between 1-D and 2-D indexes involving months and years.~ ~ In this exercise, you'll transform a 2-D array indexed by Month_of_year and Year to a 1-D array indexed by Month. And then you'll do the inverse transformation as well. You are allowed to take advantage of the fact that the cells correspond to dates, if that helps. Author: Lonnie Chrisman, Ph.D. ~ Lumina Decision Systems Date: Mon, May 16, 2016 7:33 PM DiagState: 2,1,0,746,474,17 WindState: 2,294,191,725,359 FontStyle: Arial,15 FileInfo: 0,Model A1_D______2_D_date_t,2,2,0,0,C:\Users\Lonnie\Documents\Month-Year-Transformations.ana Index Month_of_year Title: Month of year Definition: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] NodeLocation: 96,64,1 NodeSize: 48,24 ValueState: 2,88,95,441,379,0,MIDM {!40000|Att_PrevIndexValue: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']} Index Year Title: Year Definition: 2016..2025 NodeLocation: 96,128,1 NodeSize: 48,24 {!40000|Att_PrevIndexValue: [2016,2017,2018,2019,2020,2021,2022,2023,2024,2025]} Index Month Title: Month Definition: Sequence(1-Jan-2016, 1-Dec-2025, dateUnit:'M') NodeLocation: 96,192,1 NodeSize: 48,24 ValueState: 2,539,38,439,448,0,MIDM {!40000|Att_PrevIndexValue: [1-Jan-2016,1-Feb-2016,1-Mar-2016,1-Apr-2016,1-May-2016,1-Jun-2016,1-Jul-2016,1-Aug-2016,1-Sep-2016,1-Oct-2016,1-Nov-2016,1-Dec-2016,1-Jan-2017,1-Feb-2017,1-Mar-2017,1-Apr-2017,1-May-2017,1-Jun-2017,1-Jul-2017,1-Aug-2017,1-Sep-2017,1-Oct-2017,1-Nov-2017,1-Dec-2017,1-Jan-2018,1-Feb-2018,1-Mar-2018,1-Apr-2018,1-May-2018,1-Jun-2018,1-Jul-2018,1-Aug-2018,1-Sep-2018,1-Oct-2018,1-Nov-2018,1-Dec-2018,1-Jan-2019,1-Feb-2019,1-Mar-2019,1-Apr-2019,1-May-2019,1-Jun-2019,1-Jul-2019,1-Aug-2019,1-Sep-2019,1-Oct-2019,1-Nov-2019,1-Dec-2019,1-Jan-2020,1-Feb-2020,1-Mar-2020,1-Apr-2020,1-May-2020,1-Jun-2020,1-Jul-2020,1-Aug-2020,1-Sep-2020,1-Oct-2020,1-Nov-2020,1-Dec-2020,1-Jan-2021,1-Feb-2021,1-Mar-2021,1-Apr-2021,1-May-2021,1-Jun-2021,1-Jul-2021,1-Aug-2021,1-Sep-2021,1-Oct-2021,1-Nov-2021,1-Dec-2021,1-Jan-2022,1-Feb-2022,1-Mar-2022,1-Apr-2022,1-May-2022,1-Jun-2022,1-Jul-2022,1-Aug-2022,1-Sep-2022,1-Oct-2022,1-Nov-2022,1-Dec-2022,1-Jan-2023,1-Feb-2023,1-Mar-2023,1-Apr-2023,1-May-2023,1-Jun-2023,1-Jul-2023,1-Aug-2023,1-Sep-2023,1-Oct-2023,1-Nov-2023,1-Dec-2023,1-Jan-2024,1-Feb-2024,1-Mar-2024,1-Apr-2024,1-May-2024,1-Jun-2024,1-Jul-2024,1-Aug-2024,1-Sep-2024,1-Oct-2024,1-Nov-2024,1-Dec-2024,1-Jan-2025,1-Feb-2025,1-Mar-2025,1-Apr-2025,1-May-2025,1-Jun-2025,1-Jul-2025,1-Aug-2025,1-Sep-2025,1-Oct-2025,1-Nov-2025,1-Dec-2025]} Variable Array_on_Month Title: Array on Month Description: One-D data indexed by Month. Definition: Table(Month)(103,105.2,106.5,121.7,122.7,112,104.9,115,119.7,127.2,153.4,147.7,127.5,115.9,109.9,137.2,137.8,111.8,109.8,101.4,98.3,105.8,112.7,142.5,124.5,109.3,106.3,116.7,129,129.5,128.2,133,139.7,122.7,118.4,108.2,113.2,133.7,142.6,135.8,126.4,111.2,124.1,124.2,131.6,116,125.3,116.1,119,122.6,114,108.7,102.7,104.1,107.1,96.5,82.8,78.1,74.6,77.2,77.6,74.6,81.5,88.9,89.7,110.1,112.7,142.9,129,124.1,140.9,139.8,125.4,139.2,132.1,151.5,168,174.8,188.4,168.6,185.2,194.9,205.8,198.9,248.4,270.7,278.3,313.2,284.5,309.1,362.7,428.7,436.6,383.1,455.8,471.9,445.3,446.6,430.4,464.4,408.1,426.3,450,508.4,508.5,496.2,519.2,511.9,455.3,437.9,484.9,449.2,493.2,572.5,513,522.5,419.8,431.5,447.3,428.8) NodeLocation: 232,192,1 NodeSize: 48,24 ValueState: 2,263,27,828,379,1,MIDM Aliases: Alias Al1463453188 DisplayOutputs: Variable Transformed_to_Y_x_M Variable Array_on_Year_x_MoY Title: Array on Year x MoY Description: 2-D data indexed by month_of_year and year. Definition: Table(Month_of_year,Year)(~ 103,127.5,124.5,113.2,119,77.6,125.4,248.4,445.3,455.3,~ 105.2,115.9,109.3,133.7,122.6,74.6,139.2,270.7,446.6,437.9,~ 106.5,109.9,106.3,142.6,114,81.5,132.1,278.3,430.4,484.9,~ 121.7,137.2,116.7,135.8,108.7,88.9,151.5,313.2,464.4,449.2,~ 122.7,137.8,129,126.4,102.7,89.7,168,284.5,408.1,493.2,~ 112,111.8,129.5,111.2,104.1,110.1,174.8,309.1,426.3,572.5,~ 104.9,109.8,128.2,124.1,107.1,112.7,188.4,362.7,450,513,~ 115,101.4,133,124.2,96.5,142.9,168.6,428.7,508.4,522.5,~ 119.7,98.3,139.7,131.6,82.8,129,185.2,436.6,508.5,419.8,~ 127.2,105.8,122.7,116,78.1,124.1,194.9,383.1,496.2,431.5,~ 153.4,112.7,118.4,125.3,74.6,140.9,205.8,455.8,519.2,447.3,~ 147.7,142.5,108.2,116.1,77.2,139.8,198.9,471.9,511.9,428.8) NodeLocation: 232,88,1 NodeSize: 48,32 Aliases: Alias Al1463453189 DisplayOutputs: Variable Transformed_to_Month Variable Transformed_to_Y_x_M Title: Transformed to Y x MoY Description: Write a definition that transforms the 1-D data in Array_on_month into a 2-D array on Month_of_year x Year. ~ ~ If you do it correctly, your result should be the same as the result for Array_on_Year_x_MoY. NodeLocation: 424,192,1 NodeSize: 56,24 WindState: 2,551,201,476,224 ValueState: 2,621,94,462,285,0,MIDM ReformVal: [Year,Month_of_year] DisplayInputs: Variable Array_on_Month {!40000|Att_XRole: Year} {!40000|Att_ColorRole: Month_of_year} Module Solutions Title: Solutions NodeLocation: 608,128,1 NodeSize: 48,24 NodeInfo: 1,0,1,1,1,1,0,,0,,0 DiagState: 2,413,23,670,419,17 Variable Transformed_to_Y_x_1 Title: Transformed to Y x MoY Description: When mapping from a 1-D array to a 2-D array, all you need is a 2-D map, where for each of the 2-D combinations, it specifies the element from the 1-D array. This map establishes the correspondence between the indexes. Once you have that map, then the transformation is just x[ i = map ], where i is the index of x. This general pattern generalizes to any number of target dimensions (e.g., mapping from 1-D to 4-D). ~ ~ In this example, the map is obtained easily using MakeDate. In more complex cases, you might want to use a separate variable to hold the map, so that the mapping is computed only once. Definition: Array_on_Month[ Month = MakeDate( Year, @Month_of_year) ] NodeLocation: 264,144,1 NodeSize: 56,24 WindState: 2,102,87,695,296 ValueState: 2,621,94,462,285,0,MIDM ReformVal: [Year,Month_of_year] {!40000|Att_XRole: Year} {!40000|Att_ColorRole: Month_of_year} Variable Transformed_to_Mont1 Title: Transformed to Month Description: This is a super-efficient way to do it, although it makes an assumption that our Month index starts in the first month and extends to the last month of the year. Definition: ConcatRows( Array_on_Year_x_MoY, Year, Month_of_year, Month ) NodeLocation: 400,56,1 NodeSize: 56,24 WindState: 2,102,87,791,395 ValueState: 2,216,223,416,303,0,MIDM Alias Al1463453188 Title: Array on Month Definition: 1 NodeLocation: 104,144,1 NodeSize: 48,24 Original: Array_on_Month Alias Al1463453189 Title: Array on Year x MoY Definition: 1 NodeLocation: 96,56,1 NodeSize: 48,32 Original: Array_on_Year_x_MoY Variable Transformed_to_Mont2 Title: Transformed to Month Description: This demonstrates one possible method, which is extremely general, for mapping from 2-D to 1-D (or really from any fixed number of dimensions to any arbitrary number of dimensions). We have two mappings, from the target dimensions to the source dimensions. For example, DatePart(Month,'Y') maps from Month to Year -- our source array has Year, and we want to go to Month. Definition: Array_on_Year_x_MoY[ Year = DatePart(Month,'Y'), ~ @Month_of_year = DatePart(Month,'M')] NodeLocation: 264,56,1 NodeSize: 56,24 WindState: 2,102,87,784,329 Close Solutions Variable Transformed_to_Month Title: Transformed to Month Description: Write a definition here that transforms the 2-D data in Array_on_Year_x_Month to a 1-D array on Month.~ ~ If you do it correctly, your result should be the same as the result for Array_on_month. NodeLocation: 424,88,1 NodeSize: 56,24 WindState: 2,564,281,476,224 ValueState: 2,216,223,416,303,0,MIDM DisplayInputs: Variable Array_on_Year_x_MoY Close A1_D______2_D_date_t