My statistics is a bit rusty, and tye has a better handle on what you're actually doing, but this might help. When working with statistics, you generally define a range of acceptable sample values, and any values outside of this range are discarded. These are called outliers. For example, below is your code modified to ignore the samples where po == 0, so they will not skew your results.
my $tlsamples = @series_po; # = @series_fr
my $ok_samples = 0;
my $sum_po = 0;
my $sum_fr = 0;
for (my $i; $i < $tlsamples; $i++){
# set up any conditions to skip outliers here
if($series_po[$i] == 0){
next;
}
# count & sum only good samples
$ok_samples++;
$sum_po += $series_po[$i];
$sum_fr += $series_fr[$i];
}
return 0 if ($ok_samples == 0);
$sum_fr = 1 if ($sum_fr == 0);
my $avg_po = $sum_po / $ok_samples; # =150 / 5 = 30
my $avg_fr = $sum_fr / $ok_samples; # = 10 / 5 = 2
$avg_fr = 1 (if $avg_fr == 0); # avoid div/0
my $pofr = $avg_po / $avg_fr; # = 15
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|