예제 #1
0
def generate_tree_vs_bassic(tree_file, bassic_file, output_name=None):
    results_tree = parse_file(tree_file)
    results_bassic = parse_file(bassic_file)

    x_values = results_tree['x'] #it has 5, bassic only 4
    times_tree = results_tree['y1']
    times_bassic = results_bassic['y1']
    distances_tree = results_tree['y2']
    distances_bassic = results_bassic['y2']

    axis_x, axis_y1, axis_y2 = create_axis_group(
        "Algorithm's depth (n)", 
        "Tolerance (%1)", BLUES[0], 
        "Time (s)", GREENS[0]  )

    trace_accurance_bassic = create_scatter(
        x=x_values,
        y=distances_bassic,
        mode='markers+lines',
        name='bassic tolerance',
        color=BLUES[0]
    )

    trace_time_bassic = create_scatter(
        x=x_values,
        y=times_bassic,
        mode='markers+lines',
        name='bassic time',
        color=GREENS[0],
        yaxis='y2'
    )
    trace_accurance_tree = create_scatter(
        x=x_values,
        y=distances_tree,
        mode='markers+lines',
        name='tree tolerance',
        color=BLUES[5],
        symbol='square'
    )

    trace_time_tree = create_scatter(
        x=x_values,
        y=times_tree,
        mode='markers+lines',
        name='tree time',
        color=GREENS[5],
        yaxis='y2',
        symbol='square'
    )
    layout = create_layout(title=go.layout.Title(
        text="Results kd-tree finder vs bassic (largest group)",
        xref='paper',
        y=0
    ), xaxis=axis_x, 
                yaxis=axis_y1, yaxis2=axis_y2, legend={'x': 1.1,'xanchor': 'left', 'y': 1 })
    traces = [trace_accurance_bassic, trace_time_bassic, trace_accurance_tree, trace_time_tree]

    finish(tree_file, output_name, traces, layout)
예제 #2
0
def generate_n_from_error(errors_dict, errors_dict2={}):

    # n = ln( ln(eph * 32 )/ln(0.14 * 32 ) / 0.405
    x_values, y_values = get_values(errors_dict)
    x_values_2, y_values_2 = get_values(errors_dict2)

    axis_x, axis_y1, _ = create_axis_group(
        "Error reached (%1)",
        "Algorithm's depth (n)",
        x_args={'type': 'log'},
        y1_color=BLUES[2],
        y1_args={'rangemode': 'nonnegative'})

    trace = dots_trace(x_values,
                       y_values,
                       name="n level large group",
                       color=BLUES[2])
    trace_2 = dots_trace(x_values_2,
                         y_values_2,
                         name="n level other groups",
                         color=GREENS[2])
    x_lin = np.linspace(5e-8, 0.05, 500)

    trace_real = create_scatter(
        x=x_lin,
        y=np.ceil(np.log(np.log(x_lin * 32) / np.log(0.014 * 32)) / 0.405),
        color=REDS[2],
        yaxis='y1',
        mode="lines",
        name="theorical n(error) 0.014")
    trace_real2 = create_scatter(
        x=x_lin,
        y=np.ceil(np.log(np.log(x_lin * 32) / np.log(0.009 * 32)) / 0.405),
        color=REDS[6],
        yaxis='y1',
        mode="lines",
        name="theorical n(error) 0.009")
    layout = create_layout("Error reached for depth levels",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           width=1000,
                           legend={
                               'x': 1.1,
                               'xanchor': 'left',
                               'y': 1
                           })

    output_name = "n_from_error"
    finish("", output_name, [trace, trace_2, trace_real, trace_real2], layout)
