示例#1
0
def get_table_string_and_scripts_from_logs(start_stop_pairs, log_paths,
                                           nsamples):
    """
    This is for analysis of remote execution.
    """
    # build the array for the R table
    data_arr = []
    sequence_lengths = []
    midpoints = []
    for start_stop_pair, log_path in zip(start_stop_pairs, log_paths):
        start_pos, stop_pos = start_stop_pair
        sequence_length = stop_pos - start_pos + 1
        means, variations, covs = read_log(log_path, nsamples)
        midpoint = (start_pos + stop_pos) / 2.0
        row = [sequence_length, midpoint]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
        sequence_lengths.append(sequence_length)
        midpoints.append(midpoint)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    scripts = get_ggplot2_scripts(nsamples, sequence_lengths, midpoints)
    # return the table string and scripts
    return table_string, scripts
示例#2
0
def get_table_string_and_scripts(start_stop_pairs, nsamples):
    """
    Command-line only.
    """
    # build the array for the R table
    data_arr = []
    sequence_lengths = []
    midpoints = []
    for start_pos, stop_pos in start_stop_pairs:
        sequence_length = stop_pos - start_pos + 1
        means, variations, covs = get_value_lists(start_pos, stop_pos,
                                                  nsamples)
        midpoint = (start_pos + stop_pos) / 2.0
        row = [sequence_length, midpoint]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
        sequence_lengths.append(sequence_length)
        midpoints.append(midpoint)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    scripts = get_ggplot2_scripts(nsamples, sequence_lengths, midpoints)
    # return the table string and scripts
    return table_string, scripts
示例#3
0
def get_table_string_and_scripts(stop_positions, nsamples):
    """
    Command-line only.
    """
    start_position = 1
    # build the array for the R table
    data_arr = []
    for stop_position in stop_positions:
        sequence_length = stop_position - start_position + 1
        means, variations, covs = get_value_lists(start_position,
                                                  stop_position, nsamples)
        row = [sequence_length]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    sequence_lengths = [x - start_position + 1 for x in stop_positions]
    scripts = get_ggplot2_scripts(sequence_lengths)
    # return the table string and scripts
    return table_string, scripts
示例#4
0
def get_table_string_and_scripts(stop_positions, nsamples):
    """
    Command-line only.
    """
    start_position = 1
    # build the array for the R table
    data_arr = []
    for stop_position in stop_positions:
        sequence_length = stop_position - start_position + 1
        means, variations, covs = get_value_lists(
                start_position, stop_position, nsamples)
        row = [sequence_length]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    sequence_lengths = [x - start_position + 1 for x in stop_positions]
    scripts = get_ggplot2_scripts(sequence_lengths)
    # return the table string and scripts
    return table_string, scripts
示例#5
0
def get_table_string_and_scripts_from_logs(
        start_stop_pairs, log_paths, nsamples):
    """
    This is for analysis of remote execution.
    """
    # build the array for the R table
    data_arr = []
    sequence_lengths = []
    midpoints = []
    for start_stop_pair, log_path in zip(
            start_stop_pairs, log_paths):
        start_pos, stop_pos = start_stop_pair
        sequence_length = stop_pos - start_pos + 1
        means, variations, covs = read_log(log_path, nsamples)
        midpoint = (start_pos + stop_pos) / 2.0
        row = [sequence_length, midpoint]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
        sequence_lengths.append(sequence_length)
        midpoints.append(midpoint)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    scripts = get_ggplot2_scripts(nsamples, sequence_lengths, midpoints)
    # return the table string and scripts
    return table_string, scripts
