첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
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
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요