Master
Master

Reputation: 1

Introducing probabilities to patches to replace each-other

I want to create a model which stimulates cell replication in human tissues. To do this I will only be working with patches and not turtles. A key concept to cell replication is fitness. Fitness in simplified terms is how 'strong' a cell is to replace the cell next to it. Initially I created a tissue like stimulation where each color is a cell type with a fixed fitness 100. Then I introduced a mutated cell whose fitness ranges from 90 to 110. What I want to do now is introduce probabilities for cell replication based on different fitness values.

So if we have 2 cells next to each other, one with fitness 95 and the other with fitness 100, I want to have a code that says the cell with fitness 100 has a 75% to replace the cell with fitness 95. Of course this should go across the ranges from 90-110 and this probability will depend on what the fitness values of cells next to each other have.

patches-own [ fitness ]

to setup
  clear-all
  setup-patches
  reset-ticks
end

to  setup-patches
 ask patches  ;; randomly set the patches' colors
    [   set fitness 100
        set pcolor (random colors) * 10 + 5
        if pcolor = 75  ;; 75 is too close to another color so change it to 125
          [ set pcolor 125 ] ]
end

to go
  if (variance [pcolor] of patches) = 0
    [ stop ]
  ask patches [
    ;; each patch randomly picks a neighboring patch
    ;; to copy a color from
    set pcolor [pcolor] of one-of neighbors
    set fitness [fitness] of one-of neighbors
    
    if fitness > 100 
    [set  pcolor 65]  
  ]
  
  tick
end

to mutate
  ;let mutateSet [patches with [ pcolor = 125]]
  ask patches
  [
    if ( (random-float 1) < 0.05 ) [
    set pcolor 65
    set fitness ((random 20) + 90)
    ]
  ]

end

This is what I have so far, and I cannot figure out how to introduce this probability parameter accordingly inside the go section. I saw somewhere the rnd function helps with probabilities, but it was using turtles and not patches.

Upvotes: 0

Views: 51

Answers (1)

LeirsW
LeirsW

Reputation: 2305

One very important tip I want to give you is to think about the stochasticity and scheduling in your model. Currently your agents take their action one at a time, with the order within each tick being randomised. This means that the order in which the patches change their pcolor has an influence on the outcome.

A way to circumvent this is to ask turtles twice. The first one lets each patch choose whether or not they want to change, the second ask actually does the changing. That way they all choose before any of them change. The segregation model is a good example of that (it uses turtles but that doesn't make any important difference).

This choosing part (probably a separate procedure that you write) is where the magic happens. You can have each patch check their own fitness and the fitness of all nearby patches ([fitness] of neighbors). When you have these fitness values, you can use them to calculate the probabilities that you want (which depends completely on what you are trying to model).

When you have all your probabilities, you can use one of various methods to determine which one is randomly picked. I'm not going to write this out as there are already numerous examples of this exact thing on stackoverflow:

Upvotes: 1

Related Questions