whizard is hosted by Hepforge, IPPP Durham

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#252 closed defect (fixed)

W2 calculates wrong errors

Reported by: sschmidt Owned by: kilian
Priority: P3 Milestone:
Component: core Version: 2.0.0rc3
Severity: normal Keywords: analysis
Cc:

Description

W2 computes the wrong standard deviations:

Instead of (examples for unweighted values)

\sqrt{ \frac{1}{n-1} \sum ( x_i - <x> )^2 }

it computes

\sqrt{ \frac{1}{n-1} \sum ( x_i )^2 }

See analysis.f90, function observable_get_error (obs)

   err = sqrt (obs%sum_squared_values / obs%sum_squared_weights) &
          / sqrt (real (obs%count - 1, default))

Attachments (1)

ticket252.sin (1.0 KB) - added by sschmidt 15 years ago.
example file with two histograms, these histograms are mirrors of each other, they should hav the same error.

Download all attachments as: .zip

Change History (7)

Changed 15 years ago by sschmidt

Attachment: ticket252.sin added

example file with two histograms, these histograms are mirrors of each other, they should hav the same error.

comment:1 Changed 15 years ago by sschmidt

With r2042 I committed a tentative fix, the error is now not calculated using

\sqrt{ \frac{1}{n(n-1)} \sum_i ( x_i - <x> )^2 }

which would have the need to store all values of x_i for a correct calculation, but

\sqrt{ \frac{1}{n(n-1)} \sum_i ( x_i - <x>_i )^2 } with <x>_i the average of the x from x_1 to x_i

This should be alright as long as

  • n is not small,
  • the observable is not correlated with the event number.

Both should be sufficiently fulfilled.
I'll leave this open in case someone wants to implement a correct solution.

comment:2 in reply to:  1 ; Changed 15 years ago by ohl

Replying to sschmidt:

\sqrt{ \frac{1}{n(n-1)} \sum_i ( x_i - <x>_i )^2 } with <x>_i the average of the x from x_1 to x_i

It's wasteful, because you have to calculate the average every time observable_record_value_* is called. But probably this doesn't matter much in the grand scheme of things.

More importantly, I'm not sure that this is an unbiased estimator of the error. Why not

\sqrt{ \frac{1}{n(n-1)} \sum_i x_i^2 - \frac{1}{n^2(n-1)} (\sum x_i )^2  }

which is both faster and unbiased (please check that I didn't screw up the powers of n ...)

comment:3 in reply to:  2 Changed 15 years ago by sschmidt

Replying to ohl:

More importantly, I'm not sure that this is an unbiased estimator of the error. Why not

\sqrt{ \frac{1}{n(n-1)} \sum_i x_i^2 - \frac{1}{n^2(n-1)} (\sum x_i )^2  }

which is both faster and unbiased (please check that I didn't screw up the powers of n ...)

Yes that's correct and better (didn't think of this formula at first.) Even the powers of n are correct.

comment:4 Changed 15 years ago by kilian

Status: newassigned

I implemented the formula in r2057. Please double-check, then close the ticket.

comment:5 Changed 15 years ago by ohl

Resolution: fixed
Status: assignedclosed

Looks good to me ...

comment:6 Changed 15 years ago by Juergen Reuter

Milestone: v2.0-rc4

Milestone v2.0-rc4 deleted

Note: See TracTickets for help on using tickets.