Exemplo n.º 1
0
 def test_inv_wo_test_id(self):
     inv_test = INV(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="inv test without test id")
     assert inv_test.test_id is None
Exemplo n.º 2
0
def object_test():
    global food_ret, sport_ret, drug_ret, nondrug_ret
    """
    codeDictionary = {"D":0, "M":1, "S":2, "H":3, "F":4, "O":5, "E":6, "NA":7}
    """

    editor = Editor()
    food_ret1 = editor.template('How often do you get {food}?',
                                food=food,
                                labels=0,
                                save=True)  #, nsamples=100)   a
    food_ret2 = editor.template('I can\'t stop thinking about {food}!',
                                food=food,
                                labels=0,
                                save=True)  #, nsamples=100)

    food_ret = food_ret1 + food_ret2

    mft_food = MFT(food_ret.data,
                   labels=food_ret.labels,
                   name='Object Rec: Food',
                   capability='Objects',
                   description='Food')

    sport_ret1 = editor.template('I have to participate in {sport}?',
                                 sport=sport,
                                 labels=6,
                                 save=True)  #, nsamples=100)
    sport_ret2 = editor.template(
        'It is good to move your body, like doing {sport}.',
        sport=sport,
        labels=6,
        save=True)  #, nsamples=100)

    sport_ret = sport_ret1 + sport_ret2

    mft_sport = MFT(sport_ret.data,
                    labels=sport_ret.labels,
                    name='Object Rec: Sport',
                    capability='Objects',
                    description='Sport')

    nondrug_ret1 = editor.template('How often do you take {nondrug}?',
                                   nondrug=nondrug,
                                   labels=5)  #, save=True) #, nsamples=100)
    nondrug_ret2 = editor.template(
        'Have you taken {nondrug} for the last five months?',
        nondrug=nondrug,
        labels=5)  #, save=True) #, nsamples=100)

    nondrug_ret = nondrug_ret1 + nondrug_ret2

    mft_nondrug = MFT(nondrug_ret.data,
                      labels=nondrug_ret.labels,
                      name='Object Rec: Non Drug',
                      capability='Objects',
                      description='Non Drug')

    drug_ret1 = editor.template('How often do you get {drug}?',
                                drug=drug,
                                labels=1,
                                save=True)  #, nsamples=100)
    drug_ret2 = editor.template(
        'Have you taken {drug} for the last five months?',
        drug=drug,
        labels=1,
        save=True)  #, nsamples=100)

    drug_ret = drug_ret1 + drug_ret2

    mft_drug = MFT(drug_ret.data,
                   labels=drug_ret.labels,
                   name='Object Rec: Drug',
                   capability='Objects',
                   description='Drug')

    #print(nondrug_ret.data)

    nt = Perturb.perturb(nondrug_ret.data, swap_nondrug)
    inv_n = INV(**nt,
                name='swap nondrug name in both questions',
                capability='objects',
                description='')

    #print(len(nt.data))
    #exit()
    """
    import numpy as np
    def pp(inputs):
        p1 = np.array([0.5 for x in inputs]).reshape(-1, 1)
        p0 = 1- p1
        return np.hstack((p0, p1))
    from checklist.pred_wrapper import PredictorWrapper
    wrapped = PredictorWrapper.wrap_softmax(pp)
    inv_n.run(wrapped)
    """

    dt = Perturb.perturb(drug_ret.data, swap_drug)
    inv_d = INV(**dt,
                name='swap drug name in both questions',
                capability='objects',
                description='')

    nondrug_monodec = Expect.monotonic(label=5,
                                       increasing=False,
                                       tolerance=0.1)
    drug_monodec = Expect.monotonic(label=1, increasing=False, tolerance=0.1)

    ndt = Perturb.perturb(nondrug_ret.data, swap_nd)
    dir_nd = DIR(**ndt, expect=nondrug_monodec)

    dnt = Perturb.perturb(drug_ret.data, swap_dn)
    dir_dn = DIR(**dnt, expect=drug_monodec)

    # diet    #exercise   # other     # medical  # other # medical, # o -> m, # m->o
    tests = [mft_food, mft_sport, mft_nondrug,
             mft_drug]  #, inv_n , inv_d, dir_nd, dir_dn ]
    names = [
        x.strip(",")
        for x in "mft_food, mft_sport, mft_nondrug, mft_drug".split()
    ]  #, inv_n, inv_d, dir_nd, dir_dn".split() ]

    assert (len(tests) == len(names))

    for test, name in zip(tests, names):
        test.to_raw_file('./tests/' + name + '.txt')

    return tests, names
Exemplo n.º 3
0
 def test_inv_w_test_id(self):
     inv_test = INV(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="inv test with test id",
                    test_id=self.test_id)
     assert inv_test.test_id == self.test_id
Exemplo n.º 4
0
 def test_dir_wo_test_id(self):
     dir_test = DIR(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="dir test without test id")
     assert dir_test.test_id is None
Exemplo n.º 5
0
 def test_dir_w_test_id(self):
     dir_test = DIR(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="dir test with test id",
                    test_id=self.test_id)
     assert dir_test.test_id == self.test_id
Exemplo n.º 6
0
 def test_mft_wo_test_id(self):
     mft_test = MFT(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="mft test without test id")
     assert mft_test.test_id is None
Exemplo n.º 7
0
 def test_mft_w_test_id(self):
     mft_test = MFT(**self.dummy_test_data,
                    expect=Expect.eq(),
                    name="mft test with test id",
                    test_id=self.test_id)
     assert mft_test.test_id == self.test_id