Combining Distributions for Accurate Function Timing: A Statistical Approach

  • Context: Graduate 
  • Thread starter Thread starter CRGreathouse
  • Start date Start date
  • Tags Tags
    Distributions
Click For Summary

Discussion Overview

The discussion revolves around the statistical approach to accurately timing functions in a programming context, specifically focusing on the estimation of overhead time through confidence intervals. Participants explore methods for combining distributions to account for measurement errors and the implications of these errors on the confidence of the results.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes their method of measuring overhead by running a test suite with an empty function and calculating a 95% confidence interval based on the average and standard deviation of the overhead.
  • Another participant questions the validity of the confidence interval calculation, suggesting that the correct form should account for estimating the standard deviation using the t-distribution.
  • A participant provides an example of calculating the confidence interval for overhead measurements and expresses uncertainty about how to accurately subtract this overhead from function measurements.
  • Concerns are raised about the assumption that the overhead and measurement errors are correlated, with a participant suggesting that this may lead to an overestimation of confidence in the final results.
  • One participant proposes that if the overhead and function measurements are independent, the error could be modeled using a normal distribution that combines the means and variances of both measurements.
  • Another participant expresses confusion about the concept of overhead and its implications for the timing process, seeking clarification on its significance.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for calculating confidence intervals or the assumptions regarding the independence of errors. Multiple competing views on the statistical approach remain unresolved.

Contextual Notes

Participants highlight potential limitations in their assumptions regarding the independence of measurement errors and the estimation of standard deviations, which could affect the accuracy of their confidence intervals.

CRGreathouse
Science Advisor
Homework Helper
Messages
2,832
Reaction score
0
Warning: I've only taken one stats class, back as an undergrad (though it was a very fast-paced class designed for mathematicians). My understanding of all things statistical is consequently weak.

I'm trying to design a program to accurately time functions. The functions themselves are of no importance here, only the timing code.

At the moment my program runs the test suite (10 million runs) with an empty function, to measure overhead. It stores a fixed number of runs, 7 at the moment, then computes the average and standard deviation of the overhead. This let's me construct a 95% confidence interval for the overhead:
[\mu-1.96\sigma,\mu+1.96\sigma]

Simple enough so far, yes? So then I time each actual function once. (I don't want to ruin them multiple times because the real functions, as expected, take a fair bit longer than the empty function.) At this point I make the assumption that the distribution of the timing errors of the functions is the same as that of the overhead function (which seems reasonable to me). This gives me a 95% confidence interval (under my assumption) as such:
[t(1-1.96\sigma/\mu), t(1+1.96\sigma/\mu)]

Here's the part I want help on. I combine the intervals by taking the low-end estimate for the function's speed and subtracting the high-end estimate for the overhead, to the high-end estimate for the function minus the low-end estimate for the overhead. How do I describe my confidence that this is correct? Less than 95% (errors can accumulate), more than 95% (errors are likely to cancel, maybe like sqrt(2) rather than 2?), or just 95%? Is there a better way to calculate this? Have I made mistakes or bad assumptions in my analysis?
 
Physics news on Phys.org
I am somewhat confused about what you are trying to do. Maybe if you write it out in maths language I could be of more help. From what I understand you are trying to get a 95% confidence interval for the mean (of some sort). Pardon me if I am wrong here but I am thinking that you wish to approximate \mu for N(\mu,\sigma^2) from a set of data by taking the mean as an estimate for \mu. The confidance interval you have makes sense only if you write it as[\hat{\mu}-1.96\sigma,\hat{\mu}+1.96\sigma]. This assumes that you know \sigma which I highly doubt. To get a confidence interval when you also have to estimate \sigma is given by [\hat{\mu}-t_{n-1,0.025} \hat{\sigma},\hat{\mu}+t_{n-1,0.025} \hat{\sigma}] where the t is from Students t-distribution.

Don't quite understand the rest of it but I hope this helps.

Warning: I found statistics quite boring, I may be trying to blacken its name.
 
I'm being quite lax in my notation, forgive me. I wrote \mu for \hat{\mu} and \sigma for \hat{\sigma}. These figures come from a small sample of a potentially infinite data source.

Example:
I have, say, five measurements for the overhead:
[0.5, 0.6, 0.4, 0.5, 0.35]
which have average 0.47 and standard deviation 0.0975. This gives a 95% confidence interval of
[0.279, 0.661]
for the true value of the overhead. (This is the sample mean plus/minus the standard deviation times 1.96; the 1.96 comes from a z-table.)

Now I don't actually want this interval. What I want is to subtract the true value of the overhead from a set of measurements and get the measurements less overhead. But since I don't have that, I subtract the range from the measurements:
[m-0.661,m-0.279]
But of course I don't actually have the true value for the measurements themselves; I have only a single measurement for each. So I make the assumption in my first post which let's me estimate the confidence interval for the measurements. First I construct the relative error:
e_\text{rel}\approx1.96\hat{\sigma}/\hat{\mu}\approx1.96\cdot0.0975/0.46=0.406
Then I form the interval about the measurement:
[m(1-e_\text{rel}),m(1+e_\text{rel})]

But this assumes, in effect, that the worst case of the overhead error corresponds to the worst case of the measurement error, which doesn't seem likely. So I seem to think that the actual confidence of my final result is more than 95%. I'd like a way to calculate my confidence in this final interval -- in this case, so I can reduce the size of my final interval by dropping the confidence from perhaps 99% to 95%.
 
If you want to substract the true value of the overhead then surely your CI should just be N(0,k). I'm still really confused about what you are trying to do so excuse me. You should also use [\hat{\mu}-t_{n-1,0.025} \hat{\sigma},\hat{\mu}+t_{n-1,0.025} \hat{\sigma}] to compute your CI as you are estimating sigma^2 as well. I also have no idea what an overhead is but it sounds quite fancy, good luck with it!
 
Focus said:
I also have no idea what an overhead is but it sounds quite fancy, good luck with it!

Nothing fancy. I'm timing a certain process for (say) ten million iterations, and there is time taken up by the iterations themselves (and I just want to measure the time of the process). so I run a 'do-nothing' process in the same loop, and that's my overhead. The actual recorded time should be the time of the process (ten-millionfold) plus the time of the overhead. But with measurement errors, that's hard to get right -- sometimes the process is fast enough that the overhead dominates the runtime.
 
Well then you should measure the overhead and the process which means your error for the process without the overhead is (given that they are independent) N(\hat{\mu_1}-\hat{\mu_2},\hat{\sigma_1}^2+\hat{\sigma_2}^2) be sure to use students t distribution when calculating the CI as the extra uncertainty from estimating variances is accounted for in that.

Must be quite boring running do-nothings all day. I hope they are paying you well for this :D.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K