Last active
February 7, 2026 10:02
-
-
Save coderodde/e865abd9e60c48c2ad7f4aa8ae42b25e to your computer and use it in GitHub Desktop.
Todennakoisyyslaskenta I viikko 4 tehtava 1 koodi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package viikko4; | |
| // https://github.com/coderodde/DiscreteRandomVariables.java | |
| import io.github.coderodde.prob.randomvariables.support.BinomialDistribution; | |
| import io.github.coderodde.prob.randomvariables.support.PoissonDistribution; | |
| import java.math.BigDecimal; | |
| import java.math.RoundingMode; | |
| public class Tehtavat4 { | |
| public static void tehtava1() { | |
| System.out.println("k: f(k)"); | |
| System.out.println("Binomial:"); | |
| BinomialDistribution binomial = | |
| new BinomialDistribution(50L, 1.0 / 13.0); | |
| for (int k = 0; k <= 5; ++k) { | |
| System.out.print(k + ": "); | |
| System.out.println( | |
| binomial.getProbabilityMass(k) | |
| .setScale(5, RoundingMode.HALF_UP)); | |
| } | |
| System.out.println(); | |
| System.out.println("Poisson:"); | |
| BigDecimal lambda = | |
| binomial.getSuccessProbability() | |
| .multiply(new BigDecimal(binomial.n())); | |
| PoissonDistribution poisson = new PoissonDistribution(lambda); | |
| for (int k = 0; k <= 5; ++k) { | |
| System.out.print(k + ": "); | |
| System.out.println( | |
| poisson.getProbabilityMass(k) | |
| .setScale(5, RoundingMode.HALF_UP)); | |
| } | |
| System.out.println(); | |
| System.out.println("Lambda = " + lambda); | |
| System.out.println(); | |
| BigDecimal result = BigDecimal.ONE; | |
| for (int k = 0; k < 5; ++k) { | |
| result = result.subtract(poisson.getProbabilityMass(k)); | |
| } | |
| System.out.println("P(Y >= 5) = " + result); | |
| } | |
| public static void main(String[] args) { | |
| tehtava1(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment