private void doParalellpiped() { int iNX, iNY; int x, y; int iMatchingClass = 0; int iClass, iGrid; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; final double dStdDev[][] = new double[m_Classes.size()][m_Window.length]; double dValue; ArrayList stats; MeanAndStdDev substats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { substats = ((MeanAndStdDev) stats.get(iGrid)); dMean[iClass][iGrid] = substats.mean; dStdDev[iClass][iGrid] = substats.stdDev; } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0; iClass < m_Classes.size(); iClass++) { iMatchingClass = iClass; for (iGrid = 0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { if (Math.abs(m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]) > dStdDev[iClass][iGrid]) { iMatchingClass = -1; break; } } else { break; } } if (iMatchingClass != -1) { break; } } if (iMatchingClass != -1) { m_Output.setCellValue(x, y, iMatchingClass + 1); } else { m_Output.setNoData(x, y); } } } }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { int x, y; int iN; int iNX, iNY; double dValue; double dProb; boolean bCDF; final IRasterLayer layer = m_Parameters.getParameterValueAsRasterLayer(INPUT); bCDF = m_Parameters.getParameterValueAsBoolean(CDF); dProb = m_Parameters.getParameterValueAsDouble(P); iN = m_Parameters.getParameterValueAsInt(N); layer.setFullExtent(); final AnalysisExtent gridExtent = new AnalysisExtent(layer); final IRasterLayer result = getNewRasterLayer( PROBABILITY, Sextante.getText("Probability__binomial"), IRasterLayer.RASTER_DATA_TYPE_DOUBLE, gridExtent); iNX = layer.getNX(); iNY = layer.getNY(); for (y = 0; y < iNY && setProgress(y, iNY); y++) { for (x = 0; x < iNX; x++) { dValue = layer.getCellValueAsDouble(x, y); if (!layer.isNoDataValue(dValue)) { if (bCDF) { result.setCellValue(x, y, PDF.binomialCDF(dProb, iN, (int) dValue)); } else { result.setCellValue(x, y, PDF.binomial(dProb, iN, (int) dValue)); } } else { result.setNoData(x, y); } } } return !m_Task.isCanceled(); }
@Override public boolean processAlgorithm() throws GeoAlgorithmExecutionException { int x, y; int iNX, iNY; double dValue; double dMean, dStdDev; boolean bCDF; final IRasterLayer window = m_Parameters.getParameterValueAsRasterLayer(INPUT); bCDF = m_Parameters.getParameterValueAsBoolean(CDF); dMean = m_Parameters.getParameterValueAsDouble(MEAN); dStdDev = m_Parameters.getParameterValueAsDouble(STDDEV); window.setFullExtent(); final AnalysisExtent gridExtent = new AnalysisExtent(window); final IRasterLayer result = getNewRasterLayer( PROBABILITY, Sextante.getText("Probability__exponential"), IRasterLayer.RASTER_DATA_TYPE_DOUBLE, gridExtent); iNX = window.getNX(); iNY = window.getNY(); for (y = 0; y < iNY && setProgress(y, iNY); y++) { for (x = 0; x < iNX; x++) { dValue = window.getCellValueAsDouble(x, y); if (!window.isNoDataValue(dValue)) { if (bCDF) { result.setCellValue(x, y, PDF.exponentialCDF(dMean, dStdDev, dValue)); } else { result.setCellValue(x, y, PDF.exponential(dMean, dStdDev, dValue)); } } else { result.setNoData(x, y); } } } return !m_Task.isCanceled(); }
private void doMinimumDistance() { int iNX, iNY; int x, y; int iClass, iGrid, iMin = 0; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; double dMin, d, e; double dValue; ArrayList stats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { dMean[iClass][iGrid] = ((MeanAndStdDev) stats.get(iGrid)).mean; } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0, dMin = -1.0; iClass < m_Classes.size(); iClass++) { for (iGrid = 0, d = 0.0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { e = m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]; d += e * e; if ((dMin < 0.0) || (dMin > d)) { dMin = d; iMin = iClass; } } else { dMin = -1; } } } if (dMin >= 0.0) { m_Output.setCellValue(x, y, iMin + 1); } else { m_Output.setNoData(x, y); } } } }
private void doMaximumLikelihood() { int iNX, iNY; int x, y; int iClass, iGrid, iMax = 0; final double dMean[][] = new double[m_Classes.size()][m_Window.length]; final double dStdDev[][] = new double[m_Classes.size()][m_Window.length]; final double dK[][] = new double[m_Classes.size()][m_Window.length]; double dMax, d, e; double dValue; ArrayList stats; MeanAndStdDev substats; Set set; Iterator iter; iNX = m_Output.getWindowGridExtent().getNX(); iNY = m_Output.getWindowGridExtent().getNY(); set = m_Classes.keySet(); iter = set.iterator(); iClass = 0; while (iter.hasNext()) { stats = (ArrayList) m_Classes.get(iter.next()); for (iGrid = 0; iGrid < m_Window.length; iGrid++) { substats = ((MeanAndStdDev) stats.get(iGrid)); dMean[iClass][iGrid] = substats.mean; dStdDev[iClass][iGrid] = substats.stdDev; dK[iClass][iGrid] = 1.0 / (dStdDev[iClass][iGrid] * Math.sqrt(2.0 * Math.PI)); } iClass++; } for (y = 0; y < iNY; y++) { for (x = 0; x < iNX; x++) { for (iClass = 0, dMax = 0.0; iClass < m_Classes.size(); iClass++) { for (iGrid = 0, d = 0.0; iGrid < m_Window.length; iGrid++) { dValue = m_Window[iGrid].getCellValueAsDouble(x, y); if (!m_Window[iGrid].isNoDataValue(dValue)) { e = (m_Window[iGrid].getCellValueAsDouble(x, y) - dMean[iClass][iGrid]) / dStdDev[iClass][iGrid]; e = dK[iClass][iGrid] * Math.exp(-0.5 * e * e); d += e * e; if (dMax < d) { dMax = d; iMax = iClass; } } else { dMax = -1; } } } if (dMax > 0.0) { m_Output.setCellValue(x, y, iMax + 1); } else { m_Output.setNoData(x, y); } } } }