/** * */ package analyze; import java.text.*; import javax.swing.*; // Front End Imports import model.compute.Compute; import util.*; /** *

Title:ShowCorrelMatrix

*

Description: correlates the output from two processes * of the model, say DOG to some Gabor processing. * The correlation is done with every possible positioning * of the two arrays and the output of each of * these correlations is shown in a table. * Just a thought.

*

Copyright: Copyright (c) 2009

*

Company: Hanover College

* @author John H. Krantz, Ph.D. * @version 0.1 */ public class CorrelTable { // array labels private String label1 = Defaults.LABEL1; private String label2 = Defaults.LABEL2; // arrays to be correlated private double [][] output1; private double [][] output2; private DecimalFormat rFmt = new DecimalFormat("0.000"); // table parameters private int width = 0; private int height = 0; // show the output private TableFrame table = new TableFrame(); // the correlation array double [][] r = new double[0][0]; String [] colTitles; String [] rowTitles; public CorrelTable(){}// empty constructor public JPanel showCorrel(){ JPanel tempPanel = new JPanel(); if (output1 != null & output2 != null){ r = runCorrel(); // now report the correlation // convert Correlations to text String [][] rString = new String[r.length][r[0].length]; for (int i = 0; i < r.length; i ++){ for (int j = 0; j < r[0].length; j ++){ rString[i][j] = rFmt.format(r[i][j]); } } table = new TableFrame(); tempPanel = table.getTablePanel("Correlation Matrix", label1, label2, colTitles, rowTitles, rString); width = table.getPanelWidth(); height = table.getPanelHeight(); } return tempPanel; } public double [][] runCorrel(){ boolean shortX1 = true; // flag for which array // is shorter in the x dimension if (output2.length < output1.length){ shortX1 = false; } boolean shortY1 = true; // flag for which array // is shorter in the y dimension if (output2[0].length < output1[0].length){ shortY1 = false; } // the differences in the length of the two arrays int difX = Math.abs(output1.length-output2.length); int difY = Math.abs(output1[0].length - output2[0].length); colTitles = new String[difX+1]; rowTitles = new String[difY+1]; double rTemp [][] = new double[difY+1][difX+1]; // create the common arrays dimensions int dimX = output2.length; if (shortX1){ dimX = output1.length; } int dimY = output2[0].length; if (shortY1){ dimY = output1[0].length; } // now do the correlations for (int x = 0; x <= difX; x ++){ colTitles[x] = ""+x; for (int y = 0; y <= difY; y ++){ rowTitles[y] = ""+y; int xOff1 = 0; int xOff2 = 0; int yOff1 = 0; int yOff2 = 0; if (shortX1){ xOff1 = 0; xOff2 = x; } else { xOff1 = x; xOff2 = 0; } if (shortY1){ yOff1 = 0; yOff2 = y; } else { yOff1 = y; yOff2 = 0; } double [][] out1 = new double[dimX][dimY]; double [][] out2 = new double[dimX][dimY]; for (int x1 = 0; x1 < dimX; x1 ++){ for (int y1 = 0; y1 < dimY; y1 ++){ out1[x1][y1] = output1[x1+xOff1][y1+yOff1]; out2[x1][y1] = output2[x1+xOff2][y1+yOff2]; } } // now do the correlation rTemp[y][x] = -2; rTemp[y][x] = Compute.Correl2D(out1, out2); } } return rTemp; } // set methods /** * Set the labels for the two outputs being correlated * @param lbl1 label for first output * @param lbl2 label for second output */ public void setLabels(String lbl1, String lbl2){ label1 = lbl1; label2 = lbl2; } /** * Set the two output arrays to be analyzed * @param out1 * @param out2 */ public void setOutputs(double [][] out1, double [][] out2){ output1 = out1; output2 = out2; } // get methods /** * Returns the width of the panel * @return width */ public int getWidth() { return width; } /** * Returns the height of the panel * @return height */ public int getHeight() { return height; } /** * Get the correlation matrix * @return */ public double [][] getRs() { return r; } }