Skip to content

Issue 152#156

Open
mensch72 wants to merge 4 commits into
imitation_componentfrom
issue_152
Open

Issue 152#156
mensch72 wants to merge 4 commits into
imitation_componentfrom
issue_152

Conversation

@mensch72

Copy link
Copy Markdown
Contributor

No description provided.

@mensch72 mensch72 requested a review from leander-j December 10, 2021 12:45
@mensch72 mensch72 linked an issue Dec 10, 2021 that may be closed by this pull request

@leander-j leander-j left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, but no coherent defaulting, i.e.

  1. if not set at all, defaults to 1
  2. if set only for other trait(s), defaults to None
  3. if set only for other (source, target) combination(s), defaults to 0

I would suggest either defaulting to 1 always, or requiring setting always (in cases 2 and 3 with '*') and giving an error when not done so

@leander-j

leander-j commented Dec 15, 2021

Copy link
Copy Markdown

Attention: simple contagion does not work with this implementation!

E.g.:

culture = M.Culture(
    imi_rate = {
        'bool': 10000,   # -> 10000 updates
        #'ord': 10,  # *10 in batch -> 10000 updates
        # 'pair': 200, # *~50 in batch -> 10000 updates
        '*': 0,
        },
    imi_type = 'simple',
    imi_batch_n = {'bool': 1, 'ord': 10},
    imi_p_in_batch = {'pair': 0.5},
    imi_network = M.Culture.acquaintance_network,
    imi_p_neighbor_drawn = {'bool': 1.0, 'pair': 1.0},
    imi_n_neighbors_drawn = {'ord': 1},
    imi_rel_threshold = {'bool': { 
            ((False,),(True,)): 0.4, 
            ((True,),(False,)): 0.8
        }, 'ord': 0, 'pair': 0},
   # imi_abs_threshold = {'ord': 0, 'pair': 0},
    imi_include_own_trait = {'pair': True, '*': False},
    imi_delta = {'pair': 10.0},  # evaluation will be done by Individual.imi_evaluate_pair
    imi_p_imitate = {'pair': 1.0, 'bool': {
            ((False,),(True,)): 0.9, 
            ((True,),(False,)): 0.7
        }, 'ord': 1.0}  # for 'ord', the value is set by Cell.imi_p_imitate_ord
    )

yields

Traceback (most recent call last):
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/studies/_testing/generic_imitation_simple.py", line 122, in <module>
    traj = doit()
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/studies/_testing/generic_imitation_simple.py", line 117, in doit
    res = runner.run(t_0=0, t_1=t_1, dt=1)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/runners/runner.py", line 592, in run
    method(inst, t)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/generic_imitation/implementation/culture.py", line 474, in perform_event
    self.trigger_imitation(key)
  File "/home/leander/Documents/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/generic_imitation/implementation/culture.py", line 449, in trigger_imitation
    if (nominated_trait != my_trait) and uniform() < actual_p_imitates[nominated_trait]:
UnboundLocalError: local variable 'actual_p_imitates' referenced before assignment

Edit: same error with ord variable, no matter if imitation probability is specified in the run file or via Cell.imi_p_imitate_ord

@leander-j

Copy link
Copy Markdown

Regarding setting specific default values:

At the moment it is possible to use

    imi_p_imitate = {
        'ord': {
            ((1,), (5,)): 1.0,
            ('*', '*'): 0.5,
            }

It could also make sense to allow just

    imi_p_imitate = {
        'ord': {
            ((1,), (5,)): 1.0,
            '*': 0.5,
            }

AlbinaMuzafarova and others added 2 commits December 19, 2021 13:08
@mensch72

Copy link
Copy Markdown
Contributor Author

Type="simple" should now work.
The value of a parameter (including p_imitate) is now determined like this:

  1. If the entity has a function for it, that function sets the value. Otherwise:
  2. If the parameter is None, the default value specified in the interface is used
  3. If the parameter is a single value, that is used
  4. If the parameter is a dict:
    • If the dict contains the trait as key, it is based on the corresponding dict entry:
      • If the entry is a single value, that is used
      • If the entry is again a dict:
        • If this inner dict contains the (source_trait, candidate_target_trait) as key, that entry is used
        • Otherwise, if the inner dict contains (source_trait, '*'), that entry is used
        • Otherwise, if the inner dict contains ('*', candidate_target_trait), that entry is used
        • Otherwise, if the inner dict contains ('', ''), that entry is used
        • Otherwise, if the inner dict contains '*', that entry is used
        • Otherwise the default value specified in the interface is used
    • Otherwise, if the outer dict contains '*', that entry (value or inner dict) is used (similar to above)
    • Otherwise, the default value specified in the interface is used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[generic_imitation] imi_p_imitate not working properly

3 participants