Create initial distribution range for opinion models #249
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For opinion models, this PR seeks to adds optional params to set the range of initial distribution, allowing greater control of model and initial network.
💻 Changing functionality: Allow setting initial distribution range for opinion models
Issue or RFC Endorsed by NDlib's Maintainers
#250
Description of the Change
For the opinion models where nodes have a status of [0,1] or [-1,1] (including
AlgorithmicBias
,WHK
, etc.), it is desirable to be able to set the range of the distribution of the initial status. This fine-tuned control of the starting population can be useful, for instance, in allowing developers to test how models are able to break out of that initial range or to simulate dynamics based on extreme populations.This PR adds two optional params,
init_dist_lower
andinit_dist_upper
that are then used in the random real value sampling of the selected models.Alternate Designs
An alternative would have been to update
add_model_initial_configuration,
however this method seems reserved for node statuses likeInfected
andSusceptible
, not numerical status values. In addition,add_model_initial_configuration
asks for setting a specific subset of nodes, but we want to be able to control the initial distribution range of all nodes.The selected models already had overrides for setting the initial status using real values. This extends that override directly in-line by setting the range of where those real values are drawn from.
Possible Drawbacks
The
range
attribute of a parameter does not seem to be verified for any params (including existing params likeepsilon
,gamma.
Therefore, despite setting the correct ranges of [0,1] or [-1,1], these are not enforced and can allow initial condition bounds outside of them.Verification Process
I have created multiple different models with various values set for the
init_dist_lower
andinit_dist_upper
params. Because they are directly fed intonp.random.uniform,
it is easy to verify that they accurately set the range: Here, I setinit_dist_lower = 0.95
init_dist_upper = 1
Without these params set, we can verify the default behavior preserves the original intended range of the
AlgorithmicBias
model:Note: Some models have had their distributions changed to
np.random.uniform,
however this is just a specific sub-version ofnp.random.random_sample()
with a defined range. In fact,np.random.uniform
usesnp.random.random_sample()
under-the-hood. (Source)Release Notes