signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def get_ops(self, ops): | time = <NUM_LIT:0.><EOL>for op, count in ops.items():<EOL><INDENT>time += self.get(op) * count<EOL><DEDENT>return time<EOL> | Return timings for dictionary ops holding the operation names as
keys and the number of applications as values. | f11476:c11:m2 |
def __and__(self, other): | left = numpy.max([self.left, other.left])<EOL>right = numpy.min([self.right, other.right])<EOL>if left <= right:<EOL><INDENT>return Interval(left, right)<EOL><DEDENT>return None<EOL> | Return intersection interval or None | f11476:c22:m1 |
def __or__(self, other): | if self & other:<EOL><INDENT>left = numpy.min([self.left, other.left])<EOL>right = numpy.max([self.right, other.right])<EOL>return Interval(left, right)<EOL><DEDENT>return None<EOL> | Return union of intervals if they intersect or None. | f11476:c22:m2 |
def contains(self, alpha): | return self.left <= alpha and alpha <= self.right<EOL> | Returns True if alpha is an element of the interval. | f11476:c22:m4 |
def distance(self, other): | if self & other:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>return numpy.max([other.left-self.right, self.left-other.right])<EOL> | Returns the distance to other (0 if intersection is nonempty). | f11476:c22:m5 |
def min_pos(self): | if self.__len__() == <NUM_LIT:0>:<EOL><INDENT>return ArgumentError('<STR_LIT>')<EOL><DEDENT>if self.contains(<NUM_LIT:0>):<EOL><INDENT>return None<EOL><DEDENT>positive = [interval for interval in self.intervals<EOL>if interval.left > <NUM_LIT:0>]<EOL>if len(positive) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>... | Returns minimal positive value or None. | f11476:c23:m9 |
def max_neg(self): | if self.__len__() == <NUM_LIT:0>:<EOL><INDENT>return ArgumentError('<STR_LIT>')<EOL><DEDENT>if self.contains(<NUM_LIT:0>):<EOL><INDENT>return None<EOL><DEDENT>negative = [interval for interval in self.intervals<EOL>if interval.right < <NUM_LIT:0>]<EOL>if len(negative) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT... | Returns maximum negative value or None. | f11476:c23:m10 |
def min_abs(self): | if self.__len__() == <NUM_LIT:0>:<EOL><INDENT>return ArgumentError('<STR_LIT>')<EOL><DEDENT>if self.contains(<NUM_LIT:0>):<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>return numpy.min([numpy.abs(val)<EOL>for val in [self.max_neg(), self.min_pos()]<EOL>if val is not None])<EOL> | Returns minimum absolute value. | f11476:c23:m11 |
def max_abs(self): | if self.__len__() == <NUM_LIT:0>:<EOL><INDENT>return ArgumentError('<STR_LIT>')<EOL><DEDENT>return numpy.max(numpy.abs([self.max(), self.min()]))<EOL> | Returns maximum absolute value. | f11476:c23:m12 |
def __init__(self, evals, exclude_zeros=False): | if isinstance(evals, Intervals):<EOL><INDENT>evals = [evals.min(), evals.max()]<EOL>if evals[<NUM_LIT:0>] <= <NUM_LIT:0>:<EOL><INDENT>raise AssumptionError(<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if len(evals) == <NUM_LIT:0>:<EOL><INDENT>raise AssumptionError('<STR_LIT>')<EOL><DEDENT>if not numpy.isreal(evals).all():<EOL... | Initialize with array/list of eigenvalues or Intervals object. | f11476:c24:m0 |
def eval_step(self, step): | return <NUM_LIT:2> * self.base**step<EOL> | Evaluate bound for given step. | f11476:c24:m1 |
def get_step(self, tol): | return numpy.log(tol/<NUM_LIT>)/numpy.log(self.base)<EOL> | Return step at which bound falls below tolerance. | f11476:c24:m2 |
def __new__(cls, evals): | pos = False<EOL>if isinstance(evals, Intervals):<EOL><INDENT>if evals.min() > <NUM_LIT:0>:<EOL><INDENT>pos = True<EOL><DEDENT><DEDENT>elif (numpy.array(evals) > -<NUM_LIT>).all():<EOL><INDENT>pos = True<EOL><DEDENT>if pos:<EOL><INDENT>return BoundCG(evals)<EOL><DEDENT>return super(BoundMinres, cls).__new__(cls)<EOL> | Use BoundCG if all eigenvalues are non-negative. | f11476:c25:m0 |
def __init__(self, evals): | if isinstance(evals, Intervals):<EOL><INDENT>if evals.contains(<NUM_LIT:0>):<EOL><INDENT>raise AssumptionError(<EOL>'<STR_LIT>')<EOL><DEDENT>evals = [val for val in [evals.min(), evals.max_neg(),<EOL>evals.min_pos(), evals.max()]<EOL>if val is not None]<EOL><DEDENT>if len(evals) == <NUM_LIT:0>:<EOL><INDENT>raise Assump... | Initialize with array/list of eigenvalues or Intervals object. | f11476:c25:m1 |
def eval_step(self, step): | return <NUM_LIT:2> * self.base**numpy.floor(step/<NUM_LIT>)<EOL> | Evaluate bound for given step. | f11476:c25:m2 |
def get_step(self, tol): | return <NUM_LIT:2> * numpy.log(tol/<NUM_LIT>)/numpy.log(self.base)<EOL> | Return step at which bound falls below tolerance. | f11476:c25:m3 |
def __init__(self, roots): | <EOL>roots = numpy.asarray(roots)<EOL>if len(roots.shape) != <NUM_LIT:1>:<EOL><INDENT>raise ArgumentError('<STR_LIT>')<EOL><DEDENT>self.roots = roots<EOL> | r'''A polynomial with specified roots and p(0)=1.
Represents the polynomial
.. math::
p(\lambda) = \prod_{i=1}^n \left(1-\frac{\lambda}{\theta_i}\right).
:param roots: array with roots :math:`\theta_1,\dots,\theta_n` of the
polynomial and ``roots.shape==(n,)``. | f11476:c26:m0 |
def minmax_candidates(self): | from numpy.polynomial import Polynomial as P<EOL>p = P.fromroots(self.roots)<EOL>return p.deriv(<NUM_LIT:1>).roots()<EOL> | Get points where derivative is zero.
Useful for computing the extrema of the polynomial over an interval if
the polynomial has real roots. In this case, the maximum is attained
for one of the interval endpoints or a point from the result of this
function that is contained in the interva... | f11476:c26:m1 |
def __call__(self, points): | <EOL>p = numpy.asarray(points)<EOL>if len(p.shape) > <NUM_LIT:1>:<EOL><INDENT>raise ArgumentError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>n = self.roots.shape[<NUM_LIT:0>]<EOL>vals = <NUM_LIT:1> - p/self.roots.reshape(n, <NUM_LIT:1>)<EOL>for j in range(vals.shape[<NUM_LIT:1>]):<EOL><INDENT>sort_tmp = numpy.argsort(num... | Evaluate polyonmial at given points.
:param points: a point :math:`x` or array of points
:math:`x_1,\dots,x_m` with ``points.shape==(m,)``.
:returns: :math:`p(x)` or array of shape ``(m,)`` with
:math:`p(x_1),\dots,p(x_m)`. | f11476:c26:m2 |
def __init__(self, DeflatedSolver,<EOL>vector_factory=None<EOL>): | self._DeflatedSolver = DeflatedSolver<EOL>self._vector_factory = vector_factory<EOL>self.timings = utils.Timings()<EOL>'''<STR_LIT>'''<EOL>self.last_solver = None<EOL>'''<STR_LIT>'''<EOL> | Initialize recycling solver base.
:param DeflatedSolver: a deflated solver from
:py:mod:`~krypy.deflation`.
:param vector_factory: (optional) An instance of a subclass of
:py:class:`krypy.recycling.factories._DeflationVectorFactory`
that constructs deflation vectors for re... | f11477:c0:m0 |
def solve(self, linear_system,<EOL>vector_factory=None,<EOL>*args, **kwargs): | <EOL>if not isinstance(linear_system, linsys.TimedLinearSystem):<EOL><INDENT>linear_system = linsys.ConvertedTimedLinearSystem(linear_system)<EOL><DEDENT>with self.timings['<STR_LIT>']:<EOL><INDENT>if vector_factory is None:<EOL><INDENT>vector_factory = self._vector_factory<EOL><DEDENT>if vector_factory == '<STR_LIT>':... | Solve the given linear system with recycling.
The provided `vector_factory` determines which vectors are used for
deflation.
:param linear_system: the :py:class:`~krypy.linsys.LinearSystem` that
is about to be solved.
:param vector_factory: (optional) see description in const... | f11477:c0:m1 |
def get(self, solver): | raise NotImplementedError('<STR_LIT>')<EOL> | Get deflation vectors.
:returns: numpy.array of shape ``(N,k)`` | f11478:c0:m0 |
def __init__(self,<EOL>subset_evaluator,<EOL>subsets_generator=None,<EOL>mode='<STR_LIT>',<EOL>print_results=None<EOL>): | if subsets_generator is None:<EOL><INDENT>subsets_generator = generators.RitzSmall()<EOL><DEDENT>self.subsets_generator = subsets_generator<EOL>self.subset_evaluator = subset_evaluator<EOL>self.mode = mode<EOL>self.print_results = print_results<EOL> | Factory of Ritz vectors for automatic recycling.
:param subset_evaluator: an instance of
:py:class:`~krypy.recycling.evaluators._RitzSubsetEvaluator` that
evaluates a proposed subset of Ritz vectors for deflation.
:param subsets_generator: (optional) an instance of
:py:cla... | f11478:c1:m0 |
def _get_best_subset(self, ritz): | <EOL>overall_evaluations = {}<EOL>def evaluate(_subset, _evaluations):<EOL><INDENT>try:<EOL><INDENT>_evaluations[_subset] =self.subset_evaluator.evaluate(ritz, _subset)<EOL><DEDENT>except utils.AssumptionError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>current_subset = frozenset()<EOL>evaluate(current_subset, overall_evalua... | Return candidate set with smallest goal functional. | f11478:c1:m2 |
def __init__(self, mode='<STR_LIT>', n_vectors=<NUM_LIT:0>, which='<STR_LIT>'): | self.mode = mode<EOL>self.n_vectors = n_vectors<EOL>self.which = which<EOL> | Selects a fixed number of Ritz or harmonic Ritz vectors
with respect to a prescribed criterion.
:param mode: See ``mode`` parameter of
:py:class:`~krypy.deflation.Ritz`.
:param n_vectors: number of vectors that are chosen. Actual number of
deflation vectors may be lower if t... | f11478:c2:m0 |
def __init__(self, factories): | self._factories = factories<EOL> | Combine a list of factories.
:param factories: a list of factories derived from
:py:class:`_DeflationVectorFactory`. | f11478:c3:m0 |
def evaluate(self, ritz, subset): | raise NotImplementedError('<STR_LIT>')<EOL> | Returns a list of subsets with indices of Ritz vectors that are
considered for deflation. | f11479:c0:m0 |
def __init__(self,<EOL>Bound,<EOL>tol=None,<EOL>strategy='<STR_LIT>',<EOL>deflweight=<NUM_LIT:1.0><EOL>): | self.Bound = Bound<EOL>self.tol = tol<EOL>self.strategy = strategy<EOL>self.deflweight = deflweight<EOL> | Evaluates a choice of Ritz vectors with an a-priori bound for
self-adjoint problems.
:param Bound: the a-priori bound which is used for estimating the
convergence behavior.
:param tol: (optional) the tolerance for the stopping criterion, see
:py:class:`~krypy.linsys._Krylo... | f11479:c1:m0 |
@staticmethod<EOL><INDENT>def _estimate_eval_intervals(ritz, indices, indices_remaining,<EOL>eps_min=<NUM_LIT:0>,<EOL>eps_max=<NUM_LIT:0>,<EOL>eps_res=None):<DEDENT> | if len(indices) == <NUM_LIT:0>:<EOL><INDENT>return utils.Intervals(<EOL>[utils.Interval(mu-resnorm, mu+resnorm)<EOL>for mu, resnorm in zip(ritz.values, ritz.resnorms)])<EOL><DEDENT>if len(ritz.values) == len(indices):<EOL><INDENT>raise utils.AssumptionError(<EOL>'<STR_LIT>')<EOL><DEDENT>if eps_res is None:<EOL><INDENT>... | Estimate evals based on eval inclusion theorem + heuristic.
:returns: Intervals object with inclusion intervals for eigenvalues | f11479:c1:m2 |
def __init__(self,<EOL>mode='<STR_LIT>',<EOL>tol=None,<EOL>pseudospectra=False,<EOL>bound_pseudo_kwargs=None,<EOL>deflweight=<NUM_LIT:1.0>): | self._arnoldifyer = None<EOL>self.mode = mode<EOL>self.tol = tol<EOL>self.pseudospectra = pseudospectra<EOL>if bound_pseudo_kwargs is None:<EOL><INDENT>bound_pseudo_kwargs = {}<EOL><DEDENT>self.bound_pseudo_kwargs = bound_pseudo_kwargs<EOL>self.deflweight = deflweight<EOL> | Evaluates a choice of Ritz vectors with a tailored approximate
Krylov subspace method.
:param mode: (optional) determines how the number of iterations
is estimated. Must be one of the following:
* ``extrapolate`` (default): use the iteration count where the
extrapolatio... | f11479:c2:m0 |
def generate(self, ritz, remaining_subset): | raise NotImplementedError('<STR_LIT>')<EOL> | Returns a list of subsets with indices of Ritz vectors that are
considered for deflation. | f11481:c0:m0 |
def bound_pseudo(arnoldifyer, Wt,<EOL>g_norm=<NUM_LIT:0.>,<EOL>G_norm=<NUM_LIT:0.>,<EOL>GW_norm=<NUM_LIT:0.>,<EOL>WGW_norm=<NUM_LIT:0.>,<EOL>tol=<NUM_LIT>,<EOL>pseudo_type='<STR_LIT>',<EOL>pseudo_kwargs=None,<EOL>delta_n=<NUM_LIT:20>,<EOL>terminate_factor=<NUM_LIT:1.><EOL>): | if pseudo_kwargs is None:<EOL><INDENT>pseudo_kwargs = {}<EOL><DEDENT>Hh, Rh, q_norm, vdiff_norm, PWAW_norm = arnoldifyer.get(Wt)<EOL>ls_orig = arnoldifyer._deflated_solver.linear_system<EOL>k = Wt.shape[<NUM_LIT:1>]<EOL>if k > <NUM_LIT:0>:<EOL><INDENT>WAW = Wt.T.conj().dot(arnoldifyer.J.dot(arnoldifyer.L.dot(Wt)))<EOL>... | r'''Bound residual norms of next deflated system.
:param arnoldifyer: an instance of
:py:class:`~krypy.deflation.Arnoldifyer`.
:param Wt: coefficients :math:`\tilde{W}\in\mathbb{C}^{n+d,k}` of the
considered deflation vectors :math:`W` for the basis :math:`[V,U]`
where ``V=last_solver.V`` and... | f11482:m0 |
def __init__(self, linear_system, U, **kwargs): | raise NotImplementedError('<STR_LIT>')<EOL> | Abstract base class of a projection for deflation.
:param A: the :py:class:`~krypy.linsys.LinearSystem`.
:param U: basis of the deflation space with ``U.shape == (N, d)``.
All parameters of :py:class:`~krypy.utils.Projection` are valid except
``X`` and ``Y``. | f11482:c0:m0 |
def __init__(self, linear_system, U, qr_reorthos=<NUM_LIT:0>, **kwargs): | <EOL>self.linear_system = linear_system<EOL>(N, d) = U.shape<EOL>U, _ = utils.qr(U, ip_B=linear_system.get_ip_Minv_B(),<EOL>reorthos=qr_reorthos)<EOL>self.U = U<EOL>'''<STR_LIT>'''<EOL>self.AU = linear_system.MlAMr*U<EOL>'''<STR_LIT>'''<EOL>self._MAU = None<EOL>super(_Projection, self).__init__(self.AU, self.U,<EOL>ip_... | Oblique projection for left deflation. | f11482:c1:m0 |
def correct(self, z): | c = self.linear_system.Ml*(<EOL>self.linear_system.b - self.linear_system.A*z)<EOL>c = utils.inner(self.W, c, ip_B=self.ip_B)<EOL>if self.Q is not None and self.R is not None:<EOL><INDENT>c = scipy.linalg.solve_triangular(self.R, self.Q.T.conj().dot(c))<EOL><DEDENT>if self.WR is not self.VR:<EOL><INDENT>c = self.WR.dot... | Correct the given approximate solution ``z`` with respect to the
linear system ``linear_system`` and the deflation space defined by
``U``. | f11482:c1:m1 |
@property<EOL><INDENT>def MAU(self):<DEDENT> | if self._MAU is None:<EOL><INDENT>self._MAU = self.linear_system.M * self.AU<EOL><DEDENT>return self._MAU<EOL> | Result of preconditioned operator to deflation space, i.e.,
:math:`MM_lAM_rU`. | f11482:c1:m2 |
def _apply_projection(self, Av): | PAv, UAv = self.projection.apply_complement(Av, return_Ya=True)<EOL>self.C = numpy.c_[self.C, UAv]<EOL>return PAv<EOL> | Apply the projection and store inner product.
:param v: the vector resulting from an application of :math:`M_lAM_r`
to the current Arnoldi vector. (CG needs special treatment, here). | f11482:c2:m2 |
def _get_initial_residual(self, x0): | if x0 is None:<EOL><INDENT>Mlr = self.linear_system.Mlb<EOL><DEDENT>else:<EOL><INDENT>r = self.linear_system.b - self.linear_system.A*x0<EOL>Mlr = self.linear_system.Ml*r<EOL><DEDENT>PMlr, self.UMlr = self.projection.apply_complement(Mlr, return_Ya=True)<EOL>MPMlr = self.linear_system.M*PMlr<EOL>MPMlr_norm = utils.norm... | Return the projected initial residual.
Returns :math:`MPM_l(b-Ax_0)`. | f11482:c2:m3 |
@property<EOL><INDENT>def B_(self):<DEDENT> | (n_, n) = self.H.shape<EOL>ls = self.linear_system<EOL>if self._B_ is None or self._B_.shape[<NUM_LIT:1>] < n_:<EOL><INDENT>if ls.self_adjoint:<EOL><INDENT>self._B_ = self.C.T.conj()<EOL>if n_ > n:<EOL><INDENT>self._B_ = numpy.r_[self._B_,<EOL>utils.inner(self.V[:, [-<NUM_LIT:1>]],<EOL>self.projection.AU,<EOL>ip_B=ls.i... | r''':math:`\underline{B}=\langle V_{n+1},M_lAM_rU\rangle`.
This property is obtained from :math:`C` if the operator is
self-adjoint. Otherwise, the inner products have to be formed
explicitly. | f11482:c2:m5 |
def estimate_time(self, nsteps, ndefl, deflweight=<NUM_LIT:1.0>): | <EOL>solver_ops = self.operations(nsteps)<EOL>proj_ops = {'<STR_LIT:A>': ndefl,<EOL>'<STR_LIT:M>': ndefl,<EOL>'<STR_LIT>': ndefl,<EOL>'<STR_LIT>': ndefl,<EOL>'<STR_LIT>': (ndefl*(ndefl+<NUM_LIT:1>)/<NUM_LIT:2><EOL>+ ndefl**<NUM_LIT:2> + <NUM_LIT:2>*ndefl*solver_ops['<STR_LIT>']),<EOL>'<STR_LIT>': (ndefl*(ndefl+<NUM_LIT... | Estimate time needed to run nsteps iterations with deflation
Uses timings from :py:attr:`linear_system` if it is an instance of
:py:class:`~krypy.linsys.TimedLinearSystem`. Otherwise, an
:py:class:`~krypy.utils.OtherError`
is raised.
:param nsteps: number of iterations.
... | f11482:c2:m6 |
def _apply_projection(self, Av): | PAv, UAp = self.projection.apply_complement(Av, return_Ya=True)<EOL>self._UAps.append(UAp)<EOL>c = UAp.copy()<EOL>rhos = self.rhos<EOL>if self.iter > <NUM_LIT:0>:<EOL><INDENT>c -= (<NUM_LIT:1> + rhos[-<NUM_LIT:1>]/rhos[-<NUM_LIT:2>])*self._UAps[-<NUM_LIT:2>]<EOL><DEDENT>if self.iter > <NUM_LIT:1>:<EOL><INDENT>c += rhos... | r'''Computes :math:`\langle C,M_lAM_rV_n\rangle` efficiently with a
three-term recurrence. | f11482:c3:m1 |
def __init__(self, deflated_solver): | self._deflated_solver = deflated_solver<EOL>H = deflated_solver.H<EOL>B_ = deflated_solver.B_<EOL>C = deflated_solver.C<EOL>E = deflated_solver.E<EOL>V = deflated_solver.V<EOL>U = deflated_solver.projection.U<EOL>AU = deflated_solver.projection.AU<EOL>ls = deflated_solver.linear_system<EOL>MAU = deflated_solver.project... | r'''Obtain Arnoldi relations for approximate deflated Krylov subspaces.
:param deflated_solver: an instance of a deflated solver. | f11482:c6:m0 |
def get(self, Wt, full=False): | n = self.n<EOL>n_ = self.n_<EOL>d = self.d<EOL>k = Wt.shape[<NUM_LIT:1>]<EOL>if k > <NUM_LIT:0>:<EOL><INDENT>Wto, _ = scipy.linalg.qr(Wt)<EOL>Wt = Wto[:, :k]<EOL>Wto = Wto[:, k:]<EOL><DEDENT>else:<EOL><INDENT>Wto = numpy.eye(Wt.shape[<NUM_LIT:0>])<EOL><DEDENT>deflated_solver = self._deflated_solver<EOL>Pt = utils.Proje... | r'''Get Arnoldi relation for a deflation subspace choice.
:param Wt: the coefficients :math:`\tilde{W}` of the deflation vectors
in the basis :math:`[V_n,U]` with ``Wt.shape == (n+d, k)``, i.e., the
deflation vectors are :math:`W=[V_n,U]\tilde{W}`. Must fulfill
:math:`\tilde{W}^*\... | f11482:c6:m1 |
def __init__(self, deflated_solver, mode='<STR_LIT>'): | self._deflated_solver = deflated_solver<EOL>linear_system = deflated_solver.linear_system<EOL>self.values = None<EOL>'''<STR_LIT>'''<EOL>self.coeffs = None<EOL>'''<STR_LIT>'''<EOL>H_ = deflated_solver.H<EOL>(n_, n) = H_.shape<EOL>H = H_[:n, :n]<EOL>projection = deflated_solver.projection<EOL>m = projection.U.shape[<NUM... | Compute Ritz pairs from a deflated Krylov subspace method.
:param deflated_solver: an instance of a deflated solver.
:param mode: (optional)
* ``ritz`` (default): compute Ritz pairs.
* ``harmonic``: compute harmonic Ritz pairs. | f11482:c7:m0 |
def get_vectors(self, indices=None): | H_ = self._deflated_solver.H<EOL>(n_, n) = H_.shape<EOL>coeffs = self.coeffs if indices is None else self.coeffs[:, indices]<EOL>return numpy.c_[self._deflated_solver.V[:, :n],<EOL>self._deflated_solver.projection.U].dot(coeffs)<EOL> | Compute Ritz vectors. | f11482:c7:m1 |
def get_explicit_residual(self, indices=None): | ritz_vecs = self.get_vectors(indices)<EOL>return self._deflated_solver.linear_system.MlAMr * ritz_vecs- ritz_vecs * self.values<EOL> | Explicitly computes the Ritz residual. | f11482:c7:m2 |
def get_explicit_resnorms(self, indices=None): | res = self.get_explicit_residual(indices)<EOL>linear_system = self._deflated_solver.linear_system<EOL>Mres = linear_system.M * res<EOL>resnorms = numpy.zeros(res.shape[<NUM_LIT:1>])<EOL>for i in range(resnorms.shape[<NUM_LIT:0>]):<EOL><INDENT>resnorms[i] = utils.norm(res[:, [i]], Mres[:, [i]],<EOL>ip_B=linear_system.ip... | Explicitly computes the Ritz residual norms. | f11482:c7:m3 |
def somewhat_fun_method(self): | return '<STR_LIT>'<EOL> | LULZ | f11485:c0:m0 |
def somewhat_fun_method(self): | return '<STR_LIT>'<EOL> | LULZ | f11486:c0:m0 |
def some_method(self): | return '<STR_LIT>'<EOL> | Super Class Docs | f11487:c0:m0 |
@overrides<EOL><INDENT>def some_method(self):<DEDENT> | return <NUM_LIT:1><EOL> | Subber | f11487:c2:m0 |
def some_method(self): | return '<STR_LIT>'<EOL> | Super Class Docs | f11488:c0:m0 |
def overrides(method): | for super_class in _get_base_classes(sys._getframe(<NUM_LIT:2>), method.__globals__):<EOL><INDENT>if hasattr(super_class, method.__name__):<EOL><INDENT>super_method = getattr(super_class, method.__name__)<EOL>if hasattr(super_method, "<STR_LIT>"):<EOL><INDENT>finalized = getattr(super_method, "<STR_LIT>")<EOL>if finali... | Decorator to indicate that the decorated method overrides a method in
superclass.
The decorator code is executed while loading class. Using this method
should have minimal runtime performance implications.
This is based on my idea about how to do this and fwc:s highly improved
algorithm for the imp... | f11490:m0 |
def _get_base_class_names(frame): | co, lasti = frame.f_code, frame.f_lasti<EOL>code = co.co_code<EOL>extends = []<EOL>for (op, oparg) in op_stream(code, lasti):<EOL><INDENT>if op in dis.hasconst:<EOL><INDENT>if type(co.co_consts[oparg]) == str:<EOL><INDENT>extends = []<EOL><DEDENT><DEDENT>elif op in dis.hasname:<EOL><INDENT>if dis.opname[op] == '<STR_LI... | Get baseclass names from the code object | f11490:m2 |
def final(method): | setattr(method, "<STR_LIT>", True)<EOL>return method<EOL> | Decorator to indicate that the decorated method is finalized and cannot be overridden.
The decorator code is executed while loading class. Using this method
should have minimal runtime performance implications.
Currently, only methods with @overrides are checked.
How to use:
from overrides import f... | f11491:m0 |
def get_dummy_request(): | request = RequestFactory().get("<STR_LIT:/>", HTTP_HOST='<STR_LIT>')<EOL>request.session = {}<EOL>request.user = AnonymousUser()<EOL>return request<EOL> | Returns a Request instance. | f11493:m0 |
@register.simple_tag(takes_context=True)<EOL>def staff_toolbar(context): | request = context['<STR_LIT>']<EOL>if not request.user.is_staff:<EOL><INDENT>return u'<STR_LIT>'<EOL><DEDENT>toolbar_html = toolbar_root(request, context)<EOL>return format_html(u'<STR_LIT>', toolbar_html)<EOL> | Display the staff toolbar
:param context:
:type context:
:return:
:rtype: | f11495:m0 |
@register.simple_tag(takes_context=True)<EOL>def set_staff_object(context, object): | request = context['<STR_LIT>']<EOL>request.staff_object = object<EOL>return u'<STR_LIT>'<EOL> | Assign an object to be the "main object" of this page.
Example::
{% set_staff_object page %} | f11495:m1 |
@register.tag<EOL>def set_staff_url(parser, token): | nodelist = parser.parse(('<STR_LIT>',))<EOL>parser.delete_first_token()<EOL>return AdminUrlNode(nodelist)<EOL> | Assign an URL to be the "admin link" of this page.
Example::
{% set_staff_url %}{% url 'admin:fluent_pages_page_change' page.id %}{% end_set_staff_url %} | f11495:m2 |
def get_staff_url(self): | object = self.get_staff_object()<EOL>if object is not None:<EOL><INDENT>return reverse(admin_urlname(object._meta, '<STR_LIT>'), args=(object.pk,))<EOL><DEDENT>model = _get_view_model(self)<EOL>if model is not None:<EOL><INDENT>return reverse(admin_urlname(object._meta, '<STR_LIT>'))<EOL><DEDENT>return None<EOL> | Return the Admin URL for the current view.
By default, it uses the :func:`get_staff_object` function to base the URL on. | f11497:c0:m1 |
def get_toolbar_root(): | global _toolbar_root<EOL>if _toolbar_root is None:<EOL><INDENT>items = [load_toolbar_item(item) for item in appsettings.STAFF_TOOLBAR_ITEMS]<EOL>_toolbar_root = RootNode(*items)<EOL><DEDENT>return _toolbar_root<EOL> | Init on demand.
:rtype: RootNode | f11498:m0 |
def load_toolbar_item(import_path, *args, **kwargs): | if isinstance(import_path, (tuple, list)):<EOL><INDENT>children = [load_toolbar_item(path) for path in import_path]<EOL>return Group(*children)<EOL><DEDENT>elif isinstance(import_path, basestring):<EOL><INDENT>symbol = _import_symbol(import_path, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>symbol = import_path<EOL><DEDE... | Load an item in the toolbar
:param import_path: the dotted python path to class or function.
:param args: For classes, any arguments to pass to the constructor.
:param kwargs: For classes, any keyword arguments to pass to the constructor. | f11498:m1 |
def _import_symbol(import_path, setting_name): | mod_name, class_name = import_path.rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL>try:<EOL><INDENT>mod = import_module(mod_name)<EOL>cls = getattr(mod, class_name)<EOL><DEDENT>except ImportError as e:<EOL><INDENT>__, __, exc_traceback = sys.exc_info()<EOL>frames = traceback.extract_tb(exc_traceback)<EOL>if len(frames) > <NUM_L... | Import a class or function by name. | f11498:m2 |
def toolbar_title(title): | return LazyToolbarItem('<STR_LIT>', title)<EOL> | Define a title to be included in the toolbar. | f11500:m0 |
def toolbar_literal(title): | return LazyToolbarItem('<STR_LIT>', title)<EOL> | Define a literal text to be included in the toolbar. | f11500:m1 |
def toolbar_item(callable_path, *args, **kwargs): | return LazyToolbarItem(callable_path, *args, **kwargs)<EOL> | Defining a toolbar item in the settings that also received arguments.
It won't be loaded until the toolbar is actually rendered. | f11500:m2 |
def toolbar_link(url, title): | return LazyToolbarItem('<STR_LIT>', url=url, title=title)<EOL> | Define a link to be included in the toolbar. | f11500:m3 |
def get_object(context): | object = None<EOL>view = context.get('<STR_LIT>')<EOL>if view:<EOL><INDENT>object = getattr(view, '<STR_LIT:object>', None)<EOL><DEDENT>if object is None:<EOL><INDENT>object = context.get('<STR_LIT:object>', None)<EOL><DEDENT>return object<EOL> | Get an object from the context or view. | f11501:m0 |
def __call__(self, request, context): | rows = self.get_rows(request, context)<EOL>return self.render(rows)<EOL> | Render the group | f11501:c2:m1 |
def get_rows(self, request, context): | from staff_toolbar.loading import load_toolbar_item<EOL>rows = []<EOL>for i, hook in enumerate(self.children):<EOL><INDENT>if isinstance(hook, (basestring, tuple, list)):<EOL><INDENT>hook = load_toolbar_item(hook)<EOL>self.children[i] = hook<EOL><DEDENT>html = hook(request, context)<EOL>if not html:<EOL><INDENT>continu... | Get all rows as HTML | f11501:c2:m2 |
def render(self, rows): | if not rows:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>li_tags = mark_safe(u"<STR_LIT:\n>".join(format_html(u'<STR_LIT>', force_text(row)) for row in rows))<EOL>if self.title:<EOL><INDENT>return format_html(u'<STR_LIT>', self.title, li_tags)<EOL><DEDENT>else:<EOL><INDENT>return format_html(u'<STR_LIT>', li_tags)<EOL><... | Join the HTML rows. | f11501:c2:m3 |
def send_login_code(self, code, context, **kwargs): | from_number = self.from_number or getattr(settings, '<STR_LIT>')<EOL>sms_content = render_to_string(self.template_name, context)<EOL>self.twilio_client.messages.create(<EOL>to=code.user.phone_number,<EOL>from_=from_number,<EOL>body=sms_content<EOL>)<EOL> | Send a login code via SMS | f11528:c0:m1 |
def rest(f): | @wraps(f)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>ret = f(*args, **kwargs)<EOL>if ret is None:<EOL><INDENT>response = '<STR_LIT>', <NUM_LIT><EOL><DEDENT>elif isinstance(ret, current_app.response_class):<EOL><INDENT>response = ret<EOL><DEDENT>elif isinstance(ret, tuple):<EOL><INDENT>if isinstance(ret[<NUM_LIT:1>],... | Decorator for simple REST endpoints.
Functions must return one of these values:
- a dict to jsonify
- nothing for an empty 204 response
- a tuple containing a status code and a dict to jsonify | f11533:m6 |
@classmethod<EOL><INDENT>def by_col(cls, df, cols, w=None, inplace=False, pvalue='<STR_LIT>', outvals=None, **stat_kws):<DEDENT> | if outvals is None:<EOL><INDENT>outvals = []<EOL>outvals.extend(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>pvalue = '<STR_LIT>'<EOL><DEDENT>return _univariate_handler(df, cols, w=w, inplace=inplace, pvalue=pvalue,<EOL>outvals=outvals, stat=cls,<EOL>swapname='<STR_LIT>', **stat_kws)<EOL> | Function to compute a Join_Count statistic on a dataframe
Arguments
---------
df : pandas.DataFrame
a pandas dataframe with a geometry column
cols : string or list of string
name or list of names of columns to use to compute the statistic
w : pysal weight... | f11545:c0:m4 |
@property<EOL><INDENT>def _statistic(self):<DEDENT> | return self.C<EOL> | a standardized accessor for esda statistics | f11553:c0:m1 |
@classmethod<EOL><INDENT>def by_col(cls, df, cols, w=None, inplace=False, pvalue='<STR_LIT>', outvals=None, **stat_kws):<DEDENT> | return _univariate_handler(df, cols, w=w, inplace=inplace, pvalue=pvalue,<EOL>outvals=outvals, stat=cls,<EOL>swapname=cls.__name__.lower(), **stat_kws)<EOL> | Function to compute a Geary statistic on a dataframe
Arguments
---------
df : pandas.DataFrame
a pandas dataframe with a geometry column
cols : string or list of string
name or list of names of columns to use to compute the statistic
w : pysal weights obj... | f11553:c0:m4 |
def _univariate_handler(df, cols, stat=None, w=None, inplace=True,<EOL>pvalue = '<STR_LIT>', outvals = None, swapname='<STR_LIT>', **kwargs): | <EOL>if not inplace:<EOL><INDENT>new_df = df.copy()<EOL>_univariate_handler(new_df, cols, stat=stat, w=w, pvalue=pvalue,<EOL>inplace=True, outvals=outvals,<EOL>swapname=swapname, **kwargs)<EOL>return new_df<EOL><DEDENT>if w is None:<EOL><INDENT>for name in df._metadata:<EOL><INDENT>this_obj = df.__dict__.get(name)<EOL>... | Compute a univariate descriptive statistic `stat` over columns `cols` in
`df`.
Parameters
----------
df : pandas.DataFrame
the dataframe containing columns to compute the descriptive
statistics
cols : string or list of strings
one or more names of columns in `d... | f11554:m0 |
def _bivariate_handler(df, x, y=None, w=None, inplace=True, pvalue='<STR_LIT>',<EOL>outvals=None, **kwargs): | real_swapname = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>if isinstance(y, str):<EOL><INDENT>y = [y]<EOL><DEDENT>if isinstance(x, str):<EOL><INDENT>x = [x]<EOL><DEDENT>if not inplace:<EOL><INDENT>new_df = df.copy()<EOL>_bivariate_handler(new_df, x, y=y, w=w, inplace=True,<EOL>swapname=real_swapname,<EOL>pvalue=pvalue, o... | Compute a descriptive bivariate statistic over two sets of columns, `x` and
`y`, contained in `df`.
Parameters
----------
df : pandas.DataFrame
dataframe in which columns `x` and `y` are contained
x : string or list of strings
one or more column names to use as variates i... | f11554:m1 |
def _swap_ending(s, ending, delim='<STR_LIT:_>'): | parts = [x for x in s.split(delim)[:-<NUM_LIT:1>] if x != '<STR_LIT>']<EOL>parts.append(ending)<EOL>return delim.join(parts)<EOL> | Replace the ending of a string, delimited into an arbitrary
number of chunks by `delim`, with the ending provided
Parameters
----------
s : string
string to replace endings
ending : string
string used to replace ending of `s`
delim : string
string that splits s into o... | f11554:m2 |
@property<EOL><INDENT>def _statistic(self):<DEDENT> | return self.G<EOL> | Standardized accessor for esda statistics | f11555:c0:m3 |
@classmethod<EOL><INDENT>def by_col(cls, df, cols, w=None, inplace=False, pvalue='<STR_LIT>', outvals=None, **stat_kws):<DEDENT> | return _univariate_handler(df, cols, w=w, inplace=inplace, pvalue=pvalue,<EOL>outvals=outvals, stat=cls,<EOL>swapname=cls.__name__.lower(), **stat_kws)<EOL> | Function to compute a G statistic on a dataframe
Arguments
---------
df : pandas.DataFrame
a pandas dataframe with a geometry column
cols : string or list of string
name or list of names of columns to use to compute the statistic
w : pysal weights object
... | f11555:c0:m4 |
@property<EOL><INDENT>def _statistic(self):<DEDENT> | return self.Gs<EOL> | Standardized accessor for esda statistics | f11555:c1:m4 |
@classmethod<EOL><INDENT>def by_col(cls, df, cols, w=None, inplace=False, pvalue='<STR_LIT>', outvals=None, **stat_kws):<DEDENT> | return _univariate_handler(df, cols, w=w, inplace=inplace, pvalue=pvalue,<EOL>outvals=outvals, stat=cls,<EOL>swapname=cls.__name__.lower(), **stat_kws)<EOL> | Function to compute a G_Local statistic on a dataframe
Arguments
---------
df : pandas.DataFrame
a pandas dataframe with a geometry column
cols : string or list of string
name or list of names of columns to use to compute the statistic
w : pysal weights o... | f11555:c1:m5 |
def flatten(l, unique=True): | l = reduce(lambda x, y: x + y, l)<EOL>if not unique:<EOL><INDENT>return list(l)<EOL><DEDENT>return list(set(l))<EOL> | flatten a list of lists
Parameters
----------
l : list
of lists
unique : boolean
whether or not only unique items are wanted (default=True)
Returns
-------
list
of single items
Examples
--------
Creating a sample list who... | f11556:m0 |
def weighted_median(d, w): | dtype = [('<STR_LIT:w>', '<STR_LIT:%s>' % w.dtype), ('<STR_LIT:v>', '<STR_LIT:%s>' % d.dtype)]<EOL>d_w = np.array(list(zip(w, d)), dtype=dtype)<EOL>d_w.sort(order='<STR_LIT:v>')<EOL>reordered_w = d_w['<STR_LIT:w>'].cumsum()<EOL>cumsum_threshold = reordered_w[-<NUM_LIT:1>] * <NUM_LIT:1.0> / <NUM_LIT:2><EOL>median_inx = ... | A utility function to find a median of d based on w
Parameters
----------
d : array
(n, 1), variable for which median will be found
w : array
(n, 1), variable on which d's median will be decided
Notes
-----
d and w are arranged in the sam... | f11556:m1 |
def sum_by_n(d, w, n): | t = len(d)<EOL>h = t // n <EOL>d = d * w<EOL>return np.array([sum(d[i: i + h]) for i in range(<NUM_LIT:0>, t, h)])<EOL> | A utility function to summarize a data array into n values
after weighting the array with another weight array w
Parameters
----------
d : array
(t, 1), numerical values
w : array
(t, 1), numerical values for weighting
n : integer
... | f11556:m2 |
def crude_age_standardization(e, b, n): | r = e * <NUM_LIT:1.0> / b<EOL>b_by_n = sum_by_n(b, <NUM_LIT:1.0>, n)<EOL>age_weight = b * <NUM_LIT:1.0> / b_by_n.repeat(len(e) // n)<EOL>return sum_by_n(r, age_weight, n)<EOL> | A utility function to compute rate through crude age standardization
Parameters
----------
e : array
(n*h, 1), event variable measured for each age group across n spatial units
b : array
(n*h, 1), population at risk variable measured for each age grou... | f11556:m3 |
def direct_age_standardization(e, b, s, n, alpha=<NUM_LIT>): | age_weight = (<NUM_LIT:1.0> / b) * (s * <NUM_LIT:1.0> / sum_by_n(s, <NUM_LIT:1.0>, n).repeat(len(s) // n))<EOL>adjusted_r = sum_by_n(e, age_weight, n)<EOL>var_estimate = sum_by_n(e, np.square(age_weight), n)<EOL>g_a = np.square(adjusted_r) / var_estimate<EOL>g_b = var_estimate / adjusted_r<EOL>k = [age_weight[i:i + len... | A utility function to compute rate through direct age standardization
Parameters
----------
e : array
(n*h, 1), event variable measured for each age group across n spatial units
b : array
(n*h, 1), population at risk variable measured for each age gro... | f11556:m4 |
def indirect_age_standardization(e, b, s_e, s_b, n, alpha=<NUM_LIT>): | smr = standardized_mortality_ratio(e, b, s_e, s_b, n)<EOL>s_r_all = sum(s_e * <NUM_LIT:1.0>) / sum(s_b * <NUM_LIT:1.0>)<EOL>adjusted_r = s_r_all * smr<EOL>e_by_n = sum_by_n(e, <NUM_LIT:1.0>, n)<EOL>log_smr = np.log(smr)<EOL>log_smr_sd = <NUM_LIT:1.0> / np.sqrt(e_by_n)<EOL>norm_thres = norm.ppf(<NUM_LIT:1> - <NUM_LIT:0.... | A utility function to compute rate through indirect age standardization
Parameters
----------
e : array
(n*h, 1), event variable measured for each age group across n spatial units
b : array
(n*h, 1), population at risk variable measured for each age g... | f11556:m5 |
def standardized_mortality_ratio(e, b, s_e, s_b, n): | s_r = s_e * <NUM_LIT:1.0> / s_b<EOL>e_by_n = sum_by_n(e, <NUM_LIT:1.0>, n)<EOL>expected = sum_by_n(b, s_r, n)<EOL>smr = e_by_n * <NUM_LIT:1.0> / expected<EOL>return smr<EOL> | A utility function to compute standardized mortality ratio (SMR).
Parameters
----------
e : array
(n*h, 1), event variable measured for each age group across n spatial units
b : array
(n*h, 1), population at risk variable measured for each age group a... | f11556:m6 |
def choynowski(e, b, n, threshold=None): | e_by_n = sum_by_n(e, <NUM_LIT:1.0>, n)<EOL>b_by_n = sum_by_n(b, <NUM_LIT:1.0>, n)<EOL>r_by_n = sum(e_by_n) * <NUM_LIT:1.0> / sum(b_by_n)<EOL>expected = r_by_n * b_by_n<EOL>p = []<EOL>for index, i in enumerate(e_by_n):<EOL><INDENT>if i <= expected[index]:<EOL><INDENT>p.append(poisson.cdf(i, expected[index]))<EOL><DEDENT... | Choynowski map probabilities [Choynowski1959]_ .
Parameters
----------
e : array(n*h, 1)
event variable measured for each age group across n spatial units
b : array(n*h, 1)
population at risk variable measured for each age group across n spatial units... | f11556:m7 |
def assuncao_rate(e, b): | y = e * <NUM_LIT:1.0> / b<EOL>e_sum, b_sum = sum(e), sum(b)<EOL>ebi_b = e_sum * <NUM_LIT:1.0> / b_sum<EOL>s2 = sum(b * ((y - ebi_b) ** <NUM_LIT:2>)) / b_sum<EOL>ebi_a = s2 - ebi_b / (float(b_sum) / len(e))<EOL>ebi_v = ebi_a + ebi_b / b<EOL>return (y - ebi_b) / np.sqrt(ebi_v)<EOL> | The standardized rates where the mean and stadard deviation used for
the standardization are those of Empirical Bayes rate estimates
The standardized rates resulting from this function are used to compute
Moran's I corrected for rate variables [Choynowski1959]_ .
Parameters
----------
e ... | f11556:m8 |
@classmethod<EOL><INDENT>def by_col(cls, df, e,b, inplace=False, **kwargs):<DEDENT> | if not inplace:<EOL><INDENT>new = df.copy()<EOL>cls.by_col(new, e, b, inplace=True, **kwargs)<EOL>return new<EOL><DEDENT>if isinstance(e, str):<EOL><INDENT>e = [e]<EOL><DEDENT>if isinstance(b, str):<EOL><INDENT>b = [b]<EOL><DEDENT>if len(b) == <NUM_LIT:1> and len(e) > <NUM_LIT:1>:<EOL><INDENT>b = b * len(e)<EOL><DEDENT... | Compute smoothing by columns in a dataframe.
Parameters
-----------
df : pandas.DataFrame
a dataframe containing the data to be smoothed
e : string or list of strings
the name or names of columns containing event variables to be
smoothed
b : string or list of string... | f11556:c0:m1 |
@classmethod<EOL><INDENT>def by_col(cls, df, e,b, w=None, inplace=False, **kwargs):<DEDENT> | if not inplace:<EOL><INDENT>new = df.copy()<EOL>cls.by_col(new, e, b, w=w, inplace=True, **kwargs)<EOL>return new<EOL><DEDENT>if isinstance(e, str):<EOL><INDENT>e = [e]<EOL><DEDENT>if isinstance(b, str):<EOL><INDENT>b = [b]<EOL><DEDENT>if w is None:<EOL><INDENT>found = False<EOL>for k in df._metadata:<EOL><INDENT>w = d... | Compute smoothing by columns in a dataframe.
Parameters
-----------
df : pandas.DataFrame
a dataframe containing the data to be smoothed
e : string or list of strings
the name or names of columns containing event variables to be
smoothed
b : string or list of string... | f11556:c3:m1 |
@_requires('<STR_LIT>')<EOL><INDENT>@classmethod<EOL>def by_col(cls, df, e,b, w=None, s=None, **kwargs):<DEDENT> | if s is None:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>import pandas as pd<EOL>if isinstance(e, str):<EOL><INDENT>e = [e]<EOL><DEDENT>if isinstance(b, str):<EOL><INDENT>b = [b]<EOL><DEDENT>if isinstance(s, str):<EOL><INDENT>s = [s]<EOL><DEDENT>if w is None:<EOL><INDENT>found = False<EOL>for k in df._metadat... | Compute smoothing by columns in a dataframe.
Parameters
-----------
df : pandas.DataFrame
a dataframe containing the data to be smoothed
e : string or list of strings
the name or names of columns containing event variables to be
smoothed
b : string or list of string... | f11556:c7:m1 |
@_requires('<STR_LIT>')<EOL><INDENT>@classmethod<EOL>def by_col(cls, df, e, b, x_grid, y_grid, geom_col='<STR_LIT>', **kwargs):<DEDENT> | import pandas as pd<EOL>if isinstance(e, str):<EOL><INDENT>e = [e]<EOL><DEDENT>if isinstance(b, str):<EOL><INDENT>b = [b]<EOL><DEDENT>if len(e) > len(b):<EOL><INDENT>b = b * len(e)<EOL><DEDENT>if isinstance(x_grid, (int, float)):<EOL><INDENT>x_grid = [x_grid] * len(e)<EOL><DEDENT>if isinstance(y_grid, (int, float)):<EO... | Compute smoothing by columns in a dataframe. The bounding box and point
information is computed from the geometry column.
Parameters
-----------
df : pandas.DataFrame
a dataframe containing the data to be smoothed
e : string or list of strings
the name or names of columns containing ... | f11556:c10:m1 |
@_requires('<STR_LIT>')<EOL><INDENT>@classmethod<EOL>def by_col(cls, df, e, b, t=None, geom_col='<STR_LIT>', inplace=False, **kwargs):<DEDENT> | import pandas as pd<EOL>if not inplace:<EOL><INDENT>new = df.copy()<EOL>cls.by_col(new, e, b, t=t, geom_col=geom_col, inplace=True, **kwargs)<EOL>return new<EOL><DEDENT>import pandas as pd<EOL>if isinstance(e, str):<EOL><INDENT>e = [e]<EOL><DEDENT>if isinstance(b, str):<EOL><INDENT>b = [b]<EOL><DEDENT>if len(e) > len(b... | Compute smoothing by columns in a dataframe. The bounding box and point
information is computed from the geometry column.
Parameters
-----------
df : pandas.DataFrame
a dataframe containing the data to be smoothed
e : string or list of strings
the name or names of columns containing ... | f11556:c12:m4 |
@property<EOL><INDENT>def p_sim(self):<DEDENT> | return self.p_sim_g<EOL> | new name to fit with Moran module | f11558:c0:m2 |
def Moran_BV_matrix(variables, w, permutations=<NUM_LIT:0>, varnames=None): | try:<EOL><INDENT>import pandas<EOL>if isinstance(variables, pandas.DataFrame):<EOL><INDENT>varnames = pandas.Index.tolist(variables.columns)<EOL>variables_n = []<EOL>for var in varnames:<EOL><INDENT>variables_n.append(variables[str(var)].values)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>variables_n = variables<EOL><DEDENT>... | Bivariate Moran Matrix
Calculates bivariate Moran between all pairs of a set of variables.
Parameters
----------
variables : array or pandas.DataFrame
sequence of variables to be assessed
w : W
a spatial weights object
permutations : int
number of permutation... | f11560:m0 |
def _Moran_BV_Matrix_array(variables, w, permutations=<NUM_LIT:0>, varnames=None): | if varnames is None:<EOL><INDENT>varnames = ['<STR_LIT>'.format(i) for i in range(k)]<EOL><DEDENT>k = len(variables)<EOL>rk = list(range(<NUM_LIT:0>, k - <NUM_LIT:1>))<EOL>results = {}<EOL>for i in rk:<EOL><INDENT>for j in range(i + <NUM_LIT:1>, k):<EOL><INDENT>y1 = variables[i]<EOL>y2 = variables[j]<EOL>results[i, j] ... | Base calculation for MORAN_BV_Matrix | f11560:m1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.