/** * Evaluate a clustering result. * * @param db Database * @param c Clustering * @param refc Reference clustering */ protected void evaluteResult(Database db, Clustering<?> c, Clustering<?> refc) { ClusterContingencyTable contmat = new ClusterContingencyTable(selfPairing, noiseSpecialHandling); contmat.process(refc, c); ScoreResult sr = new ScoreResult(contmat); sr.addHeader(c.getLongName()); db.getHierarchy().add(c, sr); }
@Override public ScoreResult score(SparseMatrix m) { ScoreResult hitsResult = hits.score(m); double[] colScore = hitsResult.getColScore(); SingularValueDecompositionLibJ svd = new SingularValueDecompositionLibJ(); svd.factorize(m, Math.min(20, Math.min(m.rows(), m.columns()) * 7 / 11)); Matrix u = svd.dataClasses(); Matrix v = new TransposedMatrix(svd.classFeatures()); if (hasNaN(u) || hasNaN(v)) return hitsResult; double[] svs = svd.singularValues(); PriorityQueue<Double, Integer> cos2dim = PriorityQueue.make( Math.min(5, svs.length), SortUtils.reverse(Double.class), SortUtils.comp(Integer.class)); for (int j = 0; j < v.columns(); j++) { double cos = MatrixUtils.cosine(colScore, v.getColumn(j)); cos2dim.add(cos, j); } List<Integer> dims = cos2dim.values(); double[] hub = new double[u.rows()]; for (int k = 0; k < u.rows(); k++) { double sum = 0; for (int i : dims) sum += u.get(k, i) * u.get(k, i) * svs[i] * svs[i]; hub[k] = Math.sqrt(sum); } MatrixUtils.normalize(hub); double[] authority = new double[v.rows()]; for (int k = 0; k < v.rows(); k++) { double sum = 0; for (int i : dims) sum += v.get(k, i) * v.get(k, i) * svs[i] * svs[i]; authority[k] = Math.sqrt(sum); } MatrixUtils.normalize(authority); return new ScoreResult(hub, authority); }