Esempio n. 1
0
def fit_model_and_calc_idr(r1,
                           r2,
                           starting_point=None,
                           max_iter=idr.MAX_ITER_DEFAULT,
                           convergence_eps=idr.CONVERGENCE_EPS_DEFAULT,
                           fix_mu=False,
                           fix_sigma=False):
    # in theory we would try to find good starting point here,
    # but for now just set it to somethign reasonable
    if type(starting_point) == type(None):
        starting_point = (DEFAULT_MU, DEFAULT_SIGMA, DEFAULT_RHO,
                          DEFAULT_MIX_PARAM)

    idr.log("Initial parameter values: [%s]" %
            " ".join("%.2f" % x for x in starting_point))

    # fit the model parameters
    idr.log("Fitting the model parameters", 'VERBOSE')
    if idr.PROFILE:
        import cProfile
        cProfile.runctx(
            """theta, loss = estimate_model_params(
                                    r1,r2,
                                    starting_point, 
                                    max_iter=max_iter, 
                                    convergence_eps=convergence_eps,
                                    fix_mu=fix_mu, fix_sigma=fix_sigma)
                                   """,
            {'estimate_model_params': estimate_model_params}, {
                'r1': r1,
                'r2': r2,
                'starting_point': starting_point,
                'max_iter': max_iter,
                'convergence_eps': convergence_eps,
                'fix_mu': fix_mu,
                'fix_sigma': fix_sigma
            })
        assert False
    theta, loss = estimate_model_params(r1,
                                        r2,
                                        starting_point,
                                        max_iter=max_iter,
                                        convergence_eps=convergence_eps,
                                        fix_mu=fix_mu,
                                        fix_sigma=fix_sigma)

    idr.log("Finished running IDR on the datasets", 'VERBOSE')
    idr.log("Final parameter values: [%s]" % " ".join("%.2f" % x
                                                      for x in theta))

    # calculate the global IDR
    localIDRs, IDRs = calc_IDR(numpy.array(theta), r1, r2)

    return localIDRs, IDRs
Esempio n. 2
0
def fit_model_and_calc_idr(r1, r2, 
                           starting_point=None,
                           max_iter=idr.MAX_ITER_DEFAULT, 
                           convergence_eps=idr.CONVERGENCE_EPS_DEFAULT, 
                           fix_mu=False, fix_sigma=False ):
    # in theory we would try to find good starting point here,
    # but for now just set it to somethign reasonable
    if type(starting_point) == type(None):
        starting_point = (DEFAULT_MU, DEFAULT_SIGMA, 
                          DEFAULT_RHO, DEFAULT_MIX_PARAM)
    
    idr.log("Initial parameter values: [%s]" % " ".join(
            "%.2f" % x for x in starting_point))
    
    # fit the model parameters    
    idr.log("Fitting the model parameters", 'VERBOSE');
    if idr.PROFILE:
            import cProfile
            cProfile.runctx("""theta, loss = estimate_model_params(
                                    r1,r2,
                                    starting_point, 
                                    max_iter=max_iter, 
                                    convergence_eps=convergence_eps,
                                    fix_mu=fix_mu, fix_sigma=fix_sigma)
                                   """, 
                            {'estimate_model_params': estimate_model_params}, 
                            {'r1':r1, 'r2':r2, 
                             'starting_point': starting_point,
                             'max_iter': max_iter, 
                             'convergence_eps': convergence_eps,
                             'fix_mu': fix_mu, 'fix_sigma': fix_sigma} )
            assert False
    theta, loss = estimate_model_params(
        r1, r2,
        starting_point, 
        max_iter=max_iter, 
        convergence_eps=convergence_eps,
        fix_mu=fix_mu, fix_sigma=fix_sigma)
    
    idr.log("Finished running IDR on the datasets", 'VERBOSE')
    idr.log("Final parameter values: [%s]"%" ".join("%.2f" % x for x in theta))
    
    # calculate the global IDR
    localIDRs, IDRs = calc_IDR(numpy.array(theta), r1, r2)

    return localIDRs, IDRs