Scipy优化最小化仅执行1次迭代

问题描述

我正在尝试优化一个函数,该函数采用权重的输入列表,并使用这些权重更改图像的像素,然后计算一些得分(NSS得分)。 我们的目标是找到能够获得最高NSS得分的最佳输入权重。 为此,我们使用了Scipy最小化功能

    # Our input initial Weights,which we want to find the highest values of them
    weights_init= [i for i in range(82)]
    weights_init[0] = 0 

    min_result= minimize(global_stimuli_optimization,weights_init,method='L-BFGS-B',options={'disp': True})

global_stimuli_optimization函数采用权重als输入并进行一些处理,然后计算一些分数(NSS)

def global_stimuli_optimization(weights):
    
    ... some attributs ... 

    for index,boundary in enumerate (boundaries):
        ... Some processing  ...
                
    
    all_stimuli = [all_stimuli_sorted for _,all_stimuli_sorted in sorted(zip(indices_sorted,all_stimuli_sorted))]

    # we create a model
    model  = MySaliencyMapModel(all_stimuli)
    # we calculate a score
    nss_score = np.nanmean(model.NSSs(mit_stimuli,mit_fixations))
    
    print('Weights : ',weights,' NSS :',nss_score)
    
    return  - nss_score


优化功能运行良好,但仅执行1次迭代,然后停止

输出


           * * *

Tit   = total number of iterations
Tnf   = total number of function evaluations
Tnint = total number of segments explored during Cauchy searches
Skip  = number of BFGS updates skippeds
Nact  = number of active bounds at final generalized Cauchy point
Projg = norm of the final projected gradient
F     = final function value

           * * *

   N    Tit     Tnf  Tnint  Skip  Nact     Projg        F
   82      0      1      0     0     0   0.000D+00  -6.932D-01
  F = -0.693229780993317 


CONVERGENCE: norM_OF_PROJECTED_GRADIENT_<=_PGTOL

 Cauchy                time 0.000E+00 seconds.
 Subspace minimization time 0.000E+00 seconds.
 Line search           time 0.000E+00 seconds.

 Total User time 0.000E+00 seconds.

是否有人知道它会在第一次迭代后停止?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)