def optimize( self, black_box: BlackBox, initial_guess: Optional[numpy.ndarray] = None, initial_guess_array: Optional[numpy.ndarray] = None ) -> OptimizationResult: if initial_guess is None: # coverage: ignore initial_guess = numpy.zeros(black_box.dimension) opt = black_box.evaluate(initial_guess) return OptimizationResult(optimal_value=opt, optimal_parameters=initial_guess, num_evaluations=1, cost_spent=0.0, status=0, message='success')
def optimize(self, black_box: BlackBox, initial_guess: Optional[numpy.ndarray]=None, initial_guess_array: Optional[numpy.ndarray]=None ) -> OptimizationResult: opt = numpy.inf opt_params = None for _ in range(5): guess = numpy.random.randn(black_box.dimension) val = black_box.evaluate(guess) if val < opt: opt = val opt_params = guess return OptimizationResult( optimal_value=opt, optimal_parameters=cast(numpy.ndarray, opt_params), num_evaluations=1, cost_spent=0.0, status=0, message='success')
def test_black_box_is_abstract_cant_instantiate(): with pytest.raises(TypeError): _ = BlackBox()