How to use the gpkit.nomials.nomial_math.Signomial function in gpkit

To help you get started, we’ve selected a few gpkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
Arguments
        ---------
        substitutions : dict or key
            Either a dictionary whose keys are strings, Variables, or VarKeys,
            and whose values are numbers, or a string, Variable or Varkey.
        val : number (optional)
            If the substitutions entry is a single key, val holds the value
        require_positive : boolean (optional, default is True)
            Controls whether the returned value can be a Signomial.

        Returns
        -------
        Returns substituted nomial.
        """
        _, exps, cs, _ = substitution(self, substitutions)
        return Signomial(exps, cs, require_positive=require_positive)
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
if isinstance(self.cs, Quantity) or isinstance(other.cs, Quantity):
                if not isinstance(self.cs, Quantity):
                    sunits = ureg.dimensionless
                else:
                    sunits = Quantity(1, self.cs[0].units)
                if not isinstance(other.cs, Quantity):
                    ounits = ureg.dimensionless
                else:
                    ounits = Quantity(1, other.cs[0].units)
                # HACK: fix for pint not working with np.outer
                C = C * sunits * ounits
            Exps = np.empty((len(self.exps), len(other.exps)), dtype="object")
            for i, exp_s in enumerate(self.exps):
                for j, exp_o in enumerate(other.exps):
                    Exps[i, j] = exp_s + exp_o
            return Signomial(Exps.flatten(), C.flatten())
        elif isinstance(other, NomialArray):
            return np.array(self)*other
        else:
            return NotImplemented
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
def __init__(self, left, oper, right):
        super(ScalarSingleEquationConstraint,
              self).__init__(Signomial(left), oper, Signomial(right))
        self.varkeys = KeySet(self.left.varlocs)
        self.varkeys.update(self.right.varlocs)
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
def diff(self, wrt):
        """Derivative of this with respect to a Variable

        Arguments
        ---------
        wrt (Variable):
        Variable to take derivative with respect to

        Returns
        -------
        Signomial (or Posynomial or Monomial)
        """
        deriv = super(Signomial, self).diff(wrt)
        # pylint: disable=unexpected-keyword-arg
        return Signomial(deriv.exps, deriv.cs, require_positive=False)
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
def subinplace(self, substitutions):
        "Substitutes in place."
        _, exps, cs, _ = substitution(self, substitutions)
        super(Signomial, self).__init__(exps, cs)
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
def diff(self, wrt):
        """Derivative of this with respect to a Variable

        Arguments
        ---------
        wrt (Variable):
        Variable to take derivative with respect to

        Returns
        -------
        Signomial (or Posynomial or Monomial)
        """
        deriv = super(Signomial, self).diff(wrt)
        # pylint: disable=unexpected-keyword-arg
        return Signomial(deriv.exps, deriv.cs, require_positive=False)
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
def __sub__(self, other):
        from .. import SIGNOMIALS_ENABLED
        if SIGNOMIALS_ENABLED:
            return self + -other
        else:
            return NotImplemented

    def __rsub__(self, other):
        from .. import SIGNOMIALS_ENABLED
        if SIGNOMIALS_ENABLED:
            return other + -self
        else:
            return NotImplemented


class Posynomial(Signomial):
    """A Signomial with strictly positive cs

    Arguments
    ---------
    Same as Signomial.
    Note: Posynomial historically supported several different init formats
          These will be deprecated in the future, replaced with a single
          __init__ syntax, same as Signomial.
    """
    def __le__(self, other):
        if isinstance(other, Numbers + (Monomial,)):
            return PosynomialInequality(self, "<=", other)
        else:
            # fall back on other's __ge__
            return NotImplemented
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
return NotImplemented

    def __neg__(self):
        from .. import SIGNOMIALS_ENABLED
        return -1*self if SIGNOMIALS_ENABLED else NotImplemented

    def __sub__(self, other):
        from .. import SIGNOMIALS_ENABLED
        return self + -other if SIGNOMIALS_ENABLED else NotImplemented

    def __rsub__(self, other):
        from .. import SIGNOMIALS_ENABLED
        return other + -self if SIGNOMIALS_ENABLED else NotImplemented


class Posynomial(Signomial):
    """A Signomial with strictly positive cs

    Arguments
    ---------
    Same as Signomial.
    Note: Posynomial historically supported several different init formats
          These will be deprecated in the future, replaced with a single
          __init__ syntax, same as Signomial.
    """
    def __le__(self, other):
        if isinstance(other, Numbers + (Monomial,)):
            return PosynomialInequality(self, "<=", other)
        # fall back on other's __ge__
        return NotImplemented

    # Posynomial.__ge__ falls back on Signomial.__ge__
github convexengineering / gpkit / gpkit / nomials / nomial_math.py View on Github external
Arguments
        ---------
        substitutions : dict or key
            Either a dictionary whose keys are strings, Variables, or VarKeys,
            and whose values are numbers, or a string, Variable or Varkey.
        val : number (optional)
            If the substitutions entry is a single key, val holds the value
        require_positive : boolean (optional, default is True)
            Controls whether the returned value can be a Signomial.

        Returns
        -------
        Returns substituted nomial.
        """
        _, exps, cs, _ = substitution(self, substitutions)
        return Signomial(exps, cs, require_positive=require_positive)