Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // effectuer un tirage au sort (simulation d'un individu)
- function trial()
- {
- // probabilité de croyance de chaque théorie d'après l'enquête
- static $probs = [0.55, 0.54, 0.32, 0.31, 0.28, 0.24, 0.20, 0.18, 0.17, 0.16, 0.09];
- $count = 0;
- // pour chaque théorie, on tire au sort conformément à sa prob. si l'individu
- // y adhere ou non
- foreach($probs as $p)
- {
- if((float)rand()/(float)getrandmax() < $p)
- $count++;
- }
- return $count;
- }
- // on simule un grand nombre d'individus pour tendre vers la vérité
- // (erreur stat totalement négligeable)
- $trials = 10000000;
- // init
- $pop = [];
- for($i = 0; $i <= 11; ++$i)
- {
- $pop[$i] = 0;
- }
- // essais
- for($i = 0; $i < $trials; ++$i)
- {
- $pop[trial()]++;
- }
- // normalisation
- $sum = array_sum($pop);
- for($i = 0; $i <= 11; ++$i)
- {
- $pop[$i] /= $sum/100;
- }
- // affichage
- for($i = 0; $i <= 4; ++$i)
- {
- echo "$i {$pop[$i]}\n";
- }
- $fs = $pop[5]+$pop[6];
- echo "5,6 $fs\n";
- $s = 0;
- for($i = 7; $i <= 11; ++$i)
- {
- $s += $pop[$i];
- }
- echo "7+ $s";
Add Comment
Please, Sign In to add comment