2017-03-01 19 views
0

我想通過模擬退火來優化天線的位置和方向問題。我相信scipy.basinhopping會做我需要的,但我不明白accept_test函數中f_new和f_old的含義。我在文檔中看不到解釋。如果有人能夠啓發我那些非常棒的kwargs的意義。我感到困惑,具體可調用的是:scipy basinhopping accept_test:什麼是f_new和f_old

accept_test : callable, accept_test(f_new=f_new, x_new=x_new, f_old=fold, x_old=x_old), optional 

謝謝

朗高

回答

0

從文檔https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.basinhopping.html#scipy-optimize-basinhopping

accept_test : callable, ``accept_test(f_new=f_new, x_new=x_new, f_old=fold, x_old=x_old)``, optional 
    Define a test which will be used to judge whether or not to accept the 
    step. This will be used in addition to the Metropolis test based on 
    "temperature" ``T``. The acceptable return values are True, 
    False, or ``"force accept"``. If any of the tests return False 
    then the step is rejected. If the latter, then this will override any 
    other tests in order to accept the step. This can be used, for example, 
    to forcefully escape from a local minimum that ``basinhopping`` is 
    trapped in. 

,你可以收集這是信息,呼籲參數a

  1. a是可調用的,因此可以提供一個函數。
  2. a充當進化算法的決定。可能的返回值是True和False,與Metropolis條件結合使用(即兩個條件必須返回True才能被接受)和「強制接受」。如果您想在Metropolis拒絕的情況下強制接受,則必須使用後一選項。
  3. 您可以在自定義條件中使用當前步驟x_oldf_old(這裏是值,不是可調用的)的值以及新步驟x_newf_new的值。

下面,我建立了一個玩具示例,其中accept_test功能勢力驗收時的步驟是正確的參數空間

def f(x): 
    return x**2 

def a(f_new, x_new, f_old, x_old): 
    if x_new>x_old: 
     return "force accept" 
    else: 
     return True 

basinhopping(f, 1, accept_test=a) 
+0

感謝您迴應,但我還是不明白f_old和f_new根據你的解釋。是否有可能修改您的示例以使用f_old和f_new。 – LostInTheFrequencyDomain

+1

'f_old'和'f_new'是* x_old到* x_new更新前後能量函數的值。對於一個普通的統計物理系統來說,這是在Metropolis準則exp( - (e_old-e_new)/(k_B * T))中的舊能量'e_old'和新能量'e_new'' –