Implement `sequence.py` to find dyadic conversation sequence
Opened this issue · 0 comments
aridyckovsky commented
Summary
A complete generate.py
in #2 requires that the generated topology satisfies a sufficiency condition: it must permit r rounds of interaction to take place between dyads given experimental constraints, i.e., a valid sequence of interactions between participant nodes relative to its config.yml
.
Motivation
This relates to the following milestones:
- Custom assignment to small world networks
- Generated sequence of chats per game
- YAML-spec treatment configurations
Completing this will also get us closer to #2 being complete.
Implementation
The below implementation is still missing a mechanism to dictate how many matchings a node must be a part of. It finds a sequence of rounds = 3
matchings:
import random
from itertools import chain
rounds = 3
dyads = [(u,v) for (u,v) in graph.edges]
interaction_sequence = []
tries = 5000
# This is 8 for n = 16
ideal_matching_size = round(len(graph.nodes()) / 2)
tries_since_ideal_matching = 0
print(f"Total available dyads: {len(dyads)}")
while tries:
matching = set()
matching.add(random.choice(dyads))
nodes_in_matching = set(chain(*matching))
for dyad in dyads:
u,v = dyad
if u not in nodes_in_matching and v not in nodes_in_matching:
matching.add((u,v))
nodes_in_matching.update({u,v})
if len(matching) == ideal_matching_size:
interaction_sequence.append(matching)
print("Matching added to sequence")
for matched in matching:
dyads.remove(matched)
print(f"{len(dyads)} remain for matching")
if len(interaction_sequence) == rounds:
break
if tries_since_ideal_matching > 1000:
ideal_matching_size -= 1
print(f"new ideal matching size: {ideal_matching_size}")
tries_since_ideal_matching = 0
tries -= 1
tries_since_ideal_matching += 1
print(f"Interaction sequence for {rounds} rounds found:")
interaction_sequence
The completion of this issue requires:
- Refactor from
playground.ipynb
to a newsrc/sequence.py
method - Take
interactions
parameters aftervalidate_config(study_name)
as input forsequence
- Enforce a range of interactions that must exist per participant for a given number of rounds
- Return a JavaScript aware data structure of the sequence