backspaces / agentscript

An Agent Based Modeling system (ABM)
http://backspaces.github.io/agentscript/
GNU General Public License v3.0
107 stars 14 forks source link

Understanding diffuse #47

Closed bennlich closed 3 years ago

bennlich commented 3 years ago

@backspaces I'm looking w/ my dad at https://github.com/backspaces/agentscript/blob/master/src/Patches.js#L301 :

const dv = p[v] * rate            
const dvn = dv / n            
const neighbors = n === 8 ? p.neighbors : p.neighbors4            
const nn = neighbors.length
p._diffuseNext += p[v] - dv + (n - nn) * dvn

I'm having trouble understanding the last term on the last line. Isn't (n - nn) always 0?

stephenguerin commented 3 years ago

corner patches have neighbors (nn) = 3 neighbors and edge patches have nn = 5. they will be different from n=4 or 8. To explore this I set a conditional breakpoint to pause whenever n != nn and saw it pausing on the patches with 3's and 5s. Note in the image below the debugger is currently paused on patch id 4 in the right "Block" tree you can see it has 5 neighbors

image

and when I mouse over "nn" it gives me the current value.

image

stephenguerin commented 3 years ago

To edit a breakpoint to be conditional, right click on it and put in your expression.

image

You can also have the option to make a "logpoint" here which is convenient for console logging especially when you can't modify the source:

https://www.thedevelobear.com/post/logpoints/

stephenguerin commented 3 years ago

I suspect Benny's dad wants to know if the diffuse process conserves the quantity being diffused. I once answered him with a confident yes wrt to Netlogo :-) Reading through Owen's code (very cool btw), I think it is also true for Agentscript

bennlich commented 3 years ago

Ahhhhh, I see. Nice breakdown. Thanks @stephenguerin

plichtner commented 3 years ago

Is diffusion unstable if rate > 1? See attached figure with rate = 1.5.

Screen Shot 2021-05-21 at 10 25 40 AM