반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 5 -1: Poisson Distribution I



13 번째 문제!

Objective 
In this challenge, we learn about Poisson distributions. Check out the Tutorial tab for learning materials!

Task 
A random variable, , follows Poisson distribution with mean of . Find the probability with which the random variable  is equal to .

Input Format

The first line contains 's mean. The second line contains the value we want the probability for:

2.5
5

If you do not wish to read this information from stdin, you can hard-code it into your program.

Output Format

Print a single line denoting the answer, rounded to a scale of  decimal places (i.e.,  format).


문제해석!

1. 값이 랜덤인 변수 X 가 있다

2. X는 평균 2.5의 포아송 분포다.

3. X 가 5를 찾을 확률은?

여기서 잠깐!. 포아송 분포요?....

 

정의[편집]

정해진 시간 안에 어떤 사건이 일어날 횟수에 대한 기댓값을 라고 했을 때, 그 사건이 회 일어날 확률은 다음과 같다.

여기서 는 자연상수이다.

(출처: 위키, https://ko.wikipedia.org/wiki/%ED%91%B8%EC%95%84%EC%86%A1_%EB%B6%84%ED%8F%AC)


어디다가 쓰냐고요?...

응용[편집]

다음과 같은 확률적인 문제를 알아내기 위해 쓰이고 있다.

  • 일정 주어진 시간 동안에 도착한 고객의 수
  • 1킬로미터 도로에 있는 흠집의 수
  • 일정 주어진 생산시간 동안 발생하는 불량 수
  • 하룻동안 발생하는 출생자 수
  • 어떤 시간 동안 톨게이트를 통과하는 차량의 수
  • 어떤 페이지 하나를 완성하는 데 발생하는 오타의 발생률
  • 어떤 특정 량의 방사선을 DNA에 쬐였을 때 발생하는 돌연변이의 수
  • 어떤 특정 면적의 다양한 종류의 나무가 섞여 자라는 삼림에서 소나무의 수
  • 어떤 특정 진도 이상의 지진이 발생하는 수

(출처: 위키, https://ko.wikipedia.org/wiki/%ED%91%B8%EC%95%84%EC%86%A1_%EB%B6%84%ED%8F%AC)


이런다고 합니다 ㅋㅋ


난 잘 모르겟고 n!분의 람다(n승)* e(-람다승) 이라니깐 고대로 ㅋㅋ



계산식 포인트

Math.Pow(Math.E, -Expected_value) * Math.Pow(Expected_value,X) / Factorial(X)

Math.E(?응?) - 문제에서 e는 자연 상수를 나타내는데 값으로 나타내면 약 2.71828 이라고 수학에서 상수라고 한다

그럼 코드공개!

class Solution {
    private static readonly double EXPECTED_VALUE = 2.5;
    private static readonly int X = 5;
    static void Main(String[] args)
    {
        Console.WriteLine("{0:f3}", Math.Pow(Math.E, -EXPECTED_VALUE) * Math.Pow(EXPECTED_VALUE, X) / Factorial(X));
    }
    static int Factorial(int n)
    {
        return (n == 0) ? 1 : n * Factorial(n - 1);
    }
}





제출!!!





그럼이만! 혹시 설명이 부족하다면 댓글 달아주세용 ㅎ


(출처:https://www.hackerrank.com/challenges/s10-poisson-distribution-1/problem)

반응형

+ Recent posts