python - How to determine if a black-box is polynomial or exponential -
i have problem reduces this:
- you have black-box function accepts inputs of length n.
- you can measure amount of time function takes return answer, can't see how calculated.
- you have determine whether time-complexity of function polynomial or exponential.
the way did running thousands of random sample inputs of varying lengths through function, plotting them on scatter plot times on y-axis , input length on x-axis.
i have scatter plotted using numpy, how draw polynomial , exponential best fit lines? , metrics can calculate determine best fit lines fit best?
(asked similar question theoretically , no emphasis on particular language on computer science: https://cs.stackexchange.com/questions/23686/how-to-determine-if-a-black-box-is-polynomial-or-exponential)
take logarithm of y values. polynomial results still expose logarithmical growth (since log x^n = n * log x
), exponential curve transform proper straight line (log exp(x) = x
).
if approximate enough of result points linear lsq, can pretty sure algorithm exponential if fits nicely (allow difference present, though -- suggest deducing reasonable epsilon empirically examining algorithm know complexity of!), , polynomial otherwise.
you can raise confidence level bit examining deviation regression line: if of values below it, data logarithmic (i. e. program ran in polynomial time).
Comments
Post a Comment