コード例 #1
0
ファイル: tests.py プロジェクト: aflaxman/pymc-cod-correct
    def test_bad_model(self):
        X = data.sim_data(10)
        Y = models.bad_model(X)
        assert pl.allclose(Y.sum(axis=2), 1), 'should be all ones, (%s found)' % str(Y.sum(axis=2))

        # test again for 10x2x3 dataset
        X = data.sim_data(10, [[.1, .4, .5]], [.1, .1, .1])
        Y = models.bad_model(X)
        assert pl.allclose(Y.sum(axis=2), 1), 'should be all ones, (%s found)' % str(Y.sum(axis=2))
コード例 #2
0
    def test_bad_model(self):
        X = data.sim_data(10)
        Y = models.bad_model(X)
        assert pl.allclose(
            Y.sum(axis=2),
            1), 'should be all ones, (%s found)' % str(Y.sum(axis=2))

        # test again for 10x2x3 dataset
        X = data.sim_data(10, [[.1, .4, .5]], [.1, .1, .1])
        Y = models.bad_model(X)
        assert pl.allclose(
            Y.sum(axis=2),
            1), 'should be all ones, (%s found)' % str(Y.sum(axis=2))
コード例 #3
0
def validate_once(true_cf = [pl.ones(3)/3.0, pl.ones(3)/3.0], true_std = 0.01*pl.ones(3), std_bias = [1., 1., 1.], save=False, dir='', i=0):
    """
    Generate a set of simulated estimates for the provided true cause fractions; Fit the bad model and 
    the latent simplex model to this simulated data and calculate quality metrics. 
    """ 
    
    # generate simulation data
    X = data.sim_data_for_validation(1000, true_cf, true_std, std_bias)

    # fit bad model, calculate fit metrics 
    bad_model = models.bad_model(X)
    bad_model_metrics = calc_quality_metrics(true_cf, true_std, std_bias, bad_model)
    retrieve_estimates(bad_model, True, 'bad_model', dir, i)
    
    # fit latent simplex model, calculate fit metrics 
    m, latent_simplex = models.fit_latent_simplex(X)
    latent_simplex_metrics = calc_quality_metrics(true_cf, true_std, std_bias, latent_simplex)
    retrieve_estimates(latent_simplex, True, 'latent_simplex', dir, i)
    
    # either write results to disk or return them 
    if save: 
        pl.rec2csv(bad_model_metrics, '%s/metrics_bad_model_%i.csv' % (dir, i)) 
        pl.rec2csv(latent_simplex_metrics, '%s/metrics_latent_simplex_%i.csv' % (dir, i))
    else: 
        return bad_model_metrics, latent_simplex_metrics
コード例 #4
0
def validate_once(true_cf=[pl.ones(3) / 3.0,
                           pl.ones(3) / 3.0],
                  true_std=0.01 * pl.ones(3),
                  std_bias=[1., 1., 1.],
                  save=False,
                  dir='',
                  i=0):
    """
    Generate a set of simulated estimates for the provided true cause fractions; Fit the bad model and 
    the latent simplex model to this simulated data and calculate quality metrics. 
    """

    # generate simulation data
    X = data.sim_data_for_validation(1000, true_cf, true_std, std_bias)

    # fit bad model, calculate fit metrics
    bad_model = models.bad_model(X)
    bad_model_metrics = calc_quality_metrics(true_cf, true_std, std_bias,
                                             bad_model)
    retrieve_estimates(bad_model, True, 'bad_model', dir, i)

    # fit latent simplex model, calculate fit metrics
    m, latent_simplex = models.fit_latent_simplex(X)
    latent_simplex_metrics = calc_quality_metrics(true_cf, true_std, std_bias,
                                                  latent_simplex)
    retrieve_estimates(latent_simplex, True, 'latent_simplex', dir, i)

    # either write results to disk or return them
    if save:
        pl.rec2csv(bad_model_metrics, '%s/metrics_bad_model_%i.csv' % (dir, i))
        pl.rec2csv(latent_simplex_metrics,
                   '%s/metrics_latent_simplex_%i.csv' % (dir, i))
    else:
        return bad_model_metrics, latent_simplex_metrics