示例#6
0
def get_table_string_and_scripts(start_stop_pairs, nsamples):
    """
    Command-line only.
    """
    # build the array for the R table
    data_arr = []
    sequence_lengths = []
    midpoints = []
    for start_pos, stop_pos in start_stop_pairs:
        sequence_length = stop_pos - start_pos + 1
        means, variations, covs = get_value_lists(
                start_pos, stop_pos, nsamples)
        midpoint = (start_pos + stop_pos) / 2.0
        row = [sequence_length, midpoint]
        for values in means, variations, covs:
            corr_info = mcmc.Correlation()
            corr_info.analyze(values)
            hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
            row.extend([hpd_low, corr_info.mean, hpd_high])
        data_arr.append(row)
        sequence_lengths.append(sequence_length)
        midpoints.append(midpoint)
    # build the table string
    table_string = RUtil.get_table_string(data_arr, g_headers)
    # get the scripts
    scripts = get_ggplot2_scripts(nsamples, sequence_lengths, midpoints)
    # return the table string and scripts
    return table_string, scripts
示例#7
0
def get_html(values_name_pairs):
    """
    Web based only.
    """
    out = StringIO()
    #
    #print >> out, 'statistic:', name
    #print >> out, 'mean:', corr_info.mean
    #print >> out, 'standard error of mean:', corr_info.stdErrorOfMean
    #print >> out, 'auto correlation time (ACT):', corr_info.ACT
    #print >> out, 'standard deviation of ACT:', corr_info.stdErrOfACT
    #print >> out, 'effective sample size (ESS):', corr_info.ESS
    #print >> out, 'posterior density interval (0.95): [%f, %f]' % hpd
    #print >> out
    print >> out, '<html>'
    # write the html head
    print >> out, '<head>'
    print >> out, '<script'
    print >> out, '  type="text/javascript"'
    print >> out, '  src="https://www.google.com/jsapi">'
    print >> out, '</script>'
    print >> out, '<script type="text/javascript">'
    print >> out, "  google.load('visualization', '1', {packages:['table']});"
    print >> out, "  google.setOnLoadCallback(drawTable);"
    print >> out, "  function drawTable() {"
    print >> out, "    var data = new google.visualization.DataTable();"
    # add columns
    print >> out, "    data.addColumn('string', 'description');"
    print >> out, "    data.addColumn('number', '95% HPD low');"
    print >> out, "    data.addColumn('number', 'mean');"
    print >> out, "    data.addColumn('number', '95% HPD high');"
    print >> out, "    data.addColumn('number', 'ACT');"
    print >> out, "    data.addColumn('number', 'ESS');"
    # add rows
    print >> out, "    data.addRows(3);"
    # add entries
    for i, (values, name) in enumerate(values_name_pairs):
        corr_info = mcmc.Correlation()
        corr_info.analyze(values)
        hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
        print >> out, "    data.setCell(%d, 0, '%s');" % (i, name)
        print >> out, "    data.setCell(%d, 1, %f);" % (i, hpd_low)
        print >> out, "    data.setCell(%d, 2, %f);" % (i, corr_info.mean)
        print >> out, "    data.setCell(%d, 3, %f);" % (i, hpd_high)
        print >> out, "    data.setCell(%d, 4, %f);" % (i, corr_info.ACT)
        print >> out, "    data.setCell(%d, 5, %f);" % (i, corr_info.ESS)
    print >> out, "    var table = new google.visualization.Table("
    print >> out, "      document.getElementById('table_div'));"
    print >> out, "    table.draw(data, {showRowNumber: false});"
    print >> out, "  }"
    print >> out, "</script>"
    print >> out, '</head>'
    # write the html body
    print >> out, '<body><div id="table_div"></div></body>'
    # end the html
    print >> out, '</html>'
    # return the html string
    return out.getvalue().rstrip()
