def get_number_of_components(filename, window_size, min_weight, influence_graph_grep='ig\:#', **kargs):
     pos_callback = lambda x: SwarmAnalyzer.get_number_of_components_of_graph(
         x, min_weight=min_weight * 2 * window_size, pre_callback=Callback.to_symmetric)
     all_graph_matrices, _ = SwarmParser.read_file_and_measures(
         filename, influence_graph_grep=influence_graph_grep, pos_callback=pos_callback,
         window_size=window_size, **kargs)
     return all_graph_matrices
 def create_influence_graph(filename, influence_graph_grep='ig\:#', window_size=1000, calculate_on=1000):
     pre_callback = Callback.to_symmetric
     graph, _ = SwarmParser.read_file_and_measures(
         filename, influence_graph_grep=influence_graph_grep, window_size=window_size, pre_callback=pre_callback,
         calculate_on=calculate_on)
     igraph_graph = InfluenceGraph.create_graph_from_matrix(graph[0][1])
     return igraph_graph
 def get_swarm_informations_from_file(filename,
                                      informations_grep,
                                      information_map=float,
                                      **kargs):
     _, informations = SwarmParser.read_files_and_measures(
         [('', filename)],
         informations_grep=informations_grep,
         information_map=information_map,
         **kargs)
     informations = informations[''][-1]  # there is no window here!
     # let's get the longest information sequence
     max_information_length = float("-inf")
     max_information_key = None
     for information_grep in informations:
         if len(informations[information_grep]) > max_information_length:
             max_information_length = len(informations[information_grep])
             max_information_key = information_grep
     iterations = [
         iteration for (iteration, _) in informations[max_information_key]
     ]
     iterations.sort()
     df = pd.DataFrame({'x': iterations})
     for information_grep in informations:
         dict_information = dict(informations[information_grep])
         df[information_grep] = [
             dict_information[i] if i in dict_information else float("nan")
             for i in iterations
         ]
     return df
 def get_graph_matrices_from_files(filenames,
                                   influence_graph_grep='ig\:#',
                                   **kargs):
     pos_callback = Callback.to_symmetric
     graph_matrices, _ = SwarmParser.read_files_and_measures(
         filenames,
         influence_graph_grep=influence_graph_grep,
         pos_callback=pos_callback,
         **kargs)
     return graph_matrices
Example #5
0
    def plot_boxplot_fitness(sets_of_filenames,
                             output_filename=None,
                             info_grep="it\:#",
                             yticks_args=None,
                             legends=None,
                             showmeans=False,
                             showfliers=True,
                             whis=1.,
                             widths=0.7,
                             bootstrap=2000,
                             jump_lines=None,
                             **kargs):
        """
        :param sets_of_filenames:
        :param output_filename:
        :param info_grep:
        :return:
        """
        get_infos = lambda x: [
            SwarmParser.read_file_and_measures(
                filename, informations_grep=info_grep, jump_lines=jump_lines)[
                    1][info_grep][-1][1] for filename in x
        ]
        values = map(get_infos, sets_of_filenames)

        boxes_kargs = {
            'color': 'black',
            'linewidth': 1.3,
            'zorder': 3,
            'fillstyle': 'full',
            'facecolor': '#a6bddb'
        }
        means_kargs = {
            'color': 'black',
            'fillstyle': 'full',
            'markerfacecolor': "black",
            'marker': "s",
            'markersize': 3,
            'mew': 1,
            'mec': 'black',
            'zorder': 5
        }
        fliers_kargs = {
            'color': 'black',
            'marker': "s",
            'markersize': 1,
            'mew': 1.2,
            'mec': 'black'
        }
        whiskers_kargs = {
            'color': 'black',
            'linewidth': 1.2,
            'zorder': 2,
            'linestyle': '-',
            'alpha': 1.0,
            'mec': 'black'
        }
        medians_kargs = {
            'color': 'black',
            'linewidth': 1.6,
            'zorder': 5,
            'alpha': 0.3
        }
        caps_kargs = {'linewidth': 1.5, 'color': 'black'}
        xticks_args = None
        if legends is not None:
            xticks_args = (range(1, len(legends) + 1), legends)
        Plotter.plot_boxplots(values,
                              grid_only='y',
                              xlim=(0.3, len(sets_of_filenames) + 0.6),
                              yticks_args=yticks_args,
                              whis=whis,
                              xticks_args=xticks_args,
                              grid=False,
                              widths=widths,
                              bootstrap=bootstrap,
                              boxes_kargs=boxes_kargs,
                              showmeans=showmeans,
                              showfliers=showfliers,
                              fliers_kargs=fliers_kargs,
                              means_kargs=means_kargs,
                              whiskers_kargs=whiskers_kargs,
                              medians_kargs=medians_kargs,
                              caps_kargs=caps_kargs,
                              output=output_filename,
                              **kargs)