예제 #3
0
def generate_time_from_error(errors, times, errors_2, times_2):
    # n = ln( ln(eph * 32 )/ln(0.14 * 32 ) / 0.405
    y_values, x_values = times, errors
    y_values_2, x_values_2 = times_2, errors_2

    axis_x, axis_y1, _ = create_axis_group("Error reached (%1)",
                                           "Time required (s)",
                                           x_args={'type': 'log'},
                                           y1_color=BLUES[2],
                                           y1_args={
                                               'type': 'log',
                                               'rangemode': 'nonnegative'
                                           })

    trace = dots_trace(x_values,
                       y_values,
                       name="error large group",
                       color=BLUES[2])
    trace_2 = dots_trace(x_values_2,
                         y_values_2,
                         name="error other groups",
                         color=GREENS[2])
    x_lin = np.linspace(1e-7, 1, 100)

    trace_real = create_scatter(x=x_lin,
                                y=np.log(1 / x_lin)**2.71,
                                color=REDS[2],
                                yaxis='y1',
                                mode="lines",
                                name="theorical time(error)")
    trace_real2 = create_scatter(x=x_lin,
                                 y=0.003 * np.log(1 / x_lin)**2.71,
                                 color=REDS[6],
                                 yaxis='y1',
                                 mode="lines",
                                 name="theorical time(error) x0.003")
    layout = create_layout("Time required for reached errors",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           width=1000,
                           legend={
                               'x': 1.1,
                               'xanchor': 'left',
                               'y': 1
                           })

    output_name = "time_required_give_error"
    finish("", output_name, [trace, trace_2, trace_real, trace_real2], layout)
예제 #4
0
 def _complete_stuff(results,
                     traces,
                     sk_type,
                     color_scale,
                     symbol,
                     text=False,
                     pos=None):
     densities, times, distances = results
     studing_densities = densities if pos == None else densities[pos:pos +
                                                                 1]
     for jj, density in enumerate(studing_densities):
         index = jj if pos == None else p
         x_values = [t[index] for ene, t in times.iteritems()]
         y_values = [err[index] for ene, err in distances.iteritems()]
         traces.append(
             create_scatter(
                 x=x_values,
                 y=y_values,
                 name="%s d=%d" % (sk_type, density),
                 mode="lines+markers+text",
                 text=['n=%s' % (nn + 1)
                       for nn in range(len(x_values))] if text else [],
                 textposition='top center',
                 textfont=dict(color=color_scale[index]),
                 color=color_scale[index],
                 symbol=symbol))
예제 #5
0
def generate_error_from_n(errors_dict, errors_dict2={}):
    # n = ln( ln(eph * 32 )/ln(0.14 * 32 ) / 0.405
    y_values, x_values = get_values(errors_dict)
    y_values_2, x_values_2 = get_values(errors_dict2)

    axis_x, axis_y1, _ = create_axis_group("Algorithm's depth (n)",
                                           "Error reached (%1)",
                                           y1_args={'type': 'log'},
                                           y1_color=BLUES[2],
                                           x_args={'rangemode': 'nonnegative'})

    trace = dots_trace(x_values,
                       y_values,
                       name="error large group",
                       color=BLUES[2])
    trace_2 = dots_trace(x_values_2,
                         y_values_2,
                         name="error other groups",
                         color=GREENS[2])
    x_lin = np.linspace(1, 6, 100)
    import pdb
    pdb.set_trace()
    trace_real = create_scatter(x=x_lin,
                                y=0.0325 *
                                np.power(0.014 * 32, np.power(1.5, x_lin)),
                                color=REDS[2],
                                yaxis='y1',
                                mode="lines",
                                name="theorical error(n) 0.014")
    trace_real2 = create_scatter(x=x_lin,
                                 y=0.0325 * (0.009 * 32)**((1.5)**x_lin),
                                 color=REDS[6],
                                 yaxis='y1',
                                 mode="lines",
                                 name="theorical error(n) 0.009")
    layout = create_layout("Level of recursion required for given errors",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           width=1000,
                           legend={
                               'x': 1.1,
                               'xanchor': 'left',
                               'y': 1
                           })

    output_name = "error_from_n"
    finish("", output_name, [trace, trace_2, trace_real, trace_real2], layout)
