⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 impuritymeasures.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * Title: XELOPES Data Mining Library
 * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
 * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
 * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
 * @author Sascha Trautzsch
 * @author Michael Thess
 * @version 1.0
 */

package com.prudsys.pdm.Models.Classification.DecisionTree.Algorithms.GenTree;

/**
 * Defines different impurity measures.
 */
public class ImpurityMeasures
{
  static final double Rez_log2 = 3.321928094887;
  static final double MINDOUBLE = -1.79769313486231570E+308;
  static final double DBL_EPSILON = 2.2204460492503131E-16;

  static final int FS_InfGain = 0;
  static final int FS_InfGain_MC = 1;
  static final int FS_GainRatio = 2;
  static final int FS_GainRatio_MC = 3;
  static final int FS_Chi2 = 4;
  static final int FS_Chi2_MC = 5;
  static final int FS_Chi2Prob = 6;
  static final int FS_Chi2Prob_MC = 7;
  static final int FS_Gini = 8;
  static final int FS_Gini_MC = 9;
  static final int D_InfGain = 0;
  static final int D_MDLP = 1;

  public ImpurityMeasures()
  {
  }

  /*****************************************************************************
  *  Funktion: logE                                                            *
  *                                                                            *
  *  Aufrufparameter:   double value: Wahrscheinlichkeit p                     *
  *  R點kgabeparameter: double: p*ln(p)                                        *
  *                                                                            *
  *  Beschreibung                                                              *
  *  ============                                                              *
  *  Berechnet die Funktion p*ln(p). Bei p=0 wird 0.0 im Sine des Grenzwertes  *
  *  p->0 angenommen.                                                          *
  ******************************************************************************/

  public static double logE(double value)
  {
    if (value <= 0.0)
      return(0.0);
    else
      return(value*Math.log(value) / Math.log(2));
  }

  /*****************************************************************************
  *  Funktion: log2                                                            *
  *                                                                            *
  *  Aufrufparameter:   double value: Argument f黵 ld-Funktion                 *
  *  R點kgabeparameter: double: ld(value)                                      *
  *                                                                            *
  *  Beschreibung                                                              *
  *  ============                                                              *
  *  Berechnet die Funktion ld(value). Bei value<=0.0 wird MINDOUBLE im Sine   *
  *  des Grenzwertes p->0 angenommen. Die Berechnung erfolgt durch             *
  *  log2(value)=log(value)/log(2).                                            *
  ******************************************************************************/

  public static double log2r(double value)
  {
    if (value<=0.0)
      return MINDOUBLE;
    else
      return Math.log(value)*Rez_log2;
  }

  /*****************************************************************************
  *  Funktion: NormalDistribution                                              *
  *                                                                            *
  *  Aufrufparameter:   double x: Argument f黵 Normalverteilung                *
  *  R點kgabeparameter: Wert der Normalverteilung                              *
  *                                                                            *
  *  Beschreibung                                                              *
  *  ============                                                              *
  *  Berechnung der Normalverteilung nach Hasting [2]. Der Approximations-     *
  *  fehler ist kleiner 7.5*10E-8.                                             *
  ******************************************************************************/

  public static double NormalDistribution(double x)
  {
    int i;
    double t,f,z,p=0.2316419;
    double b[] = {0.0, 0.319381530, -0.356563782, 1.781477937, -1.821255978,
                  1.330274429 };
    t=1.0/(1.0+p*Math.abs(x));
    z=Math.exp(-x*x*0.5)/2.506628275;
    f=b[5];
    for(i=4;i>=0;i--) f=f*t+b[i];
    return((x<0) ? f*z :1.0-f*z);
  }

  /*****************************************************************************
  *  Funktion: X2Distribution                                                  *
  *                                                                            *
  *  Aufrufparameter:   double chi: Argument f黵 Chi-Quadrat-Verteilung        *
  *  R點kgabeparameter: Wert der Normalverteilung                              *
  *                                                                            *
  *  Beschreibung                                                              *
  *  ============                                                              *
  *  Berechnung der Chi-Quadrat-Verteilung [2]. F黵 gro遝 chi-Werte (chi>150)  *
  *  kann durch die Normalverteilung approximiert werden.                      *
  ******************************************************************************/

  public static double X2Distribution(double chi, int DF)
  {
    int f1,i,g;
    double x,y,sum,t,p;
    if(DF<1 || chi<=0.0) return 0.0;
    if(chi>150.0) return NormalDistribution(Math.sqrt(2.0*chi)-Math.sqrt(2*DF-1));
    f1=(int)(DF+1)/2;
    sum=t=1.0;
    p=0.0;
    for(i=DF;i>=2;i-=2) p+=Math.log((double)i);
    x=f1*Math.log(chi)-chi*0.5-p;
    y=(DF % 2)>0? Math.sqrt(2.0/(chi*Math.PI)) : 1.0;
    g=DF;
    do
    {
      g+=2;
      t*=chi/g;
      sum+=t;
    }
    while(t>1.0e-6);
    return Math.exp(x)*y*sum;
  }

  /*****************************************************************************
  *  Funktion: GetBaseInfo                                                     *
  *                                                                            *
  *  Aufrufparameter:   FLine ct[]:     Contigenztafel f黵 ein Attribut und    *
  *                                     die Klasse                             *
  *                     int splitcount: Anzahl der Attributwerte oder          *
  *                                     Intervalle                             *
  *  R點kgabeparameter: double: BaseInfo im fehlerfreien Fall sonst 0.0        *
  *                                                                            *
  *  Beschreibung                                                              *
  *  ============                                                              *
  *  Berechnung der Baseinfo oder Klasseninformation [1].                      *
  ******************************************************************************/

  public static double EntropyClassMember(ContTable ct)
  {
    double entropy = 0.0;

    if (ct.sum > 0) {
      for (int i = 0; i < ct.getNumberOfClasses(); i++)
        entropy = entropy - logE( (double) ct.classNumb[i] / ct.sum );
    };

    return entropy;
  }

  /*****************************************************************************
  *  Funktion: MarshallCorrection                                              *
  *                                                                            *
  *  Aufrufparameter:   FLine ct[]:     Contigenztafel f黵 ein Attribut und    *
  *                                     die Klasse                             *
  *                     int splitcount: Anzahl der Attributwerte oder          *
  *                                     Intervalle                             *
  *                     double Measure: Featureauswahl-Ma

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -