Skip to content

Injection

Injection

Bases: BaseInteraction

Source code in titan/interactions/injection.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Injection(base_interaction.BaseInteraction):
    name = "injection"

    @classmethod
    def get_num_acts(cls, model: "model.TITAN", rel: "agent.Relationship") -> int:
        """
        Simulate random transmission of HIV between two PWID agents through injection.

        args:
            model: The currently running model
            rel: The relationship in which the interaction is happening
        """

        # make sure both agents have Inj drug type, should only be possible for
        # the relationship to have the injection interaction type if both agents PWID
        assert rel.agent1.drug_type == "Inj"
        assert rel.agent2.drug_type == "Inj"

        agent_params = (
            rel.agent1.location.params.demographics[rel.agent1.race]
            .sex_type[rel.agent1.sex_type]
            .injection
        )
        partner_params = (
            rel.agent2.location.params.demographics[rel.agent2.race]
            .sex_type[rel.agent2.sex_type]
            .injection
        )

        mean_num_acts = (
            min(agent_params.num_acts, partner_params.num_acts)
            * model.calibration.injection.act
        )
        share_acts = poisson(model.np_random, mean_num_acts)

        if share_acts < 1:
            return 0

        if (
            rel.agent1.syringe_services.active or rel.agent2.syringe_services.active  # type: ignore[attr-defined]
        ):  # syringe services program risk
            p_unsafe_injection = features.SyringeServices.enrolled_risk
        else:
            p_unsafe_injection = agent_params.unsafe_prob

        # diagnosis risk reduction
        if rel.agent1.hiv.dx or rel.agent1.hiv.dx:  # type: ignore[attr-defined]
            p_unsafe_injection *= 1 - model.params.hiv.dx.risk_reduction.injection

        for n in range(share_acts):
            if model.run_random.random() > p_unsafe_injection:
                share_acts -= 1

        return share_acts

get_num_acts(model, rel) classmethod

Simulate random transmission of HIV between two PWID agents through injection.

Parameters:

Name Type Description Default
model TITAN

The currently running model

required
rel Relationship

The relationship in which the interaction is happening

required
Source code in titan/interactions/injection.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@classmethod
def get_num_acts(cls, model: "model.TITAN", rel: "agent.Relationship") -> int:
    """
    Simulate random transmission of HIV between two PWID agents through injection.

    args:
        model: The currently running model
        rel: The relationship in which the interaction is happening
    """

    # make sure both agents have Inj drug type, should only be possible for
    # the relationship to have the injection interaction type if both agents PWID
    assert rel.agent1.drug_type == "Inj"
    assert rel.agent2.drug_type == "Inj"

    agent_params = (
        rel.agent1.location.params.demographics[rel.agent1.race]
        .sex_type[rel.agent1.sex_type]
        .injection
    )
    partner_params = (
        rel.agent2.location.params.demographics[rel.agent2.race]
        .sex_type[rel.agent2.sex_type]
        .injection
    )

    mean_num_acts = (
        min(agent_params.num_acts, partner_params.num_acts)
        * model.calibration.injection.act
    )
    share_acts = poisson(model.np_random, mean_num_acts)

    if share_acts < 1:
        return 0

    if (
        rel.agent1.syringe_services.active or rel.agent2.syringe_services.active  # type: ignore[attr-defined]
    ):  # syringe services program risk
        p_unsafe_injection = features.SyringeServices.enrolled_risk
    else:
        p_unsafe_injection = agent_params.unsafe_prob

    # diagnosis risk reduction
    if rel.agent1.hiv.dx or rel.agent1.hiv.dx:  # type: ignore[attr-defined]
        p_unsafe_injection *= 1 - model.params.hiv.dx.risk_reduction.injection

    for n in range(share_acts):
        if model.run_random.random() > p_unsafe_injection:
            share_acts -= 1

    return share_acts