예제 #6
0
def dots_trace(x_values, y_values, name, color):
    return create_scatter(
        x=x_values,
        y=y_values,
        name=name,
        mode="markers",
        #text=['n=%s'%(nn+1) for nn in range(len(x_values))],
        color=color,
        yaxis='y1')
def generate_distances_and_times(filesnames, output_name=None):
    x_values, times, distances = parse_several(filesnames)
    traces_times = []
    traces_distances = []
    axis_x, axis_y1, axis_y2 = create_axis_group(
        "Group density (#items)",
        y1_color=BLUES[2],
        y1_title="Error for each density (%1)",
        y2_color=GREENS[2],
        y2_title="Time for each density (s)",
        y1_args={'type': 'log'},
        y2_args={'type': 'log'})
    ns = times.keys()
    for nn in ns:
        traces_times.append(
            create_scatter(x=x_values,
                           y=times[nn],
                           mode='markers+lines+text',
                           name="time for n=%s" % nn,
                           symbol='square',
                           text=[''] * 3 + ['n=%s' % nn],
                           textposition='top center',
                           color=GREENS[int(nn) - 1],
                           yaxis='y2'))
        traces_distances.append(
            create_scatter(x=x_values,
                           y=distances[nn],
                           mode='markers+lines+text',
                           name="distance for n=%s" % nn,
                           text=['n=%s' % nn],
                           textposition='top center',
                           color=BLUES[int(nn) - 1]))
    layout = create_layout("Distace and time increasing group density",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           yaxis2=axis_y2,
                           width=1000,
                           legend={
                               'x': 1.1,
                               'xanchor': 'left',
                               'y': 1
                           })
    _finish('distance_and_time', output_name, traces_times + traces_distances,
            layout)
예제 #8
0
def get_rate_trace(x_values, y_values, color=REDS[0], width=4):

    trace = create_scatter(x=x_values,
                           y=y_values,
                           mode='markers+lines',
                           color=color,
                           name='theoretical',
                           line=dict(color=color, width=width))

    return trace
예제 #9
0
def _random_vs_shorter_stuff(directory, output_name, yaxis_title, key_results, legend_text, plot_title, color1, color2):
    random_files = search_files(directory, "*finder-random-kdtree*.csv")
    shorter_files = search_files(directory, "*finder-kdtree*.csv")
    results = several_random_shorter_parse(random_files, shorter_files)
    x_values = results['x']
    axis_x, axis_y1, _ = create_axis_group(
        "Group density (#items)", 
        yaxis_title, y1_args={'type': 'log'})

    traces_shorter = []
    traces_random = []
    for nn, values in results[key_results + '_random'].items():
        traces_random.append(
            create_scatter(
                x=x_values,
                y=values,
                mode='markers+lines',
                name='random %s n=%s'%(legend_text, nn),
                color=color1[int(nn)-1],
                symbol='square'
            )
        )
    for nn, values in results[key_results + '_shorter'].items():
        traces_shorter.append(
            create_scatter(
                x=x_values,
                y=values,
                text=['n=%s'%nn],
                textposition='top center',
                mode='text+markers+lines',
                name='shorter %s n=%s'%(legend_text, nn),
                color=color2[int(nn)-1],
                symbol='circle'
            )
        )
    layout = create_layout(plot_title, 
                            xaxis=axis_x, yaxis=axis_y1, width=1000,
                            legend={'x': 1.1,'xanchor': 'left', 'y': 1 }
                            )
    traces = traces_random + traces_shorter

    finish(directory, output_name, traces, layout)
