コード例 #1
0
    def __init__(self, fun,
                 constr=None,
                 bounds=None,
                 eta=1e-3,
                 eps=1e-4,
                 max_iter=200):

        COptimizer.__init__(self, fun=fun,
                            constr=constr, bounds=bounds)

        # Read/write attributes
        self.eta = eta  # gradient step size
        self.max_iter = max_iter  # maximum number of iterations
        self.eps = eps  # tolerance value for stop criterion
コード例 #2
0
    def _init_solver(self):
        """Create solver instance."""
        if self._solver_clf is None or self.distance is None \
                or self.discrete is None:
            raise ValueError('Solver not set properly!')

        # map attributes to fun, constr, box
        fun = CFunction(fun=self._objective_function,
                        gradient=self._objective_function_gradient,
                        n_dim=self.n_dim)

        constr = CConstraint.create(self._distance)
        constr.center = self._x0
        constr.radius = self.dmax

        # only feature increments or decrements are allowed
        lb = self._x0.todense() if self.lb == 'x0' else self.lb
        ub = self._x0.todense() if self.ub == 'x0' else self.ub

        bounds = CConstraint.create('box', lb=lb, ub=ub)

        self._solver = COptimizer.create(self._solver_type,
                                         fun=fun,
                                         constr=constr,
                                         bounds=bounds,
                                         discrete=self._discrete,
                                         **self._solver_params)

        # TODO: fix this verbose level propagation
        self._solver.verbose = self.verbose
    def _init_solver(self):
        """Create solver instance."""

        if self._solver_clf is None or self.discrete is None:
            raise ValueError('Solver not set properly!')

        # map attributes to fun, constr, box
        fun = CFunction(fun=self._objective_function,
                        gradient=self._objective_function_gradient,
                        n_dim=self._classifier.n_features)

        bounds, constr = self._constraint_creation()

        # FIXME: many solvers do now work in discrete spaces.
        #  this is a workaround to raise a proper error, but we should better
        #  handle these problems
        solver_params = self.solver_params
        if self.discrete is True:
            solver_params['discrete'] = True

        self._solver = COptimizer.create(
            self._solver_type,
            fun=fun, constr=constr,
            bounds=bounds,
            **self.solver_params)

        self._solver.verbose = 0
        self._warm_start = None
コード例 #4
0
ファイル: c_optimizer_pgd_ls.py プロジェクト: pralab/secml
    def __init__(self,
                 fun,
                 constr=None,
                 bounds=None,
                 eta=1e-3,
                 eta_min=None,
                 eta_max=None,
                 max_iter=1000,
                 eps=1e-4):

        COptimizer.__init__(self, fun=fun, constr=constr, bounds=bounds)

        # Read/write attributes
        self.eta = eta
        self.eta_min = eta_min
        self.eta_max = eta_max
        self.max_iter = max_iter
        self.eps = eps

        # Internal attributes
        self._line_search = None
        self._dtype = None
コード例 #5
0
	def _init_internal_solver(self, x0: CArray):
		fun = CFunction(
			fun=self._objective_function,
			gradient=self._objective_function_gradient,
			n_dim=self.n_dim,
		)
		constraint = CConstraint.create("l1")
		constraint.center = x0
		constraint.radius = 0
		lb = x0.todense() if self.lb == "x0" else self.lb
		ub = x0.todense() if self.ub == "x0" else self.ub
		bounds = CConstraint.create("box", lb=lb, ub=ub)
		self._solver = COptimizer.create(
			"pgd-ls", fun=fun, constr=constraint, bounds=bounds, discrete=True
		)
コード例 #6
0
    def _init_solver(self):
        """Create solver instance."""

        if self.classifier is None:
            raise ValueError('Solver not set properly!')

        # map attributes to fun, constr, box
        fun = CFunction(fun=self.objective_function,
                        gradient=self.objective_function_gradient,
                        n_dim=self._classifier.n_features)

        bounds, constr = self._constraint_creation()

        self._solver = COptimizer.create(
            self._solver_type,
            fun=fun, constr=constr,
            bounds=bounds,
            **self.solver_params)

        self._solver.verbose = 0
        self._warm_start = None