001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.utilities.statistics; 020 021import org.apache.log4j.Logger; 022 023public class RawAgreement { 024 025 private static Logger logger = Logger.getLogger(FleissKappa.class); 026 027 public static float computeRawAgreement(short[][] mat) { 028 final int K = mat.length; 029 final int C = mat[0].length; 030 031 logger.debug("Rated cases: " + K); 032 logger.debug("Categories: " + C); 033 034 float O = 0; 035 int S_j; 036 for (int j = 0; j < C; j++) { 037 S_j = 0; 038 for (int k = 1; k < K; k++) { 039 S_j += mat[k][j] * (mat[k][j] - 1); 040 } 041 O += S_j; 042 } 043 logger.debug("O = " + O); 044 045 float O_poss = 0; 046 int n_k; 047 for (short[] aMat : mat) { 048 n_k = 0; 049 for (int j = 0; j < C; j++) { 050 n_k += aMat[j]; 051 } 052 System.out.println(n_k); 053 O_poss += (n_k * (n_k - 1)); 054 } 055 logger.debug("O_poss = " + O_poss); 056 057 float p_0 = O / O_poss; 058 logger.debug("p_0 = " + p_0); 059 060 return p_0; 061 } 062 063}