IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Décomposition de Cholesky


Sujet :

C++

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 34
    Points : 22
    Points
    22
    Par défaut Décomposition de Cholesky
    Hello,

    Je suis un débutant en c++ qui cherche à calculer la racine carrée d'une matrice par la décomposition de Cholesky.
    J'ai trouvé une bibliothèque qui fournit une fonction Cholesky. http://www.robertnz.net/download.html.
    Cette fonction demande en paramètre une matrice de variance-covariance de type const SymmetricMatrix&.
    C'est la que ça coince, je n'arrive pas à construire la classe SymmetricMatrix (ça pourra également coincer plus tard mais je n'en suis qu'au début). Lorsque j'essaie de mettre des données dans la matrice de type const SymmetricMatrix, j'ai droit à plusieurs erreurs.


    Erreur 1:

    'initializing' : cannot convert from 'int' to 'SymmetricMatrix &'


    Erreur 2:

    error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Correl' (or there is no acceptable conversion)

    Avec ces suggestions:

    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(520): could be 'void GeneralMatrix::operator <<(const double *)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(521): or 'void GeneralMatrix::operator <<(const float *)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(522): or 'void GeneralMatrix::operator <<(const int *)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(523): or 'void GeneralMatrix::operator <<(const BaseMatrix &)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(576): or 'MatrixInput GeneralMatrix::operator <<(double)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(577): or 'MatrixInput GeneralMatrix::operator <<(float)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(578): or 'MatrixInput GeneralMatrix::operator <<(int)'
    1> while trying to match the argument list '(SymmetricMatrix, Correl)'
    1>h:\vba appl\alpha_project\alpha_project\alpha_project.cpp(36) :


    Erreur 3:
    error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Correl' (or there is no acceptable conversion)

    Avec ces suggestions:


    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(633): could be 'void Matrix::operator =(const BaseMatrix &)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(634): or 'void Matrix::operator =(Real)'
    1> c:\program files\microsoft visual studio 8\vc\include\newmat.h(635): or 'void Matrix::operator =(const Matrix &)'
    1> while trying to match the argument list '(Matrix, Correl)'
    1>Build log was saved at "file://h:\VBA appl\Alpha_Project\Alpha_Project\Debug\BuildLog.htm"
    1>Alpha_Project - 3 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     
     
    #include "stdafx.h"
    #include "newmatap.h"
    #include <math.h>
    #include <vector>
    #include <iostream>
     
     
    class Correl
    {
    public:
    	double Input[2][2];
        Correl(double covx, double covyx, double covxy, double covyy)
    	{
    		Input[0][0]=covx;
    		Input[0][1]=covyx;
                  	Input[1][0]=covxy;
                              Input[1][1]=covyy;
        }
    };
     
    int _tmain(int argc, _TCHAR* argv[])
    {
     
     
     
    	Correl PourTruc(1,1,1,1);
                  Matrix lb(2,2);
     
    	SymmetricMatrix& Truc(2);
    	Truc << PourTruc;
                 lb=PourTruc;
    	return 0;
    }


    En gros mon problème est comment passer en paramètres la matrice d'input.
    Si quelqu'un à une solution qui passe par une autre voie que la librairy newmat, je suis également preneur...


    Merci par avance,

  2. #2
    Membre confirmé Avatar de themadmax
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    446
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 446
    Points : 496
    Points
    496
    Par défaut
    Trop de fichier dans ta lib. Donne nous la definition et le code de la class SymmetricMatrix ( ou SMatrix )
    ________________________________________________
    http://bliquid.fr : Blog sur Android et l'Acer Liquid

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 34
    Points : 22
    Points
    22
    Par défaut
    Voici le code de SymmetricMatrix....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
     
    class SymmetricMatrix : public GeneralMatrix
    {
       GeneralMatrix* Image() const;                // copy of matrix
    public:
       SymmetricMatrix() {}
       ~SymmetricMatrix() {}
       SymmetricMatrix(ArrayLengthSpecifier);
       SymmetricMatrix(const BaseMatrix&);
       void operator=(const BaseMatrix&);
       void operator=(Real f) { GeneralMatrix::operator=(f); }
       void operator=(const SymmetricMatrix& m) { Eq(m); }
       Real& operator()(int, int);                  // access element
       Real& element(int, int);                     // access element
       Real operator()(int, int) const;             // access element
       Real element(int, int) const;                // access element
    #ifdef SETUP_C_SUBSCRIPTS
       Real* operator[](int m) { return store+(m*(m+1))/2; }
       const Real* operator[](int m) const { return store+(m*(m+1))/2; }
    #endif
       MatrixType type() const;
       SymmetricMatrix(const SymmetricMatrix& gm)
          : GeneralMatrix() { GetMatrix(&gm); }
       Real sum_square() const;
       Real sum_absolute_value() const;
       Real sum() const;
       Real trace() const;
       void GetRow(MatrixRowCol&);
       void GetCol(MatrixRowCol&);
       void GetCol(MatrixColX&);
       void RestoreCol(MatrixRowCol&) {}
       void RestoreCol(MatrixColX&);
       GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
       void resize(int);                           // change dimensions
       void ReSize(int m) { resize(m); }
       void resize_keep(int);
       void resize(const GeneralMatrix& A);
       void ReSize(const GeneralMatrix& A) { resize(A); }
       void operator+=(const SymmetricMatrix& M) { PlusEqual(M); }
       void operator-=(const SymmetricMatrix& M) { MinusEqual(M); }
       void operator+=(Real f) { GeneralMatrix::Add(f); }
       void operator-=(Real f) { GeneralMatrix::Add(-f); }
       void swap(SymmetricMatrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); }
       NEW_DELETE(SymmetricMatrix)
    };

    La classe SymmetricMatrix hérite de la classe GeneralMatrix
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
     
     
    class GeneralMatrix : public BaseMatrix         // declarable matrix types
    {
       virtual GeneralMatrix* Image() const;        // copy of matrix
    protected:
       int tag_val;                                 // shows whether can reuse
       int nrows_val, ncols_val;                    // dimensions
       int storage;                                 // total store required
       Real* store;                                 // point to store (0=not set)
       GeneralMatrix();                             // initialise with no store
       GeneralMatrix(ArrayLengthSpecifier);         // constructor getting store
       void Add(GeneralMatrix*, Real);              // sum of GM and Real
       void Add(Real);                              // add Real to this
       void NegAdd(GeneralMatrix*, Real);           // Real - GM
       void NegAdd(Real);                           // this = this - Real
       void Multiply(GeneralMatrix*, Real);         // product of GM and Real
       void Multiply(Real);                         // multiply this by Real
       void Negate(GeneralMatrix*);                 // change sign
       void Negate();                               // change sign
       void ReverseElements();                      // internal reverse of elements
       void ReverseElements(GeneralMatrix*);        // reverse order of elements
       void operator=(Real);                        // set matrix to constant
       Real* GetStore();                            // get store or copy
       GeneralMatrix* BorrowStore(GeneralMatrix*, MatrixType);
                                                    // temporarily access store
       void GetMatrix(const GeneralMatrix*);        // used by = and initialise
       void Eq(const BaseMatrix&, MatrixType);      // used by =
       void Eq(const GeneralMatrix&);               // version with no conversion
       void Eq(const BaseMatrix&, MatrixType, bool);// used by <<
       void Eq2(const BaseMatrix&, MatrixType);     // cut down version of Eq
       int search(const BaseMatrix*) const;
       virtual GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
       void CheckConversion(const BaseMatrix&);     // check conversion OK
       void resize(int, int, int);                  // change dimensions
       virtual short SimpleAddOK(const GeneralMatrix*) { return 0; }
                 // see bandmat.cpp for explanation
       virtual void MiniCleanUp()
          { store = 0; storage = 0; nrows_val = 0; ncols_val = 0; tag_val = -1;}
                 // CleanUp when the data array has already been deleted
       void PlusEqual(const GeneralMatrix& gm);
       void MinusEqual(const GeneralMatrix& gm);
       void PlusEqual(Real f);
       void MinusEqual(Real f);
       void swap(GeneralMatrix& gm);                // swap values
    public:
       GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
       virtual MatrixType type() const = 0;         // type of a matrix
       MatrixType Type() const { return type(); }
       int Nrows() const { return nrows_val; }      // get dimensions
       int Ncols() const { return ncols_val; }
       int Storage() const { return storage; }
       Real* Store() const { return store; }
       // updated names
       int nrows() const { return nrows_val; }      // get dimensions
       int ncols() const { return ncols_val; }
       int size() const { return storage; }
       Real* data() { return store; }
       const Real* data() const { return store; }
       const Real* const_data() const { return store; }
       virtual ~GeneralMatrix();                    // delete store if set
       void tDelete();                              // delete if tag_val permits
       bool reuse();                                // true if tag_val allows reuse
       void protect() { tag_val=-1; }               // cannot delete or reuse
       void Protect() { tag_val=-1; }               // cannot delete or reuse
       int tag() const { return tag_val; }
       int Tag() const { return tag_val; }
       bool is_zero() const;                        // test matrix has all zeros
       bool IsZero() const { return is_zero(); }    // test matrix has all zeros
       void Release() { tag_val=1; }                // del store after next use
       void Release(int t) { tag_val=t; }           // del store after t accesses
       void ReleaseAndDelete() { tag_val=0; }       // delete matrix after use
       void release() { tag_val=1; }                // del store after next use
       void release(int t) { tag_val=t; }           // del store after t accesses
       void release_and_delete() { tag_val=0; }     // delete matrix after use
       void operator<<(const double*);              // assignment from an array
       void operator<<(const float*);               // assignment from an array
       void operator<<(const int*);                 // assignment from an array
       void operator<<(const BaseMatrix& X)
          { Eq(X,this->type(),true); }              // = without checking type
       void inject(const GeneralMatrix&);           // copy stored els only
       void Inject(const GeneralMatrix& GM) { inject(GM); }
       void operator+=(const BaseMatrix&);
       void operator-=(const BaseMatrix&);
       void operator*=(const BaseMatrix&);
       void operator|=(const BaseMatrix&);
       void operator&=(const BaseMatrix&);
       void operator+=(Real);
       void operator-=(Real r) { operator+=(-r); }
       void operator*=(Real);
       void operator/=(Real r) { operator*=(1.0/r); }
       virtual GeneralMatrix* MakeSolver();         // for solving
       virtual void Solver(MatrixColX&, const MatrixColX&) {}
       virtual void GetRow(MatrixRowCol&) = 0;      // Get matrix row
       virtual void RestoreRow(MatrixRowCol&) {}    // Restore matrix row
       virtual void NextRow(MatrixRowCol&);         // Go to next row
       virtual void GetCol(MatrixRowCol&) = 0;      // Get matrix col
       virtual void GetCol(MatrixColX&) = 0;        // Get matrix col
       virtual void RestoreCol(MatrixRowCol&) {}    // Restore matrix col
       virtual void RestoreCol(MatrixColX&) {}      // Restore matrix col
       virtual void NextCol(MatrixRowCol&);         // Go to next col
       virtual void NextCol(MatrixColX&);           // Go to next col
       Real sum_square() const;
       Real sum_absolute_value() const;
       Real sum() const;
       Real maximum_absolute_value1(int& i) const;
       Real minimum_absolute_value1(int& i) const;
       Real maximum1(int& i) const;
       Real minimum1(int& i) const;
       Real maximum_absolute_value() const;
       Real maximum_absolute_value2(int& i, int& j) const;
       Real minimum_absolute_value() const;
       Real minimum_absolute_value2(int& i, int& j) const;
       Real maximum() const;
       Real maximum2(int& i, int& j) const;
       Real minimum() const;
       Real minimum2(int& i, int& j) const;
       LogAndSign log_determinant() const;
       virtual bool IsEqual(const GeneralMatrix&) const;
                                                    // same type, same values
       void CheckStore() const;                     // check store is non-zero
       virtual void SetParameters(const GeneralMatrix*) {}
                                                    // set parameters in GetMatrix
       operator ReturnMatrix() const;               // for building a ReturnMatrix
       ReturnMatrix for_return() const;
       ReturnMatrix ForReturn() const;
       //virtual bool SameStorageType(const GeneralMatrix& A) const;
       //virtual void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
       //virtual void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
       virtual void resize(const GeneralMatrix& A);
       virtual void ReSize(const GeneralMatrix& A) { resize(A); }
       MatrixInput operator<<(double);                // for loading a list
       MatrixInput operator<<(float);                // for loading a list
       MatrixInput operator<<(int f);
    //   ReturnMatrix Reverse() const;                // reverse order of elements
       void cleanup();                              // to clear store
     
       friend class Matrix;
       friend class SquareMatrix;
       friend class nricMatrix;
       friend class SymmetricMatrix;
       friend class UpperTriangularMatrix;
       friend class LowerTriangularMatrix;
       friend class DiagonalMatrix;
       friend class CroutMatrix;
       friend class RowVector;
       friend class ColumnVector;
       friend class BandMatrix;
       friend class LowerBandMatrix;
       friend class UpperBandMatrix;
       friend class SymmetricBandMatrix;
       friend class BaseMatrix;
       friend class AddedMatrix;
       friend class MultipliedMatrix;
       friend class SubtractedMatrix;
       friend class SPMatrix;
       friend class KPMatrix;
       friend class ConcatenatedMatrix;
       friend class StackedMatrix;
       friend class SolvedMatrix;
       friend class ShiftedMatrix;
       friend class NegShiftedMatrix;
       friend class ScaledMatrix;
       friend class TransposedMatrix;
       friend class ReversedMatrix;
       friend class NegatedMatrix;
       friend class InvertedMatrix;
       friend class RowedMatrix;
       friend class ColedMatrix;
       friend class DiagedMatrix;
       friend class MatedMatrix;
       friend class GetSubMatrix;
       friend class ReturnMatrix;
       friend class LinearEquationSolver;
       friend class GenericMatrix;
       NEW_DELETE(GeneralMatrix)
    };
    Cette classe hérite à son tour d'une classe Janitor... Comme ça continue ainsi de suite de classes en classes, j'attends de savoir tu as besoin d'autres éléments.
    Merci de ton aide,
    @+
    Merci pour ton aide...

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    43
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 43
    Points : 32
    Points
    32
    Par défaut
    Ben il faut que tu utilise ce constructeur je crois :
    "SymmetricMatrix(const BaseMatrix&);"
    A toi de chercher comment on crée un "BaseMatrix".

  5. #5
    Membre confirmé Avatar de themadmax
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    446
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 446
    Points : 496
    Points
    496
    Par défaut
    L'opérateur << n'a pas l'air d'etre implementer dans la class SymmetricMatrix.
    Pour setter les valeurs de ta matrice SymmetricMatrix du doit utiliser le constructeur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SymmetricMatrix(const BaseMatrix&);
    Maitenant il te reste a savoir comment setter les valeurs d'une BaseMatrix...
    Mais il me semble que tu ne dois pas declarer toi meme faire une class Matrix (Correl dans ton cas)
    ________________________________________________
    http://bliquid.fr : Blog sur Android et l'Acer Liquid

Discussions similaires

  1. Décomposition de cholesky sous SAS
    Par carine bebe dans le forum SAS STAT
    Réponses: 0
    Dernier message: 09/04/2014, 10h55
  2. Réponses: 5
    Dernier message: 31/05/2007, 12h46
  3. Décomposition d'une chaine de caractères
    Par stephdiplo150 dans le forum C
    Réponses: 3
    Dernier message: 04/03/2004, 22h50
  4. Décomposition RGB
    Par Claythest dans le forum Langage
    Réponses: 3
    Dernier message: 16/06/2003, 11h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo