# Source code for cvxpy.atoms.eye_minus_inv

"""

you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
"""

from cvxpy.atoms.atom import Atom
import numpy as np

[docs]def resolvent(X, s):
r"""The resolvent of a positive matrix, :math:(sI - X)^{-1}.

For an elementwise positive matrix :math:X and a positive scalar
:math:s, this atom computes

.. math::

(sI - X)^{-1},

and it enforces the constraint that the spectral radius of :math:X/s
is at most :math:1.

This atom is log-log convex.

Parameters
----------
X : cvxpy.Expression
A positive square matrix.
s : cvxpy.Expression or numeric
A positive scalar.
"""
return 1.0 / s * eye_minus_inv(X / s)

[docs]class eye_minus_inv(Atom):
r"""The unity resolvent of a positive matrix, :math:(I - X)^{-1}.

For an elementwise positive matrix :math:X, this atom represents

.. math::

(I - X)^{-1},

and it enforces the constraint that the spectral radius of :math:X
is at most :math:1.

This atom is log-log convex.

Parameters
----------
X : cvxpy.Expression
A positive square matrix.
"""
def __init__(self, X):
super(eye_minus_inv, self).__init__(X)
if len(X.shape) != 2 or X.shape != X.shape:
raise ValueError("The argument to eye_minus_inv must be a "
self.args = X

def numeric(self, values):
return np.linalg.inv(np.eye(self.args.shape) - values)

def name(self):
return "%s(%s)" % (self.__class__.__name__, self.args)

def shape_from_args(self):
"""Returns the (row, col) shape of the expression.
"""
return self.args.shape

def sign_from_args(self):
"""Returns sign (is positive, is negative) of the expression.
"""
return (True, False)

def is_atom_convex(self):
"""Is the atom convex?
"""
return False

def is_atom_concave(self):
"""Is the atom concave?
"""
return False

def is_atom_log_log_convex(self):
"""Is the atom log-log convex?
"""
return True

def is_atom_log_log_concave(self):
"""Is the atom log-log concave?
"""
return False

# TODO(akshayka): Figure out monotonicity.
def is_incr(self, idx):
"""Is the composition non-decreasing in argument idx?
"""
return False

def is_decr(self, idx):
"""Is the composition non-increasing in argument idx?
"""
return False