我正在尝试使用非线性最小二乘法对函数进行优化,但是我似乎得到了一些非常大的值,从实际的角度来看这没有多大意义。
def Model(vCoef):
vK = np.arange(1, 360+1)
vTerm1 = np.ones(len(vK))
vTerm2 = (1 - np.exp(-vCoef[3]*vK)) / (vCoef[3]*vK)
vTerm3 = vTerm2 - np.exp(-vCoef[3]*vK)
NS = vCoef[0]*vTerm1 + vCoef[1]*vTerm2 + vCoef[2]*vTerm3
return NS
def SSR(vCoef, y):
return (y - Model(vCoef))
y值的示例是
array([5.27529034, 5.29560185, 5.3268597 , 5.36827412, 5.41710411,
5.46992323, 5.52362229, 5.57591598, 5.62538192, 5.67124282,
5.71312767, 5.75090079, 5.78453287, 5.81401957, 5.83939688,
5.86084395, 5.87877961, 5.89383876, 5.9066982 , 5.91785479,
5.92750835, 5.93561891, 5.94208467, 5.94692732, 5.95039893,
5.95298145, 5.95528889, 5.95791827, 5.96132878, 5.96580722,
5.97149682, 5.97841632, 5.98643873, 5.99527459, 6.00451769,
6.01375548, 6.02268915, 6.03119963, 6.03933192, 6.04722161,
6.05501159, 6.06278 , 6.0704587 , 6.07772661, 6.08394116,
6.08826676, 6.09012987, 6.08988299, 6.08921934, 6.09077189,
6.09684071, 6.10810782, 6.12338393, 6.14045757, 6.15718216,
6.17204988, 6.18421973, 6.19335232, 6.19947848, 6.20290471,
6.2041021 , 6.20360154, 6.20195385, 6.1997257 , 6.19741254,
6.19526544, 6.19324036, 6.19116462, 6.18893652, 6.18660888,
6.18437798, 6.18253541, 6.18140214, 6.1812485 , 6.18221833,
6.18428917, 6.18728914, 6.19095869, 6.1950229 , 6.19924476,
6.20344945, 6.20752586, 6.21141626, 6.21510252, 6.2185933 ,
6.22191361, 6.22509669, 6.22817763, 6.23118837, 6.23415395,
6.23708996, 6.24000154, 6.24288371, 6.24572295, 6.24849965,
6.25119113, 6.25377519, 6.25623398, 6.25855818, 6.26075141,
6.26283408, 6.26484611, 6.26684722, 6.26891392, 6.27113289,
6.27359143, 6.27636684, 6.27951726, 6.28307594, 6.2870501 ,
6.29142384, 6.29616387, 6.30122616, 6.30656214, 6.31212361,
6.31786599, 6.3237502 , 6.32974325, 6.33581823, 6.34195367,
6.34813286, 6.35434299, 6.36057437, 6.36681978, 6.37307386,
6.37933268, 6.38559335, 6.39185374, 6.39811227, 6.40436774,
6.41061925, 6.41686608, 6.42310764, 6.42934347, 6.43557315,
6.44179632, 6.44801264, 6.45422183, 6.4604236 , 6.46661768,
6.47280379, 6.47898165, 6.48515096, 6.49131138, 6.49746252,
6.50360389, 6.50973491, 6.51585483, 6.52196268, 6.52805724,
6.5341369 , 6.54019962, 6.54624277, 6.55226298, 6.55825601,
6.5642165 , 6.57013779, 6.57601164, 6.581828 , 6.58757472,
6.59323728, 6.59879858, 6.60423877, 6.60953514, 6.61466221,
6.619592 , 6.62429448, 6.62873833, 6.63289204, 6.63672524,
6.64021034, 6.64332435, 6.64605072, 6.64838107, 6.65031662,
6.6518691 , 6.65306094, 6.65392478, 6.65450217, 6.65484164,
6.65499631, 6.65502124, 6.65497089, 6.65489674, 6.6548454 ,
6.6548572 , 6.65496539, 6.65519572, 6.65556655, 6.65608925,
6.65676877, 6.65760439, 6.65859043, 6.65971699, 6.6609706 ,
6.6623348 , 6.66379061, 6.66531693, 6.66689092, 6.66848826,
6.67008353, 6.67165053, 6.6731627 , 6.67459357, 6.67591737,
6.67710968, 6.67814807, 6.67901283, 6.67968759, 6.68015979,
6.68042103, 6.68046709, 6.68029772, 6.6799162 , 6.67932867,
6.67854335, 6.6775697 , 6.67641769, 6.67509714, 6.6736173 ,
6.67198661, 6.67021269, 6.66830256, 6.66626288, 6.66410041,
6.66182238, 6.6594368 , 6.65695262, 6.6543797 , 6.6517285 ,
6.64900961, 6.64623312, 6.6434079 , 6.64054098, 6.63763709,
6.63469842, 6.63172467, 6.62871328, 6.62565997, 6.62255928,
6.61940526, 6.61619206, 6.61291448, 6.6095684 , 6.60615105,
6.60266114, 6.59909882, 6.59546548, 6.59176352, 6.58799587,
6.58416564, 6.58027564, 6.57632791, 6.57232346, 6.56826191,
6.56414137, 6.55995843, 6.55570832, 6.55138514, 6.54698237,
6.54249341, 6.5379123 , 6.53323444, 6.52845743, 6.52358175,
6.51861147, 6.5135547 , 6.50842389, 6.50323585, 6.49801146,
6.49277503, 6.48755347, 6.48237508, 6.47726827, 6.47226021,
6.46737548, 6.46263498, 6.45805515, 6.45364743, 6.44941821,
6.44536905, 6.44149714, 6.43779603, 6.4342564 , 6.43086686,
6.42761475, 6.42448684, 6.42146993, 6.41855134, 6.4157193 ,
6.41296324, 6.41027401, 6.40764395, 6.40506698, 6.40253859,
6.40005574, 6.39761676, 6.39522117, 6.39286935, 6.3905623 ,
6.38830118, 6.38608695, 6.38391993, 6.3817994 , 6.37972337,
6.37768836, 6.37568941, 6.37372018, 6.37177319, 6.36984009,
6.36791193, 6.36597947, 6.36403327, 6.36206377, 6.36006124,
6.35801556, 6.35591601, 6.35375085, 6.35150693, 6.34916931,
6.34672075, 6.34414142, 6.34140857, 6.33849647, 6.33537652,
6.33201775, 6.32838766, 6.32445349, 6.32018397, 6.31555126,
6.31053306, 6.30511458, 6.29928998, 6.29306315, 6.28644753,
6.27946515, 6.27214482, 6.26452002, 6.25662656, 6.24850047,
6.24017628, 6.23168568, 6.22305686, 6.2143141 , 6.20547796,
6.19656569, 6.18759202, 6.17857019, 6.16951326, 6.16043571,
6.15135513, 6.14229412, 6.13328208, 6.12435686, 6.11556588,
6.10696669, 6.09862667, 6.09062162, 6.08303343, 6.07594653])
我尝试使用scipy.optimize中的minimumsq通过以下系数来解决此问题:
leastsq(SSR, vCoef, args=(y), full_output=1, maxfev=2500)
array([-1.01345719e+03, 1.01905962e+03, 1.07333189e+03, 3.68129556e-04])
但是,该值并没有太大意义,因为期望所有这四个系数的系数大约在-10和10之间。