CorrelationProcessor implements AnalysisProcessor { @Override public void run(IProgressMonitor monitor) { Date startTime = new Date(); CorrelationMethod method = CorrelationMethodFactory.createMethod(analysis.getMethod(), analysis.getMethodProperties()); IMatrix data = analysis.getData().get(); int layerIndex = analysis.getAttributeIndex(); IMatrixLayer<Double> layer = data.getLayers().get(layerIndex); IMatrixDimension comparedDimension = analysis.isTransposeData() ? data.getDimension(COLUMNS) : data.getDimension(ROWS); IMatrixDimension correlatedDimension = analysis.isTransposeData() ? data.getDimension(ROWS) : data.getDimension(COLUMNS); monitor.begin("Running correlation analysis ...", correlatedDimension.size() * (correlatedDimension.size() - 1) / 2); LayerAdapter<CorrelationResult> adapter = new LayerAdapter<>(CorrelationResult.class); final IMatrix results = new HashMatrix( adapter.getMatrixLayers(), new HashMatrixDimension(ROWS, correlatedDimension), new HashMatrixDimension(COLUMNS, correlatedDimension) ); analysis.setResults(new ResourceReference<>("results", results)); IMatrixPosition positionX = data.newPosition(); IMatrixPosition positionY = data.newPosition(); for (String X : positionX.iterate(correlatedDimension)) { if (monitor.isCancelled()) { break; } for (String Y : positionY.iterate(correlatedDimension.from(X))) { monitor.info("Correlating " + X + " with " + Y); try { CorrelationResult result = method.correlation( positionX.iterate(layer, comparedDimension), positionY.iterate(layer, comparedDimension), analysis.getReplaceNanValue() ); adapter.set(results, result, X, Y); adapter.set(results, result, Y, X); } catch (MethodException ex) { throw new AnalysisException(ex); } monitor.worked(1); } } analysis.setStartTime(startTime); analysis.setElapsedTime(new Date().getTime() - startTime.getTime()); } CorrelationProcessor(CorrelationAnalysis analysis); @Override void run(IProgressMonitor monitor);  }
@Test public void testAnalysisProcessor() throws IOException { CorrelationAnalysis analysis = getAnalysis(); IMatrix resultsOk = analysis.getResults().get(); analysis.setResults(null); try { AnalysisProcessor processor = new CorrelationProcessor(analysis); processor.run(getProgressMonitor()); } catch (AnalysisException e) { e.printStackTrace(); } IMatrix results = storeAndLoadMatrix(analysis.getResults().get()); AssertMatrix.assertEquals(resultsOk, results); }