Esempio n. 1
0
def get_response_content(fs):
    f_info = divtime.get_fisher_info_known_distn_fast
    requested_triples = []
    for triple in g_process_triples:
        name, desc, zoo_obj = triple
        if getattr(fs, name):
            requested_triples.append(triple)
    if not requested_triples:
        raise ValueError('nothing to plot')
    # define the R table headers
    r_names = [a.replace('_', '.') for a, b, c in requested_triples]
    headers = ['t'] + r_names
    # Spend a lot of time doing the optimizations
    # to construct the points for the R table.
    arr = []
    for t in cbreaker.throttled(progrid.gen_binary(fs.start_time,
                                                   fs.stop_time),
                                nseconds=5,
                                ncount=200):
        row = [t]
        for python_name, desc, zoo_class in requested_triples:
            zoo_obj = zoo_class(fs.d)
            df = zoo_obj.get_df()
            opt_dep = OptDep(zoo_obj, t, f_info)
            if df:
                X0 = np.random.randn(df)
                xopt = scipy.optimize.fmin(opt_dep,
                                           X0,
                                           maxiter=10000,
                                           maxfun=10000)
                # I would like to use scipy.optimize.minimize
                # except that this requires a newer version of
                # scipy than is packaged for ubuntu right now.
                # fmin_bfgs seems to have problems sometimes
                # either hanging or maxiter=10K is too big.
                """
                xopt = scipy.optimize.fmin_bfgs(opt_dep, X0,
                        gtol=1e-8, maxiter=10000)
                """
            else:
                xopt = np.array([])
            info_value = -opt_dep(xopt)
            row.append(info_value)
        arr.append(row)
    arr.sort()
    npoints = len(arr)
    # create the R table string and scripts
    # get the R table
    table_string = RUtil.get_table_string(arr, headers)
    # get the R script
    script = get_ggplot()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter(
        table_string, script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
Esempio n. 2
0
def get_response_content(fs):
    f_info = divtime.get_fisher_info_known_distn_fast
    requested_triples = []
    for triple in g_process_triples:
        name, desc, zoo_obj = triple
        if getattr(fs, name):
            requested_triples.append(triple)
    if not requested_triples:
        raise ValueError('nothing to plot')
    # define the R table headers
    r_names = [a.replace('_', '.') for a, b, c in requested_triples]
    headers = ['t'] + r_names
    # Spend a lot of time doing the optimizations
    # to construct the points for the R table.
    arr = []
    for t in cbreaker.throttled(
            progrid.gen_binary(fs.start_time, fs.stop_time),
            nseconds=5, ncount=200):
        row = [t]
        for python_name, desc, zoo_class in requested_triples:
            zoo_obj = zoo_class(fs.d)
            df = zoo_obj.get_df()
            opt_dep = OptDep(zoo_obj, t, f_info)
            if df:
                X0 = np.random.randn(df)
                xopt = scipy.optimize.fmin(
                        opt_dep, X0, maxiter=10000, maxfun=10000)
                # I would like to use scipy.optimize.minimize
                # except that this requires a newer version of
                # scipy than is packaged for ubuntu right now.
                # fmin_bfgs seems to have problems sometimes
                # either hanging or maxiter=10K is too big.
                """
                xopt = scipy.optimize.fmin_bfgs(opt_dep, X0,
                        gtol=1e-8, maxiter=10000)
                """
            else:
                xopt = np.array([])
            info_value = -opt_dep(xopt)
            row.append(info_value)
        arr.append(row)
    arr.sort()
    npoints = len(arr)
    # create the R table string and scripts
    # get the R table
    table_string = RUtil.get_table_string(arr, headers)
    # get the R script
    script = get_ggplot()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter(
            table_string, script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
Esempio n. 3
0
def get_response_content(fs):
    M = get_input_matrix(fs)
    nstates = len(M)
    nsites = fs.nsites
    if nstates**nsites > 16:
        raise ValueError('the site dependent rate matrix is too big')
    # precompute some stuff
    M_site_indep = get_site_independent_process(M, nsites)
    v = mrate.R_to_distn(M)
    v_site_indep = get_site_independent_distn(v, nsites)
    if fs.info_fis:
        f_info = divtime.get_fisher_info_known_distn_fast
    elif fs.info_mut:
        f_info = ctmcmi.get_mutual_info_known_distn
    else:
        raise ValueError('no info type specified')
    f_selection = mrate.to_gtr_hb_known_energies
    # Spend a lot of time doing the optimizations
    # to construct the points for the R table.
    arr = []
    for t in cbreaker.throttled(progrid.gen_binary(fs.start_time,
                                                   fs.stop_time),
                                nseconds=4,
                                ncount=100):
        row = [t]
        # get the site-dependent mutation selection balance information
        if fs.dep_balance:
            dep_balance = OptDep(M_site_indep, v_site_indep, t, f_info,
                                 f_selection)
            X0 = np.random.randn(nstates**nsites - 1)
            xopt = scipy.optimize.fmin(dep_balance, X0)
            max_dep_balance_info = -dep_balance(xopt)
            row.append(max_dep_balance_info)
            # for debug
            Q_bal, v_bal = dep_balance.get_process(xopt)
            print 'dependent balance:'
            print max_dep_balance_info
            print v_bal
            print Q_bal
            print
        # get the site-independent mutation selection balance information
        if fs.indep_balance:
            indep_balance = OptIndep(M, v, nsites, t, f_info, f_selection)
            X0 = np.random.randn(nstates - 1)
            xopt = scipy.optimize.fmin(indep_balance, X0)
            max_indep_balance_info = -indep_balance(xopt)
            row.append(max_indep_balance_info)
            # for debug
            Q_bal, v_bal = indep_balance.get_process(xopt)
            print 'independent balance:'
            print max_indep_balance_info
            print v_bal
            print Q_bal
            print
        # get the site-independent mutation process information
        if fs.indep_mutation:
            indep_mut_info = f_info(M_site_indep, v_site_indep, t)
            row.append(indep_mut_info)
        # add the data row to the table
        arr.append(row)
    arr.sort()
    npoints = len(arr)
    # create the R table string and scripts
    headers = ['t']
    if fs.dep_balance:
        headers.append('max.site.dep.balance')
    if fs.indep_balance:
        headers.append('max.site.indep.balance')
    if fs.indep_mutation:
        headers.append('site.indep.mutation')
    # get the R table
    table_string = RUtil.get_table_string(arr, headers)
    # get the R script
    script = get_ggplot()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter(
        table_string, script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data
Esempio n. 4
0
 def test_binary(self):
     observed = list(cbreaker.throttled(gen_binary(0, 1), ncount=9))
     expected = [0.0, 1.0, 0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875]
     self.assertEqual(observed, expected)
Esempio n. 5
0
def get_response_content(fs):
    M = get_input_matrix(fs)
    nstates = len(M)
    nsites = fs.nsites
    if nstates ** nsites > 16:
        raise ValueError('the site dependent rate matrix is too big')
    # precompute some stuff
    M_site_indep = get_site_independent_process(M, nsites)
    v = mrate.R_to_distn(M)
    v_site_indep = get_site_independent_distn(v, nsites)
    if fs.info_fis:
        f_info = divtime.get_fisher_info_known_distn_fast
    elif fs.info_mut:
        f_info = ctmcmi.get_mutual_info_known_distn
    else:
        raise ValueError('no info type specified')
    f_selection = mrate.to_gtr_hb_known_energies
    # Spend a lot of time doing the optimizations
    # to construct the points for the R table.
    arr = []
    for t in cbreaker.throttled(
            progrid.gen_binary(fs.start_time, fs.stop_time),
            nseconds=4, ncount=100):
        row = [t]
        # get the site-dependent mutation selection balance information
        if fs.dep_balance:
            dep_balance = OptDep(
                    M_site_indep, v_site_indep, t, f_info, f_selection)
            X0 = np.random.randn(nstates ** nsites - 1)
            xopt = scipy.optimize.fmin(dep_balance, X0)
            max_dep_balance_info = -dep_balance(xopt)
            row.append(max_dep_balance_info)
            # for debug
            Q_bal, v_bal = dep_balance.get_process(xopt)
            print 'dependent balance:'
            print max_dep_balance_info
            print v_bal
            print Q_bal
            print
        # get the site-independent mutation selection balance information
        if fs.indep_balance:
            indep_balance = OptIndep(
                    M, v, nsites, t, f_info, f_selection)
            X0 = np.random.randn(nstates-1)
            xopt = scipy.optimize.fmin(indep_balance, X0)
            max_indep_balance_info = -indep_balance(xopt)
            row.append(max_indep_balance_info)
            # for debug
            Q_bal, v_bal = indep_balance.get_process(xopt)
            print 'independent balance:'
            print max_indep_balance_info
            print v_bal
            print Q_bal
            print
        # get the site-independent mutation process information
        if fs.indep_mutation:
            indep_mut_info = f_info(M_site_indep, v_site_indep, t)
            row.append(indep_mut_info)
        # add the data row to the table
        arr.append(row)
    arr.sort()
    npoints = len(arr)
    # create the R table string and scripts
    headers = ['t']
    if fs.dep_balance:
        headers.append('max.site.dep.balance')
    if fs.indep_balance:
        headers.append('max.site.indep.balance')
    if fs.indep_mutation:
        headers.append('site.indep.mutation')
    # get the R table
    table_string = RUtil.get_table_string(arr, headers)
    # get the R script
    script = get_ggplot()
    # create the R plot image
    device_name = Form.g_imageformat_to_r_function[fs.imageformat]
    retcode, r_out, r_err, image_data = RUtil.run_plotter(
            table_string, script, device_name)
    if retcode:
        raise RUtil.RError(r_err)
    return image_data