1
$\begingroup$

Suppose I have a set of data that I want to apply a segmented regression to, fitting linearly across the breakpoint. I aim to find the offsets and slopes of either line and the position of the breakpoint that minimizes an error function given the data I have, and then use them as sufficiently close initial guesses to find the exact solutions using a curve fit. I'll elect to choose the bounds as the mins and maxes of $x$ and $y$ of my data, and an arbitrary bound for a slope with $slope = a * \frac{y_{max}-y_{min}}{x_{max}-x_{min}}$ for a suitable $a$ where I can safely assume the magnitude of $a$ is greater than any possible slope that realistically represents the data. Let's suppose I define a function (in Python):

 def generate_genetic_Parameters():
            initial_parameters=[]
            x_max=np.max(xData)
            x_min=np.min(xData)
            y_max=np.max(yData)
            y_min=np.min(yData)
            slope=10*(y_max-y_min)/(x_max-x_min)

            initial_parameters.append([x_max,x_min]) #Bounds for module break point
            initial_parameters.append([-slope,slope]) #Bounds for slopeA
            initial_parameters.append([-slope,slope]) #Bounds for slopeB
            initial_parameters.append([y_max,y_min]) #Bounds for offset A
            initial_parameters.append([y_max,y_min]) #Bounds for offset B

            result=differential_evolution(sumSquaredError,initial_parameters,seed=3)

            return result.x

        geneticParameters = generate_genetic_Parameters() #Generates genetic parameters

fittedParameters, pcov= curve_fit(func, xData, yData, geneticParameters) 

This will do the trick, but what is the implicit standard of fitness that the differential evolution here deals with?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.