From a35d0e90678144d894401016a978892fcb3954b6 Mon Sep 17 00:00:00 2001 From: Cesar Souza Date: Tue, 3 Dec 2013 20:12:50 +0100 Subject: [PATCH] Updating release notes. --- Release notes.txt | 58 +++++++ .../SingularValueDecomposition.cs | 128 +++++++++------ .../SingularValueDecomposition.tt | 139 ++++++++++++++-- .../SingularValueDecompositionF.cs | 151 ++++++++++++++++-- 4 files changed, 400 insertions(+), 76 deletions(-) diff --git a/Release notes.txt b/Release notes.txt index 4413e14ba..24795d5c5 100644 --- a/Release notes.txt +++ b/Release notes.txt @@ -1,3 +1,61 @@ +Accord.NET Framework 2.12b1 release notes +----------------------------------------- +06.12.2013. + +Version updates and fixes: + +* General + - The general focus for this release was again to improve + the documentation and provide standard bug-fixing; + - The project now also provides Debug binaries which be used + to provide more detailed information when debugging applications. + +* Accord.Controls + - Adding a WavechartBox control to display wavecharts with ease, in + the same way as MessageBox can display text messages on screen. + +* Accord.Audio + - Correcting WaveDecoder.AverageBytesPerSecond (Google Code #80); + - Correcting the creation of base audio windows; + - Adding the ExtractChannel filter for extracting single channels + from multiple-channel audio signals. + +* Accord.Statistics + - Adding generic base classes for probability distributions; + - Adding support for computing the cumulative multivariate normal + distribution function for specifically one and two dimensions; + - Correcting behavior of the Binomial test under .NET 4.5; + - Updating DescriptiveAnalysis to provide sums and confidence intervals; + - Updating ChiSquareTest to accept ConfusionMatrices as input; + - Unifying Univariate and Multivariate mixture distribution fitting + through Expectation-Maximization into a single and generic class; + - Updating the WeightedMean method to accept unnormalized weights; + - Updating the Codification filter to work without DataTables; + - Adding fitting options for empirical distributions (Google Code #66); + - Adding options to robustly fit Multivariate Normal Distributions using + the Singular Value Decomposition, avoiding non-positive definite issues. + +* Accord.MachineLearning + - GaussianMixtureModel now accepts a maximum number of iterations; + - Updating the KDTree class to provide a non-generic version when there + is no interest in the kind of values stored as information in the nodes; + - Adding specialized methods for when only the closest neighbor is needed + in a KDTree. Also adding options to provide only an approximate answer; + - Updating the K-Means algorithm to fully support parallel processing; + - Adding support for generating decision rules from Decision Trees. + +* Accord.Math + - Correcting InsertColumn and InsertRow implementations; + - Improving Submatrix creation to avoid extra memory allocations when desired; + - Reshape method for jagged arrays can now work with non-rectangular arrays; + - Correcting relative convergence issues with negative watched interest values; + - Adding Modulo and Modular distance for double-precision floating point inputs. + +* AForge Compatibility + - Compiled against AForge.NET Framework 2.2.5. May work with newer versions. + + + Accord.NET Framework 2.11.0 release notes ----------------------------------------- 27.10.2013. diff --git a/Sources/Accord.Math/Decompositions/SingularValueDecomposition.cs b/Sources/Accord.Math/Decompositions/SingularValueDecomposition.cs index 2c280037a..76ebd3614 100644 --- a/Sources/Accord.Math/Decompositions/SingularValueDecomposition.cs +++ b/Sources/Accord.Math/Decompositions/SingularValueDecomposition.cs @@ -32,6 +32,7 @@ namespace Accord.Math.Decompositions /// /// Singular Value Decomposition for a rectangular matrix. /// + /// /// /// /// For an m-by-n matrix A with m >= n, the singular value decomposition @@ -69,10 +70,10 @@ public sealed class SingularValueDecomposition : ICloneable, ISolverMatrixDecomp private const Double eps = 2 * Constants.DoubleEpsilon; private const Double tiny = Constants.DoubleSmall; - double? determinant; - double? lndeterminant; - double? pseudoDeterminant; - double? lnpseudoDeterminant; + Double? determinant; + Double? lndeterminant; + Double? pseudoDeterminant; + Double? lnpseudoDeterminant; /// /// Returns the condition number max(S) / min(S). @@ -102,11 +103,11 @@ public Double TwoNorm } /// - /// Returns the effective numerical matrix rank. - /// - /// + /// Returns the effective numerical matrix rank. + /// + /// /// Number of non-negligible singular values. - /// + /// public int Rank { get @@ -121,59 +122,71 @@ public int Rank } } - /// - /// Gets whether the decomposed matrix is singular. - /// - /// - public bool IsSingular + /// + /// Gets whether the decomposed matrix is singular. + /// + /// + public bool IsSingular { get { return Rank < Math.Min(m, n); } } /// - /// Gets the one-dimensional array of singular values. - /// - /// + /// Gets the one-dimensional array of singular values. + /// + /// public Double[] Diagonal { get { return this.s; } } - /// Returns the block diagonal matrix of singular values. + /// + /// Returns the block diagonal matrix of singular values. + /// + /// public Double[,] DiagonalMatrix { get { return Matrix.Diagonal(s); } } - /// Returns the V matrix of Singular Vectors. + /// + /// Returns the V matrix of Singular Vectors. + /// + /// public Double[,] RightSingularVectors { get { return v; } } - /// Returns the U matrix of Singular Vectors. + /// + /// Returns the U matrix of Singular Vectors. + /// + /// public Double[,] LeftSingularVectors { get { return u; } } - /// Returns the ordering in which the singular values have been sorted. + /// + /// Returns the ordering in which the singular values have been sorted. + /// + /// public int[] Ordering { get { return si; } } - /// + /// /// Returns the absolute value of the matrix determinant. /// /// - public double AbsoluteDeterminant + public Double AbsoluteDeterminant { get { if (!determinant.HasValue) { - double det = 1; + Double det = 1; for (int i = 0; i < s.Length; i++) det *= s[i]; determinant = det; @@ -187,7 +200,7 @@ public double AbsoluteDeterminant /// Returns the log of the absolute value for the matrix determinant. /// /// - public double LogDeterminant + public Double LogDeterminant { get { @@ -196,7 +209,7 @@ public double LogDeterminant double det = 0; for (int i = 0; i < s.Length; i++) det += Math.Log(s[i]); - lndeterminant = det; + lndeterminant = (Double)det; } return lndeterminant.Value; @@ -208,13 +221,13 @@ public double LogDeterminant /// Returns the pseudo-determinant for the matrix. /// /// - public double PseudoDeterminant + public Double PseudoDeterminant { get { if (!pseudoDeterminant.HasValue) { - double det = 1; + Double det = 1; for (int i = 0; i < s.Length; i++) if (s[i] != 0) det *= s[i]; pseudoDeterminant = det; @@ -228,7 +241,7 @@ public double PseudoDeterminant /// Returns the log of the pseudo-determinant for the matrix. /// /// - public double LogPseudoDeterminant + public Double LogPseudoDeterminant { get { @@ -237,7 +250,7 @@ public double LogPseudoDeterminant double det = 0; for (int i = 0; i < s.Length; i++) if (s[i] != 0) det += Math.Log(s[i]); - lnpseudoDeterminant = det; + lnpseudoDeterminant = (Double)det; } return lnpseudoDeterminant.Value; @@ -245,16 +258,23 @@ public double LogPseudoDeterminant } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. + /// public SingularValueDecomposition(Double[,] value) : this(value, true, true) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -265,12 +285,17 @@ public SingularValueDecomposition(Double[,] value) /// Pass if the right singular vector matrix V /// should be computed. Pass otherwise. Default /// is . - public SingularValueDecomposition(Double[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors) + /// + public SingularValueDecomposition(Double[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors) : this(value, computeLeftSingularVectors, computeRightSingularVectors, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -285,12 +310,17 @@ public SingularValueDecomposition(Double[,] value, bool computeLeftSingularVecto /// Pass to automatically transpose the value matrix in /// case JAMA's assumptions about the dimensionality of the matrix are violated. /// Pass otherwise. Default is . - public SingularValueDecomposition(Double[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) + /// + public SingularValueDecomposition(Double[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) : this(value, computeLeftSingularVectors, computeRightSingularVectors, autoTranspose, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -308,8 +338,10 @@ public SingularValueDecomposition(Double[,] value, bool computeLeftSingularVecto /// /// Pass to perform the decomposition in place. The matrix /// will be destroyed in the process, resulting in less - /// memory consumption. - public unsafe SingularValueDecomposition(Double[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) + /// memory comsumption. + /// + public unsafe SingularValueDecomposition(Double[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) { if (value == null) { @@ -320,11 +352,11 @@ public unsafe SingularValueDecomposition(Double[,] value, bool computeLeftSingul m = value.GetLength(0); // rows n = value.GetLength(1); // cols - if (m == 0 || n == 0) - { - throw new ArgumentException("Matrix does not have any rows or columns.", "value"); - } - + if (m == 0 || n == 0) + { + throw new ArgumentException("Matrix does not have any rows or columns.", "value"); + } + if (m < n) // Check if we are violating JAMA's assumption @@ -637,13 +669,13 @@ public unsafe SingularValueDecomposition(Double[,] value, bool computeLeftSingul // This section of the program inspects for // negligible elements in the s and e arrays. On - // completion the variables case and k are set as follows. + // completion the variables kase and k are set as follows. - // case = 1 if s(p) and e[k-1] are negligible and k

= -1; k--) { @@ -692,7 +724,7 @@ public unsafe SingularValueDecomposition(Double[,] value, bool computeLeftSingul k++; - // Perform the task indicated by case. + // Perform the task indicated by kase. switch (kase) { // Deflate negligible s(p). diff --git a/Sources/Accord.Math/Decompositions/SingularValueDecomposition.tt b/Sources/Accord.Math/Decompositions/SingularValueDecomposition.tt index 0c8d40853..c4bd7cfef 100644 --- a/Sources/Accord.Math/Decompositions/SingularValueDecomposition.tt +++ b/Sources/Accord.Math/Decompositions/SingularValueDecomposition.tt @@ -34,6 +34,7 @@ namespace Accord.Math.Decompositions ///

/// Singular Value Decomposition for a rectangular matrix. /// + /// /// /// /// For an m-by-n matrix A with m >= n, the singular value decomposition @@ -71,6 +72,11 @@ namespace Accord.Math.Decompositions private const <#=T#> eps = 2 * Constants.<#=T#>Epsilon; private const <#=T#> tiny = Constants.<#=T#>Small; + <#=T#>? determinant; + <#=T#>? lndeterminant; + <#=T#>? pseudoDeterminant; + <#=T#>? lnpseudoDeterminant; + /// /// Returns the condition number max(S) / min(S). /// @@ -136,42 +142,141 @@ namespace Accord.Math.Decompositions get { return this.s; } } - /// Returns the block diagonal matrix of singular values. + /// + /// Returns the block diagonal matrix of singular values. + /// + /// public <#=T#>[,] DiagonalMatrix { get { return Matrix.Diagonal(s); } } - /// Returns the V matrix of Singular Vectors. + /// + /// Returns the V matrix of Singular Vectors. + /// + /// public <#=T#>[,] RightSingularVectors { get { return v; } } - /// Returns the U matrix of Singular Vectors. + /// + /// Returns the U matrix of Singular Vectors. + /// + /// public <#=T#>[,] LeftSingularVectors { get { return u; } } - /// Returns the ordering in which the singular values have been sorted. + /// + /// Returns the ordering in which the singular values have been sorted. + /// + /// public int[] Ordering { get { return si; } } + /// + /// Returns the absolute value of the matrix determinant. + /// + /// + public <#=T#> AbsoluteDeterminant + { + get + { + if (!determinant.HasValue) + { + <#=T#> det = 1; + for (int i = 0; i < s.Length; i++) + det *= s[i]; + determinant = det; + } + + return determinant.Value; + } + } + + /// + /// Returns the log of the absolute value for the matrix determinant. + /// + /// + public <#=T#> LogDeterminant + { + get + { + if (!lndeterminant.HasValue) + { + double det = 0; + for (int i = 0; i < s.Length; i++) + det += Math.Log(s[i]); + lndeterminant = (<#=T#>)det; + } + + return lndeterminant.Value; + } + } - /// Constructs a new singular value decomposition. + /// + /// Returns the pseudo-determinant for the matrix. + /// + /// + public <#=T#> PseudoDeterminant + { + get + { + if (!pseudoDeterminant.HasValue) + { + <#=T#> det = 1; + for (int i = 0; i < s.Length; i++) + if (s[i] != 0) det *= s[i]; + pseudoDeterminant = det; + } + + return pseudoDeterminant.Value; + } + } + + /// + /// Returns the log of the pseudo-determinant for the matrix. + /// + /// + public <#=T#> LogPseudoDeterminant + { + get + { + if (!lnpseudoDeterminant.HasValue) + { + double det = 0; + for (int i = 0; i < s.Length; i++) + if (s[i] != 0) det += Math.Log(s[i]); + lnpseudoDeterminant = (<#=T#>)det; + } + + return lnpseudoDeterminant.Value; + } + } + + + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. + /// public SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value) : this(value, true, true) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -182,12 +287,17 @@ namespace Accord.Math.Decompositions /// Pass if the right singular vector matrix V /// should be computed. Pass otherwise. Default /// is . - public SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors) + /// + public SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors) : this(value, computeLeftSingularVectors, computeRightSingularVectors, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -202,12 +312,17 @@ namespace Accord.Math.Decompositions /// Pass to automatically transpose the value matrix in /// case JAMA's assumptions about the dimensionality of the matrix are violated. /// Pass otherwise. Default is . - public SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) + /// + public SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) : this(value, computeLeftSingularVectors, computeRightSingularVectors, autoTranspose, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -226,7 +341,9 @@ namespace Accord.Math.Decompositions /// Pass to perform the decomposition in place. The matrix /// will be destroyed in the process, resulting in less /// memory comsumption. - public unsafe SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) + /// + public unsafe SingularValueDecomposition<#=Suffix#>(<#=T#>[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) { if (value == null) { diff --git a/Sources/Accord.Math/Decompositions/SingularValueDecompositionF.cs b/Sources/Accord.Math/Decompositions/SingularValueDecompositionF.cs index a5d87bf3d..fa63868e6 100644 --- a/Sources/Accord.Math/Decompositions/SingularValueDecompositionF.cs +++ b/Sources/Accord.Math/Decompositions/SingularValueDecompositionF.cs @@ -32,6 +32,7 @@ namespace Accord.Math.Decompositions /// /// Singular Value Decomposition for a rectangular matrix. /// + /// /// /// /// For an m-by-n matrix A with m >= n, the singular value decomposition @@ -69,6 +70,11 @@ public sealed class SingularValueDecompositionF : ICloneable, ISolverMatrixDecom private const Single eps = 2 * Constants.SingleEpsilon; private const Single tiny = Constants.SingleSmall; + Single? determinant; + Single? lndeterminant; + Single? pseudoDeterminant; + Single? lnpseudoDeterminant; + /// /// Returns the condition number max(S) / min(S). /// @@ -134,42 +140,141 @@ public Single[] Diagonal get { return this.s; } } - /// Returns the block diagonal matrix of singular values. + /// + /// Returns the block diagonal matrix of singular values. + /// + /// public Single[,] DiagonalMatrix { get { return Matrix.Diagonal(s); } } - /// Returns the V matrix of Singular Vectors. + /// + /// Returns the V matrix of Singular Vectors. + /// + /// public Single[,] RightSingularVectors { get { return v; } } - /// Returns the U matrix of Singular Vectors. + /// + /// Returns the U matrix of Singular Vectors. + /// + /// public Single[,] LeftSingularVectors { get { return u; } } - /// Returns the ordering in which the singular values have been sorted. + /// + /// Returns the ordering in which the singular values have been sorted. + /// + /// public int[] Ordering { get { return si; } } + /// + /// Returns the absolute value of the matrix determinant. + /// + /// + public Single AbsoluteDeterminant + { + get + { + if (!determinant.HasValue) + { + Single det = 1; + for (int i = 0; i < s.Length; i++) + det *= s[i]; + determinant = det; + } + + return determinant.Value; + } + } + + /// + /// Returns the log of the absolute value for the matrix determinant. + /// + /// + public Single LogDeterminant + { + get + { + if (!lndeterminant.HasValue) + { + double det = 0; + for (int i = 0; i < s.Length; i++) + det += Math.Log(s[i]); + lndeterminant = (Single)det; + } + + return lndeterminant.Value; + } + } - /// Constructs a new singular value decomposition. + /// + /// Returns the pseudo-determinant for the matrix. + /// + /// + public Single PseudoDeterminant + { + get + { + if (!pseudoDeterminant.HasValue) + { + Single det = 1; + for (int i = 0; i < s.Length; i++) + if (s[i] != 0) det *= s[i]; + pseudoDeterminant = det; + } + + return pseudoDeterminant.Value; + } + } + + /// + /// Returns the log of the pseudo-determinant for the matrix. + /// + /// + public Single LogPseudoDeterminant + { + get + { + if (!lnpseudoDeterminant.HasValue) + { + double det = 0; + for (int i = 0; i < s.Length; i++) + if (s[i] != 0) det += Math.Log(s[i]); + lnpseudoDeterminant = (Single)det; + } + + return lnpseudoDeterminant.Value; + } + } + + + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. + /// public SingularValueDecompositionF(Single[,] value) : this(value, true, true) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -180,12 +285,17 @@ public SingularValueDecompositionF(Single[,] value) /// Pass if the right singular vector matrix V /// should be computed. Pass otherwise. Default /// is . - public SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors) + /// + public SingularValueDecompositionF(Single[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors) : this(value, computeLeftSingularVectors, computeRightSingularVectors, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -200,12 +310,17 @@ public SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVect /// Pass to automatically transpose the value matrix in /// case JAMA's assumptions about the dimensionality of the matrix are violated. /// Pass otherwise. Default is . - public SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) + /// + public SingularValueDecompositionF(Single[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose) : this(value, computeLeftSingularVectors, computeRightSingularVectors, autoTranspose, false) { } - /// Constructs a new singular value decomposition. + /// + /// Constructs a new singular value decomposition. + /// + /// /// /// The matrix to be decomposed. /// @@ -223,8 +338,10 @@ public SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVect /// /// Pass to perform the decomposition in place. The matrix /// will be destroyed in the process, resulting in less - /// memory consumption. - public unsafe SingularValueDecompositionF(Single[,] value, bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) + /// memory comsumption. + /// + public unsafe SingularValueDecompositionF(Single[,] value, + bool computeLeftSingularVectors, bool computeRightSingularVectors, bool autoTranspose, bool inPlace) { if (value == null) { @@ -552,11 +669,11 @@ public unsafe SingularValueDecompositionF(Single[,] value, bool computeLeftSingu // This section of the program inspects for // negligible elements in the s and e arrays. On - // completion the variables case and k are set as follows. + // completion the variables kase and k are set as follows. - // case = 1 if s(p) and e[k-1] are negligible and k