Here you can find the source of calculateMeanAndStandardDeviationVectors( float[][] vectors)
public static float[][] calculateMeanAndStandardDeviationVectors( float[][] vectors)
//package com.java2s; /*//from w w w . j av a 2s . com * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler. * * This file is part of MART. * MART is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2, as published * by the Free Software Foundation. * * MART is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with MART; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { public static float[][] calculateMeanAndStandardDeviationVectors( float[][] vectors) { float[][] out = new float[2][vectors[0].length]; for (int i = 0; i < vectors[0].length; i++) { float[] inputVector = new float[vectors.length]; for (int j = 0; j < inputVector.length; j++) { inputVector[j] = vectors[j][i]; } float[] data = calculateMeanAndStandardDeviation(inputVector); out[0][i] = data[0]; out[1][i] = data[1]; } return out; } public static float[] calculateMeanAndStandardDeviation(float[] data) { float sumMean = 0; float sumDev = 0; float mean, dev; int count = 0; for (int i = 0; i < data.length; i++) { sumMean += data[i]; count++; } mean = sumMean / count; for (int i = 0; i < data.length; i++) { sumDev += (mean - data[i]) * (mean - data[i]); } dev = (float) Math.sqrt(sumDev / count); float[] out = new float[2]; out[0] = mean; out[1] = dev; return out; } public static float[] calculateMeanAndStandardDeviation(float[][] data) { float sumMean = 0; float sumDev = 0; float mean, dev; int count = 0; for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { sumMean += data[i][j]; count++; } } mean = sumMean / count; for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { sumDev += (mean - data[i][j]) * (mean - data[i][j]); } } dev = (float) Math.sqrt(sumDev / count); float[] out = new float[2]; out[0] = mean; out[1] = dev; return out; } }