diff options
author | Nao Pross <np@0hm.ch> | 2024-05-05 17:47:42 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-05-05 18:05:01 +0200 |
commit | 623b44d55cf62818de7dd2448cc828d3f1b9d5e2 (patch) | |
tree | 88063bd138b1d4b65cd2f7c3e32b0e7f321feae2 | |
parent | Add __str__ to OptVariable (diff) | |
download | sumofsquares-623b44d55cf62818de7dd2448cc828d3f1b9d5e2.tar.gz sumofsquares-623b44d55cf62818de7dd2448cc828d3f1b9d5e2.zip |
Delete SOSExpr and SOSExprBase
Made obsolete by introducing OptVariable
23 files changed, 1 insertions, 691 deletions
diff --git a/sumofsquares/__init__.py b/sumofsquares/__init__.py index 0bc6e7d..da35128 100644 --- a/sumofsquares/__init__.py +++ b/sumofsquares/__init__.py @@ -1,5 +1 @@ -from sumofsquares.sosexpr.abc import ParamSOSExpr, SOSExpr -from sumofsquares.sosexpr.init import init_sos_expr, init_param_expr, init_param_expr_from_reference, init_putinar_epsilon -from sumofsquares.cvxopt import solve_cone, solve_cone2, solve_sos_problem, solve_sos_problem2 - -from sumofsquares.optvariable import from_names +from sumofsquares.optvariable import from_names
\ No newline at end of file diff --git a/sumofsquares/cvxopt.py b/sumofsquares/cvxopt.py index ec31892..d656d83 100644 --- a/sumofsquares/cvxopt.py +++ b/sumofsquares/cvxopt.py @@ -4,9 +4,6 @@ import polymatrix import numpy as np import math -from sumofsquares.sosexpr.abc import ParamSOSExpr, SOSExpr - - @dataclasses.dataclass class CVXOptConeQPResult: x: np.ndarray diff --git a/sumofsquares/sosexpr/__init__.py b/sumofsquares/sosexpr/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/sumofsquares/sosexpr/__init__.py +++ /dev/null diff --git a/sumofsquares/sosexpr/abc.py b/sumofsquares/sosexpr/abc.py deleted file mode 100644 index 389956f..0000000 --- a/sumofsquares/sosexpr/abc.py +++ /dev/null @@ -1,12 +0,0 @@ -import abc - -from sumofsquares.sosexpr.mixins.parametermixin import ParamSOSExprMixin -from sumofsquares.sosexpr.mixins.sosexpropmixin import SOSExprOPMixin - - -class SOSExpr(SOSExprOPMixin, abc.ABC): - pass - - -class ParamSOSExpr(SOSExprOPMixin, ParamSOSExprMixin, abc.ABC): - pass diff --git a/sumofsquares/sosexpr/impl.py b/sumofsquares/sosexpr/impl.py deleted file mode 100644 index 4453588..0000000 --- a/sumofsquares/sosexpr/impl.py +++ /dev/null @@ -1,37 +0,0 @@ -import dataclassabc - -from sumofsquares.sosexprbase.abc import ParamSOSExprBase, SOSExprBase -from sumofsquares.sosexpr.mixins.putinarepsilonmixin import PutinarEpsilonMixin -from sumofsquares.sosexpr.abc import ParamSOSExpr, SOSExpr - - -@dataclassabc.dataclassabc(frozen=True) -class SOSExprImpl(SOSExpr): - underlying: SOSExprBase - - -@dataclassabc.dataclassabc(frozen=True) -class ParamSOSExprImpl(ParamSOSExpr): - underlying: ParamSOSExprBase - - def __eq__(self, other): - if isinstance(other, ParamSOSExprImpl): - return self.underlying == other.underlying - - elif isinstance(other, ParamSOSExprBase): - return self.underlying == other - - else: - return False - - def __hash__(self): - return hash(self.underlying) - - -@dataclassabc.dataclassabc(frozen=True) -class PutinarEpsilonImpl(PutinarEpsilonMixin): - name: str - epsilon: ParamSOSExpr - gamma: dict[str, ParamSOSExpr] - sos_constraints: tuple[SOSExpr] - condition: SOSExpr diff --git a/sumofsquares/sosexpr/init.py b/sumofsquares/sosexpr/init.py deleted file mode 100644 index c94df85..0000000 --- a/sumofsquares/sosexpr/init.py +++ /dev/null @@ -1,148 +0,0 @@ -import polymatrix - -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin -from sumofsquares.sosexprbase.init import init_param_sos_expr_base, init_sos_expr_base -from sumofsquares.sosexpr.mixins.sosexprmixin import SOSExprMixin -from sumofsquares.sosexpr.abc import SOSExpr -from sumofsquares.sosexpr.impl import ParamSOSExprImpl, SOSExprImpl, PutinarEpsilonImpl - - -def init_sos_expr( - expr: polymatrix.Expression, - variables: polymatrix.Expression, - dependence: tuple[ParameterMixin], -): - return SOSExprImpl( - underlying=init_sos_expr_base( - expr=expr, - variables=variables, - dependence=dependence, - ), - ) - - -def init_param_expr( - name: str, - variables: polymatrix.Expression, - monom: polymatrix.Expression | None = None, - n_row: int | None = None, - n_col: int | None = None, -): - return ParamSOSExprImpl( - underlying=init_param_sos_expr_base( - name=name, - monom=monom, - variables=variables, - n_row=n_row, - n_col=n_col, - ), - ) - - -def init_param_expr_from_reference( - name: str, - reference: SOSExpr, - # variables: polymatrix.Expression, - multiplicand: SOSExpr | polymatrix.Expression | None = None, -): - variables = reference.variables - - if multiplicand is None: - multiplicand_expr = polymatrix.from_(1) - - elif isinstance(multiplicand, polymatrix.Expression): - multiplicand_expr = multiplicand - - elif isinstance(multiplicand, SOSExprMixin): - assert multiplicand.variables == variables, f'{multiplicand.variables=}, {variables=}' - - multiplicand_expr = multiplicand.expr - - else: - multiplicand_expr = polymatrix.from_(multiplicand) - - m_sos_monom = multiplicand_expr.quadratic_monomials(variables) - - max_degree = m_sos_monom.degree().T.max() - - m_max_monom = m_sos_monom.filter( - m_sos_monom.degree() - max_degree, - inverse=True, - ) - - sos_monom = reference.expr.quadratic_monomials(variables).subtract_monomials(m_max_monom) - - expr = (sos_monom @ sos_monom.T).reshape(1, -1).sum() - - monom = expr.linear_monomials(variables).cache() - - return init_param_expr( - name=name, - monom=monom, - variables=variables, - ) - - -def init_putinar_epsilon( - name: str, - f0: SOSExpr, - fi: dict[str, SOSExpr | polymatrix.Expression] | None = None, - gi: dict[str, SOSExpr | polymatrix.Expression] | None = None, - epsilon_min: SOSExpr | None = None, - decrease_rate: SOSExpr | polymatrix.Expression | None = None, -): - sos_constraints = tuple() - - condition = f0 - - def gen_gamma(fi): - for key, val in fi.items(): - yield key, init_param_expr_from_reference( - name=f'gamma_{key}_{name}', - reference=f0, - multiplicand=val, - ) - - if fi is None: - gamma_fi = {} - - else: - gamma_fi = dict(gen_gamma(fi)) - - for key, gamma_i in gamma_fi.items(): - sos_constraints += (gamma_i,) - condition = condition - gamma_i * fi[key] - - if gi is None: - gamma_gi = {} - - else: - gamma_gi = dict(gen_gamma(gi)) - - for key, gamma_i in gamma_gi.items(): - condition = condition - gamma_i * gi[key] - - if epsilon_min is None: - epsilon = None - - else: - epsilon = init_param_expr( - name=f'epsilon_{name}', - variables=f0.variables, - ) - - sos_constraints += (epsilon - epsilon_min,) - condition += epsilon - - if decrease_rate is not None: - condition -= decrease_rate - - sos_constraints += (condition,) - - return PutinarEpsilonImpl( - name=name, - epsilon=epsilon, - gamma=gamma_fi | gamma_gi, - sos_constraints=sos_constraints, - condition=condition, - ) diff --git a/sumofsquares/sosexpr/mixins/__init__.py b/sumofsquares/sosexpr/mixins/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/sumofsquares/sosexpr/mixins/__init__.py +++ /dev/null diff --git a/sumofsquares/sosexpr/mixins/getsosconstraintmixin.py b/sumofsquares/sosexpr/mixins/getsosconstraintmixin.py deleted file mode 100644 index f3a0710..0000000 --- a/sumofsquares/sosexpr/mixins/getsosconstraintmixin.py +++ /dev/null @@ -1,10 +0,0 @@ -import abc - -from sumofsquares.sosexpr.abc import SOSExpr - - -class GetSOSConstraintMixin(abc.ABC): - @property - @abc.abstractmethod - def sos_constraints(self) -> tuple[SOSExpr]: - ... diff --git a/sumofsquares/sosexpr/mixins/parametermixin.py b/sumofsquares/sosexpr/mixins/parametermixin.py deleted file mode 100644 index 5f8dd5f..0000000 --- a/sumofsquares/sosexpr/mixins/parametermixin.py +++ /dev/null @@ -1,25 +0,0 @@ -import abc -import polymatrix - -from sumofsquares.sosexpr.mixins.sosexprmixin import SOSExprMixin -from sumofsquares.sosexprbase.abc import ParamSOSExprBase -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - - -class ParamSOSExprMixin(ParameterMixin, SOSExprMixin): - @property - @abc.abstractmethod - def underlying(self) -> ParamSOSExprBase: - ... - - @property - def name(self) -> polymatrix.Expression: - return self.underlying.name - - @property - def param(self) -> polymatrix.Expression: - return self.underlying.param - - @property - def monom(self) -> polymatrix.Expression: - return self.underlying.monom diff --git a/sumofsquares/sosexpr/mixins/putinarepsilonmixin.py b/sumofsquares/sosexpr/mixins/putinarepsilonmixin.py deleted file mode 100644 index fdf6e9a..0000000 --- a/sumofsquares/sosexpr/mixins/putinarepsilonmixin.py +++ /dev/null @@ -1,26 +0,0 @@ -import abc - -from sumofsquares.sosexpr.abc import ParamSOSExpr, SOSExpr -from sumofsquares.sosexpr.mixins.getsosconstraintmixin import GetSOSConstraintMixin - - -class PutinarEpsilonMixin(GetSOSConstraintMixin, abc.ABC): - @property - @abc.abstractmethod - def name(self) -> str: - ... - - @property - @abc.abstractmethod - def epsilon(self) -> ParamSOSExpr: - ... - - @property - @abc.abstractmethod - def gamma(self) -> dict[str, ParamSOSExpr]: - ... - - @property - @abc.abstractmethod - def condition(self) -> SOSExpr: - ... diff --git a/sumofsquares/sosexpr/mixins/sosexprmixin.py b/sumofsquares/sosexpr/mixins/sosexprmixin.py deleted file mode 100644 index 2e7eaa6..0000000 --- a/sumofsquares/sosexpr/mixins/sosexprmixin.py +++ /dev/null @@ -1,31 +0,0 @@ -import abc -import polymatrix - -from sumofsquares.sosexprbase.abc import SOSExprBase - - -class SOSExprMixin(abc.ABC): - @property - @abc.abstractmethod - def underlying(self) -> SOSExprBase: - ... - - @property - def expr(self) -> polymatrix.Expression: - return self.underlying.expr - - @property - def variables(self) -> polymatrix.Expression: - return self.underlying.variables - - @property - def dependence(self) -> polymatrix.Expression: - return self.underlying.dependence - - @property - def sos_matrix(self) -> polymatrix.Expression: - return self.underlying.sos_matrix - - @property - def sos_matrix_vec(self) -> polymatrix.Expression: - return self.underlying.sos_matrix_vec diff --git a/sumofsquares/sosexpr/mixins/sosexpropmixin.py b/sumofsquares/sosexpr/mixins/sosexpropmixin.py deleted file mode 100644 index 5d6e7d7..0000000 --- a/sumofsquares/sosexpr/mixins/sosexpropmixin.py +++ /dev/null @@ -1,186 +0,0 @@ -import dataclasses -import typing - -from numpy import isin - -import polymatrix -import polymatrix.expression.from_ - -from sumofsquares.sosexpr.mixins.sosexprmixin import SOSExprMixin -from sumofsquares.sosexprbase.init import init_sos_expr_base - - -class SOSExprOPMixin(SOSExprMixin): - @staticmethod - def _binary( - op, - left: 'SOSExprOPMixin', - right: typing.Union[polymatrix.Expression, 'SOSExprOPMixin'], - ) -> 'SOSExprOPMixin': - - if not isinstance(left, SOSExprOPMixin): - if isinstance(left, tuple): - return NotImplemented - - left = polymatrix.expression.from_.from_expr_or_none(left) - - if left is None: - return NotImplemented - - underlying = init_sos_expr_base( - expr=op(polymatrix.from_(left), right.expr), - variables=right.variables, - dependence=right.dependence, - ) - - return dataclasses.replace( - right, - underlying=underlying, - ) - - if not isinstance(right, SOSExprOPMixin): - if isinstance(right, tuple): - return NotImplemented - - right = polymatrix.expression.from_.from_expr_or_none(right) - - if right is None: - return NotImplemented - - underlying = init_sos_expr_base( - expr=op(left.expr, polymatrix.from_(right)), - variables=left.variables, - dependence=left.dependence, - ) - - else: - # var_set_left = set(left.variables) - # var_set_right = set(right.variables) - # assert var_set_left.issubset(var_set_right) or var_set_right.issubset(var_set_left), f'{left.variables=}, {right.variables=}' - - assert left.variables == right.variables, f'{left.variables=}, {right.variables=}' - - underlying=init_sos_expr_base( - expr=op(left.expr, right.expr), - variables=left.variables, - dependence=tuple(set(left.dependence + right.dependence)), - ) - - return dataclasses.replace( - left, - underlying=underlying, - ) - - @staticmethod - def _unary(op, expr: 'SOSExprOPMixin') -> 'SOSExprOPMixin': - return dataclasses.replace( - expr, - underlying=init_sos_expr_base( - expr=op(expr.expr), - variables=expr.variables, - dependence=expr.dependence, - ), - ) - - def __add__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__add__, self, other) - - def __matmul__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__matmul__, self, other) - - def __mul__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__mul__, self, other) - - def __neg__(self) -> 'SOSExprOPMixin': - return self._unary(polymatrix.Expression.__neg__, self) - - def __radd__(self, other): - return self._binary(polymatrix.Expression.__add__, self, other) - - def __rmatmul__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__matmul__, other, self) - - def __rmul__(self, other): - return self._binary(polymatrix.Expression.__mul__, self, other) - - def __rsub__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__sub__, other, self) - - def __sub__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': - return self._binary(polymatrix.Expression.__sub__, self, other) - - def __getitem__(self, key: tuple[int, int]): - return dataclasses.replace( - self, - underlying=init_sos_expr_base( - expr=self.expr[key[0], key[1]], - variables=self.variables, - dependence=self.dependence, - ), - ) - - def cache(self) -> 'SOSExprOPMixin': - return self._unary(polymatrix.Expression.cache, self) - - def diff( - self, - variables: polymatrix.Expression | None = None, - ) -> 'SOSExprOPMixin': - if variables is None: - variables = self.variables - - return dataclasses.replace( - self, - underlying=init_sos_expr_base( - expr=self.expr.diff(variables), - variables=self.variables, - dependence=self.dependence, - ), - ) - - def divergence( - self, - variables: polymatrix.Expression | None = None, - ) -> 'SOSExprOPMixin': - if variables is None: - variables = self.variables - - return dataclasses.replace( - self, - underlying=init_sos_expr_base( - expr=self.expr.divergence(variables), - variables=self.variables, - dependence=self.dependence, - ), - ) - - @property - def T(self): - return self._unary(polymatrix.Expression.transpose, self) - - def substitute(self, substitutions, variables): - return dataclasses.replace( - self, - underlying=init_sos_expr_base( - expr=self.expr.substitute(substitutions), - # variables=self.variables.substitute(substitutions), - variables=variables, - dependence=self.dependence, - ), - ) - - def set_variables(self, variables): - return dataclasses.replace( - self, - underlying=init_sos_expr_base( - expr=self.expr, - variables=variables, - dependence=self.dependence, - ), - ) - - def v_stack(self, other): - def op(left, right): - return polymatrix.v_stack((left, right)) - - return self._binary(op, self, other) diff --git a/sumofsquares/sosexprbase/__init__.py b/sumofsquares/sosexprbase/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/sumofsquares/sosexprbase/__init__.py +++ /dev/null diff --git a/sumofsquares/sosexprbase/abc.py b/sumofsquares/sosexprbase/abc.py deleted file mode 100644 index e6b6d89..0000000 --- a/sumofsquares/sosexprbase/abc.py +++ /dev/null @@ -1,13 +0,0 @@ -import abc - -from sumofsquares.sosexprbase.mixins.selfdependencemixin import SelfDependenceMixin -from sumofsquares.sosexprbase.mixins.sosexprbasemixin import SOSExprBaseMixin -from sumofsquares.sosexprbase.mixins.exprfrommonommixin import ExprFromMonomMixin - - -class SOSExprBase(SOSExprBaseMixin, abc.ABC): - pass - - -class ParamSOSExprBase(SelfDependenceMixin, SOSExprBaseMixin, ExprFromMonomMixin, abc.ABC): - pass diff --git a/sumofsquares/sosexprbase/impl.py b/sumofsquares/sosexprbase/impl.py deleted file mode 100644 index 5a3a800..0000000 --- a/sumofsquares/sosexprbase/impl.py +++ /dev/null @@ -1,22 +0,0 @@ -import dataclassabc -import polymatrix - -from sumofsquares.sosexprbase.abc import ParamSOSExprBase, SOSExprBase -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - - -@dataclassabc.dataclassabc(frozen=True) -class SOSExprBaseImpl(SOSExprBase): - expr: polymatrix.Expression - variables: polymatrix.Expression - dependence: tuple[ParameterMixin] - - -@dataclassabc.dataclassabc(frozen=True) -class ParamSOSExprBaseImpl(ParamSOSExprBase): - name: str - param: polymatrix.Expression - monom: polymatrix.Expression - variables: polymatrix.Expression - param_matrix: polymatrix.Expression - n_row: int diff --git a/sumofsquares/sosexprbase/init.py b/sumofsquares/sosexprbase/init.py deleted file mode 100644 index f8f97fd..0000000 --- a/sumofsquares/sosexprbase/init.py +++ /dev/null @@ -1,64 +0,0 @@ -import polymatrix - -from sumofsquares.sosexprbase.impl import ParamSOSExprBaseImpl, SOSExprBaseImpl -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - - -def init_sos_expr_base( - expr: polymatrix.Expression, - variables: polymatrix.Expression, - dependence: tuple[ParameterMixin] | None = None, -): - - if not isinstance(expr, polymatrix.Expression): - expr = polymatrix.from_(expr) - - # if variables is None: - # variables = polymatrix.from_(1) - - if dependence is None: - dependence = tuple() - - return SOSExprBaseImpl( - expr=expr, - variables=variables, - dependence=dependence, - ) - - -def init_param_sos_expr_base( - name: str, - variables: polymatrix.Expression, - monom: polymatrix.Expression | None = None, - n_row: int | None = None, - n_col: int | None = None, -): - if monom is None: - monom = polymatrix.from_(1) - - if n_row == None: - n_row = 1 - - if n_col == None: - n_col = 1 - - if n_row == 1 and n_col == 1: - param = monom.parametrize(f'{name}') - param_matrix = param.T - - else: - param = monom.rep_mat(n_col * n_row, 1).parametrize(f'{name}') - param_matrix = param.reshape(monom, -1).T - - # params = tuple(monom.parametrize(f'{name}_{row+1}_{col+1}') for col in range(n_col) for row in range(n_row)) - # param = polymatrix.v_stack(params) - # param_matrix = polymatrix.v_stack(tuple(param.T for param in params)) - - return ParamSOSExprBaseImpl( - name=name, - param=param, - monom=monom, - variables=variables, - param_matrix=param_matrix, - n_row=n_row, - ) diff --git a/sumofsquares/sosexprbase/mixins/__init__.py b/sumofsquares/sosexprbase/mixins/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/sumofsquares/sosexprbase/mixins/__init__.py +++ /dev/null diff --git a/sumofsquares/sosexprbase/mixins/dependencemixin.py b/sumofsquares/sosexprbase/mixins/dependencemixin.py deleted file mode 100644 index fa60f19..0000000 --- a/sumofsquares/sosexprbase/mixins/dependencemixin.py +++ /dev/null @@ -1,10 +0,0 @@ -import abc - -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - -class DependenceMixin(abc.ABC): - @property - @abc.abstractmethod - def dependence(self) -> tuple[ParameterMixin]: - ... - diff --git a/sumofsquares/sosexprbase/mixins/exprbasemixin.py b/sumofsquares/sosexprbase/mixins/exprbasemixin.py deleted file mode 100644 index 9d1e30a..0000000 --- a/sumofsquares/sosexprbase/mixins/exprbasemixin.py +++ /dev/null @@ -1,16 +0,0 @@ -import abc -import polymatrix - -from sumofsquares.sosexprbase.mixins.dependencemixin import DependenceMixin - - -class ExprBaseMixin(DependenceMixin): - @property - @abc.abstractmethod - def expr(self) -> polymatrix.Expression: - ... - - @property - @abc.abstractmethod - def variables(self) -> polymatrix.Expression: - ... diff --git a/sumofsquares/sosexprbase/mixins/exprfrommonommixin.py b/sumofsquares/sosexprbase/mixins/exprfrommonommixin.py deleted file mode 100644 index 6e6e80b..0000000 --- a/sumofsquares/sosexprbase/mixins/exprfrommonommixin.py +++ /dev/null @@ -1,28 +0,0 @@ -import abc -import polymatrix - -from sumofsquares.sosexprbase.mixins.exprbasemixin import ExprBaseMixin -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - - -class ExprFromMonomMixin(ParameterMixin, ExprBaseMixin): - @property - @abc.abstractmethod - def param_matrix(self) -> polymatrix.Expression: - ... - - @property - @abc.abstractmethod - def n_row(self) -> int: - ... - - @property - def expr(self) -> polymatrix.Expression: - expr_vec = (self.param_matrix @ self.monom).cache() - - if self.n_row == 1: - return expr_vec - - else: - return expr_vec.reshape(self.n_row, -1) - diff --git a/sumofsquares/sosexprbase/mixins/parametermixin.py b/sumofsquares/sosexprbase/mixins/parametermixin.py deleted file mode 100644 index 61755a5..0000000 --- a/sumofsquares/sosexprbase/mixins/parametermixin.py +++ /dev/null @@ -1,23 +0,0 @@ -import abc -import polymatrix - - -class ParameterMixin(abc.ABC): - """ - - """ - - @property - @abc.abstractmethod - def name(self) -> str: - ... - - @property - @abc.abstractmethod - def param(self) -> polymatrix.Expression: - ... - - @property - @abc.abstractmethod - def monom(self) -> polymatrix.Expression: - ... diff --git a/sumofsquares/sosexprbase/mixins/selfdependencemixin.py b/sumofsquares/sosexprbase/mixins/selfdependencemixin.py deleted file mode 100644 index 8227e48..0000000 --- a/sumofsquares/sosexprbase/mixins/selfdependencemixin.py +++ /dev/null @@ -1,9 +0,0 @@ -import abc - -from sumofsquares.sosexprbase.mixins.dependencemixin import DependenceMixin -from sumofsquares.sosexprbase.mixins.parametermixin import ParameterMixin - -class SelfDependenceMixin(DependenceMixin): - @property - def dependence(self) -> set[ParameterMixin]: - return (self,) diff --git a/sumofsquares/sosexprbase/mixins/sosexprbasemixin.py b/sumofsquares/sosexprbase/mixins/sosexprbasemixin.py deleted file mode 100644 index e9eabac..0000000 --- a/sumofsquares/sosexprbase/mixins/sosexprbasemixin.py +++ /dev/null @@ -1,23 +0,0 @@ -import functools -import polymatrix - -from sumofsquares.sosexprbase.mixins.exprbasemixin import ExprBaseMixin - - -class SOSExprBaseMixin(ExprBaseMixin): - @functools.cached_property - def sos_monom(self) -> polymatrix.Expression: - return self.expr.quadratic_monomials(self.variables).cache() - - @functools.cached_property - def sos_matrix(self) -> polymatrix.Expression: - sos_matrix = self.expr.quadratic_in( - variables=self.variables, - monomials=self.sos_monom, - ).symmetric().cache() - - return sos_matrix - - @property - def sos_matrix_vec(self) -> polymatrix.Expression: - return self.sos_matrix.reshape(-1, 1) |