def pareto_surface_from_kde_sampling():
    from scipy.stats import uniform, gaussian_kde

    n_design_variables = 1
    n_obj_functions = 2
    N_iterations = 10
    N_samples_per_iteration = 10000

    column_names = ['id'] \
            + ['x{}'.format(i+1) for i in range(n_design_variables)] \
            + ['f{}'.format(i+1) for i in range(n_obj_functions)]

    data = []
    df = None
    for i_iteration in range(N_iterations):
        if i_iteration == 0:
            x_sampler = [uniform(-5,10) for i in range(n_design_variables)]
            for i in range(N_samples_per_iteration):
                x = [u.rvs() for u in x_sampler]
                f1,f2 = schaffer(x)
                row = [i] + x + [f1,f2]
                data.append([i] + x + [f1,f2])
                df = pd.DataFrame(data, columns=column_names)

        else:
            pareto_rows = pareto.pareto(df[['f1','f2']].values.tolist())
            print("i={},n_pareto={}".format(i_iteration,len(pareto_rows)))
            print(df.loc[pareto_rows,['x1','x2','x3']].T)
            kde = gaussian_kde(df.loc[pareto_rows,['x1','x2','x3']].T)
            data = []
            for i in range(N_samples_per_iteration):
                x = kde.resample(1)

                f1,f2 = schaffer([x[i] for i in range(3)])
                row = [i] + x + [f1,f2]
                data.append([i] + [x[i][0] for i in range(3)] + [f1,f2])
            df = pd.DataFrame(data, columns=column_names)
    return df
Beispiel #2
0
    def filter_by_pareto_membership(self,df=None,v=None):
        """ filter by pareto membership

        Calculation of pareto membership by removal of dominated points

        Args:
            df(pandas.DataFrame): the dataframe of results.  By default this is set to None,
                which uses the results_df property from a PyposmatDataFile which was
                read into this instance.

        Returns:
            (tuple): the results of the pareto membership consisting of a :obj:`'list`  of integers 
            which hare the indices of the of the surviving candidate parameterizations, and an
            :obj:`OrderedDict` containing the information for Pareto membership

        """

        assert df is None or isintance(df,pd.DataFrame)

        if df is None:
            df = self.results_df
    
        for qn in self.qoi_names:
            df['{}.abserr'.format(qn)] = df['{}.err'.format(qn)].abs()
      
        abs_error_names = ['{}.abserr'.format(v) for v in self.qoi_names]
        is_survive_idx = pareto(df[abs_error_names].values.tolist())
        
        n_potentials_start, n_cols = df.shape
        n_potentials_final = len(is_survive_idx)
        pct_potentials_final = n_potentials_final/n_potentials_start
        pareto_set_info = OrderedDict()
        pareto_set_info['n_potentials_start'] = n_potentials_start
        pareto_set_info['n_potentials_final'] = n_potentials_final
        pareto_set_info['pct_potentials_final'] = pct_potentials_final

        return set(is_survive_idx), pareto_set_info
Beispiel #3
0
    datafile.read(filename=_data_fn)

    from pypospack.pareto import pareto

    df = copy.deepcopy(datafile.df)
    nr,nc = df.shape
    _nsimulations = OrderedDict()
    _nsimulations['start'] = nr
    abs_error_names = ["{}.abserr".format(q) for q in datafile.qoi_names]
    for q in datafile.qoi_names:
        qe = "{}.err".format(q)
        qne = "{}.abserr".format(q)
        df[qne] = df[qe].abs()
    names = list(df.columns.values)
    abs_err_idx = [names.index(n) for n in abs_error_names]
    pareto_idx = pareto(df[abs_error_names].values.tolist())
    datafile.df = df.loc[pareto_idx,datafile.names]
    datafile.write("results.pareto.out")

    #pareto_idx = pareto_bruteforce(df[abs_error_names].values.tolist())

    #print(pareto_set)
    if make_rugplots:
        datafile = PyposmatDataFile()
        datafile.read("results.pareto.out")
        datafile.qoi_references = OrderedDict()
        datafile.qoi_references['TARGET'] = copy.deepcopy(qoi_targets)
        datafile.score_by_d_metric(scaling_factors='TARGET')
        datafile.subselect_by_score(
                score_name='d_metric',
                n=_n_potentials)
            data = []
            for i in range(N_samples_per_iteration):
                x = kde.resample(1)

                f1,f2 = schaffer([x[i] for i in range(3)])
                row = [i] + x + [f1,f2]
                data.append([i] + [x[i][0] for i in range(3)] + [f1,f2])
            df = pd.DataFrame(data, columns=column_names)
    return df

if True:
    plt.close("all")
    fig, ax = plt.subplots(1,1)
    n_simulations = 0
    cg_df = pareto_surface_from_conjugate_gradient_method()
    cg_pareto_rows = pareto.pareto(cg_df[['f1','f2']].values.tolist())
    cg_pareto_df = cg_df.loc[cg_pareto_rows]
    cg_pareto_df = cg_pareto_df.sort_values('f1')
    ax.scatter(
        cg_df['f1'],
        cg_df['f2'],
        c='black',marker=".",s=1,
    )
    ax.plot(
        cg_pareto_df['f1'],
        cg_pareto_df['f2'],
        c='red',linewidth=1,marker=".",ms=5
    )
    #ax.set_xlim(-20,0)
    #ax.set_ylim(-12.5,7.5)
    ax.set_xlabel(r"$f_1(x)$")
Beispiel #5
0
from pypospack.pareto import pareto
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from pareto_visualization import make_pareto_plot_3d
if __name__ == "__main__":
    x = np.random.normal(0,1,1000)
    y = np.random.normal(0,1,1000)
    z = np.random.normal(0,1,1000)
    df = pd.DataFrame()
    df['x'] = x
    df['y'] = y
    df['z'] = z

    pareto_idx = pareto(df.values.tolist())

    make_pareto_plot_3d(df,pareto_idx)