<jupyter_start><jupyter_text>.. _nb_initialization:  Biased Initialization One way of customizing an algorithm is a biased initial population. This can be very helpful if expert knowledge already exists, and known solutions should be improved. In the following, two different ways of initialization are provided: **a)** just providing the design space of the variables and **b)** a `Population` object where the objectives and constraints are provided and are not needed to be calculated again.**NOTE:** This works with all **population-based** algorithms in *pymoo*. Technically speaking, all algorithms which inherit from `GeneticAlgorithm`. For **local-search** based algorithm, the initial solution can be provided by setting `x0` instead of `sampling`.  By Array<jupyter_code>import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.optimize import minimize

problem = get_problem("zdt2")

X = np.random.random((300, problem.n_var))

algorithm = NSGA2(pop_size=100, sampling=X)

minimize(problem,
         algorithm,
         ('n_gen', 10),
         seed=1,
         verbose=True)<jupyter_output>Compiled modules for significant speedup can not be used!
https://pymoo.org/installation.html#installation

To disable this warning:
from pymoo.config import Config
Config.show_compile_hint = False

============================================================
n_gen |  n_eval |     igd      |      gd      |      hv     
============================================================
    1 |     300 |  3.563283924 |  3.698538861 |  0.00000E+00
    2 |     400 |  3.355133731 |  3.673914262 |  0.00000E+00
    3 |     500 |  3.235952433 |  3.485391101 |  0.00000E+00<jupyter_text>By Population (pre-evaluated)<jupyter_code>import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.core.evaluator import Evaluator
from pymoo.core.population import Population
from pymoo.optimize import minimize

problem = get_problem("zdt2")

# create initial data and set to the population object
X = np.random.random((300, problem.n_var))
pop = Population.new("X", X)
Evaluator().eval(problem, pop)

algorithm = NSGA2(pop_size=100, sampling=pop)

minimize(problem,
         algorithm,
         ('n_gen', 10),
         seed=1,
         verbose=True)<jupyter_output>============================================================
n_gen |  n_eval |     igd      |      gd      |      hv     
============================================================
    1 |       0 |  3.297458740 |  3.780797098 |  0.00000E+00
    2 |     100 |  3.290866878 |  3.540237590 |  0.00000E+00
    3 |     200 |  3.248240096 |  3.696915511 |  0.00000E+00
    4 |     300 |  3.096284128 |  3.386724120 |  0.00000E+00
    5 |     400 |  2.862701469 |  3.169902469 |  0.00000E+00
    6 |     500 |  2.602238712 |  2.909145341 |  0.00000E+00
{'fraction_non_alphanumeric': 0.1691302853214163, 'fraction_numerical': 0.1075971124097628, 'mean_word_length': 3.619047619047619, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '22590', 'license': 'Apache-2.0', 'n_tokens_mistral': 1101, 'n_tokens_neox': 900, 'n_words': 260, 'path': 'source/customization/initialization.ipynb', 'repo_name': 'zhaofeng-shu33/pymoo-doc', 'size': '2909'}