<jupyter_start><jupyter_text>Calculate a Pareto optimal set [Pareto optimality](https://en.wikipedia.org/wiki/Pareto_efficiency) (or multi-objective optimization) allows one to search for optimal solutions for an optimization problem with multiple objectives. The Pareto class in the Orthogonal Array package allows one to calculate the Pareto optimal elements (called the Pareto frontier).<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

import oapackage<jupyter_output><empty_output><jupyter_text>First, define a dataset of 50 random vectors. The vectors have length 2, so there are 2 objectives to be optimized.<jupyter_code>datapoints=np.random.rand(2, 50)

for ii in range(0, datapoints.shape[1]):
    w=datapoints[:,ii]
    fac=.6+.4*np.linalg.norm(w)
    datapoints[:,ii]=(1/fac)*w

h=plt.plot(datapoints[0,:], datapoints[1,:], '.b', markersize=16, label='Non Pareto-optimal')
_=plt.title('The input data', fontsize=15)
plt.xlabel('Objective 1', fontsize=16)
plt.ylabel('Objective 2', fontsize=16)<jupyter_output><empty_output><jupyter_text>Create a structure (`ParetoDoubleLong`) to keep track of the data.<jupyter_code>pareto=oapackage.ParetoDoubleLong()

for ii in range(0, datapoints.shape[1]):
    w=oapackage.doubleVector( (datapoints[0,ii], datapoints[1,ii]))
    pareto.addvalue(w, ii)

pareto.show(verbose=1)<jupyter_output>Pareto: 12 optimal values, 12 objects<jupyter_text>Plot the results.<jupyter_code>lst=pareto.allindices() # the indices of the Pareto optimal designs

optimal_datapoints=datapoints[:,lst]

h=plt.plot(datapoints[0,:], datapoints[1,:], '.b', markersize=16, label='Non Pareto-optimal')
hp=plt.plot(optimal_datapoints[0,:], optimal_datapoints[1,:], '.r', markersize=16, label='Pareto optimal')
plt.xlabel('Objective 1', fontsize=16)
plt.ylabel('Objective 2', fontsize=16)
plt.xticks([])
plt.yticks([])
_=plt.legend(loc=3, numpoints=1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13739669421487602, 'fraction_numerical': 0.0253099173553719, 'mean_word_length': 7.458515283842795, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '521694', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 763, 'n_tokens_neox': 710, 'n_words': 157, 'path': 'docs/examples/example_pareto.ipynb', 'repo_name': 'ABohynDOE/oapackage', 'size': '1936'}