Misclogo
Misclogo

Reputation: 117

Q: How to calculate 'hub integration' / how many of your link-neighbors are also my link-neighbors?

In the model I am building I need to make turtles calculate the 'hub integration' of their link-neighbors. By 'hub integration'(HI) I mean the following: HI = number-of-shared-neighbors/n-of-your-neighbors.

HI is a value that the 'turtle x' assigns to every other turtle that shares a link with her (we will call every linked turtles as 'turtle y'). The value of HI is thus the fraction of the number of nodes that are linked to both turtles x and y, with the number of nodes linked to turtle y.

I am using as references the Netlogo dictionary and the book 'An Introduction to Agent-Based Modeling' from Wilensky and Rand. Still, without the help of this community it would be really hard for me, if not impossible, to learn more advanced procedures.

EDIT 3 ---

I am greatly thankful for all the help received. I finally have a running procedure.

For the record, my final code of the 'hub integration procedure' is the following:

to find-hi
  ask turtles [
  foreach  sort link-neighbors [
  ask ? [
  if count [my-links] of self > 1 and count [my-links] of myself > 1 [
  let hi ( calc-HI self myself  )
  run-procedure  ] ] ] ]
end


to-report calc-HI [ XX YY ]
  let sizeX count [my-links] of XX
  let sizeY count [my-links] of YY
  let sizeXY count (turtle-set [link-neighbors] of XX [link-neighbors] of YY)
  report (sizeX + sizeY - sizeXY) / sizeY
end

Upvotes: 1

Views: 116

Answers (2)

JenB
JenB

Reputation: 17678

I think you want to count the number of neighbours, not list them all out.

One approach to count the number in common is to count the neighbours of X, count the neighbours of Y and count the agents who are either neighbours of X or Y. A turtle who is a neighbour of both X and Y will still only appear once in the agentset constructed, so the size of the intersection is the sum of the individual counts then subtract the size of the union.

This code expects you to nominate two turtles and reports the HI of turtle YY from the perspective of turtle XX (note that there is no checking that the two turtles have a link between them). I am not sure I have understood the calculation that you want, but you can amend as required.

to-report calc-HI [ XX YY ]
  let sizeX count [my-links] of XX
  let sizeY count [my-links] of YY
  let sizeXY count (turtle-set [link-neighbors] of XX [link-neighbors] of YY)
  report (sizeX + sizeY - sizeXY) / sizeY
end

Upvotes: 2

David Merinos
David Merinos

Reputation: 1295

You're using print in your reporter, try using report instead.

E.G.:

to-report who-of-neighbors
  report [who] of link-neighbors
end

More info on to-report right here.

Upvotes: 1

Related Questions