1
我想估計一個新產品的需求。客戶是代理商。每種產品都有3個變量需要根據購買情況進行優化。爲了找到使銷售最大化的最佳變量,我使用了局部優化算法,即梯度下降法。它的工作原理如下:Netlogo本地優化
1.定義重量,大小和價格的初始值。 2.搜索程序開始: dgradient是目標函數梯度的範數。 dx計算變量和新變量之間的差異。
while [dgradient > 0.00001 and numiter < 1000 and dxw > 0.00001 and dxs > 0.00001 and dxp > 0.00001]
set weightnw weight - stepsize * (the gradient)
set sizenw size - stepsize * (the gradient)
setpricenw price - stepsize * (the gradient)
搜索過程,在附近產生新的變量,但我必須確保它們在範圍內。所以我定義這個while循環,以確保他們在範圍:
while [not(((weightnw <= 400) and (weightnw >= 100)) and ((sizenw >= 5) and sizenw <= 20)) and ((pricenw >= 20) and (pricenw <=90)))]
set stepsize stepsize - 0.0001
set weightnw weight - stepsize * (the gradient)
set sizenw size - stepsize * (the gradient)
setpricenw price - stepsize * (the gradient)
然後目標函數的計算,並與新變量的目標函數的值進行比較。
程序是否有意義?
由於
如何計算梯度?爲什麼不使用重新啓動爬坡或某種搜索算法呢?請參閱http://ccl.northwestern.edu/netlogo/models/community/gradient – mattsap
另外,您遇到的問題是什麼?期望值是否被關閉?我*認爲*您可能會發現本地最小/最大值而不是全局值,但它確實取決於未顯示的其餘代碼。 – mattsap