0

I am expanding a model looking at the effect of different types of fruit and fragmentation on a population of monkeys. The model reads a landsat file made up of 1's and 0s (representing forested and deforested areas) I need to reclassify the 1's into three kinds of trees. At the moment in the code I have the three types of trees randomly set, now I want them to be divided into percentages i.e 30 percent of the forested patches are blue, 50 percent are yellow, 20 are green. I have this atm: I think I have to change the:

[ if value = 1 [ set value one-of tree-types ]

I tried with n-of but I can't seem to make it work.

Any suggestions?

to load-forest 
file-open "patch46.txt" 
let tree-types [ 1   2   3 ] 
let tree-colors [ 0 15 65 45] 
let tree-fruits [ 0 25 50 100 ] 

foreach n-values world-height [ min-pycor + ? ] 
[let num-lines ? 
foreach n-values world-width [ min-pxcor + ? ] 
[let num-cols ? 
    ask patch num-lines num-cols 
    [set value file-read 
    ] 
  ] 
] 
file-close 

ask patches 
 [ if value = 1 [ set value one-of tree-types ] 
   set pcolor item value tree-colors 
   set fruit item value tree-fruits 
 ] 
end 
4

1 回答 1

1

一种可能性是使用 NetLogo Rnd 扩展rnd:weighted-one-of中的原语。

它有点像one-of,但选择每个项目的概率可以不同(即加权)。

假设您有一个不同类型树的概率列表:

let probabilities [ 30 50 20 ]

您可以将其用作:

set value rnd:weighted-one-of tree-types [ item (? - 1) probabilities ]

请注意,这将为您提供平均30% 的蓝色树、50% 的黄色树和 20% 的绿色树,但它可能因运行而异。由于您已经在使用one-of,它具有相同的效果(即平均每种类型的 33%),我假设您对此表示满意。如果您希望每次运行都获得准确的百分比,那么答案将大不相同。

边注:

您的tree-colorstree-fruits列表有一个“虚拟”0项目,因此您可以value直接使用树类型作为这些列表的索引。由于各种原因,这很令人困惑,而且是不好的做法。例如,show length tree-fruits将打印4. 这也意味着您不能tree-types在同一foreachormap构造中使用和其他列表,例如:(foreach tree-types tree-fruits [...]). 这些事情现在可能看起来没什么大不了的,但它们最终加起来会让你的程序更难理解。

您应该硬着头皮将其value - 1用作索引,或者将您的树类型重新编号为[ 0 1 2 ].

于 2014-06-03T14:32:01.210 回答