python - Best fit from a set of curves to data points -


i have set of curves f={f1, f2, f3,..., fn}, each of them defined through set of points, ie: don't have explicit form of functions. have set of n tables so:

#f1: x  y 1.2  0.5 0.6  5.6 0.3  1.2 ...  #f2: x  y 0.3  0.1 1.2  4.1 0.8  2.2 ...  #fn: x  y 0.7  0.3 0.3  1.1 0.1  0.4 ... 

i have set of observed/measured data points o=[p1, p2, p3,..., pm] each point has x, y coordinates , given weight between [0, 1] , looks like:

#o: x  y  w 0.2  1.6  0.5 0.3  0.7  0.3 0.1  0.9  0.8 ... 

since n ~ 10000 (i have big number of functions) i'm looking efficient (more precisely: fast) way find curve best fits set of observed , weighted points o.

i know how find best fit python when have explicit form of functions (scipy.optimize.curve_fit), how do when have functions defined tables?

here's 1 possible solution. combines of comments on original post, , @elyase's solution above. @elyase has provided 1 way interpolate between points have each function. given that, , definition of best fit being weighted sum of squares, think following want:

# here model interpolated function per @elyase's solution above min_score = sys.float_info.max best_model = none model in models:     # data array of (x, y, weight) tuples     score = 0.0     data_point in data:         w = data_point[2]         x = data_point[0]         y = data_point[1]         score += w * (y - model.get_y(x)) ** 2     if score < min_score:         best_model = model return best_model 

you mention need "fast" solution. based on answers above, doing above each set of data results in 2 million iterations total. shouldn't more few seconds, python. fast enough?

if not, things more complex. example, try store models (you call them functions above) in sorted order such model1 > model2 if model1(x) > model2(x) x (given interpolation thing above). defines partial order, might enough helpful if models have right properties. given that, can akin binary search. alternatively, branch-and-bound thing bound given distance between first value in data , first value in function. depending on nature of functions , data might or might not help. there solutions consider if required exact, not optimal answer, etc., etc., etc. in short, go beyond trivial answer above, think need know more time constraints, data, , models.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -