Return the amplitude damping Kraus operators
169894
def relaxation_operators(p):
    
    k0 = np.array([[1.0, 0.0], [0.0, np.sqrt(1 - p)]])
    k1 = np.array([[0.0, np.sqrt(p)], [0.0, 0.0]])
    return k0, k1
814569
def adjoint(self):
        """"""
        op = self

        class ShearlabOperatorAdjoint(odl.Operator):

            """Adjoint of the shearlet transform.

            See Also
            --------
            odl.contrib.shearlab.ShearlabOperator
            """

            def __init__(self):
                """Initialize a new instance."""
                self.mutex = op.mutex
                self.shearlet_system = op.shearlet_system
                super(ShearlabOperatorAdjoint, self).__init__(
                    op.range, op.domain, True)

            def _call(self, x):
                """``self(x)``."""
                with op.mutex:
                    x = np.moveaxis(x, 0, -1)
                    return sheardecadjoint2D(x, op.shearlet_system)

            @property
            def adjoint(self):
                """"""
                return op

            @property
            def inverse(self):
                """The inverse operator."""
                op = self

                class ShearlabOperatorAdjointInverse(odl.Operator):

                    """
                    Adjoint of the inverse/Inverse of the adjoint
                    of shearlet transform.

                    See Also
                    --------
                    odl.contrib.shearlab.ShearlabOperator
                    """

                    def __init__(self):
                        """Initialize a new instance."""
                        self.mutex = op.mutex
                        self.shearlet_system = op.shearlet_system
                        super(ShearlabOperatorAdjointInverse, self).__init__(
                            op.range, op.domain, True)

                    def _call(self, x):
                        """``self(x)``."""
                        with op.mutex:
                            result = shearrecadjoint2D(x, op.shearlet_system)
                            return np.moveaxis(result, -1, 0)

                    @property
                    def adjoint(self):
                        """"""
                        return op.adjoint.inverse

                    @property
                    def inverse(self):
                        """The inverse operator."""
                        return op

                return ShearlabOperatorAdjointInverse()

        return ShearlabOperatorAdjoint()
413121
def operator(self):
        
        # is projection the zero operator?
        if self.V.shape[1] == 0:
            N = self.V.shape[0]
            return ZeroLinearOperator((N, N))
        return self._get_operator(self.apply, self.apply_adj)
463897
def gradF_t(X, Y, S, M_E, E, m0, rho):
    ''' 
    '''
    n, r = X.shape
    m, r = Y.shape

    XS = np.dot(X, S)
    YS = np.dot(Y, S.T)
    XSY = np.dot(XS, Y.T)

    Qx = np.dot(np.dot(X.T, ((M_E - XSY) * E)), YS) / n
    Qy = np.dot(np.dot(Y.T, ((M_E - XSY) * E).T), XS) / m

    W = np.dot((XSY - M_E) * E, YS) + np.dot(X, Qx) + rho * Gp(X, m0, r)
    Z = np.dot(((XSY - M_E) * E).T, XS) + np.dot(Y, Qy) + rho * Gp(Y, m0, r)

    return W, Z
65548
def gaussian(freq, freq0, sigma, amp, offset, drift):
    
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        return (amp * np.exp(- ((freq - freq0)**2) / (sigma**2) ) +
                drift * freq + offset)
959415
def eigen_capture(klazz, m_sym, flag, &blk)
      v_klazz = (class << klazz; self; end)
      instance_capture(v_klazz, m_sym, flag, &blk)
    end
820220
def calculate_linear_regressor_output_shapes(operator):
    '''
    
    '''
    check_input_and_output_numbers(operator, input_count_range=1, output_count_range=1)

    N = operator.inputs[0].type.shape[0]
    op = operator.raw_operator
    if hasattr(op, 'n_outputs_'):
        nout = op.n_outputs_
    else:
        nout = 1
    operator.outputs[0].type = FloatTensorType([N, nout])
67152
def to_kraus(self):
        
        return [k.data.toarray() for k in qt.to_kraus(self.sop)]
949926
def adjoint(self):
        """"""
        if not self.is_linear:
            raise ValueError('operator with nonzero pad_const ({}) is not'
                             ' linear and has no adjoint'
                             ''.format(self.pad_const))

        return -PartialDerivative(self.range, self.axis, self.domain,
                                  _ADJ_METHOD[self.method],
                                  _ADJ_PADDING[self.pad_mode],
                                  self.pad_const)
909980
def inverse_lin_decay(max_step, min_value=0.01, step=None):
  """"""
  if step is None:
    step = tf.train.get_global_step()
  if step is None:
    return 1.0
  step = to_float(step)
  progress = tf.minimum(step / float(max_step), 1.0)
  return progress * (1.0 - min_value) + min_value
453836
def levenberg_marquardt_update(x, a, c, damping=0.001):
    
    hess = hessian(x, a)
    return x - np.linalg.inv(hess + damping*np.diag(hess)).dot(gradient(x, a, c))
38561
def gradient(self):
        """"""
        functional = self
        c = self.scale

        class RosenbrockGradient(Operator):

            """The gradient operator of the Rosenbrock functional."""

            def __init__(self):
                """Initialize a new instance."""
                super(RosenbrockGradient, self).__init__(
                    functional.domain, functional.domain, linear=False)

            def _call(self, x, out):
                """Apply the gradient operator to the given point."""
                for i in range(1, self.domain.size - 1):
                    out[i] = (2 * c * (x[i] - x[i - 1]**2) -
                              4 * c * (x[i + 1] - x[i]**2) * x[i] -
                              2 * (1 - x[i]))
                out[0] = (-4 * c * (x[1] - x[0] ** 2) * x[0] +
                          2 * (x[0] - 1))
                out[-1] = 2 * c * (x[-1] - x[-2] ** 2)

            def derivative(self, x):
                """The derivative of the gradient.

                This is also known as the Hessian.
                """
                # TODO: Implement optimized version of this that does not need
                # a matrix.
                shape = (functional.domain.size, functional.domain.size)
                matrix = np.zeros(shape)

                # Straightforward computation
                for i in range(0, self.domain.size - 1):
                    matrix[i, i] = (2 * c + 2 + 12 * c * x[i] ** 2 -
                                    4 * c * x[i + 1])
                    matrix[i + 1, i] = -4 * c * x[i]
                    matrix[i, i + 1] = -4 * c * x[i]
                matrix[-1, -1] = 2 * c
                matrix[0, 0] = 2 + 12 * c * x[0] ** 2 - 4 * c * x[1]
                return MatrixOperator(matrix, self.domain, self.range)

        return RosenbrockGradient()
1028992
def numbaGaussian2d(psf, sy, sx):
    '''
    
    '''
    ps0, ps1 = psf.shape
    c0,c1 = ps0//2, ps1//2
    ssx = 2*sx**2
    ssy = 2*sy**2
    for i in range(ps0):
        for j in range(ps1):
            psf[i,j]=exp( -( (i-c0)**2/ssy
                            +(j-c1)**2/ssx) )
    psf/=psf.sum()
1256049
def indexed_sum_over_kronecker(cls, ops, kwargs):
    """"""
    from qnet.algebra.core.abstract_quantum_algebra import QuantumExpression
    term, *ranges = ops
    assert isinstance(term, QuantumExpression)
    deltas = set(Pattern(head=sympy.KroneckerDelta).findall(term))
    if len(deltas) == 0:
        return ops, kwargs  # nothing to do
    else:  # the term contains at least one KroneckerDelta
        delta_indices = set.union(*[set(
            [idx for idx in delta.free_symbols if isinstance(idx, IdxSym)])
            for delta in deltas])
        ranges = sorted(  # sort in the order we'd prefer to eliminate
            ranges,
            key=partial(_ranges_key, delta_indices=delta_indices),
            reverse=True)
        buffer = [(term, ranges)]
        i = 0  # position in buffer that we're currently handling
        i_range = 0  # position of index-range for current buffer item
        while i < len(buffer):
            t, rs = buffer[i]
            if rs[i_range].index_symbol in delta_indices:
                new_items, flag = _deltasummation(t, rs, i_range)
                new_rs = new_items[0][1]  # same for all new_items
                buffer = buffer[:i] + new_items + buffer[i + 1:]
                assert flag in [1, 2, 3]
                if flag == 2:
                    i_range += 1
                    # * for flag == 1, leaving i_range unchanged will
                    # effectively to to the next range (as the current range
                    # was removed)
                    # * for flag == 3, buffer[i] has changed, and we'll want to
                    # call it again with the same i_range
            else:
                # if the index symbol doesn't occur in any KroneckerDelta,
                # there is no chance _deltasummation will do anything; so we
                # just skip to the next index
                i_range += 1
                new_rs = rs
            if i_range >= len(new_rs):
                # if we've exhausted the index-ranges for the current buffer
                # item, go to the next buffer item
                i += 1
                i_range = 0
        if len(buffer) == 1 and buffer[0] == (term, ranges):
            return ops, kwargs  # couldn't resolve deltas
        else:
            (t, rs) = buffer[0]
            res = t
            if len(rs) > 0:
                res = cls.create(t, *rs, **kwargs)
            for (t, rs) in buffer[1:]:
                if len(rs) > 0:
                    t = cls.create(t, *rs, **kwargs)
                res += t
            return res
832875
def DampedPowerlaw(q, a, alpha, sigma):
    
    return a * q ** alpha * np.exp(-q ** 2 / (2 * sigma ** 2))
1043338
def eval(e, amplitude, e_0, alpha):
        """"""

        xx = e / e_0
        return amplitude * xx ** (-alpha)
786755
def fit_deriv(x, amplitude, mean, stddev):
        
        import operator
        return list(map(
            operator.neg, Gaussian1D.fit_deriv(x, amplitude, mean, stddev)))