I am working with a programming task that includes a randomly given parameter that I want to optimize. The tricky part is, that this parameter is not part of a function and can not be expressed as such. The task:
I am given values of 4 sets of functions, but I don't have f(x)=... but just the x and y values of the function, which have some noise. I can't fit a curve to find the function because the four functions are too different from each other to construct an algorithm to detect the data model. I am then given test points (not part of a function), which have to be assigned to one of the 4 functions depending on their distance to the function. The criteria depend on the random factor, i.e. if a test point is within a corridor of sqrt(2)*std of a function, it can be assigned to this function. In doing so, some points can not be assigned to any of the functions.
I now want to find the ideal factor for the distance so that we can assign as many points as possible to one of the functions, with the constraint that none of the points will be assigned to more than one function.
I am a beginner, so I tried to sovle it with marginal increase over a wile loop: (m is a dictionary)
while m["multiple_matches"]==0:
factor += 0.001
m=map_with_factor(factor)
print(factor)
if m["multiple_matches"]==1:
factor -= 0.0001
m_opt=map_with_factor(factor)
I get decent results, but I feel like there has to be a better way to solve this!
Is there a way that I can tell Python to marginally increase or to turn this into an optimization problem?
As I said, I can not turn the code in the map_with_factor() function into a mathematical function...