mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Measurement framework tests all pass now.
This commit is contained in:
parent
6dc204b385
commit
53f9948b02
22 changed files with 544 additions and 381 deletions
|
@ -8,40 +8,40 @@ export {
|
|||
VARIANCE
|
||||
};
|
||||
|
||||
redef record Result += {
|
||||
redef record ResultVal += {
|
||||
## For numeric data, this calculates the variance.
|
||||
variance: double &log &optional;
|
||||
variance: double &optional;
|
||||
};
|
||||
}
|
||||
|
||||
redef record Result += {
|
||||
redef record ResultVal += {
|
||||
# Internal use only. Used for incrementally calculating variance.
|
||||
prev_avg: double &optional;
|
||||
|
||||
# Internal use only. For calculating incremental variance.
|
||||
var_s: double &optional;
|
||||
var_s: double &default=0.0;
|
||||
};
|
||||
|
||||
hook add_to_reducer(r: Reducer, val: double, data: DataPoint, result: Result)
|
||||
function calc_variance(rv: ResultVal)
|
||||
{
|
||||
if ( VARIANCE in r$apply )
|
||||
result$prev_avg = result$average;
|
||||
rv$variance = (rv$num > 1) ? rv$var_s/(rv$num-1) : 0.0;
|
||||
}
|
||||
|
||||
# Reduced priority since this depends on the average
|
||||
hook add_to_reducer(r: Reducer, val: double, data: DataPoint, result: Result) &priority=-5
|
||||
hook add_to_reducer_hook(r: Reducer, val: double, data: DataPoint, rv: ResultVal) &priority=-5
|
||||
{
|
||||
if ( VARIANCE in r$apply )
|
||||
{
|
||||
if ( ! result?$var_s )
|
||||
result$var_s = 0.0;
|
||||
result$var_s += (val - result$prev_avg) * (val - result$average);
|
||||
result$variance = (val > 0) ? result$var_s/val : 0.0;
|
||||
if ( rv$num > 1 )
|
||||
rv$var_s += ((val - rv$prev_avg) * (val - rv$average));
|
||||
|
||||
calc_variance(rv);
|
||||
rv$prev_avg = rv$average;
|
||||
}
|
||||
}
|
||||
|
||||
# Reduced priority since this depends on the average
|
||||
hook compose_resultvals_hook(result: Result, rv1: Result, rv2: Result) &priority=-5
|
||||
hook compose_resultvals_hook(result: ResultVal, rv1: ResultVal, rv2: ResultVal) &priority=-5
|
||||
{
|
||||
if ( rv1?$var_s && rv2?$var_s )
|
||||
{
|
||||
|
@ -62,4 +62,6 @@ hook compose_resultvals_hook(result: Result, rv1: Result, rv2: Result) &priority
|
|||
result$prev_avg = rv1$prev_avg;
|
||||
else if ( rv2?$prev_avg )
|
||||
result$prev_avg = rv2$prev_avg;
|
||||
|
||||
calc_variance(result);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue