Changeset 751


Ignore:
Timestamp:
Feb 17, 2007, 1:25:36 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #2. Continued adding GSL_error exceptions.

Location:
trunk/yat
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/regression/MultiDimensional.h

    r739 r751  
    5656    const utility::matrix& covariance(void) const;
    5757
    58     ///
    59     /// Function fitting parameters of the linear model by miminizing
    60     /// the quadratic deviation between model and data.
    61     ///
     58    /**
     59       \brief Function fitting parameters of the linear model by
     60       miminizing the quadratic deviation between model and data.
     61
     62       \throw A GSL_error exception is thrown if memory allocation
     63       fails or the underlying GSL calls fails (usually matrix
     64       dimension errors).
     65    */
    6266    void fit(const utility::matrix& X, const utility::vector& y);
    6367
  • trunk/yat/regression/MultiDimensionalWeighted.h

    r741 r751  
    5656    double chisq(void) const;
    5757
    58     ///
    59     /// @see gsl_multifit_wlinear
    60     ///
     58    /**
     59       \see gsl_multifit_wlinear
     60
     61       \throw A GSL_error exception is thrown if memory allocation
     62       fails or the underlying GSL calls fails (usually matrix
     63       dimension errors).
     64    */
    6165    void fit(const utility::matrix& X, const utility::vector& y,
    6266             const utility::vector& w);
  • trunk/yat/utility/Exception.h

    r750 r751  
    5353
    5454    inline GSL_error(std::string message, int gsl_status) throw()
    55       : std::runtime_error("GSL_error: " + message + gsl_strerror(gsl_status)) {}
     55      : std::runtime_error("GSL_error: " + message + " " +
     56                           gsl_strerror(gsl_status)) {}
    5657  };
    5758
  • trunk/yat/utility/SVD.cc

    r719 r751  
    2323
    2424#include "SVD.h"
     25#include <sstream>
    2526
    2627namespace theplu {
     
    4041
    4142
    42   int SVD::decompose(SVDalgorithm algo)
     43  void SVD::decompose(SVDalgorithm algo)
    4344  {
     45    int status=0;
    4446    switch (algo) {
    45         case GolubReinsch:
    46           return golub_reinsch();
    47         case ModifiedGolubReinsch:
    48           return modified_golub_reinsch();
    49         case Jacobi:
    50           return jacobi();
     47    case GolubReinsch:
     48      status=golub_reinsch();
     49      break;
     50    case ModifiedGolubReinsch:
     51      status=modified_golub_reinsch();
     52      break;
     53    case Jacobi:
     54      status=jacobi();
     55      break;
     56    default:
     57      std::stringstream ss("SVD::decompose ");
     58      ss << algo << " is not a valid SVDalgorithm";
     59      throw GSL_error(ss.str());
    5160    }
    52     // Jari, the program should never end up here, return values should be
    53     // something different from normal GSL return values, or maybe
    54     // throw an exception.
    55     return 0;
     61    if (status)
     62      throw utility::GSL_error(std::string("SVD::decompose",status));
    5663  }
    5764
     
    8895
    8996
    90   int SVD::solve(const utility::vector& b, utility::vector& x)
     97  void SVD::solve(const utility::vector& b, utility::vector& x)
    9198  {
    92     return gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
    93                                s_.gsl_vector_p(), b.gsl_vector_p(),
    94                                x.gsl_vector_p());
     99    int status=gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
     100                                   s_.gsl_vector_p(), b.gsl_vector_p(),
     101                                   x.gsl_vector_p());
     102    if (status)
     103      throw utility::GSL_error(std::string("SVD::solve",status));
    95104  }
    96105
  • trunk/yat/utility/SVD.h

    r719 r751  
    3434namespace utility {
    3535
    36   // Jari check that interface is complete
    37 
    3836  /**
    3937     Class encapsulating GSL methods for singular value decomposition,
     
    4745     V = Orthogonal matrix, size NxN\n
    4846  */
    49 
    5047  class SVD
    5148  {
    5249  public:
    5350
    54     ///
    55     /// A number of SVD algorithms are implemented in GSL. They have
    56     /// their strengths and weaknesses, check the GSL documentation.
    57     ///
    58     /// There are restrictions on the matrix dimensions depending on
    59     /// which SVD algorithm is used. From the GSL's SVD source code
    60     /// one finds that the Golub-Reinsch algorithm implementation will
    61     /// not work on matrices with fewer rows than columns, the same is
    62     /// also true for the modified Golub-Reinsch algorithm.
    63     ///
    64     /// @see GSL's SVD documentation.
    65     ///
     51    /**
     52      A number of SVD algorithms are implemented in GSL. They have
     53      their strengths and weaknesses, check the GSL documentation.
     54   
     55      There are restrictions on the matrix dimensions depending on
     56       which SVD algorithm is used. From the GSL's SVD source code one
     57       finds that the Golub-Reinsch algorithm implementation will not
     58       work on matrices with fewer rows than columns, the same is also
     59      true for the modified Golub-Reinsch algorithm.
     60   
     61       \see GSL's SVD documentation.
     62    */
    6663    enum SVDalgorithm {
    6764      GolubReinsch,
     
    7067    };
    7168
    72     ///
    73     /// Constructs an SVD object using the matrix Ain as only input. The
    74     /// input matrix is copied for further use in the object.
    75     ///
     69    /**
     70       \brief Constructs an SVD object using the matrix Ain as only
     71       input. The input matrix is copied for further use in the
     72       object.
     73    */
    7674    SVD(const utility::matrix& Ain);
    7775
    78     ///
    79     /// @brief The destructor
    80     ///
     76    /**
     77       \brief The destructor
     78    */
    8179    ~SVD(void);
    8280
    83     ///
    84     /// This function will perform SVD with the method specified by \a
    85     /// algo.
    86     ///
    87     /// @return Whatever GSL returns.
    88     ///
    89     int decompose(SVDalgorithm algo=GolubReinsch);
     81    /**
     82       \brief This function will perform SVD with the method specified
     83       by \a algo.
    9084
    91     ///
    92     /// @brief Access to the s vector.
    93     ///
    94     /// @return A copy of the s vector.
    95     ///
    96     /// @note If decompose() has not been run the outcome of the call
    97     /// is undefined.
    98     ///
     85       \throw GSL_error if the underlying GSL function fails.
     86    */
     87    void decompose(SVDalgorithm algo=GolubReinsch);
     88
     89    /**
     90       \brief Access to the s vector.
     91
     92       \return A copy of the s vector.
     93
     94       \note If decompose() has not been run the outcome of the call
     95       is undefined.
     96    */
    9997    const utility::vector& s(void) const;
    10098
    101     ///
    102     /// @brief Solve the system \f$ Ax=b \f$ using the decomposition
    103     /// of A.
    104     ///
    105     /// @note If decompose() has not been run the outcome of the call
    106     /// is undefined.
    107     ///
    108     /// @return Whatever GSL returns.
    109     ///
    110     int solve(const utility::vector& b, utility::vector& x);
     99    /**
     100       \brief Solve the system \f$ Ax=b \f$ using the decomposition of
     101       A.
    111102
    112     ///
    113     /// @brief Access to the U matrix.
    114     ///
    115     /// @return A copy of the U matrix.
    116     ///
    117     /// @note If decompose() has not been run the outcome of the call
    118     /// is undefined.
    119     ///
     103       \note If decompose() has not been run the outcome of the call
     104       is undefined.
     105
     106       \throw GSL_error if the underlying GSL function fails.
     107    */
     108    void solve(const utility::vector& b, utility::vector& x);
     109
     110    /**
     111       \brief Access to the U matrix.
     112
     113       \return A copy of the U matrix.
     114
     115       \note If decompose() has not been run the outcome of the call
     116       is undefined.
     117    */
    120118    const utility::matrix& U(void) const;
    121119
    122     ///
    123     /// @brief Access to the V matrix.
    124     ///
    125     /// @return A copy of the V matrix.
    126     ///
    127     /// @note If decompose() has not been run the outcome of the call
    128     /// is undefined.
    129     ///
     120    /**
     121       \brief Access to the V matrix.
     122
     123       \return A copy of the V matrix.
     124
     125       \note If decompose() has not been run the outcome of the call
     126      is undefined.
     127    */
    130128    const utility::matrix& V(void) const;
    131129
    132130  private:
     131    /**
     132       \brief Call GSL's Jacobi algorithm for SVD.
     133
     134       \return gsl_error status.
     135    */
    133136    int jacobi(void);
     137
     138    /**
     139       \brief Call GSL's Golub-Reinsch algorithm for SVD.
     140
     141       \return gsl_error status.
     142    */
    134143    int golub_reinsch(void);
     144
     145    /**
     146       \brief Call GSL's modified Golub-Reinch algorithm for SVD.
     147
     148       \return gsl_error status.
     149    */
    135150    int modified_golub_reinsch(void);
    136151
Note: See TracChangeset for help on using the changeset viewer.