Exemple #1
0
 def test_assertion_on_wrong_param_name_tofix(self):
     # does not catch if correct argument
     HNodeSimple(self.data,
                 depends_on={
                     'non_existant': 'condition',
                     'mu': 'condition'
                 })
Exemple #2
0
    def test_concat(self):
        n_subj = 5
        data, params = kabuki.generate.gen_rand_data(gen_func_df, {'A':{'loc':0, 'scale':1}, 'B': {'loc':0, 'scale':1}}, subjs=n_subj)
        data = pd.DataFrame(data)

        models = []
        for i in range(4):
            m = HNodeSimple(data)
            m.sample(100, burn=0, db='pickle', dbname='test_%d'%i)
            models.append(m)

        super_model = kabuki.utils.concat_models(models)
        stochs = super_model.get_stochastics()
        for stoch in stochs.node:
            self.assertEqual(len(stoch.trace[:]), 100*4)

        for i in range(4):
            os.remove('test_%d'%i)
Exemple #3
0
    def test_map_approx(self):
        subjs = 40
        data, params_true = kabuki.generate.gen_rand_data(gen_func_df,
                                                          {'A':{'loc':0, 'scale':1}, 'B': {'loc':2, 'scale':1}},
                                                          subj_noise={'loc':.1}, size=1000, subjs=subjs)

        model = HNodeSimple(data, depends_on={'mu': 'condition'})

        model.approximate_map()
        model.approximate_map(individual_subjs=False)
        counter = 0
        for condition, subj_params in params_true.iteritems():
            nodes = model.nodes_db[model.nodes_db['condition'] == condition]
            for idx, params in enumerate(subj_params):
                nodes_subj = nodes[nodes['subj_idx'] == idx]
                for param_name, value in params.iteritems():
                    if param_name != 'loc':
                        continue
                    node = nodes_subj[nodes_subj.knode_name == 'mu_subj']
                    assert len(node) == 1, "Only one node should have been left after slicing."
                    abs_error = np.abs(node.map[0] - value)
                    self.assertTrue(abs_error < .2)
                    counter += 1

        # looping for each condition (i.e. twice)
        self.assertEqual(counter, subjs*2)
Exemple #4
0
 def test_save_and_load_breakdown(self):
     m = HNodeSimple(self.data)
     m.sample(500, dbname='test.db', db='pickle')
     m.save('test.model')
     m_load = kabuki.utils.load('test.model')
     os.remove('test.db')
     os.remove('test.model')
Exemple #5
0
 def test_assertion_on_wrong_param_name(self):
     HNodeSimple(self.data, depends_on={'non_existant': 'condition'})
Exemple #6
0
 def test_simple_deps(self):
     m = HNodeSimple(self.data, depends_on={'mu': 'condition'})
     n_nodes = 2 * (1 + self.n_subj*2) #n_conds * (mu_g + n_subj * (mu_subj + like))
     self.assertEqual(len(m.nodes_db), n_nodes)
Exemple #7
0
 def test_simple_no_deps(self):
     m = HNodeSimple(self.data)
     n_nodes = 1 + self.n_subj*2 #mu_g + n_subj * (mu_subj + like)
     self.assertEqual(len(m.nodes_db), n_nodes)