2016-11-21 87 views
0

我正試圖計算單個補丁上龜的擁有因子的方差。換句話說,在一個補丁中,我想知道該補丁中所有龜的因素的均值和方差。在netlogo中計算單個補丁上的龜擁有因子的方差

我知道'烏龜的意思[因素] - 在這裏'會給我的意思,但由於某種原因,差異不是很好。 問題1:請求補丁輸出一個龜擁有的因子的方差的正確語法是什麼?

我已經制作了一個超級簡單的示例模型。只需將其粘貼到代碼中,然後在界面上創建「設置」和「去」按鈕即可。它應該有粉紅色的海龜尋找和停止黑色補丁。

turtles-own 
    [FACTOR] 
patches-own 
    [DEPTH] 
to setup 
    clear-all 
    reset-ticks 
    make_patches 
    make_turtles 
end 

to go 
    move 
    if count (turtles with [DEPTH > 0]) = 0 [stop] 
end 

to make_patches 
    ask patches [set depth 20 set pcolor green - 2] 
    ask n-of 5 patches [set depth -50 set pcolor black] 
end 

to make_turtles 
    create-turtles 10 
    ask turtles 
    [ 
    set color pink 
    set size 2 
    set xcor random max-pxcor 
    set ycor random max-pycor 
    set FACTOR random 100 
    ] 
end 

to move 
    ask turtles[ 
    let D min [DEPTH] of patches in-radius 3 
    let Dn min-one-of patches in-radius 3 [DEPTH] 
    let LDe [DEPTH] of patch-here 

ifelse DEPTH < 0 
[ 
    move-to patch-here 
    stop 
] 
[ifelse LDE > D AND D < 0 
    [ 
    move-to DN 
    stop 
    ] 
    [ 
    right random-float 150 
    forward random 3 
    ] 
] 
    ] 
end 

最後,我想上做一個行爲空間實驗,其中在每一個的端部運行具有DEPTH < 0計算每個補丁並輸出平均值,標準偏差,和因子的方差爲龜那確切的補丁。我的計劃是創建排序列表

ask patches with [DEPTH< 0] [set FACTOR_LIST (list ("[")(COORDINATES) (",") (VARIANCE_FACTOR) ("]"))] 

其中FACTOR_LIST被導出列表,座標由x和補丁的y座標列表,並VARIANCE_FACTOR是因子的方差(我在這裏要問怎麼辦)。 問題2:是否有更有效的方法來獲取此列表?

非常感謝!

回答

0

寫下這個問題至少讓我回答了第一個問題。

我改變:

patches-own 
    [ 
    DEPTH 
    DENSITY 
    FACTOR_VARIANCE 
    FACTOR_LIST 
    ] 
to go 
    move 
    if count (turtles with [DEPTH > 0]) = 0 
    [ 
    final_tick 
    ask patches with [DEPTH < 0] [show FACTOR_LIST] 
    stop 
    ] 

end 

,並補充說,計算方差,並把它放在一個列表,我可以從補丁調用

to final_tick 
    ask patches with [DEPTH < 0] [set DENSITY count turtles-here] 
    ask patches with [DEPTH < 0 AND DENSITY <= 1] [set FACTOR_VARIANCE 0] 
    ask patches with [DEPTH < 0 AND DENSITY > 1] [set FACTOR_VARIANCE (variance [FACTOR] of turtles-here)] 
    ask patches with [DEPTH < 0] [set FACTOR_LIST (list (pxcor)(",")(pycor)(",")(FACTOR_VARIANCE))] 
end 

還是想知道如果任何人有一個新的程序一個更有效的方式來實現這個目標。

相關問題