示例#8
0
def get_html(values_name_pairs):
    """
    Web based only.
    """
    out = StringIO()
    #
    #print >> out, 'statistic:', name
    #print >> out, 'mean:', corr_info.mean
    #print >> out, 'standard error of mean:', corr_info.stdErrorOfMean
    #print >> out, 'auto correlation time (ACT):', corr_info.ACT
    #print >> out, 'standard deviation of ACT:', corr_info.stdErrOfACT
    #print >> out, 'effective sample size (ESS):', corr_info.ESS
    #print >> out, 'posterior density interval (0.95): [%f, %f]' % hpd
    #print >> out
    print >> out, '<html>'
    # write the html head
    print >> out, '<head>'
    print >> out, '<script'
    print >> out, '  type="text/javascript"'
    print >> out, '  src="https://www.google.com/jsapi">'
    print >> out, '</script>'
    print >> out, '<script type="text/javascript">'
    print >> out, "  google.load('visualization', '1', {packages:['table']});"
    print >> out, "  google.setOnLoadCallback(drawTable);"
    print >> out, "  function drawTable() {"
    print >> out, "    var data = new google.visualization.DataTable();"
    # add columns
    print >> out, "    data.addColumn('string', 'description');"
    print >> out, "    data.addColumn('number', '95% HPD low');"
    print >> out, "    data.addColumn('number', 'mean');"
    print >> out, "    data.addColumn('number', '95% HPD high');"
    print >> out, "    data.addColumn('number', 'ACT');"
    print >> out, "    data.addColumn('number', 'ESS');"
    # add rows
    print >> out, "    data.addRows(3);"
    # add entries
    for i, (values, name) in enumerate(values_name_pairs):
        corr_info = mcmc.Correlation()
        corr_info.analyze(values)
        hpd_low, hpd_high = mcmc.get_hpd_interval(0.95, values)
        print >> out, "    data.setCell(%d, 0, '%s');" % (i, name)
        print >> out, "    data.setCell(%d, 1, %f);" % (i, hpd_low)
        print >> out, "    data.setCell(%d, 2, %f);" % (i, corr_info.mean)
        print >> out, "    data.setCell(%d, 3, %f);" % (i, hpd_high)
        print >> out, "    data.setCell(%d, 4, %f);" % (i, corr_info.ACT)
        print >> out, "    data.setCell(%d, 5, %f);" % (i, corr_info.ESS)
    print >> out, "    var table = new google.visualization.Table("
    print >> out, "      document.getElementById('table_div'));"
    print >> out, "    table.draw(data, {showRowNumber: false});"
    print >> out, "  }"
    print >> out, "</script>"
    print >> out, '</head>'
    # write the html body
    print >> out, '<body><div id="table_div"></div></body>'
    # end the html
    print >> out, '</html>'
    # return the html string
    return out.getvalue().rstrip()
示例#9
0
def forked_function(start_stop_n):
    """
    This function should accept and return as little data as possible.
    In particular do not return a huge multimegabyte nested list.
    @param start_stop_n: start_pos, stop_pos, nsamples
    @return: (corr_info, hpd_interval) for mean, variation, covariance
    """
    start_pos, stop_pos, nsamples = start_stop_n
    means, variations, covs = get_value_lists(start_pos, stop_pos, nsamples)
    post_pairs = []
    for values in means, variations, covs:
        corr_info = mcmc.Correlation()
        corr_info.analyze(values)
        hpd_interval = mcmc.get_hpd_interval(0.95, values)
        post_pairs.append((corr_info, hpd_interval))
    return post_pairs
示例#10
0
def forked_function(start_stop_n):
    """
    This function should accept and return as little data as possible.
    In particular do not return a huge multimegabyte nested list.
    @param start_stop_n: start_pos, stop_pos, nsamples
    @return: (corr_info, hpd_interval) for mean, variation, covariance
    """
    start_pos, stop_pos, nsamples = start_stop_n
    means, variations, covs = get_value_lists(start_pos, stop_pos, nsamples)
    post_pairs = []
    for values in means, variations, covs:
        corr_info = mcmc.Correlation()
        corr_info.analyze(values)
        hpd_interval = mcmc.get_hpd_interval(0.95, values)
        post_pairs.append((corr_info, hpd_interval))
    return post_pairs