Ask Your Question

Empirical Data Plot

asked 2013-03-15 08:07:41 +0200

jtaa gravatar image

updated 2013-03-15 12:06:38 +0200

kcrisman gravatar image

I wish to make a plot of N vs Time where $N=$ # of edges in a graph. i.e. i want to make an empirical estimate of the time complexity it takes to compute certain things about a graph based on its number of edges.

so i guess i'm wanting to know how i can plot these data points in sage and find a polynomial that best fits?

N = [(16,28,59,120)]
T = [(0.135,0.523,7.36,248)] --where time is measured in seconds

i'm a beginner so any help will be much appreciated.

edit retag flag offensive close merge delete



It's highly unlikely that you'll want a polynomial that gives best fit; you can get a polynomial with a PERFECT fit if you choose a high enough degree polynomial! You may want to look at general books on data analysis.

kcrisman gravatar imagekcrisman ( 2013-03-15 08:47:00 +0200 )edit

That said, you could certainly try fitting to various things like `x^2` or `x log(x)` with `find_fit`, see

kcrisman gravatar imagekcrisman ( 2013-03-15 08:47:27 +0200 )edit

well, i just want to know the order of growth. i.e. as the edges increase what is the order of growth in terms of time taken to compute my function.

jtaa gravatar imagejtaa ( 2013-03-15 10:28:19 +0200 )edit

@kcrisman is right. You can always have a polynomial of degree at most len(N)-1 that perfectly fits the solution. Finding such a polynomial would require the same time as inverting a (len(N)-1) x (len(N)-1) matrix. There possibly exists a more "straightforward" (but complex) expression too since the inverse of a Vandermond matrix is known.

ppurka gravatar imageppurka ( 2013-03-15 10:33:38 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-03-15 12:06:19 +0200

kcrisman gravatar image

updated 2013-03-15 12:08:42 +0200

Here is a sample of what you can do in Sage.

model(x) = a*x^n
N = [16,28,59,120] 
T = [0.135,0.523,7.36,248]
data = zip(N,T)
def _(n=[1..5]):
    L = find_fit(data,model.subs(n=n))

See it live and in action here. Note that with four data points, of course the fifth-degree one is perfect! My guess is that here you may have (yuck) exponential growth, but without more data it's hard to be sure - definitely could also be $O(x^3)$ or $O(x^4)$ or something.

edit flag offensive delete link more


Actually, a degree 3 polynomial is sufficient to fit the data. See [this interact]( The complexity is polynomial in the number of data points.

ppurka gravatar imageppurka ( 2013-03-15 12:45:47 +0200 )edit

Time = [0.135, 0.523, 2.72, 7.36, 23.2, 45.1, 96.3, 248]   Edges = [16.0, 28.0, 47.0, 59.0, 77.0, 84.0, 98.0, 120.0] -- seems like it's more like O(N^5) growth with these additional points?

jtaa gravatar imagejtaa ( 2013-03-15 18:36:18 +0200 )edit

Try [this interact]( with log log scales; that's often more helpful for determining these things. @ppurka - my model intentionally started with zero edges = zero time, so degree three wouldn't suffice.

kcrisman gravatar imagekcrisman ( 2013-03-16 12:54:01 +0200 )edit

awesome thanks

jtaa gravatar imagejtaa ( 2013-03-17 23:14:09 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-15 08:07:41 +0200

Seen: 401 times

Last updated: Mar 15 '13