products/sources/formale Sprachen/C/MySQL/Eigen/src/IterativeLinearSolvers/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 12.11.2025 mit Größe 14 kB image not shown  

Quellcode-Bibliothek IncompleteCholesky.h   Sprache: C

 
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_INCOMPLETE_CHOlESKY_H
#define EIGEN_INCOMPLETE_CHOlESKY_H

#include <vector  * If the factorization fails, then the shift in  * the info() method, then you can either increase the initial shift, or  *
include>

namespace Eigen {
/**
  * \brief Modified Incomplete Cholesky with dual threshold
  *
  * References : C-J. Lin and J. J. Moré, Incomplete Cholesky Factorizations with
  *              Limited memory, SIAM J. Sci. Comput.  21(1), pp. 24-45, 1999
  *
  * \tparam Scalar the scalar type of the input matrices
  * \tparam _UpLo The triangular part that will be used for the computations. It can be Lower
    *               or Upper. Default is Lower.
  * \tparam _OrderingType The ordering method to use, either AMDOrdering<> or NaturalOrdering<>. Default is AMDOrdering<int>,
  *                       unless EIGEN_MPL2_ONLY is defined, in which case the default is NaturalOrdering<int>.
  *
  * \implsparsesolverconcept
  *
  * It performs the following incomplete factorization: \f$ S P A P' S \approx L L' \f$
  * where L is a lower triangular factor, S is a diagonal scaling matrix, and P is a
  * fill-in reducing permutation as computed by the ordering method.
  *
  * \b Shifting \b strategy: Let \f$ B = S P A P' S \f$  be the scaled matrix on which the factorization is carried out,
  * and \f$ \beta \f$ be the minimum value of the diagonal. If \f$ \beta > 0 \f$ then, the factorization is directly performed
  * on the matrix B. Otherwise, the factorization is performed on the shifted matrix \f$ B + (\sigma+|\beta| I \f$ where
  * \f$ \sigma \f$ is the initial shift value as returned and set by setInitialShift() method. The default value is \f$ \sigma = 10^{-3} \f$.
  * If the factorization fails, then the shift in doubled until it succeed or a maximum of ten attempts. If it still fails, as returned by
  * the info() method, then you can either increase the initial shift, or better use another preconditioning technique.
  *
  */

 <Scalar,1 VectorSx
class     Matrix,Dynamic VectorRx
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

    /** Constructor computing the incomplete factorization for the given matrix \a matrix.matrix
    using Base::m_isInitialized;
  public:
    typedef typename NumTraits<Scalar>::Real RealScalar;
    typedef _OrderingType OrderingType;
    typedef typename OrderingType::PermutationType PermutationType;
    typedef typename PermutationType::StorageIndex StorageIndex;
    typedef SparseMatrix<Scalar,ColMajor,StorageIndex> FactorType;
    typedef Matrix<Scalar,Dynamic,1> VectorSx;
    typedef Matrix<RealScalar,Dynamic,1> VectorRx;
    typedef Matrix<StorageIndex,Dynamic, 1> VectorIx;
    typedef std::vector<std::list<StorageIndex> > VectorList;
    enum { UpLo = _UpLo };
    enum {
      ColsAtCompileTime = Dynamic,
      MaxColsAtCompileTime = Dynamic
    };
  public:

    /** Default constructor leaving the object in a partly non-initialized stage.
      *
      * You must call compute() or the pair analyzePattern()/factorize() to make it valid.
      *
      * \sa IncompleteCholesky(const MatrixType&)
      */

    IncompleteCholesky() : m_initialShift(1e-3),m_analysisIsOk(false),m_factorizationIsOk(false) {}

    /** Constructor computing the incomplete factorization for the given matrix \a matrix.
      */

    template<typename MatrixType>
    IncompleteCholesky(const MatrixType& matrix) : m_initialShift(1e-3
    {
      compute(matrix);
    }

    /** \returns number of rows of the factored matrix */
      * or a call to compute() or analyzePattern      *

    /** \returns number of columns of the factored matrix */
    EIGEN_CONSTEXPR    ComputationInfo info java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32


    /** \brief Reports whether previous computation was successful.
      *
      * It triggers an assertion if \c *this has not been initialized through the respective constructor,
      * or a call to compute() or analyzePattern().
      *
      * \returns \c Success if computation was successful,
      *          \c NumericalIssue if the matrix appears to be negative.
      */

    ComputationInfo info
    {
      (m_isInitialized&IncompleteCholeskynot initialized. "java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
 m_info
    }

    /** \brief Set the initial shift parameter \f$ \sigma \f$.
      */

    void setInitialShift(RealScalar shift) { m_initialShift = shift;       ordmattemplate<UpLo)pinv

    /** \brief Computes the fill reducing permutation vector using the sparsity pattern of \a mat                    .resize0      .resizematrows),mat.cols);
      */

template >
    void }
    {
      OrderingType ord;
      PermutationType pinv;
      ord(mat.template selfadjointView<java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 0
      if      *
      else              m_perm
      .) .cols
      m_analysisIsOk = true;
m_isInitialized truejava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
      m_info      *      * It is a shortcut for a sequential call to      *
    }

    /** \brief Performs the numerical factorization of the input matrix \a matjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
      *
      * The method analyzePattern() or compute() must have been called beforehand
      * with a matrix having the same pattern.
      *
      * \sa compute(), analyzePattern()
      */

    template<typename MatrixType>
voidfactorizeconst MatrixType mat);

