Fitting a model to data with descreate parameters

I’m using python’s iminuit package to fit my model to the data. But the input parameters I want to fit are discrete values such as 1,2,3,4,5…

“calculating the derivative of a discrete parameter is a problem” is true, but are there any good ideas that I can perform the fit somehow? I only need to find the minimum state with respect to chi2.

For example, the parameters to be searched allow values such as 0.1, 0.2, 0.3 . .0.5, but on the other hand, it is possible to write code that internally converts them to discrete values by multiplying by 10.

Does this formulation make sense? my sample code is below

Otherwise, is the only way to implement something like a grid scan?

def LeastSquareFunction(fit_parameters):  
    # float64 to int64
    fit_parameters_int = fit_parameters.astype('int64').copy()
    ratio =  fit_parameters[-1]

    # fit_parameters_int is input to my model
    # ratio must be float = fit_parameters[-1]
    return chi2

sampling = 10 # 10 parameters, I wanna set them to integer
inputs = random.choices(range(0, 30), k=sampling) # random initial values
inputs+= [0.5] # add one float prameter

m = Minuit(LeastSquareFunction, inputs)
m.errordef = Minuit.LEAST_SQUARES

limits_ls = list()
for i in range(0,10):
    limits_ls.append( (0,30) ) # integer range is [0 to 30]

limits_ls.append( (0,1) ) # float range is [0 to 1]

m.errors = 0  # no error
m.errors[-1] = 0

#m.scan(ncall=31) # bruto force scan from 0 to 30  

Hi @tomy,
welcome on the ROOT forum!
I add our fitting expert @jonas in the loop.