Create population from sampling. Args: problem: Optimization problem. sampling: Sampling strategy or population. n_initial_samples: Number of initial samples. pop: Initial population. Returns: Population.
(
problem: Any,
sampling: Any,
n_initial_samples: int,
pop: Optional[Population] = None,
)
| 560 | |
| 561 | |
| 562 | def pop_from_sampling( |
| 563 | problem: Any, |
| 564 | sampling: Any, |
| 565 | n_initial_samples: int, |
| 566 | pop: Optional[Population] = None, |
| 567 | ) -> Optional[Population]: |
| 568 | """Create population from sampling. |
| 569 | |
| 570 | Args: |
| 571 | problem: Optimization problem. |
| 572 | sampling: Sampling strategy or population. |
| 573 | n_initial_samples: Number of initial samples. |
| 574 | pop: Initial population. |
| 575 | |
| 576 | Returns: |
| 577 | Population. |
| 578 | """ |
| 579 | if pop is None: |
| 580 | pop = Population() |
| 581 | |
| 582 | if isinstance(sampling, Population): |
| 583 | pop = sampling |
| 584 | |
| 585 | else: |
| 586 | if isinstance(sampling, np.ndarray): |
| 587 | pop = pop.new("X", sampling) |
| 588 | |
| 589 | elif isinstance(sampling, Sampling): |
| 590 | pop = sampling.do(problem, n_initial_samples, pop=pop) |
| 591 | |
| 592 | else: |
| 593 | return None |
| 594 | |
| 595 | return pop |
| 596 | |
| 597 | |
| 598 | def evaluate_if_not_done_yet( |
nothing calls this directly
no test coverage detected
searching dependent graphs…