Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Functions/builtin/rank.cs @ 9407

Last change on this file since 9407 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 8.9 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using ILNumerics.Storage;
44using ILNumerics.Misc;
45using ILNumerics.Exceptions;
46
47namespace ILNumerics  {
48    public partial class ILMath {
49
50
51
52
53        /// <summary>
54        /// Rank of matrix A
55        /// </summary>
56        /// <param name="A">Input matrix</param>
57        /// <param name="tolerance">[Optional]Tolerance used to decide, if a singular value is
58        /// treated as zero. If a value &lt; 0 is specified the tolerance will be determined automatically (see below - default = -1.0)</param>
59        /// <returns>Rank of matrix A</returns>
60        /// <remarks>The rank is the number of singular values greater than
61        /// tolerance. If tolerance is smaller than zero, the following equation is used as
62        /// default: \\
63        /// tol = length(A) * norm(A) * MachineParameterDouble.epsilon \\
64        /// with
65        /// <list type="bullet">
66        /// <item>length(A) - the longest dimension of A</item>
67        /// <item>norm(A) being the largest singular value of A, </item>
68        /// <item>MachineParameterDouble.eps - the distance between 1 and the smallest next greater value</item>
69        /// </list>
70        /// </remarks>
71        public static ILRetArray< double> rank( ILInArray< double> A, double tolerance = -1.0 ) {
72            using (ILScope.Enter(A)) {
73                if (A.Size.NumberOfDimensions > 2)
74                    throw new ILArgumentSizeException("The input array must be matrix or vector");
75                ILArray< double> ret = svd(A);
76                if (tolerance < 0) {
77                    tolerance = A.Size.Longest * max(ret).GetValue(0) *  MachineParameterDouble.eps;
78                }
79                // count vector elements: ret is vector returned from svd
80                return find(ret > ( double)tolerance).Length;
81            }
82        }
83
84#region HYCALPER AUTO GENERATED CODE
85
86
87
88        /// <summary>
89        /// Rank of matrix A
90        /// </summary>
91        /// <param name="A">Input matrix</param>
92        /// <param name="tolerance">[Optional]Tolerance used to decide, if a singular value is
93        /// treated as zero. If a value &lt; 0 is specified the tolerance will be determined automatically (see below - default = -1.0)</param>
94        /// <returns>Rank of matrix A</returns>
95        /// <remarks>The rank is the number of singular values greater than
96        /// tolerance. If tolerance is smaller than zero, the following equation is used as
97        /// default: \\
98        /// tol = length(A) * norm(A) * MachineParameterDouble.epsilon \\
99        /// with
100        /// <list type="bullet">
101        /// <item>length(A) - the longest dimension of A</item>
102        /// <item>norm(A) being the largest singular value of A, </item>
103        /// <item>MachineParameterDouble.eps - the distance between 1 and the smallest next greater value</item>
104        /// </list>
105        /// </remarks>
106        public static ILRetArray< float> rank( ILInArray< fcomplex> A, double tolerance = -1.0 ) {
107            using (ILScope.Enter(A)) {
108                if (A.Size.NumberOfDimensions > 2)
109                    throw new ILArgumentSizeException("The input array must be matrix or vector");
110                ILArray< float> ret = svd(A);
111                if (tolerance < 0) {
112                    tolerance = A.Size.Longest * max(ret).GetValue(0) *  MachineParameterSingle.eps;
113                }
114                // count vector elements: ret is vector returned from svd
115                return find(ret > ( float)tolerance).Length;
116            }
117        }
118
119
120        /// <summary>
121        /// Rank of matrix A
122        /// </summary>
123        /// <param name="A">Input matrix</param>
124        /// <param name="tolerance">[Optional]Tolerance used to decide, if a singular value is
125        /// treated as zero. If a value &lt; 0 is specified the tolerance will be determined automatically (see below - default = -1.0)</param>
126        /// <returns>Rank of matrix A</returns>
127        /// <remarks>The rank is the number of singular values greater than
128        /// tolerance. If tolerance is smaller than zero, the following equation is used as
129        /// default: \\
130        /// tol = length(A) * norm(A) * MachineParameterDouble.epsilon \\
131        /// with
132        /// <list type="bullet">
133        /// <item>length(A) - the longest dimension of A</item>
134        /// <item>norm(A) being the largest singular value of A, </item>
135        /// <item>MachineParameterDouble.eps - the distance between 1 and the smallest next greater value</item>
136        /// </list>
137        /// </remarks>
138        public static ILRetArray< float> rank( ILInArray< float> A, double tolerance = -1.0 ) {
139            using (ILScope.Enter(A)) {
140                if (A.Size.NumberOfDimensions > 2)
141                    throw new ILArgumentSizeException("The input array must be matrix or vector");
142                ILArray< float> ret = svd(A);
143                if (tolerance < 0) {
144                    tolerance = A.Size.Longest * max(ret).GetValue(0) *  MachineParameterSingle.eps;
145                }
146                // count vector elements: ret is vector returned from svd
147                return find(ret > ( float)tolerance).Length;
148            }
149        }
150
151
152        /// <summary>
153        /// Rank of matrix A
154        /// </summary>
155        /// <param name="A">Input matrix</param>
156        /// <param name="tolerance">[Optional]Tolerance used to decide, if a singular value is
157        /// treated as zero. If a value &lt; 0 is specified the tolerance will be determined automatically (see below - default = -1.0)</param>
158        /// <returns>Rank of matrix A</returns>
159        /// <remarks>The rank is the number of singular values greater than
160        /// tolerance. If tolerance is smaller than zero, the following equation is used as
161        /// default: \\
162        /// tol = length(A) * norm(A) * MachineParameterDouble.epsilon \\
163        /// with
164        /// <list type="bullet">
165        /// <item>length(A) - the longest dimension of A</item>
166        /// <item>norm(A) being the largest singular value of A, </item>
167        /// <item>MachineParameterDouble.eps - the distance between 1 and the smallest next greater value</item>
168        /// </list>
169        /// </remarks>
170        public static ILRetArray< double> rank( ILInArray< complex> A, double tolerance = -1.0 ) {
171            using (ILScope.Enter(A)) {
172                if (A.Size.NumberOfDimensions > 2)
173                    throw new ILArgumentSizeException("The input array must be matrix or vector");
174                ILArray< double> ret = svd(A);
175                if (tolerance < 0) {
176                    tolerance = A.Size.Longest * max(ret).GetValue(0) *  MachineParameterDouble.eps;
177                }
178                // count vector elements: ret is vector returned from svd
179                return find(ret > ( double)tolerance).Length;
180            }
181        }
182
183#endregion HYCALPER AUTO GENERATED CODE
184
185    }
186}
Note: See TracBrowser for help on using the repository browser.