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.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


            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?


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.