def generate_time_vs_error(directory, output_name=None):

    filesnames = search_files(directory, "*results*.csv")
    all_results = parse_several_error_time(filesnames)
    #random_results = all_results['random'] #[n_items] , {N: [times]}, {N: [distances]}
    #bassic_results = all_results['bassic']
    tree_results = all_results['tree']
    axis_x, axis_y1, _ = create_axis_group("Time (s)",
                                           "Error (%1)",
                                           y1_args={'type': 'log'},
                                           x_args={
                                               'type':
                                               'log',
                                               'range':
                                               [np.log10(0.02),
                                                np.log10(150)]
                                           })

    densities = tree_results[0]
    times = tree_results[1]
    distances = tree_results[2]

    traces_tree = []
    for index in range(len(densities)):
        density = densities[index]
        x_values = [tim[index] for ene, tim in times.iteritems()]
        y_values = [err[index] for ene, err in distances.iteritems()]
        traces_tree.append(
            create_scatter(
                x=x_values,
                y=y_values,
                name="tree d=%d" % (density),
                mode="lines+markers+text",
                text=['n=%s' % (nn + 1) for nn in range(len(x_values))],
                textposition='top center',
                textfont=dict(color=GREENS[index]),
                color=GREENS[index],
                symbol='star',
                yaxis='y1'))
    traces = traces_tree
    layout = create_layout(
        "Compare error and time for tree searcher as n increases for several densities",
        xaxis=axis_x,
        yaxis=axis_y1,
        width=1000,
        legend={
            'x': 1.1,
            'xanchor': 'left',
            'y': 1
        })
    #traces = traces_random + traces_bassic + traces_tree

    output_name = "new_only_tree"
    finish(directory, output_name, traces, layout)
예제 #11
0
def generate_basic_example(filepath,
                           output_name=None,
                           rate=False,
                           exp_time=None,
                           exp_acc=None):
    results_data = parse_file(filepath)
    x_values = results_data['x']
    times = results_data['y1']
    distances = results_data['y2']

    axis_x, axis_y1, axis_y2 = create_axis_group(
        "Algorithm's depth (n)",
        "Tolerance (%1)",
        BLUES[0],
        "Time (s)",
        GREENS[0],
        x_args=dict(domain=[0, 0.8]) if rate else {},
        y2_args={'anchor': 'x'})

    trace_accurance = create_scatter(x=x_values,
                                     y=distances,
                                     mode='markers+lines',
                                     name='tolerance',
                                     color=BLUES[0])

    trace_time = create_scatter(x=x_values,
                                y=times,
                                mode='markers+lines',
                                name='time',
                                color=GREENS[0],
                                yaxis='y2')
    traces = [trace_accurance, trace_time]
    y3axis = {}
    if rate:
        y3axis['yaxis3'] = create_axis("Rate (s^-1)",
                                       side='right',
                                       overlaying='y',
                                       zeroline=False,
                                       color=REDS[0],
                                       anchor='free',
                                       position=0.9)
        traces.append(get_rate_trace(x_values, times, distances))
    if exp_time:
        trace_e = create_scatter(yaxis='y2', **exp_time)
        traces.append(trace_e)
    if exp_acc:
        trace_e = create_scatter(yaxis='y1', **exp_acc)
        traces.append(trace_e)

    layout = create_layout("Results bassic finder for largest group",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           yaxis2=axis_y2,
                           legend={
                               'x': 1,
                               'xanchor': 'left',
                               'y': 1
                           },
                           **y3axis)

    finish(filepath, output_name, traces, layout)
예제 #12
0
    ]
    teo_y = [3**l for l in x_values]
    x = np.linspace(1, 16, num=20)
    f = create_pow_function(x, 1, 3)

    axis_x, axis_y1, _ = create_axis_group("Operator max lenght",
                                           "Group size (#items)",
                                           y1_args={'type': 'log'},
                                           x_args=dict(range=[0, 17],
                                                       dtick=1,
                                                       tickangle=0))

    trace_teo = get_rate_trace(x_values, teo_y)
    trace_emp = create_scatter(x=x_values,
                               y=emp_y,
                               mode='markers+lines',
                               name='empirical',
                               color=GREENS[0])

    traces = [trace_teo, trace_emp]
    layout = create_layout("Theorical and empirical group size",
                           xaxis=axis_x,
                           yaxis=axis_y1,
                           legend={
                               'x': 1,
                               'xanchor': 'left',
                               'y': 1
                           })

    finish('filepath', 'group_len', traces, layout)