- Forward


Conformal Arrays
A Programming Pattern


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Motivation
Back SMYC Forward
  • The Idea:
    • In many situations there are multiple pieces of data that need to be organized in a way that makes them easy to work with
    • While this problem can sometimes be solved with a single array, many other times a more powerful organizational scheme is needed
  • An Example:
    • A group that has developed a categorical measure of consumer confidence wants to explore the relationships between its measure, the consumer price index (CPI), the civilian unemployment rate (in percent), and the M2 money stock (in billions of dollars) for the year 2018 (on a monthly basis)
Review
Back SMYC Forward
  • Arrays in General:
    • Make it very easy to perform the same operation(s) on homogeneous values
  • For this Example
    • If you were only interested in the CPI, for example, you could store it in a double[] with twelve elements
Thinking About the Problem
Back SMYC Forward
  • Conceptualizing Tables of Data:
    • Row-major form - a collection of rows, each of which has columns
    • Column-major form - a collection of columns, each of which has rows
  • Conformal Arrays:
    • Regardless of the form, the arrays will share a common index
The Pattern
Back SMYC Forward

Choose the form that satisfies the following criteria:

  • The elements of the array must be of the same type
  • The indexes must be easily representable as int values
Records and Fields
Back SMYC Forward

A Visualization

images/ConformalArrays.svg
The Economics Example
Back SMYC Forward

Month CPI Unemp. M2 Confidence
Jan 247.867 4.5 13855.1 Low
Feb 248.991 4.4 13841.2 Low
Mar 249.554 4.1 14022.9 Moderate
Apr 250.546 3.7 14064.4 High
May 251.588 3.6 13984.6 High
Jun 251.989 4.2 14079.2 Moderate
Jul 252.006 4.1 14113.8 Low
Aug 252.146 3.9 14170.3 Moderate
Sep 252.439 3.6 14204.7 Moderate
Oct 252.885 3.5 14211.6 High
Nov 252.038 3.5 14272.8 High
Dec 251.233 3.7 14473.0 High

The Economics Example (cont.)
Back SMYC Forward
  • Using One Array for Each Row:
    • Some elements would be double values and some would be String values
  • Using One Array for Each Column:
    • Some arrays would contain nothing but double values and some would contain nothing but String values
    • A 0-based representation of the month can be used for the index
The Economics Example (cont.)
Back SMYC Forward

The Conformal Arrays

javaexamples/programmingpatterns/conformalarrays/ConformalArrays.java (Fragment: economicdata)
 
There's Always More to Learn
Back -