Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

C# - MathNet으로 정규 분포를 따르는 데이터를 생성, PLplot으로 Histogram 표현

간혹, 테스트 등의 목적을 위해 특정 분포를 이루는 데이터가 필요할 수 있습니다. 그럴 때 MathNet을 사용해 간편하게 생성할 수 있는데 정규 분포의 경우 타음의 타입을 사용하면 됩니다. (MathNet.Numerics.Distributions 네임스페이스에는 그 외 NormalGamma, Pareto, Posisson, Rayleigh, Stable, StudentT, Triangular, Weibull, Wishart, Zipf 등의 타입이 제공됩니다.)

Normal
; https://numerics.mathdotnet.com/api/MathNet.Numerics.Distributions/Normal.htm

방법도 간단해서, 정규 분포의 경우 평균값과 표준편차만 정하면 됩니다.

Normal normal = new Normal(170, 7); // 평균 170, 표준편차 7
double[] values = new double[512];  
normal.Samples(values); // 512개의 정규 분포를 따르는 샘플 데이터를 생성

생성한 데이터로 ^^ 히스토그램도 그려볼까요? 지난 글에서는 OxyPlot을 이용했는데,

MathNET + OxyPlot을 이용한 간단한 통계 정보 처리 - Histogram
; https://www.sysnet.pe.kr/2/0/11916

이번에는 PLplot으로 해보겠습니다.

PLplot - Example 12
; http://plplot.sourceforge.net/examples.php?demo=12&lbind=PerlDL

pl.lab("Height", "count", "sample");

double accGap = 0.0;
for (int i = 0; i < binCount; i++)
{
    pl.col1(i / 9.0);
    pl.psty(0);

    double classMark = histogram[i].GetClassMark();
    double classWidth = histogram[i].GetClassWdith();
    double roundedMark = Math.Round(classMark, MidpointRounding.AwayFromZero);

    plfbox(pl, classMark, classWidth, histogram[i].Count);

    pl.ptex(minMark + accGap, histogram[i].Count + 3, 1.0, 0.0, 0.5, ((int)histogram[i].Count).ToString());
    accGap += classWidth;

    pl.mtex("b", 1.0, ((i + 1) * 0.1 - 0.05), 0.5, ((int)roundedMark).ToString());
}

PLplot의 경우, 그려지는 단위를 실제 데이터 값을 기준으로 위치 좌표가 결정된다는 특징이 있는데 개인적으로는 그 점이 약간 헷갈렸습니다. 게다가 그 위치를 장님 문고리 잡듯이 수치를 조정해가면서 일일이 맞추는 작업을 해야 합니다. (위에서 pl.mtex 인자 값들이 희한한 이유입니다.) 그 외의 편의성까지 고려해 보면 histogram 용으로는 OxyPlot으로 그리는 것이 더 좋을 듯합니다.

어쨌든 그려진 모습은 다음과 같습니다.

normal_data_histogram_1.png

(첨부 파일은 이 글의 소스 코드와 PLplot의 12번째 예제를 vcpkg의 plplot을 이용해 그대로 포팅한 프로젝트를 포함합니다.)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/17/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...
NoWriterDateCnt.TitleFile(s)
11820정성태2/20/201915232오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201913904Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201912814VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/20199972오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201912477Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201911364오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201910199오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201911801.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/20199627오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201913415오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
11810정성태2/11/201911467.NET Framework: 808. .NET Profiler - GAC 모듈에서 GAC 비-등록 모듈을 참조하는 경우의 문제
11809정성태2/11/201912988.NET Framework: 807. ClrMD를 이용해 메모리 덤프 파일로부터 특정 인스턴스를 참조하고 있는 소유자 확인
11808정성태2/8/201914048디버깅 기술: 123. windbg - 닷넷 응용 프로그램의 메모리 누수 분석
11807정성태1/29/201912358Windows: 156. 가상 디스크의 용량을 복구 파티션으로 인해 늘리지 못하는 경우 [4]
11806정성태1/29/201912106디버깅 기술: 122. windbg - 덤프 파일로부터 PID와 환경 변수 등의 정보를 구하는 방법
11805정성태1/28/201913938.NET Framework: 806. C# - int []와 object []의 차이로 이해하는 제네릭의 필요성 [4]파일 다운로드1
11804정성태1/24/201911977Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201911481디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201912850.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
11801정성태1/1/201913904개발 환경 구성: 427. Netsh의 네트워크 모니터링 기능 [3]
11800정성태12/28/201813179오류 유형: 509. WCF 호출 오류 메시지 - System.ServiceModel.CommunicationException: Internal Server Error
11799정성태12/19/201813991.NET Framework: 804. WPF(또는 WinForm)에서 UWP UI 구성 요소 사용하는 방법 [3]파일 다운로드1
11798정성태12/19/201813221개발 환경 구성: 426. vcpkg - "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++"
11797정성태12/19/201810580개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201810228개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201812654Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...