-
Notifications
You must be signed in to change notification settings - Fork 87
/
RandIndexMetric.h
101 lines (80 loc) · 2.37 KB
/
RandIndexMetric.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
// RandIndexMetric.h
// VISERAL Project http://www.viceral.eu
// VISCERAL received funding from EU FP7, contract 318068
// Created by Abdel Aziz Taha (taha@ifs.tuwien.ac.at)
// on 14.05.2013
// Copyright 2013 Vienna University of Technology
// Institute of Software Technology and Interactive Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Description:
//
// This algorithm calculates the Rand index and the adjusted rand index.
// The algorithm builds on the class contingencyTable to access the information of the volumes
// and calculate the rand index.
//
//
*/
#include "itkImage.h"
class RandIndexMetric
{
private:
ContingencyTable *contingencyTable;
bool fuzzy;
double threshold;
double a;
double b;
double c;
double d;
public:
~RandIndexMetric(){
}
RandIndexMetric(ContingencyTable *contingencyTable, bool fuzzy, double threshold){
this->contingencyTable= contingencyTable;
this->fuzzy = fuzzy;
this->threshold = threshold;
this->a = contingencyTable->a;
this->b = contingencyTable->b;
this->c = contingencyTable->c;
this->d = contingencyTable->d;
}
double CalcRandIndex(){
#ifdef _DEBUG
double X= contingencyTable->tp;
double Y= contingencyTable->tn;
double K= contingencyTable->fn;
double L= contingencyTable->fp;
double n = contingencyTable->n;
double ri = (
(Y*(Y-1) + K*(K-1) + L*(L-1) + X*(X-1))/2
+ ( n*n + X*X + Y*Y + L*L + K*K
- ( (Y + K)* (Y + K) + (L + X)*(L + X))
- ((Y + L)*(Y + L) + (K + X)*(K + X))
)/2
)/(n*(n-1)/2);
std::cout << "RI controll: "<< ri << std::endl;
#endif
return (a + d)/(a + b + c + d);
}
double CalcAdjustedRandIndex(){
double x1 = a - ((a+c)*(a+b)/(a+b+c+d));
double x2 = ( (a+c) + (a+b))/2.0;
double x3 = ( (a+c)*(a+b))/(a+b+c+d);
if(x2!=x3)
return x1/(x2-x3);
else
return 0;
}
};