📄 impuritymeasure.java
字号:
/*
Impurity.java
Definition of class ImpurityMeasure
(P)2002 Dana Cristofor
*/
/*
GAClust - Clustering categorical databases using genetic algorithms
Copyright (C) 2002 Dana Cristofor
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
GAClust was written by Dana Cristofor (dana@cs.umb.edu).
*/
/**
* Impurity measures
*
* @version 1.0
* @author Dana Cristofor
*/
public class ImpurityMeasure
{
static public final int GINI = 1;
static public final int ENTROPY = 2;
static public final int PEAK = 3;
static public final int CIRCLE = 4;
static public final int SINE = 5;
static public final int SQ = 6;
static public final int GE = 7;
static public double impurityMeasure(int type, double p)
{
if (type == GINI)
return gini(p);
else if (type == ENTROPY)
return entropy(p);
else if (type == PEAK)
return peak(p);
else if (type == CIRCLE)
return circle(p);
else if (type == SINE)
return sine(p);
else if (type == SQ)
return sq(p);
else if (type == GE)
return ge(p);
else
return -1.0;
}
static private double gini(double p)
{
return (p - p * p);
}
static private double entropy(double p)
{
if (p == 0.0)
return 0.0;
else
return (-p * Math.log(p) / Math.log(2));
}
static private double peak(double p)
{
if (p <= 0.5)
return p;
else
return 1 - p;
}
static private double circle(double p)
{
return Math.sqrt(gini(p));
}
static private double sine(double p)
{
return Math.sin(p * Math.PI);
}
static private double sq(double p)
{
return Math.sqrt(p) - p;
}
static private double ge(double p)
{
return entropy(p - p*p);
}
static public double maxImpurityMeasure(int type, int n)
{
if (type == GINI)
return max_gini(n);
else if (type == ENTROPY)
return max_entropy(n);
else if (type == PEAK)
return max_peak(n);
else if (type == CIRCLE)
return max_circle(n);
else if (type == SINE)
return max_sine(n);
else if (type == SQ)
return max_sq(n);
else if (type == GE)
return max_ge(n);
else
return -1.0;
}
static private double max_gini(int n)
{
return (1.0 - 1.0 / (double)n);
}
static private double max_entropy(int n)
{
return Math.log(n) / Math.log(2);
}
static private double max_peak(int n)
{
if (n == 1)
return 0.0;
else
return 1.0;
}
static private double max_circle(int n)
{
return Math.sqrt(n - 1);
}
static private double max_sine(int n)
{
return (double)n * Math.sin(Math.PI / ((double)n));
}
static private double max_sq(int n)
{
return Math.sqrt(n) - 1.0;
}
static private double max_ge(int n)
{
return (((double)(n-1))/n)*Math.log(((double)(n-1))/(n*n)) / Math.log(2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -