■ 엔트로피 구하기

----------------------------------------------------------------------------------------------------

using System;

 

#region 엔트로피 구하기 - GetEntropy(valueArray)

 

/// <summary>

/// 엔트로피 구하기

/// </summary>

/// <param name="valueArray">값 배열</param>

/// <returns>엔트로피</returns>

public double GetEntropy(int[] valueArray)

{

    int    length  = valueArray.Length;

    int    total   = 0;

    double entropy = 0d;

    double probability;

 

    for(int i = 0; i < length; i++)

    {

        total += valueArray[i];

    }

 

    for(int i = 0; i < length; i++)

    {

        probability = (double) valueArray[i] / total;

 

        if(probability != 0)

        {

            entropy += (-probability * Math.Log(probability, 2));

        }

    }

 

    return entropy;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요