Esempio n. 1
0
def model_exposed():
    return ExposedSumSPE(
        spe_weights=(Nationality >> choice({
            'India': 0.5,
            'USA': 0.5
        })),
        children={
            # American student.
            'USA':
            ExposedSumSPE(spe_weights=(Perfect >> choice({
                'True': 0.01,
                'False': 0.99
            })),
                          children={
                              'False': GPA >> uniform(loc=0, scale=4),
                              'True': GPA >> atomic(loc=4),
                          }),
            # Indian student.
            'India':
            ExposedSumSPE(spe_weights=(Perfect >> choice({
                'True': 0.01,
                'False': 0.99
            })),
                          children={
                              'False': GPA >> uniform(loc=0, scale=10),
                              'True': GPA >> atomic(loc=10),
                          })
        },
    )
Esempio n. 2
0
def model_perfect_nested():
    Nationality = Id('Nationality')
    Perfect = Id('Perfect')
    GPA = Id('GPA')
    command = Sequence(
        Sample(Nationality, choice({
            'India': 0.5,
            'USA': 0.5
        })),
        IfElse(
            Nationality << {'India'},
            Sequence(
                Sample(Perfect, choice({
                    'True': 0.01,
                    'False': 0.99
                })),
                IfElse(Perfect << {'True'}, Sample(GPA, atomic(loc=10)), True,
                       Sample(GPA, uniform(scale=10)))),
            Nationality << {'USA'},
            Sequence(
                Sample(Perfect, choice({
                    'True': 0.01,
                    'False': 0.99
                })),
                IfElse(
                    Perfect << {'True'},
                    Sample(GPA, atomic(loc=4)),
                    True,
                    Sample(GPA, uniform(scale=4)),
                ))))
    return command.interpret()
Esempio n. 3
0
def get_command_beta():
    return Sequence(
        Sample(simAll, beta(a=2, b=3)),
        For(
            0, 5, lambda k: Switch(
                simAll, binspace(0, 1, ns), lambda i: Sequence(
                    Sample(sim[k], bernoulli(p=i.right)),
                    Sample(p1[k], uniform()),
                    IfElse(
                        sim[k] << {1},
                        Sequence(
                            Transform(p2[k], p1[k]),
                            Switch(
                                p1[k], binspace(0, 1, ns), lambda j: Sequence(
                                    Sample(clickA[k], bernoulli(p=i.right)),
                                    Sample(clickB[k], bernoulli(p=i.right))))),
                        True,
                        Sequence(
                            Sample(p2[k], uniform()),
                            Switch(
                                p1[k], binspace(0, 1, ns), lambda j: Sample(
                                    clickA[k], bernoulli(p=j.right))),
                            Switch(
                                p2[k], binspace(0, 1, ns), lambda j: Sample(
                                    clickB[k], bernoulli(p=j.right)))))))))
Esempio n. 4
0
def model_no_latents():
    return \
        0.5 * ( # American student
            0.99 * (GPA >> uniform(loc=0, scale=4)) | \
            0.01 * (GPA >> atomic(loc=4))) | \
        0.5 * ( # Indian student
            0.99 * (GPA >> uniform(loc=0, scale=10)) | \
            0.01 * (GPA >> atomic(loc=10)))
Esempio n. 5
0
def model_ifelse_exhuastive():
    command = Sequence(
        Sample(Nationality, choice({
            'India': 0.5,
            'USA': 0.5
        })), Sample(Perfect, choice({
            'True': 0.01,
            'False': 0.99
        })),
        IfElse((Nationality << {'India'}) & (Perfect << {'False'}),
               Sample(GPA, uniform(loc=0, scale=10)),
               (Nationality << {'India'}) & (Perfect << {'True'}),
               Sample(GPA, atomic(loc=10)),
               (Nationality << {'USA'}) & (Perfect << {'False'}),
               Sample(GPA, uniform(loc=0, scale=4)),
               (Nationality << {'USA'}) & (Perfect << {'True'}),
               Sample(GPA, atomic(loc=4))))
    return command.interpret()