Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.3.0/ALGLIB-2.3.0/spddet.cs @ 5955

Last change on this file since 5955 was 2806, checked in by gkronber, 15 years ago

Added plugin for new version of ALGLIB. #875 (Update ALGLIB sources)

File size: 3.3 KB
Line 
1/*************************************************************************
2Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
3
4>>> SOURCE LICENSE >>>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation (www.fsf.org); either version 2 of the
8License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15A copy of the GNU General Public License is available at
16http://www.fsf.org/licensing/licenses
17
18>>> END OF LICENSE >>>
19*************************************************************************/
20
21using System;
22
23namespace alglib
24{
25    public class spddet
26    {
27        /*************************************************************************
28        Determinant calculation of the matrix given by the Cholesky decomposition.
29
30        Input parameters:
31            A   -   Cholesky decomposition,
32                    output of SMatrixCholesky subroutine.
33            N   -   size of matrix A.
34
35        As the determinant is equal to the product of squares of diagonal elements,
36        it’s not necessary to specify which triangle - lower or upper - the matrix
37        is stored in.
38
39        Result:
40            matrix determinant.
41
42          -- ALGLIB --
43             Copyright 2005-2008 by Bochkanov Sergey
44        *************************************************************************/
45        public static double spdmatrixcholeskydet(ref double[,] a,
46            int n)
47        {
48            double result = 0;
49            int i = 0;
50
51            result = 1;
52            for(i=0; i<=n-1; i++)
53            {
54                result = result*AP.Math.Sqr(a[i,i]);
55            }
56            return result;
57        }
58
59
60        /*************************************************************************
61        Determinant calculation of the symmetric positive definite matrix.
62
63        Input parameters:
64            A       -   matrix. Array with elements [0..N-1, 0..N-1].
65            N       -   size of matrix A.
66            IsUpper -   if IsUpper = True, then the symmetric matrix A is given by
67                        its upper triangle, and the lower triangle isn’t used by
68                        subroutine. Similarly, if IsUpper = False, then A is given
69                        by its lower triangle.
70
71        Result:
72            determinant of matrix A.
73            If matrix A is not positive definite, then subroutine returns -1.
74
75          -- ALGLIB --
76             Copyright 2005-2008 by Bochkanov Sergey
77        *************************************************************************/
78        public static double spdmatrixdet(double[,] a,
79            int n,
80            bool isupper)
81        {
82            double result = 0;
83
84            a = (double[,])a.Clone();
85
86            if( !trfac.spdmatrixcholesky(ref a, n, isupper) )
87            {
88                result = -1;
89            }
90            else
91            {
92                result = spdmatrixcholeskydet(ref a, n);
93            }
94            return result;
95        }
96    }
97}
Note: See TracBrowser for help on using the repository browser.