Skip to content

Sex

Sex

Bases: BaseInteraction

Source code in titan/interactions/sex.py
 7
 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
class Sex(base_interaction.BaseInteraction):
    name = "sex"

    @classmethod
    def get_num_acts(cls, model: "model.TITAN", rel: "agent.Relationship") -> int:
        """
        Simulate random transmission of HIV between two agents through Sex. One of the agents must be HIV+.

        args:
            model: The model being run
            rel : Relationship
        """
        # unprotected sex probabilities for primary partnerships
        mean_sex_acts = (
            rel.get_number_of_sex_acts(model.np_random) * model.calibration.sex.act
        )
        total_sex_acts = poisson(model.np_random, mean_sex_acts)

        # Get condom usage
        p_safe_sex = (
            rel.agent1.location.params.demographics[rel.agent1.race]
            .sex_type[rel.agent1.sex_type]
            .safe_sex[rel.bond_type]
            .prob
        )

        # increase condom usage if diagnosed
        if rel.agent1.hiv.dx or rel.agent2.hiv.dx:  # type: ignore[attr-defined]
            # Calculate probability of safe sex given risk reduction
            p_unsafe_sex = (1 - p_safe_sex) * (
                1 - model.params.hiv.dx.risk_reduction.sex
            )
            p_safe_sex = 1 - p_unsafe_sex

        # Reduction of risk acts between partners for condom usage
        unsafe_sex_acts = total_sex_acts
        for n in range(unsafe_sex_acts):
            if model.run_random.random() < p_safe_sex:
                unsafe_sex_acts -= 1

        return unsafe_sex_acts

get_num_acts(model, rel) classmethod

Simulate random transmission of HIV between two agents through Sex. One of the agents must be HIV+.

Parameters:

Name Type Description Default
model TITAN

The model being run

required
rel

Relationship

required
Source code in titan/interactions/sex.py
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
@classmethod
def get_num_acts(cls, model: "model.TITAN", rel: "agent.Relationship") -> int:
    """
    Simulate random transmission of HIV between two agents through Sex. One of the agents must be HIV+.

    args:
        model: The model being run
        rel : Relationship
    """
    # unprotected sex probabilities for primary partnerships
    mean_sex_acts = (
        rel.get_number_of_sex_acts(model.np_random) * model.calibration.sex.act
    )
    total_sex_acts = poisson(model.np_random, mean_sex_acts)

    # Get condom usage
    p_safe_sex = (
        rel.agent1.location.params.demographics[rel.agent1.race]
        .sex_type[rel.agent1.sex_type]
        .safe_sex[rel.bond_type]
        .prob
    )

    # increase condom usage if diagnosed
    if rel.agent1.hiv.dx or rel.agent2.hiv.dx:  # type: ignore[attr-defined]
        # Calculate probability of safe sex given risk reduction
        p_unsafe_sex = (1 - p_safe_sex) * (
            1 - model.params.hiv.dx.risk_reduction.sex
        )
        p_safe_sex = 1 - p_unsafe_sex

    # Reduction of risk acts between partners for condom usage
    unsafe_sex_acts = total_sex_acts
    for n in range(unsafe_sex_acts):
        if model.run_random.random() < p_safe_sex:
            unsafe_sex_acts -= 1

    return unsafe_sex_acts