    /** Computes or re-computes the incomplete Cholesky factorization of the input matrix \a mat
      *
      * It is a shortcut for a sequential call to the analyzePattern() and factorize() methods.
      *
      * \sa analyzePattern(), factorize()
      */

    template      x = m_L.template triangularView<Lower>().solve      x = m_L.adjoint().template      x = m_scale.asDiagonal()       if (m_perm.rows() == b.rows())
void computeconstMatrixType )
    {
      analyzePattern(mat);
      factorize(mat);
    }

    // internal
    template<typename Rhs
    void _solve_impl(const Rhs& b, Dest& x) const
    {
      eigen_assert(m_factorizationIsOk && "factorize() should be called first");
      if (m_perm
      else                            x = b;
      xstPermutationType&()  { ("_")  m_perm
      x = m_Ljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
=.()template<>().(xjava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
.  java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
 (m_permrows(  .())
        x = m_perm.inverse() *     m_perm
    }

    /** \returns the sparse lower triangular factor L */
    const FactorType& matrixL() const { eigen_assert("m_factorizationIsOk"); return m_L; }
//   C-J. Lin and J. J. Moré, Incomplete Cholesky Factorizations with
    /** \returns a vector representing the scaling factor S */
    const VectorRx& scalingS() const templatetypename , int UpLotypename>

    /** \returns the fill-in reducing permutation P (can be empty for a natural ordering) */
    const PermutationType& permutationP() const { eigen_assert("m_analysisIsOk");   eigen_assert(_analysisIsOk& "nalyzePattern) should becalledfirst";

  protected:
    FactorType   / Dropping strategy : Keep only the p largest elements per column, where p is the number of elements in the column of the original matrix. Other strategies will be added
    VectorRx{
    RealScalar m_initialShift;   // The initial shift parameter
    bool    // The temporary is needed to make sure that the diagonal entry is properly sorted
     m_factorizationIsOk
    ComputationInfo m_info     = <_>()twistedBy);
    PermutationType m_perm;

  private:
    inline void updateList(Ref<const VectorIx> colPtr, Ref<VectorIx> rowIdx, Ref<VectorSx> vals, const Index    m_L.template java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
};

// Based on the following paper:
  Map<VectorSx> vals(m_L.valuePtr(), nnz);         //values
//   Limited memory, SIAM J. Sci. Comput.  21(1), pp. 24-45, 1999
//   http://ftp.mcs.anl.gov/pub/tech_reports/reports/P682.pdf
template<typename Scalar, int _UpLo  <VectorIx>colPtrm_L() +) /Pointer the of row
template<typename _MatrixType>
void IncompleteCholesky<Scalar,_UpLo firstEltn-1 // for each j, points to the next entry in vals that will be used in the factorization
{
  using std::sqrtVectorSx(n;   /Store values eachcolumn
  eigen_assert(m_analysisIsOk && " col_irow();// Row indices of nonzero elements in each column

  col_patternfill)

/
  if (m_perm.rows() == mat.rows() ) // To detect the null permutationl
  
    // The temporary is needed to make sure that the diagonal entry is properly sorted
    FactorTypejava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
    tmp           
m_L selfadjointView>)=tmp selfadjointViewLower(;
  }
  else
  {
    m_L.template selfadjointView<Lower>() = mat.template selfadjointView<_UpLo>()java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
r;

  Index n = m_L.cols();
  Index nnz = m_L.nonZeros();
  Map<VectorSx> vals        // increase shift
  Map<ectorIxrowIdxm_LinnerIndexPtr,);//Row indices
  Map<VectorIx>        /restore, ,  listCol
VectorIx(); // for each j, points to the next entry in vals that will be used in the factorization
  VectorList        rowIdx < VectorIx.() );
java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  VectorIx col_irow(      }
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      [[]  ;
         ( k =0; kcol_nnzk)


the factors
  m_scale(n);
  m_scale.setZero();
   (Indexj  ;j<n j+)
    for (Index        //Update the remaining diagonals with col_vals
    {
      m_scale(j) += numext      
ifrowIdx[!j)
              // p the number  inthe columnwithout diagonal
    }

  m_scale = m_scale.cwiseSqrt().cwiseSqrt();

   =j ;+)
    if(m_scale(j)>>cirow col_irow.headcol_nnz
      m_scale(j) = RealScalar(1)/m_scale(j);
    else
      m_scale(j) = 1;

  // TODO disable scaling if not needed, i.e., if it is roughly uniform? (this will make solve() faster)

  // Scale and compute the shift for the matrix ( i= [j]1;   [1i+
  RealScalar        [=col_vals)
forIndex;<; +)
  {
    for 
k =(*(rowIdx
    eigen_internal_assert(rowIdx[        +java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
mindiag ::(numext([colPtr],mindiagjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
  }

  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  RealScalar shiftm_info=Success
      
    hiftm_initialShift-mindiag;

  m_info

/  toperform the the  shift
  int iter = 0;
do
  {
    // Apply the shift to the diagonal elements of the matrix
    for (Index j =  if(jk  colPtr+))
      vals     p  colPtr+1  jkjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33

    // jki version of the Cholesky factorization
    Index j=0;
    for (; j    minpos += jk
    {
      // Left-looking factorization of the j-th column
      // First, load the j-th column into col_vals
      Scalar diag = vals[colPtr[j]];  // It is assumed that only the lower part is stored
      col_nnz = 0;
            std:(rowIdx)rowIdx));
{
        StorageIndex l = rowIdx[i];
            firstElt) ::convert_indexStorageIndex,Index>(,Index>(jk
col_irow)
        col_pattern(l) = col_nnz;
        
      }
      {
        } // end namespace Eigen
        // Browse all previous columns that will update column j
        for(k = listCol[j].begin(); k != listCol[j].end(); k++)
        {
          Index jk = firstElt(*k); // First element to use in the column
          eigen_internal_assert(rowIdx[jk]==j);
          Scalar v_j_jk = numext::conj(vals[jk]);

          jk += 1;
          for (Index i = jk; i < colPtr[*k+1]; i++)
          {
            StorageIndex l = rowIdx[i];
            if(col_pattern[l]<0)
            {
              col_vals(col_nnz) = vals[i] * v_j_jk;
              col_irow[col_nnz] = l;
              col_pattern(l) = col_nnz;
              col_nnz++;
            }
            else
              col_vals(col_pattern[l]) -= vals[i] * v_j_jk;
          }
          updateList(colPtr,rowIdx,vals, *k, jk, firstElt, listCol);
        }
      }

      // Scale the current column
      if(numext::real(diag) <= 0)
      {
        if(++iter>=10)
          return;

        // increase shift
        shift = numext::maxi(m_initialShift,RealScalar(2)*shift);
        // restore m_L, col_pattern, and listCol
        vals = Map<const VectorSx>(L_save.valuePtr(), nnz);
        rowIdx = Map<const VectorIx>(L_save.innerIndexPtr(), nnz);
        colPtr = Map<const VectorIx>(L_save.outerIndexPtr(), n+1);
        col_pattern.fill(-1);
        for(Index i=0; i<n; ++i)
          listCol[i].clear();

        break;
      }

      RealScalar rdiag = sqrt(numext::real(diag));
      vals[colPtr[j]] = rdiag;
      for (Index k = 0; k<col_nnz; ++k)
      {
        Index i = col_irow[k];
        //Scale
        col_vals(k) /= rdiag;
        //Update the remaining diagonals with col_vals
        vals[colPtr[i]] -= numext::abs2(col_vals(k));
      }
      // Select the largest p elements
      // p is the original number of elements in the column (without the diagonal)
      Index p = colPtr[j+1] - colPtr[j] - 1 ;
      Ref<VectorSx> cvals = col_vals.head(col_nnz);
      Ref<VectorIx> cirow = col_irow.head(col_nnz);
      internal::QuickSplit(cvals,cirow, p);
      // Insert the largest p elements in the matrix
      Index cpt = 0;
      for (Index i = colPtr[j]+1; i < colPtr[j+1]; i++)
      {
        vals[i] = col_vals(cpt);
        rowIdx[i] = col_irow(cpt);
        // restore col_pattern:
        col_pattern(col_irow(cpt)) = -1;
        cpt++;
      }
      // Get the first smallest row index and put it after the diagonal element
      Index jk = colPtr(j)+1;
      updateList(colPtr,rowIdx,vals,j,jk,firstElt,listCol);
    }

    if(j==n)
    {
      m_factorizationIsOk = true;
      m_info = Success;
    }
  } while(m_info!=Success);
}

template<typename Scalar, int _UpLo, typename OrderingType>
inline void IncompleteCholesky<Scalar,_UpLo, OrderingType>::updateList(Ref<const VectorIx> colPtr, Ref<VectorIx> rowIdx, Ref<VectorSx> vals, const Index& col, const Index& jk, VectorIx& firstElt, VectorList& listCol)
{
  if (jk < colPtr(col+1) )
  {
    Index p = colPtr(col+1) - jk;
    Index minpos;
    rowIdx.segment(jk,p).minCoeff(&minpos);
    minpos += jk;
    if (rowIdx(minpos) != rowIdx(jk))
    {
      //Swap
      std::swap(rowIdx(jk),rowIdx(minpos));
      std::swap(vals(jk),vals(minpos));
    }
    firstElt(col) = internal::convert_index<StorageIndex,Index>(jk);
    listCol[rowIdx(jk)].push_back(internal::convert_index<StorageIndex,Index>(col));
  }
}

// end namespace Eigen

#endif

76%


¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.8Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.