■ 정규 분포 정렬 리스트를 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System; using System.Collections.Generic; #region 정규 분포 정렬 리스트 구하기 - GetNormalDistributionSortedList(intervalList, average, standardDeviation) /// <summary> /// 정규 분포 정렬 리스트 구하기 /// </summary> /// <param name="intervalList">구간 리스트</param> /// <param name="average">평균</param> /// <param name="standardDeviation">표준 편차</param> /// <returns>정규 분포 정렬 리스트</returns> public static SortedList<double, double> GetNormalDistributionSortedList(List<double> intervalList, double average, double standardDeviation) { SortedList<double, double> normalDistributionSortedList = new SortedList<double, double>(); if(intervalList == null || intervalList.Count == 0) { return normalDistributionSortedList; } foreach(double interval in intervalList) { normalDistributionSortedList.Add(interval, 0d); } double constantA = 1d / (standardDeviation * Math.Sqrt(2d * Math.PI)); foreach(double interval in intervalList) { double normalDistribution = constantA * Math.Pow(Math.E, -0.5d * Math.Pow((interval - average) / standardDeviation, 2)); normalDistributionSortedList[interval] = normalDistribution; } return normalDistributionSortedList; } #endregion |