Hello All,
I would like to use the output of a random number generator to pipe into a script that will produce three types of kernel estimates. Uniform, Triangular, Epanechnikov. I believe that there is a module in CPAN for Epanechnikov, but I would need to produce the other two manually. Seems that I am not only inferior in PERL but also in math because I cannot for the life of me figure out how to replicate the formulas in PERL: http://en.wikipedia.org/wiki/Kernel_(statistics) My code for the number generator is below.
Random number generator:
#!/usr/bin/perl -w
use strict ;
my $samplesize = $ARGV[0] ;
my $max = $ARGV[1] ;
chomp(my $prog = `basename $0`) ;
if ($#ARGV < 1)
{
print "\nUsage: ./randomnumber.pl <samplesize> <max num>\n" ;
exit ;
}
for (my $i = 0; $i<$samplesize; $i++)
{
my $range = $max ;
my $random_number = int(rand($range)) - $max/2;
print "$random_number \n";
}
I do not have any real code for the kernel as I am somewhat lost in even starting out.
#!/usr/bin/perl -w
use strict ;
my $tria ;
my $epan ;
my $unif ;
while ( <STDIN> ) {
my @line= split ;
my $point = $line[0] ;
$tria = 1-abs($point) ;
#abs($point)<=1 ? $tria = 1-abs($point) : $tria = 0 ;
$epan = .75*(1-$point*$point) ;
#abs($point)<=1 ? $epan = .75*(1-$point*$point) : $epan = 0 ;
$unif = .5 ;
#abs($point)<=1 ? $unif = .5 : $unif = 0 ;
print "$point $tria $epan $unif\n" ;
}
Thanks ahead for your help.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.