Here you can find the source of calculateMean(float[] data)
Parameter | Description |
---|---|
data | float values |
public static float calculateMean(float[] data)
//package com.java2s; /*/* w w w .j ava 2 s . c om*/ * 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 { /** * Calculates mean value of float array * * @param data float values * @return Mean Value */ public static float calculateMean(float[] data) { float sum = 0; for (int i = 0; i < data.length; i++) { sum += data[i]; } return sum / data.length; } /** * Calculates mean value of float array * * @param data float values * @return Mean Value */ public static float calculateMean(float[] data, int startIndex, int endIndex) { float sum = 0; for (int i = startIndex; i <= endIndex; i++) { sum += data[i]; } return sum / (endIndex - startIndex + 1); } }