use strict; use warnings; #use Math::StdDev; #my $d = new Math::StdDev(); #$d->Update(2); #$d->Update(3); #print $d->mean()."\n"; use Math::Random qw(random_uniform random_set_seed_from_phrase random_binomial random_set_seed); #random_set_seed_from_phrase(2); my @seed = (1 + int(rand(2147483562)), 1 + int(rand(2147483398))); random_set_seed(@seed); my $n = 10000; my @a = random_uniform($n); use Data::Dumper; #print Dumper @a; my $nt = 1; #my $p = 0.95; my $p = 0.5; @a = random_binomial($n, $nt, $p); use List::Util qw(sum); my $sum = sum(@a); my $mean = $sum/$n; print "$mean\n"; my $sample = @a[int(rand($n))]; my @data; #my @xaxis = (1..$n); my $step = $n/10; my @xaxis = map { $_/$step == int($_/$step) ? $_ : '' } 1 .. $n; for my $howmany (1..$n) { my @list; my @acopy = @a; for my $samples (1..$howmany) { my $pos = int(rand(scalar @acopy)); my $thisone = $acopy[$pos]; # splice @acopy, $pos, 1; # splice @acopy, $pos, 1; push @list, $mean - $thisone; } # print $howmany, ' ', sum(@list)/$howmany, "\n"; push @data, sum(@list)/$howmany; } #print Dumper @data; print "$sample\n"; use GD::Graph::bars; use GD::Graph::Data; use Carp; #my $data = GD::Graph::Data->new([ # ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], # [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], #]) or croak GD::Graph::Data->error; my $data = GD::Graph::Data->new([\@xaxis, \@data]) or croak GD::Graph::Data->error; my $graph = GD::Graph::lines->new(800, 600); $graph->set( # x_label => 'X Label', # y_label => 'Y label', title => $p, transparent => 0, t_margin => 10, b_margin => 10, l_margin => 10, r_margin => 10, y_max_value => 0.2, y_min_value => -0.2, ) or croak $graph->error; $graph->plot($data) or croak $graph->error; my $file = "bars$p.png"; #my $file = "barssplicy$p.png"; open(my $out, '>', $file) or croak "Cannot open '$file' for write: $!"; binmode $out; print $out $graph->gd->png; close $out; #use GD::Graph::lines;