You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(42) |
Sep
(69) |
Oct
(47) |
Nov
(28) |
Dec
(25) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2005 |
Jan
(32) |
Feb
(91) |
Mar
(60) |
Apr
(4) |
May
(51) |
Jun
(4) |
Jul
(7) |
Aug
|
Sep
(21) |
Oct
(67) |
Nov
(68) |
Dec
(36) |
| 2006 |
Jan
(45) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
| 2007 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
|
From: <mar...@us...> - 2007-10-06 20:22:07
|
Revision: 448
http://dnanalytics.svn.sourceforge.net/dnanalytics/?rev=448&view=rev
Author: marcuscuda
Date: 2007-10-06 13:22:04 -0700 (Sat, 06 Oct 2007)
Log Message:
-----------
Applied Gabriel Rosenhouse's patch
Modified Paths:
--------------
numerical/trunk/LinearAlgebra/DenseMatrix.cs
Modified: numerical/trunk/LinearAlgebra/DenseMatrix.cs
===================================================================
--- numerical/trunk/LinearAlgebra/DenseMatrix.cs 2007-03-09 04:07:57 UTC (rev 447)
+++ numerical/trunk/LinearAlgebra/DenseMatrix.cs 2007-10-06 20:22:04 UTC (rev 448)
@@ -42,7 +42,6 @@
public DenseMatrix(int order, bool useNativeLibrary)
: this(order, order, useNativeLibrary)
{
- data = new double[order * order];
}
/// <summary>
@@ -106,12 +105,6 @@
internal DenseMatrix(DenseMatrix matrix, bool useNativeLibrary)
: this(matrix.Rows, matrix.Columns, useNativeLibrary)
{
- if (matrix == null)
- {
- throw new ArgumentNullException("matrix", Strings.NullParameterException);
- }
-
- data = new double[Rows * Columns];
Buffer.BlockCopy(matrix.data, 0, data, 0, matrix.data.Length * Constants.SizeOfDouble);
}
@@ -127,8 +120,6 @@
throw new ArgumentNullException("matrix", Strings.NullParameterException);
}
- data = new double[Rows * Columns];
-
//using enumerators since they will be more efficient for copying sparse matrices
foreach (KeyValuePair<int, Vector> column in matrix.ColumnEnumerator())
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pva...@us...> - 2007-03-09 04:08:21
|
Revision: 447
http://svn.sourceforge.net/dnanalytics/?rev=447&view=rev
Author: pvandervelde
Date: 2007-03-08 20:07:57 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
- Bug fix for bug number: 1676817 - Getting Submatrix of Sparse matrix fails.
- Fixed copy-paste error in Matrix.CheckRange --> Changed 'row' to 'column'
Modified Paths:
--------------
numerical/trunk/LinearAlgebra/Matrix.cs
numerical/trunk/LinearAlgebra/SparseMatrix.cs
numerical/trunk/UnitTests/LinearAlgebra/AbstractMatrixTest.cs
numerical/trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs
Property Changed:
----------------
numerical/trunk/
Property changes on: numerical/trunk
___________________________________________________________________
Name: svn:ignore
- NumericalLibrary.csproj.user
bin
obj
NumericalLibrary.suo
NumericalLibrary.resharper.user
_ReSharper.NumericalLibrary
+ NumericalLibrary.csproj.user
bin
obj
NumericalLibrary.suo
NumericalLibrary.resharper.user
_ReSharper.NumericalLibrary
dna.nunit
Modified: numerical/trunk/LinearAlgebra/Matrix.cs
===================================================================
--- numerical/trunk/LinearAlgebra/Matrix.cs 2007-02-08 16:14:30 UTC (rev 446)
+++ numerical/trunk/LinearAlgebra/Matrix.cs 2007-03-09 04:07:57 UTC (rev 447)
@@ -1979,7 +1979,7 @@
}
if (column < 0 || column >= columns)
{
- throw new ArgumentOutOfRangeException("row");
+ throw new ArgumentOutOfRangeException("column");
}
}
#endregion Private Methods
Modified: numerical/trunk/LinearAlgebra/SparseMatrix.cs
===================================================================
--- numerical/trunk/LinearAlgebra/SparseMatrix.cs 2007-02-08 16:14:30 UTC (rev 446)
+++ numerical/trunk/LinearAlgebra/SparseMatrix.cs 2007-03-09 04:07:57 UTC (rev 447)
@@ -1174,7 +1174,7 @@
{
// check if the column index is in the range
if ((((mColumnIndices[j] - columnRange.Start) % columnRange.Stride) == 0) &&
- (mColumnIndices[j] <= columnRange.End))
+ (mColumnIndices[j] >= columnRange.Start) && (mColumnIndices[j] <= columnRange.End))
{
int column = ((mColumnIndices[j] - columnRange.Start) / columnRange.Stride);
result[row, column] = mValues[j];
Modified: numerical/trunk/UnitTests/LinearAlgebra/AbstractMatrixTest.cs
===================================================================
--- numerical/trunk/UnitTests/LinearAlgebra/AbstractMatrixTest.cs 2007-02-08 16:14:30 UTC (rev 446)
+++ numerical/trunk/UnitTests/LinearAlgebra/AbstractMatrixTest.cs 2007-03-09 04:07:57 UTC (rev 447)
@@ -3285,7 +3285,7 @@
}
}
}
-
+
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void SubMatrixArgumentOutOfRange1()
Modified: numerical/trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs
===================================================================
--- numerical/trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs 2007-02-08 16:14:30 UTC (rev 446)
+++ numerical/trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs 2007-03-09 04:07:57 UTC (rev 447)
@@ -1,4 +1,5 @@
using dnAnalytics.LinearAlgebra;
+using dnAnalytics.LinearAlgebra.IO;
using NUnit.Framework;
namespace dnAnalytics.UnitTests.LinearAlgebra
@@ -41,7 +42,63 @@
return VectorBuilder.CreateVector(source, VectorType.Sparse);
}
}
+
+ [TestFixture]
+ [Category("Managed")]
+ [Category("Sparse")]
+ public class AdditionalSparseMatrixTest
+ {
+ private static readonly double[,] square = new double[,] { { -1.1, -2.2, -3.3 }, { 1.1, 2.2, 3.3 }, { -4.4, 5.5, 6.6 } };
+ private Matrix GetMatrix(double[,] data)
+ {
+ int rows = data.GetLength(0);
+ int cols = data.GetLength(1);
+ Matrix ret = MatrixBuilder.CreateMatrix(rows, cols, MatrixType.Sparse);
+ for (int i = 0; i < rows; i++)
+ {
+ for (int j = 0; j < cols; j++)
+ {
+ ret[i, j] = data[i, j];
+ }
+ }
+
+ return ret;
+ }
+
+ // BUG FIX TEST:
+ // Bug behavior:
+ // I get an IndexOutOfRangeException when trying to get the submatrix of a sparse matrix (in special cases).
+ // Here is the sample code:
+ // DelimitedMatrixReader reader = new DelimitedMatrixReader(',');
+ // Matrix matrix = reader.ReadMatrix("matrix-bug.txt", MatrixType.Sparse);
+ // Range range = new Range(82, 138);
+ // Matrix subMatrix = matrix.SubMatrix(range, range);
+ // Bug reason: The sparse matrix did not check if the returned columns were within the
+ // range from the lower side, thereby returning negative column indices.
+
+ [Test]
+ public void SubMatrixTest()
+ {
+ Matrix matrix = GetMatrix(square);
+ Range rowRange = new Range(1, matrix.Rows - 1, 1);
+ Range colRange = new Range(1, matrix.Columns - 1, 1);
+ Matrix subMatrix = matrix.SubMatrix(rowRange, colRange);
+
+ int m = (rowRange.End - rowRange.Start) / rowRange.Stride + 1;
+ int n = (colRange.End - colRange.Start) / colRange.Stride + 1;
+ Assert.AreEqual(m, subMatrix.Rows);
+ Assert.AreEqual(n, subMatrix.Columns);
+ for (int i = rowRange.Start, ii = 0; i <= rowRange.End; i += rowRange.Stride, ii++)
+ {
+ for (int j = colRange.Start, jj = 0; j <= colRange.End; j += colRange.Stride, jj++)
+ {
+ Assert.AreEqual(matrix[i, j], subMatrix[ii, jj]);
+ }
+ }
+ }
+ }
+
[TestFixture]
[Category("Managed")]
[Category("Sparse")]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mar...@us...> - 2007-02-08 16:14:34
|
Revision: 446
http://svn.sourceforge.net/dnanalytics/?rev=446&view=rev
Author: marcuscuda
Date: 2007-02-08 08:14:30 -0800 (Thu, 08 Feb 2007)
Log Message:
-----------
Added Paths:
-----------
nli/trunk/NativeCode/ATLAS_CLAPACK/dsecnd.c
nli/trunk/NativeCode/ATLAS_CLAPACK/second.c
Added: nli/trunk/NativeCode/ATLAS_CLAPACK/dsecnd.c
===================================================================
--- nli/trunk/NativeCode/ATLAS_CLAPACK/dsecnd.c (rev 0)
+++ nli/trunk/NativeCode/ATLAS_CLAPACK/dsecnd.c 2007-02-08 16:14:30 UTC (rev 446)
@@ -0,0 +1,22 @@
+#include "f2c.h"
+#ifndef USE_CLOCK
+ #include <sys/times.h>;
+#endif
+#include <sys/types.h>
+#include <time.h>
+
+#ifndef CLK_TCK
+#define CLK_TCK 60
+#endif
+
+doublereal dsecnd_()
+{
+#ifdef USE_CLOCK
+ return (doublereal)(clock()) / CLK_TCK;
+#else
+ struct tms rusage;
+
+ times(&rusage);
+ return (doublereal)(rusage.tms_utime) / CLK_TCK;
+
+} /* dsecnd_ */
\ No newline at end of file
Added: nli/trunk/NativeCode/ATLAS_CLAPACK/second.c
===================================================================
--- nli/trunk/NativeCode/ATLAS_CLAPACK/second.c (rev 0)
+++ nli/trunk/NativeCode/ATLAS_CLAPACK/second.c 2007-02-08 16:14:30 UTC (rev 446)
@@ -0,0 +1,22 @@
+#include "f2c.h"
+#include <sys/times.h>
+#ifndef USE_CLOCK
+ #include <sys/times.h>;
+#endif
+#include <time.h>
+
+#ifndef CLK_TCK
+#define CLK_TCK 60
+#endif
+
+doublereal second_()
+{
+#ifdef USE_CLOCK
+ return (doublereal)(clock()) / CLK_TCK;
+#else
+ struct tms rusage;
+
+ times(&rusage);
+ return (doublereal)(rusage.tms_utime) / CLK_TCK;
+
+} /* second_ */
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mar...@us...> - 2007-02-08 16:05:45
|
Revision: 445
http://svn.sourceforge.net/dnanalytics/?rev=445&view=rev
Author: marcuscuda
Date: 2007-02-08 08:04:39 -0800 (Thu, 08 Feb 2007)
Log Message:
-----------
Fixed IndexOutOfRange bug in "deflate negligible s[m]".
Modified Paths:
--------------
numerical/trunk/LinearAlgebra/ManagedLapack.cs
Modified: numerical/trunk/LinearAlgebra/ManagedLapack.cs
===================================================================
--- numerical/trunk/LinearAlgebra/ManagedLapack.cs 2006-11-11 14:48:20 UTC (rev 444)
+++ numerical/trunk/LinearAlgebra/ManagedLapack.cs 2007-02-08 16:04:39 UTC (rev 445)
@@ -731,8 +731,10 @@
case 1:
f = e[m - 2];
e[m - 2] = 0.0;
- for (k = m - 2; k >= 0; k--)
+ for (int kk = l; kk < m - 1; kk++)
+ //for (k = m - 2; k >= 0; k--)
{
+ k = m - 2 - kk + l;
t1 = s[k];
Drotg(ref t1, ref f, ref cs, ref sn);
s[k] = t1;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pva...@us...> - 2006-08-30 15:04:58
|
Revision: 443
http://svn.sourceforge.net/dnanalytics/?rev=443&view=rev
Author: pvandervelde
Date: 2006-08-30 08:04:37 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
- Fixed bug number: #1549178. SparseVector.Maximum does not work.
- Also fixed bugs in SparseVector.Minimum, AbsoluteMaximum and AbsoluteMinimum.
Modified Paths:
--------------
numerical/trunk/LinearAlgebra/SparseVector.cs
numerical/trunk/NumericalLibrary.csproj
numerical/trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs
numerical/trunk/UnitTests/UnitTests.csproj
Modified: numerical/trunk/LinearAlgebra/SparseVector.cs
===================================================================
--- numerical/trunk/LinearAlgebra/SparseVector.cs 2006-08-21 16:09:46 UTC (rev 442)
+++ numerical/trunk/LinearAlgebra/SparseVector.cs 2006-08-30 15:04:37 UTC (rev 443)
@@ -68,8 +68,7 @@
/// </summary>
/// <param name="source">The <see cref="Vector" /> from which the values for the current instance will be copied.</param>
/// <exception cref="ArgumentNullException">If source is <b>null</b>.</exception>
- public SparseVector(Vector source)
- : base(source.Count)
+ public SparseVector(Vector source) : base(source.Count)
{
for (int i = 0; i < source.Count; i++)
{
@@ -427,7 +426,7 @@
{
int index = -1;
double max = 0.0;
- for (int i = 1; i < mValueCount; i++)
+ for (int i = 0; i < mValueCount; i++)
{
double test = System.Math.Abs(mValues[i]);
if (test > max)
@@ -491,7 +490,7 @@
// non-zero smallest value. Find it.
int index = -1;
double max = double.PositiveInfinity;
- for (int i = 1; i < mValueCount; i++)
+ for (int i = 0; i < mValueCount; i++)
{
double test = System.Math.Abs(mValues[i]);
if (test < max)
@@ -533,7 +532,7 @@
{
int index = -1;
double max = double.NegativeInfinity;
- for (int i = 1; i < mValueCount; i++)
+ for (int i = 0; i < mValueCount; i++)
{
double test = mValues[i];
if (test > max)
@@ -569,7 +568,7 @@
{
int index = -1;
double max = double.PositiveInfinity;
- for (int i = 1; i < mValueCount; i++)
+ for (int i = 0; i < mValueCount; i++)
{
double test = mValues[i];
if (test < max)
Modified: numerical/trunk/NumericalLibrary.csproj
===================================================================
--- numerical/trunk/NumericalLibrary.csproj 2006-08-21 16:09:46 UTC (rev 442)
+++ numerical/trunk/NumericalLibrary.csproj 2006-08-30 15:04:37 UTC (rev 443)
@@ -35,7 +35,7 @@
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.2.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Modified: numerical/trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs
===================================================================
--- numerical/trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs 2006-08-21 16:09:46 UTC (rev 442)
+++ numerical/trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs 2006-08-30 15:04:37 UTC (rev 443)
@@ -24,6 +24,34 @@
{
return MatrixBuilder.CreateMatrix(rows, columns, MatrixType.Dense);
}
+
+ // NOTE: both tests are bug-fix tests.
+ // Bug-behavior: The sparse vector would not find the maximum value if the first entry in the sparse array was the maximum
+ // Cause: An index error (starting at the second entry in the sparse array).
+
+ [Test]
+ public void MaximumWithMaximumOnFirstEntry()
+ {
+ Vector vector = GetVector(2000);
+ vector[1845] = 38;
+ vector[1857] = 25;
+ vector[1957] = 25;
+
+ Assert.AreEqual(1845, vector.MaximumIndex());
+ Assert.AreEqual(38, vector.Maximum());
+ }
+
+ [Test]
+ public void MinimumWithMinimumOnFirstEntry()
+ {
+ Vector vector = GetVector(2000);
+ vector[1845] = 15;
+ vector[1857] = 25;
+ vector[1957] = 25;
+
+ Assert.AreEqual(1845, vector.MinimumIndex());
+ Assert.AreEqual(15, vector.Minimum());
+ }
}
[TestFixture]
Modified: numerical/trunk/UnitTests/UnitTests.csproj
===================================================================
--- numerical/trunk/UnitTests/UnitTests.csproj 2006-08-21 16:09:46 UTC (rev 442)
+++ numerical/trunk/UnitTests/UnitTests.csproj 2006-08-30 15:04:37 UTC (rev 443)
@@ -30,7 +30,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.2.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <in...@dn...> - 2006-01-25 16:47:47
|
Author: patrick
Date: 2006-01-25 11:47:33 -0500 (Wed, 25 Jan 2006)
New Revision: 194
Modified:
trunk/LinearAlgebra/SparseVector.cs
trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs
trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs
Log:
- Fixed bugs in the SparseVector implementation.
- Fixed bugs in the AbstractVectorTest implementation.
Modified: trunk/LinearAlgebra/SparseVector.cs
===================================================================
--- trunk/LinearAlgebra/SparseVector.cs 2006-01-25 13:59:09 UTC (rev 193)
+++ trunk/LinearAlgebra/SparseVector.cs 2006-01-25 16:47:33 UTC (rev 194)
@@ -77,7 +77,11 @@
}
mSize = source.mSize;
mValueCount = source.mValueCount;
+
+ mValues = new double[source.mValues.Length];
Buffer.BlockCopy(source.mValues, 0, mValues, 0, source.mValues.Length*Constants.SizeOfDouble);
+
+ mIndices = new int[source.mIndices.Length];
Buffer.BlockCopy(source.mIndices, 0, mIndices, 0, source.mIndices.Length*Constants.SizeOfInt);
}
@@ -115,6 +119,11 @@
{
get
{
+ if ((index < 0) || (index >= mSize))
+ {
+ throw new IndexOutOfRangeException();
+ }
+
int itemIndex;
if (FindItem(index, out itemIndex))
{
@@ -124,6 +133,11 @@
}
set
{
+ if ((index < 0) || (index >= mSize))
+ {
+ throw new IndexOutOfRangeException();
+ }
+
int itemIndex;
if (FindItem(index, out itemIndex))
{
@@ -583,7 +597,7 @@
for (int i = 1; i < mValueCount; i++)
{
double test = mValues[i];
- if (test > max)
+ if (test < max)
{
index = mIndices[i];
max = test;
@@ -620,7 +634,7 @@
target.Clear();
for (int i = 0; i < mValueCount; i++)
{
- target[i] = mValues[mIndices[i]];
+ target[mIndices[i]] = mValues[i];
}
}
@@ -655,7 +669,7 @@
if (other.Count != mSize)
{
- throw new ArgumentOutOfRangeException("DenseVector lengths are unequal");
+ throw new NotConformableException();
}
double result = 0;
@@ -778,7 +792,7 @@
int internalIndex;
if (FindItem(i, out internalIndex))
{
- ret.InsertValue(i, mValues[internalIndex]);
+ ret.InsertValue(j, mValues[internalIndex]);
}
}
return ret;
@@ -1282,9 +1296,9 @@
// the fact that we are a sparse vector. Multiply a whole row in one go.
for (int i = 0; i < Count; i++)
{
- for (int j = 0; i < rightSide.Count; j++)
+ for (int j = 0; j < rightSide.Count; j++)
{
- result[i, j] = this[i]*rightSide[j];
+ result[i,j] = this[i]*rightSide[j];
}
}
}
Modified: trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs 2006-01-25 13:59:09 UTC (rev 193)
+++ trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs 2006-01-25 16:47:33 UTC (rev 194)
@@ -339,11 +339,10 @@
public void GetEnumerator()
{
Vector vector = GetVector(testArray);
- int i = 0;
- foreach (KeyValuePair<int, double> pair in vector)
- {
- Assert.AreEqual(testArray[i++], pair.Value);
- }
+ foreach (KeyValuePair<int, double> pair in vector)
+ {
+ Assert.AreEqual(testArray[pair.Key], pair.Value);
+ }
}
[Test]
@@ -353,12 +352,13 @@
Vector vector = GetVector(testArray);
IEnumerator<KeyValuePair<int, double>> iterator = vector.GetEnumerator(range);
- int i = 1;
while (iterator.MoveNext())
{
- Assert.AreEqual(testArray[i], iterator.Current.Value);
- i += 2;
-
+ KeyValuePair<int, double> pair = iterator.Current;
+ // Check that the key (int) is in the range.
+ Assert.AreEqual(0, (pair.Key - range.Start) % range.Stride);
+ // Check that the value is the correct value
+ Assert.AreEqual(testArray[pair.Key], pair.Value);
}
}
Modified: trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs 2006-01-25 13:59:09 UTC (rev 193)
+++ trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs 2006-01-25 16:47:33 UTC (rev 194)
@@ -4,7 +4,7 @@
namespace dnAnalytics.UnitTests.LinearAlgebra
{
[TestFixture]
- public sealed class DoubleSparseVectorTest : AbstractVectorTest
+ public sealed class SparseVectorTest : AbstractVectorTest
{
public override Vector GetVector(int order)
{
|
|
From: <in...@dn...> - 2006-01-25 13:59:32
|
Author: patrick
Date: 2006-01-25 08:59:09 -0500 (Wed, 25 Jan 2006)
New Revision: 193
Modified:
trunk/LinearAlgebra/Matrix.cs
trunk/LinearAlgebra/Solvers/BicgStabSolver.cs
trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs
trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs
trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs
trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs
trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs
trunk/LinearAlgebra/SparseMatrix.cs
trunk/LinearAlgebra/SparseVector.cs
Log:
- Working on the SparseMatrix class.
* Need to check the results of the unit tests for both the SparseMatrix and the SparseVector
Modified: trunk/LinearAlgebra/Matrix.cs
===================================================================
--- trunk/LinearAlgebra/Matrix.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Matrix.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -164,7 +164,7 @@
/// <param name="index">The column to copy.</param>
/// <param name="range">The <see cref="Range"/> of elements to copy from the requested column.</param>
/// <returns>A <see cref="Vector"/> containing the copied elements.</returns>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
/// outside the column's range. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negitive,
/// or greater than or equal to the number of columns.</exception>
@@ -176,7 +176,7 @@
/// <param name="index">The column to copy.</param>
/// <param name="range">The <see cref="Range"/> of elements to copy from the requested column.</param>
/// <param name="result">The <see cref="Vector"/> to copy the column into.</param>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
/// outside the column's range. </exception>
/// <exception cref="ArgumentNullException">If the result matrix is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negitive,
@@ -205,11 +205,11 @@
/// <summary>
/// Returns an <see cref="IEnumerator{T}"/> that enumerates the columns of this matrix.
/// </summary>
- /// <param name="range">The <paramref name="Range"/> of columns to enumerate over.</param>
+ /// <param name="range">The <paramref name="range"/> of columns to enumerate over.</param>
/// <returns>An <see cref="IEnumerator{T}"/> that enumerates over a given <see cref="Range"/> of columns of this matrix.</returns>
/// <remarks>The enumerator returns a <seealso cref="KeyValuePair{T,K}"/> with the key being the column index and the value
/// being the that column as a <see cref="Vector"/>.</remarks>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range of columns that is
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range of columns that is
/// outside the number of matrix columns. </exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public abstract IEnumerator<KeyValuePair<int, Vector>> ColumnEnumerator(Range range);
@@ -272,7 +272,7 @@
/// <param name="index">The column to copy.</param>
/// <param name="range">The <see cref="Range"/> of elements to copy.</param>
/// <returns>A <see cref="Vector"/> containing the copied elements.</returns>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
/// outside the row's range. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negitive,
/// or greater than or equal to the number of rows.</exception>
@@ -287,7 +287,7 @@
/// <returns>A <see cref="Vector"/> containing the copied elements.</returns>
/// <exception cref="ArgumentNullException">if the result matrix is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <c>result.Count != (range.End - range.Start) / range.Stride + 1</c>.</exception>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
/// outside the row's range. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negitive,
/// or greater than or equal to the number of rows.</exception>
@@ -316,11 +316,11 @@
/// <summary>
/// Returns an <see cref="IEnumerator{T}"/> that enumerates the rows of this matrix.
/// </summary>
- /// <param name="range">The <paramref name="Range"/> of rows to enumerate over.</param>
+ /// <param name="range">The <paramref name="range"/> of rows to enumerate over.</param>
/// <returns>An <see cref="IEnumerator{T}"/> that enumerates over a given <see cref="Range"/> of rows of this matrix.</returns>
/// <remarks>The enumerator returns a <seealso cref="KeyValuePair{T,K}"/> with the key being the row index and the value
/// being the that row as a <see cref="Vector"/>.</remarks>
- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="Range"/> specifies a range of rows that is
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range of rows that is
/// outside the number of matrix rows. </exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public abstract IEnumerator<KeyValuePair<int, Vector>> RowEnumerator(Range range);
Modified: trunk/LinearAlgebra/Solvers/BicgStabSolver.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/BicgStabSolver.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/BicgStabSolver.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -37,7 +37,7 @@
/// </remarks>
public sealed class BiConjugateGradientStabilizedSolver : IIterativeMatrixSolver
{
- private SparseMatrix mCoefficients = null;
+ private Matrix mCoefficients = null;
private IPreconditioner mPreconditioner = null;
private ConvergenceMonitor mConvergenceMonitor = null;
@@ -51,7 +51,7 @@
/// <param name="coefficientMatrix">The coefficient matrix.</param>
/// <exception cref="ArgumentNullException">If the <paramref name="coefficientMatrix"/> is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If the <paramref name="coefficientMatrix"/> is not square.</exception>
- public BiConjugateGradientStabilizedSolver(SparseMatrix coefficientMatrix) :
+ public BiConjugateGradientStabilizedSolver(Matrix coefficientMatrix) :
this(coefficientMatrix, null, null)
{}
@@ -66,7 +66,7 @@
/// monitor the iterative process.</param>
/// <exception cref="ArgumentNullException">If the <paramref name="coefficientMatrix"/> is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If the <paramref name="coefficientMatrix"/> is not square.</exception>
- public BiConjugateGradientStabilizedSolver(SparseMatrix coefficientMatrix, ConvergenceMonitor monitor)
+ public BiConjugateGradientStabilizedSolver(Matrix coefficientMatrix, ConvergenceMonitor monitor)
: this(coefficientMatrix, null, monitor)
{}
@@ -82,7 +82,7 @@
/// matrix equation.</param>
/// <exception cref="ArgumentNullException">If the <paramref name="coefficientMatrix"/> is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If the <paramref name="coefficientMatrix"/> is not square.</exception>
- public BiConjugateGradientStabilizedSolver(SparseMatrix coefficientMatrix, IPreconditioner preconditioner)
+ public BiConjugateGradientStabilizedSolver(Matrix coefficientMatrix, IPreconditioner preconditioner)
: this(coefficientMatrix, preconditioner, null)
{}
@@ -96,7 +96,7 @@
/// monitor the iterative process.</param>
/// <exception cref="ArgumentNullException">If the <paramref name="coefficientMatrix"/> is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If the <paramref name="coefficientMatrix"/> is not square.</exception>
- public BiConjugateGradientStabilizedSolver(SparseMatrix coefficientMatrix, IPreconditioner preconditioner,
+ public BiConjugateGradientStabilizedSolver(Matrix coefficientMatrix, IPreconditioner preconditioner,
ConvergenceMonitor monitor)
{
if (coefficientMatrix == null)
@@ -117,7 +117,7 @@
/// <summary>
/// Returns the <see cref="SparseMatrix"/> on which the solver works.
/// </summary>
- internal SparseMatrix Matrix
+ internal Matrix Matrix
{
get
{
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -54,7 +54,7 @@
/// </summary>
/// <param name="coefficientMatrix">The <see cref="SparseMatrix"/> upon which this
/// preconditioner is based.</param>
- public DiagonalIncompleteLUFactorization(SparseMatrix coefficientMatrix)
+ public DiagonalIncompleteLUFactorization(Matrix coefficientMatrix)
{
if (coefficientMatrix == null)
{
@@ -66,7 +66,7 @@
throw new NotSquareMatrixException();
}
- mCoefficientMatrix = coefficientMatrix;
+ mCoefficientMatrix = new SparseMatrix(coefficientMatrix);
}
/// <summary>
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -35,7 +35,7 @@
/// </summary>
/// <param name="coefficientMatrix">The <see cref="SparseMatrix"/> upon which this
/// preconditioner is based.</param>
- public DiagonalPreconditioner(SparseMatrix coefficientMatrix)
+ public DiagonalPreconditioner(Matrix coefficientMatrix)
{
if (coefficientMatrix == null)
{
@@ -47,7 +47,7 @@
throw new NotSquareMatrixException();
}
- mCoefficientMatrix = coefficientMatrix;
+ mCoefficientMatrix = new SparseMatrix(coefficientMatrix);
}
/// <summary>
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -42,7 +42,7 @@
/// <param name="coefficientMatrix">
/// The <see cref="SparseMatrix"/> upon which the preconditioner is based.
/// </param>
- public IncompleteLUFactorization(SparseMatrix coefficientMatrix)
+ public IncompleteLUFactorization(Matrix coefficientMatrix)
{
if (coefficientMatrix == null)
{
@@ -54,7 +54,7 @@
throw new NotSquareMatrixException();
}
- mCoefficientMatrix = coefficientMatrix;
+ mCoefficientMatrix = new SparseMatrix(coefficientMatrix);
}
/// <summary>
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -71,7 +71,7 @@
/// </summary>
/// <param name="coefficientMatrix">The <see cref="SparseMatrix"/> upon which this
/// preconditioner is based.</param>
- public IlutpPreconditioner(SparseMatrix coefficientMatrix)
+ public IlutpPreconditioner(Matrix coefficientMatrix)
{
if (coefficientMatrix == null)
{
@@ -83,7 +83,7 @@
throw new NotSquareMatrixException();
}
- mCoefficientMatrix = coefficientMatrix;
+ mCoefficientMatrix = new SparseMatrix(coefficientMatrix);
}
/// <summary>
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -25,7 +25,7 @@
/// Initializes a new instance of the <c>UnitPreconditioner</c> class.
/// </summary>
/// <param name="coefficientMatrix">The coefficient matrix to use.</param>
- public UnitPreconditioner(SparseMatrix coefficientMatrix)
+ public UnitPreconditioner(Matrix coefficientMatrix)
{
if (coefficientMatrix == null)
{
@@ -37,7 +37,7 @@
throw new NotSquareMatrixException();
}
- mCoefficientMatrix = coefficientMatrix;
+ mCoefficientMatrix = new SparseMatrix(coefficientMatrix);
}
/// <summary>
Modified: trunk/LinearAlgebra/SparseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -8,6 +8,7 @@
using System.Collections.Generic;
using dnAnalytics.Exceptions;
using dnAnalytics.LinearAlgebra;
+using dnAnalytics.Resources;
namespace dnAnalytics.LinearAlgebra
{
@@ -18,7 +19,7 @@
/// In the current implementation the <c>SparseMatrix</c> uses a
/// compressed row storage system.
/// </remarks>
- public sealed class SparseMatrix : Matrix
+ internal sealed class SparseMatrix : Matrix
{
// UPGRADE NOTE: Could create an iternal class that
// holds the sparse data structure. That way we can interchange
@@ -226,12 +227,21 @@
// because most of the time matrices are accessed sequentially which means
// that we can figure out what item to pick without having to actually
// search for it.
+
+ /// <summary>
+ /// Finds either the item indicated by the given indices (returns <c>true</c>) or the
+ /// insert position (returns <c>false</c>) in the values array.
+ /// </summary>
+ /// <param name="rowIndex"></param>
+ /// <param name="columnIndex"></param>
+ /// <param name="itemIndex"></param>
+ /// <returns></returns>
private bool FindItem(int rowIndex, int columnIndex, out int itemIndex)
{
// First find the start and end indices for the row
int startIndex;
int endIndex;
- FindColumnStartAndEnd(rowIndex, out startIndex, out endIndex);
+ FindRowStartAndEnd(rowIndex, out startIndex, out endIndex);
// Check if startIndex and endIndex are equal. If so then
// the item does not exist
@@ -294,7 +304,7 @@
return false;
}
- private void FindColumnStartAndEnd(int rowIndex, out int startIndex, out int endIndex)
+ private void FindRowStartAndEnd(int rowIndex, out int startIndex, out int endIndex)
{
// First find the start and end indices for the row
startIndex = mRowIndices[rowIndex];
@@ -473,6 +483,8 @@
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
protected internal override double ValueAt(int row, int column)
{
+ // In this case we just use the indexer because there is no way we can leave out the
+ // checks. These are essential to ensure that the search algorithm actually terminates!
return this[row, column];
}
@@ -488,7 +500,9 @@
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public override void ValueAt(int row, int column, double value)
{
- throw new NotImplementedException();
+ // In this case we just use the indexer because there is no way we can leave out the
+ // checks. These are essential to ensure that the search algorithm actually terminates!
+ this[row, column] = value;
}
/// <summary>
@@ -546,7 +560,9 @@
/// <returns>A vector containing the copied elements.</returns>
public override Vector Column(int index)
{
- throw new NotImplementedException();
+ Vector result = VectorBuilder.CreateVector(Rows, VectorType.Sparse);
+ Column(index, result);
+ return result;
}
/// <summary>
@@ -555,9 +571,36 @@
/// <param name="index">The column to copy.</param>
/// <param name="result">The vector to copy the column into.</param>
/// <exception cref="ArgumentNullException">If the result matrix is null.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative,
+ /// or greater than or equal to the number of columns.</exception>
+ /// <exception cref="NotConformableException">If the result vector is of the incorrect size.</exception>
public override void Column(int index, Vector result)
{
- throw new NotImplementedException();
+ if (result == null)
+ {
+ throw new ArgumentNullException();
+ }
+
+ if (index >= Columns || index < 0)
+ {
+ throw new ArgumentOutOfRangeException("index", Strings.OutOfRangeException);
+ }
+
+ if (result.Count != Rows)
+ {
+ throw new NotConformableException();
+ }
+
+ for (int i = 0; i < Rows; i++)
+ {
+ int itemIndex;
+ if (!FindItem(i, index, out itemIndex))
+ {
+ continue;
+ }
+
+ result[i] = mValues[itemIndex];
+ }
}
/// <summary>
@@ -568,17 +611,71 @@
/// <returns>A vector containing the copied elements.</returns>
public override Vector Column(int index, Range range)
{
- throw new NotImplementedException();
+ // the actual size of the vector is the number of elements in the
+ // range. This should be the difference between start and end + 1 (<-- off by one thing)
+ // and then the number of times the stride fits in that difference.
+ int size = range.End - range.Start;
+ size = size / range.Stride + 1;
+
+ Vector result = VectorBuilder.CreateVector(size, VectorType.Sparse);
+ Column(index, range, result);
+ return result;
}
/// <summary>
+ /// Copies the given <see cref="Range"/> of a column into the given vector.
+ /// </summary>
+ /// <param name="index">The column to copy.</param>
+ /// <param name="range">The <see cref="Range"/> of elements to copy from the requested column.</param>
+ /// <param name="result">The <see cref="Vector"/> to copy the column into.</param>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
+ /// outside the column's range. </exception>
+ /// <exception cref="ArgumentNullException">If the result matrix is <c>null</c>.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative,
+ /// or greater than or equal to the number of columns.</exception>
+ /// <exception cref="NotConformableException">If <c>result.Count != (range.End - range.Start) / range.Stride + 1</c>.</exception>
+ public override void Column(int index, Range range, Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (index >= Columns || index < 0)
+ {
+ throw new ArgumentOutOfRangeException("index", Strings.OutOfRangeException);
+ }
+ if (range.Start >= Rows || range.End >= Rows)
+ {
+ throw new ArgumentOutOfRangeException("range", Strings.OutOfRangeException);
+ }
+
+ for (int i = range.Start; i < range.End; i += range.Stride)
+ {
+ int itemIndex;
+ if (!FindItem(i, index, out itemIndex))
+ {
+ continue;
+ }
+
+ result[i] = mValues[itemIndex];
+ }
+ }
+
+ /// <summary>
/// Returns an <see cref="IEnumerator"/> that enumerates the columns of this matrix.
/// </summary>
/// <param name="range">The <see cref="Range"/> of columns to enumerate over.</param>
/// <returns>An <see cref="IEnumerator"/> that enumerates over a given <see cref="Range"/> of columns of this matrix.</returns>
public override IEnumerator<KeyValuePair<int, Vector>> ColumnEnumerator(Range range)
{
- throw new NotImplementedException();
+ if (range.Start >= Columns || range.End >= Columns)
+ {
+ throw new ArgumentOutOfRangeException("range", Strings.OutOfRangeException);
+ }
+ for (int i = range.Start; i <= range.End; i += range.Stride)
+ {
+ yield return new KeyValuePair<int, Vector>(i, Column(i));
+ }
}
/// <summary>
@@ -587,7 +684,10 @@
/// <returns>An <see cref="IEnumerator"/> that enumerates over the columns of this matrix.</returns>
public override IEnumerator<KeyValuePair<int, Vector>> ColumnEnumerator()
{
- throw new NotImplementedException();
+ for (int i = 0; i <= Columns; i++)
+ {
+ yield return new KeyValuePair<int, Vector>(i, Column(i));
+ }
}
/// <summary>
@@ -597,7 +697,9 @@
/// <returns>A vector containing the copied elements.</returns>
public override Vector Row(int index)
{
- throw new NotImplementedException();
+ Vector result = VectorBuilder.CreateVector(Rows, VectorType.Sparse);
+ Row(index, result);
+ return result;
}
/// <summary>
@@ -605,10 +707,38 @@
/// </summary>
/// <param name="index">The row to copy.</param>
/// <param name="result">The vector to copy the row into.</param>
- /// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
+ /// <exception cref="ArgumentNullException">If the result matrix is null.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative,
+ /// or greater than or equal to the number of rows.</exception>
+ /// <exception cref="NotConformableException">If the result vector is of the incorrect size.</exception>
public override void Row(int index, Vector result)
{
- throw new NotImplementedException();
+ if (result == null)
+ {
+ throw new ArgumentNullException();
+ }
+
+ if (index >= Rows || index < 0)
+ {
+ throw new ArgumentOutOfRangeException("index", Strings.OutOfRangeException);
+ }
+
+ if (result.Count != Columns)
+ {
+ throw new NotConformableException();
+ }
+
+ // The data is stored in compressed row storage so all we have to do is find the
+ // begin and end of the row and we can quickly iterate over that.
+ int begin;
+ int end;
+ FindRowStartAndEnd(index, out begin,out end);
+
+ for (int i = begin; i < end + 1; i++)
+ {
+ int insertPosition = mColumnIndices[i];
+ result[insertPosition] = mValues[i];
+ }
}
/// <summary>
@@ -619,17 +749,72 @@
/// <returns>a vector containing the copied elements.</returns>
public override Vector Row(int index, Range range)
{
- throw new NotImplementedException();
+ // the actual size of the vector is the number of elements in the
+ // range. This should be the difference between start and end + 1 (<-- off by one thing)
+ // and then the number of times the stride fits in that difference.
+ int size = range.End - range.Start;
+ size = size / range.Stride + 1;
+
+ Vector result = VectorBuilder.CreateVector(size, VectorType.Sparse);
+ Row(index, range, result);
+ return result;
}
/// <summary>
+ /// Copies the given <see cref="Range"/> of a row into an <see cref="Vector"/>.
+ /// </summary>
+ /// <param name="index">The column to copy.</param>
+ /// <param name="range">The <see cref="Range"/> of elements to copy.</param>
+ /// <param name="result">The <see cref="Vector"/> to copy the row into.</param>
+ /// <returns>A <see cref="Vector"/> containing the copied elements.</returns>
+ /// <exception cref="ArgumentNullException">if the result matrix is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <c>result.Count != (range.End - range.Start) / range.Stride + 1</c>.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
+ /// outside the row's range. </exception>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negitive,
+ /// or greater than or equal to the number of rows.</exception>
+ public override void Row(int index, Range range, Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (index >= Rows || index < 0)
+ {
+ throw new ArgumentOutOfRangeException("index", Strings.OutOfRangeException);
+ }
+ if (range.Start >= Columns || range.End >= Columns)
+ {
+ throw new ArgumentOutOfRangeException("range", Strings.OutOfRangeException);
+ }
+
+ for (int i = range.Start; i < range.End; i += range.Stride)
+ {
+ int itemIndex;
+ if (!FindItem(index, i, out itemIndex))
+ {
+ continue;
+ }
+
+ result[i] = mValues[itemIndex];
+ }
+ }
+
+ /// <summary>
/// Returns an <see cref="IEnumerator"/> that enumerates the rows of this matrix.
/// </summary>
/// <param name="range">the <see cref="Range"/> of rows to enumerate over.</param>
/// <returns>an <see cref="IEnumerator"/> that enumerates over a given <see cref="Range"/> of rowss of this matrix.</returns>
public override IEnumerator<KeyValuePair<int, Vector>> RowEnumerator(Range range)
{
- throw new NotImplementedException();
+ if (range.Start >= Rows || range.End >= Rows)
+ {
+ throw new ArgumentOutOfRangeException("range", Strings.OutOfRangeException);
+ }
+ for (int i = range.Start; i <= range.End; i += range.Stride)
+ {
+ yield return new KeyValuePair<int, Vector>(i, Row(i));
+ }
}
/// <summary>
@@ -638,7 +823,10 @@
/// <returns>an <see cref="IEnumerator"/> that enumerates over the rows of this matrix.</returns>
public override IEnumerator<KeyValuePair<int, Vector>> RowEnumerator()
{
- throw new NotImplementedException();
+ for (int i = 0; i <= Rows; i++)
+ {
+ yield return new KeyValuePair<int, Vector>(i, Row(i));
+ }
}
///<summary>Calculates the condition number of this matrix.</summary>
Modified: trunk/LinearAlgebra/SparseVector.cs
===================================================================
--- trunk/LinearAlgebra/SparseVector.cs 2006-01-25 12:50:47 UTC (rev 192)
+++ trunk/LinearAlgebra/SparseVector.cs 2006-01-25 13:59:09 UTC (rev 193)
@@ -9,7 +9,7 @@
/// <summary>
/// A vector class that only stores non-zero values.
/// </summary>
- public sealed class SparseVector : Vector
+ internal sealed class SparseVector : Vector
{
/// <summary>
/// The array containing the actual values. Only the non-zero values are stored
|
|
From: <in...@dn...> - 2006-01-25 12:50:56
|
Author: marcus
Date: 2006-01-25 07:50:47 -0500 (Wed, 25 Jan 2006)
New Revision: 192
Modified:
trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
trunk/LinearAlgebra/Decomposition/DenseLU.cs
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/LinearAlgebra/Decomposition/DenseSvd.cs
trunk/LinearAlgebra/Decomposition/ICholesky.cs
Log:
made corrections as suggested in code review ticket #38.
Modified: trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-25 12:38:37 UTC (rev 191)
+++ trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-25 12:50:47 UTC (rev 192)
@@ -10,16 +10,26 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
+
+ /// <summary>
+ /// The Compute method locks the object and call InteranlCompute. InternalCompute will
+ /// decompse the matrix, overwritting the current matrix with the decomposition, and sets the
+ /// the value of isPositiveDefinite.
+ /// </summary>
internal sealed class DenseCholesky : Algorithm, ICholesky
{
#region Fields
- private bool ispd = false;
+ private bool isPositiveDefinite = false;
private DenseMatrix matrix;
#endregion Fields
#region Constructor
+ /// <summary>
+ /// Constructs a DenseCholesky object.
+ /// </summary>
+ /// <param name="matrix">The matrix to decompose.</param>
public DenseCholesky(Matrix matrix)
{
if (matrix == null)
@@ -37,60 +47,53 @@
#endregion Constructor
- #region Properties
-
-
- #endregion Properties
-
#region Public Methods
+ ///<summary>Return a value indicating whether the matrix is positive definite.</summary>
+ ///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
public bool IsPositiveDefinite()
{
Compute();
- return ispd;
+ return isPositiveDefinite;
}
+ ///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
+ ///<returns>The lower triangular Cholesky factored matrix.</returns>
+ ///<exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
public Matrix Factor()
{
Compute();
- if (!ispd)
+ if (!isPositiveDefinite)
{
throw new NotPositiveDefiniteException();
}
return matrix.Clone();
}
+ /// <summary>
+ /// Copies the Cholesky factored matrix (lower triangular form) into the result <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> store factored matrix into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotSquareMatrixException">If <paramref name="result"/> is not a square matrix.</exception>
+ /// <exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
public void Factor(Matrix result)
{
Compute();
- if (!ispd)
+ if (!isPositiveDefinite)
{
throw new NotPositiveDefiniteException();
}
- for (int i = 0; i < result.Rows; i++)
- {
- for (int j = 0; j < result.Columns; j++)
- {
- result.ValueAt(i, j, matrix.ValueAt(i, j));
- }
- }
+ matrix.CopyTo(result);
}
-
- public void Factor(DenseMatrix result)
- {
- Compute();
- if (!ispd)
- {
- throw new NotPositiveDefiniteException();
- }
- Buffer.BlockCopy(matrix.data, 0, result.data, 0, matrix.data.Length * Constants.SizeOfDouble);
- }
-
+ /// <summary>Calculates the determinant of the matrix.</summary>
+ /// <returns>The determinant of the matrix.</returns>
+ /// <exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
public double Determinant()
{
Compute();
- if (!ispd)
+ if (!isPositiveDefinite)
{
throw new NotPositiveDefiniteException();
}
@@ -114,7 +117,7 @@
int ret = matrix.lapack.CholeskyFactor(matrix.Rows, matrix.data);
if (ret == 0)
{
- ispd = true;
+ isPositiveDefinite = true;
}
}
Modified: trunk/LinearAlgebra/Decomposition/DenseLU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-25 12:38:37 UTC (rev 191)
+++ trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-25 12:50:47 UTC (rev 192)
@@ -15,6 +15,11 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
+ /// <summary>
+ /// The Compute method locks the object and call InteranlCompute. InternalCompute will
+ /// decompose the matrix, overwritting the current matrix with the decomposition, and sets the
+ /// the value of l1Norm, infNorm, and pivots.
+ /// </summary>
internal sealed class DenseLU : Algorithm, ILU
{
#region Fields
Modified: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 12:38:37 UTC (rev 191)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 12:50:47 UTC (rev 192)
@@ -12,7 +12,9 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
/// <summary>
- /// Computes the QR decomposition of a dense <see cref="Matrix"/>.
+ /// The Compute method locks the object and call InteranlCompute. InternalCompute will
+ /// decompose the matrix, overwritting the current matrix with the decomposition, and sets the
+ /// the value of q, det and isFullRank.
/// </summary>
internal sealed class DenseQR : Algorithm, IQR
{
Modified: trunk/LinearAlgebra/Decomposition/DenseSvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-25 12:38:37 UTC (rev 191)
+++ trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-25 12:50:47 UTC (rev 192)
@@ -15,7 +15,9 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
/// <summary>
- /// Class for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
+ /// The Compute method locks the object and call InteranlCompute. InternalCompute will
+ /// decompose the matrix, set the values of u,v,s, and rank. It will will also set the
+ /// intial matrix to null.
/// </summary>
internal sealed class DenseSvd : Algorithm, ISvd
{
Modified: trunk/LinearAlgebra/Decomposition/ICholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-25 12:38:37 UTC (rev 191)
+++ trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-25 12:50:47 UTC (rev 192)
@@ -12,13 +12,13 @@
///<summary>Interface to compute the Cholesky factorization of a n by n <see cref="Matrix"/>.</summary>
internal interface ICholesky : IAlgorithm
{
- ///<summary>Return a value indicating whether the matrix is positive definite.</summary>
- ///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
+ /// <summary>Return a value indicating whether the matrix is positive definite.</summary>
+ /// <returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
bool IsPositiveDefinite();
- ///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
- ///<returns>The lower triangular Cholesky factored matrix.</returns>
- ///<exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
+ /// <summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
+ /// <returns>The lower triangular Cholesky factored matrix.</returns>
+ /// <exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
Matrix Factor();
/// <summary>
@@ -27,12 +27,12 @@
/// <param name="result">The <see cref="Matrix"/> store factored matrix into.</param>
/// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If <paramref name="result"/> is not a square matrix.</exception>
- ///<exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
+ /// <exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
void Factor(Matrix result);
- ///<summary>Calculates the determinant of the matrix.</summary>
- ///<returns>The determinant of the matrix.</returns>
- ///<exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
+ /// <summary>Calculates the determinant of the matrix.</summary>
+ /// <returns>The determinant of the matrix.</returns>
+ /// <exception cref="NotPositiveDefiniteException">If the matrix is not positive definite.</exception>
double Determinant();
}
}
|
|
From: <in...@dn...> - 2006-01-25 12:38:46
|
Author: marcus Date: 2006-01-25 07:38:37 -0500 (Wed, 25 Jan 2006) New Revision: 191 Added: trunk/UnitTests/dnAnalytics.snk Log: Added: trunk/UnitTests/dnAnalytics.snk =================================================================== (Binary files differ) Property changes on: trunk/UnitTests/dnAnalytics.snk ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
|
From: <in...@dn...> - 2006-01-25 12:14:45
|
Author: marcus
Date: 2006-01-25 07:14:35 -0500 (Wed, 25 Jan 2006)
New Revision: 190
Modified:
trunk/UnitTests/UnitTests.csproj
Log:
corrected key location.
Modified: trunk/UnitTests/UnitTests.csproj
===================================================================
--- trunk/UnitTests/UnitTests.csproj 2006-01-25 12:03:12 UTC (rev 189)
+++ trunk/UnitTests/UnitTests.csproj 2006-01-25 12:14:35 UTC (rev 190)
@@ -10,8 +10,7 @@
<RootNamespace>dnAnalytics.UnitTests</RootNamespace>
<AssemblyName>dnAnalytics.UnitTests</AssemblyName>
<SignAssembly>true</SignAssembly>
- <AssemblyOriginatorKeyFile>
- </AssemblyOriginatorKeyFile>
+ <AssemblyOriginatorKeyFile>dnAnalytics.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -80,6 +79,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <None Include="dnAnalytics.snk" />
+ </ItemGroup>
+ <ItemGroup>
<Folder Include="LinearAlgebra\Solvers\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
Author: patrick
Date: 2006-01-25 07:03:12 -0500 (Wed, 25 Jan 2006)
New Revision: 189
Modified:
trunk/LinearAlgebra/DenseMatrix.cs
trunk/LinearAlgebra/Matrix.cs
trunk/LinearAlgebra/MatrixBuilder.cs
trunk/LinearAlgebra/Solvers/BicgStabSolver.cs
trunk/LinearAlgebra/Solvers/ConvergenceMonitor.cs
trunk/LinearAlgebra/Solvers/IIterativeMatrixSolver.cs
trunk/LinearAlgebra/Solvers/IPreconditioner.cs
trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs
trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs
trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs
trunk/LinearAlgebra/Solvers/Preconditioners/IlutpHeapSorter.cs
trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs
trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs
trunk/LinearAlgebra/SparseMatrix.cs
trunk/LinearAlgebra/SparseVector.cs
trunk/NumericalLibrary.csproj
trunk/Properties/AssemblyInfo.cs
trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs
trunk/UnitTests/Properties/AssemblyInfo.cs
trunk/UnitTests/UnitTests.csproj
Log:
- Put the iterative solvers back into the vs project. All compile now with the new Vector and Matrix base classes.
- Fixing the SparseMatrix.
- Fixed errors in the SparseVector.GetEnumerator methods.
Modified: trunk/LinearAlgebra/DenseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/DenseMatrix.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/DenseMatrix.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -210,7 +210,7 @@
/// <returns>The value at the given indices.</returns>
/// <exception cref="IndexOutOfRangeException">If <paramref name="row"/> * <paramref name="column"/> is
/// greater than <c>DenseMatrix.Rows * DenseMatrix.Columns</c></exception>.
- public override double ValueAt(int row, int column)
+ protected internal override double ValueAt(int row, int column)
{
return data[column * Rows + row];
}
Modified: trunk/LinearAlgebra/Matrix.cs
===================================================================
--- trunk/LinearAlgebra/Matrix.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Matrix.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -80,7 +80,7 @@
/// <returns>The value at the given indices.</returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
- public abstract double ValueAt(int row, int column);
+ protected internal abstract double ValueAt(int row, int column);
/// <summary>
/// Set the value at the given indices to the given value. Note: This method is not ranged checked. If the
Modified: trunk/LinearAlgebra/MatrixBuilder.cs
===================================================================
--- trunk/LinearAlgebra/MatrixBuilder.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/MatrixBuilder.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Text;
using dnAnalytics.LinearAlgebra.Native;
namespace dnAnalytics.LinearAlgebra
@@ -157,7 +155,8 @@
ret = new DenseMatrix(rows, columns, useNativeLibrary);
break;
case MatrixType.Sparse:
- throw new NotImplementedException();
+ ret = new SparseMatrix(rows, columns);
+ break;
}
return ret;
}
@@ -249,7 +248,15 @@
}
break;
case MatrixType.Sparse:
- throw new NotImplementedException();
+ ret = new SparseMatrix(rows, columns);
+ for (int i = 0; i < rows; i++)
+ {
+ for (int j = 0; j < columns; j++)
+ {
+ ret.ValueAt(i, j, value);
+ }
+ }
+ break;
}
return ret;
}
@@ -260,7 +267,7 @@
/// </summary>
/// <param name="order">The order of the <see cref="Matrix"/> .</param>
/// <returns>An identity <see cref="Matrix"/> of the given order.</returns>
- [Obsolete("This is a temporary methid and will be replaced.", false)]
+ [Obsolete("This is a temporary method and will be replaced.", false)]
public static Matrix CreateIdentityMatrix(int order)
{
return new DenseMatrix(order, false);
Modified: trunk/LinearAlgebra/Solvers/BicgStabSolver.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/BicgStabSolver.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/BicgStabSolver.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -161,9 +161,9 @@
/// left hand side vector can be reused. If so it would be better to
/// use the overloaded <c>Solve</c> method.
/// </remarks>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
- IVector result = new DenseVector(mCoefficients.Rows);
+ Vector result = VectorBuilder.CreateVector(mCoefficients.Rows, VectorType.Dense);
Solve(vector, result);
return result;
}
@@ -173,7 +173,7 @@
/// </summary>
/// <param name="vector">The left hand side vector, <code>x</code>.</param>
/// <param name="result">The right hand side vector, <code>b</code>.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
// Set the convergence monitor
if (mConvergenceMonitor == null)
@@ -190,30 +190,28 @@
// Compute r_0 = b - Ax_0 for some initial guess x_0
// In this case we take x_0 = vector
// This is basically a SAXPY so it could be made a lot faster
- IVector residuals = new DenseVector(mCoefficients.Rows);
+ Vector residuals = VectorBuilder.CreateVector(mCoefficients.Rows, VectorType.Dense);
mCoefficients.Multiply(result, residuals);
residuals.Multiply(-1);
residuals.Add(vector);
//Choose r~ (for example, r~ = r_0)
- IVector tempResiduals = new DenseVector(residuals.Count);
+ Vector tempResiduals = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
residuals.CopyTo(tempResiduals);
// create five temporary vectors needed to hold temporary
// coefficients. All vectors are mangled in each iteration.
// These are defined here to prevent stressing the garbage collector
- IVector p = new DenseVector(residuals.Count);
- IVector pDash = new DenseVector(residuals.Count);
- IVector nu = new DenseVector(residuals.Count);
- IVector s = new DenseVector(residuals.Count);
- IVector sDash = new DenseVector(residuals.Count);
- IVector t = new DenseVector(residuals.Count);
+ Vector p = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
+ Vector pDash = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
+ Vector nu = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
+ Vector s = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
+ Vector sDash = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
+ Vector t = VectorBuilder.CreateVector(residuals.Count, VectorType.Dense);
// create some temporary double variables that are needed
// to hold values in between iterations
double currentRho = 0;
- double oldRho = 0;
- double beta = 0;
double alpha = 0;
double omega = 0;
@@ -221,7 +219,7 @@
while (mConvergenceMonitor.ShouldCalculationContinue(iterationNumber, result, residuals))
{
// rho_(i-1) = r~^T r_(i-1) // dotproduct r~ and r_(i-1)
- oldRho = currentRho;
+ double oldRho = currentRho;
currentRho = tempResiduals.DotProduct(residuals);
// if (rho_(i-1) == 0) // METHOD FAILS
@@ -238,7 +236,7 @@
else
{
// beta_(i-1) = (rho_(i-1)/rho_(i-2))(alpha_(i-1)/omega(i-1))
- beta = (currentRho/oldRho)*(alpha/omega);
+ double beta = (currentRho/oldRho)*(alpha/omega);
// p_i = r_(i-1) + beta_(i-1)(p_(i-1) - omega_(i-1) * nu_(i-1))
nu.Multiply(omega);
p.Subtract(nu);
Modified: trunk/LinearAlgebra/Solvers/ConvergenceMonitor.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/ConvergenceMonitor.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/ConvergenceMonitor.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -105,7 +105,7 @@
/// <param name="solutionVector">The current solution vector.</param>
/// <param name="residualVector">The current residual vector.</param>
/// <returns><c>true</c> if the iterative process may continue; otherwise, <c>false</c>.</returns>
- public bool ShouldCalculationContinue(int currentIterationNumber, IVector solutionVector, IVector residualVector)
+ public bool ShouldCalculationContinue(int currentIterationNumber, Vector solutionVector, Vector residualVector)
{
// check the iteration count. If we are over the maximum number of
// iterations we stop
Modified: trunk/LinearAlgebra/Solvers/IIterativeMatrixSolver.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/IIterativeMatrixSolver.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/IIterativeMatrixSolver.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -28,13 +28,13 @@
/// </remarks>
/// <param name="vector">The right hand side vector, <code>b</code>.</param>
/// <returns>The left hand side vector, <code>x</code>.</returns>
- IVector Solve(IVector vector);
+ Vector Solve(Vector vector);
/// <summary>
/// Solves the standard matrix equation <code>Ax = b</code>.
/// </summary>
/// <param name="vector">The left hand side vector, <code>x</code>.</param>
/// <param name="result">The right hand side vector, <code>b</code>.</param>
- void Solve(IVector vector, IVector result);
+ void Solve(Vector vector, Vector result);
}
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/Solvers/IPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/IPreconditioner.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/IPreconditioner.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -37,13 +37,13 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- IVector Solve(IVector vector);
+ Vector Solve(Vector vector);
/// <summary>
/// Solves the matrix equation <code>Ax = b</code>.
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- void Solve(IVector vector, IVector result);
+ void Solve(Vector vector, Vector result);
}
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalIluFactorization.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -178,7 +178,7 @@
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
/*
Allow to solve system Mx = y
@@ -225,7 +225,7 @@
z_i = d_ii^-1 * (y_i - SUM_(j<i) l_ij * z_j)
}
*/
- IVector rowVector = new SparseVector(mCoefficientMatrix.Rows);
+ Vector rowVector = VectorBuilder.CreateVector(mCoefficientMatrix.Rows, VectorType.Sparse);
for (int i = 0; i < mCoefficientMatrix.Rows; i++)
{
mL.Row(i, rowVector);
@@ -272,7 +272,7 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
if (vector == null)
{
@@ -284,7 +284,7 @@
throw new NotConformableException();
}
- IVector result = new DenseVector(vector.Count);
+ Vector result = VectorBuilder.CreateVector(vector.Count, VectorType.Dense);
Solve(vector, result);
return result;
}
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/DiagonalPreconditioner.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -75,7 +75,7 @@
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
// Solve Dx = y
// Since we stored the inverses of the diagonal values we can do:
@@ -117,7 +117,7 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
if (vector == null)
{
@@ -129,7 +129,7 @@
throw new NotConformableException();
}
- IVector result = new DenseVector(vector.Count);
+ Vector result = VectorBuilder.CreateVector(vector.Count, VectorType.Dense);
Solve(vector, result);
return result;
}
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/IluFactorization.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -137,7 +137,7 @@
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
if (vector == null)
{
@@ -169,7 +169,7 @@
}
NOTE: l_ii should be 1 because u_ii has to be the value
*/
- IVector rowValues = new DenseVector(mLuDecomposition.Rows);
+ Vector rowValues = VectorBuilder.CreateVector(mLuDecomposition.Rows, VectorType.Dense);
for (int i = 0; i < mLuDecomposition.Rows; i++)
{
mLuDecomposition.Row(i, rowValues);
@@ -216,7 +216,7 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
if (vector == null)
{
@@ -228,7 +228,7 @@
throw new NotConformableException();
}
- IVector result = new DenseVector(vector.Count);
+ Vector result = VectorBuilder.CreateVector(vector.Count, VectorType.Dense);
Solve(vector, result);
return result;
}
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/IlutpHeapSorter.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/IlutpHeapSorter.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/IlutpHeapSorter.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -11,7 +11,7 @@
internal static class IlutpHeapSorter
{
public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound,
- int[] sortedIndices, IVector values)
+ int[] sortedIndices, Vector values)
{
// Move all the indices that we're interested in forward
// Ignore the rest
@@ -30,7 +30,7 @@
}
- private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, IVector values)
+ private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
{
int start = (upperBound - lowerBound + 1)/2 - 1 + lowerBound;
int end = (upperBound - lowerBound + 1) - 1 + lowerBound;
@@ -45,7 +45,7 @@
}
}
- private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, IVector values)
+ private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
{
while (start >= 0)
{
@@ -54,7 +54,7 @@
}
}
- private static void SiftDoubleIndices(int[] sortedIndices, IVector values, int begin, int count)
+ private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
{
int root = begin;
int child;
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/IlutpPreconditioner.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -239,8 +239,8 @@
{
mPivots[i] = i;
}
- IVector workVector = new DenseVector(mCoefficientMatrix.Rows);
- IVector rowVector = new DenseVector(mCoefficientMatrix.Columns);
+ Vector workVector = VectorBuilder.CreateVector(mCoefficientMatrix.Rows, VectorType.Dense);
+ Vector rowVector = VectorBuilder.CreateVector(mCoefficientMatrix.Columns, VectorType.Dense);
int[] indexSorting = new int[mCoefficientMatrix.Rows];
// spaceLeft = lfilNnz * nnz(A)
int spaceLeft = (int) mFillLevel*mCoefficientMatrix.NonZeros;
@@ -373,7 +373,7 @@
mWasPreconditionerCreated = true;
}
- private void PivotRow(IVector row)
+ private void PivotRow(Vector row)
{
Hashtable knownPivots = new Hashtable();
// pivot the row
@@ -412,7 +412,7 @@
return false;
}
- private static void SwapColumns(IMatrix matrix, int firstColumn, int secondColumn)
+ private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn)
{
for (int i = 0; i < matrix.Rows; i++)
{
@@ -422,7 +422,7 @@
}
}
- private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, IVector values)
+ private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
{
// Copy the indices for the values into the array
for (int i = 0; i < upperBound + 1 - lowerBound; i++)
@@ -445,7 +445,7 @@
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
if (vector == null)
{
@@ -469,7 +469,7 @@
// Solve equation here
// Pivot(vector, result);
// Solve L*Y = B(piv,:)
- IVector rowValues = new DenseVector(mL.Rows);
+ Vector rowValues = VectorBuilder.CreateVector(mL.Rows, VectorType.Dense);
for (int i = 0; i < mL.Rows; i++)
{
mL.Row(i, rowValues);
@@ -499,11 +499,11 @@
// We have a column pivot so we only need to pivot the
// end result not the incomming right hand side vector
- IVector temp = new DenseVector(result);
+ Vector temp = result.Clone();
Pivot(temp, result);
}
- private void Pivot(IVector vector, IVector result)
+ private void Pivot(Vector vector, Vector result)
{
for (int i = 0; i < mPivots.Length; i++)
{
@@ -521,7 +521,7 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
if (vector == null)
{
@@ -533,7 +533,7 @@
throw new NotConformableException();
}
- IVector result = new DenseVector(vector.Count);
+ Vector result = VectorBuilder.CreateVector(vector.Count,VectorType.Dense);
Solve(vector, result);
return result;
}
Modified: trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs
===================================================================
--- trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/Solvers/Preconditioners/UnitPreconditioner.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -55,7 +55,7 @@
/// </summary>
/// <param name="vector">The right hand side vector.</param>
/// <param name="result">The left hand side vector.</param>
- public void Solve(IVector vector, IVector result)
+ public void Solve(Vector vector, Vector result)
{
if (vector == null)
{
@@ -85,7 +85,7 @@
/// </remarks>
/// <param name="vector">The right hand side vector.</param>
/// <returns>The left hand side vector.</returns>
- public IVector Solve(IVector vector)
+ public Vector Solve(Vector vector)
{
if (vector == null)
{
@@ -97,7 +97,7 @@
throw new NotConformableException();
}
- IVector result = new DenseVector(vector.Count);
+ Vector result = VectorBuilder.CreateVector(vector.Count, VectorType.Dense);
Solve(vector, result);
return result;
}
Modified: trunk/LinearAlgebra/SparseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -68,7 +68,7 @@
/// <param name="dimension">The number of rows and columns in the matrix.</param>
public SparseMatrix(int dimension) : this(dimension, dimension)
{
- // Redirects to CDoubleSparseMatrix(int rows, int columns)
+ // Redirects to SparseMatrix(int rows, int columns)
}
/// <summary>
@@ -471,9 +471,9 @@
/// <returns>The value at the given indices.</returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
- public override double ValueAt(int row, int column)
+ protected internal override double ValueAt(int row, int column)
{
- throw new NotImplementedException();
+ return this[row, column];
}
/// <summary>
Modified: trunk/LinearAlgebra/SparseVector.cs
===================================================================
--- trunk/LinearAlgebra/SparseVector.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/LinearAlgebra/SparseVector.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -670,21 +670,9 @@
public override IEnumerator<KeyValuePair<int,double>> GetEnumerator()
{
// Iterate over the vector size and return each value.
- for (int i = 0; i < mSize; i++)
+ for (int i = 0; i < mValueCount; i++)
{
- // See if the item exists. If so then return the value otherwise
- // return zero.
- // NOTE: we could potentially keep track of the last 'real' index
- // that we used. That way we wouldn't have to do a search.
- int internalIndex;
- if (FindItem(i, out internalIndex))
- {
- yield return new KeyValuePair<int, double>(i, mValues[internalIndex]);
- }
- else
- {
- yield return new KeyValuePair<int, double>(i, 0.0);
- }
+ yield return new KeyValuePair<int, double>(mIndices[i], mValues[i]);
}
}
@@ -703,18 +691,25 @@
{
throw new ArgumentOutOfRangeException("range");
}
-
- for (int i = range.Start; i <= range.End; i += range.Stride)
+
+ // Find the start
+ int begin;
+ FindItem(range.Start, out begin);
+
+ // Find the end
+ int end;
+ FindItem(range.End, out end);
+
+ // for each item between start and end
+ for (int i = begin; i <= end; i++)
{
- int internalIndex;
- if (FindItem(i, out internalIndex))
+ int difference = mIndices[i] - range.Start;
+ if (difference % range.Stride != 0)
{
- yield return new KeyValuePair<int, double>(i, mValues[internalIndex]);
+ continue;
}
- else
- {
- yield return new KeyValuePair<int, double>(i, 0.0);
- }
+
+ yield return new KeyValuePair<int, double>(mIndices[i], mValues[i]);
}
}
Modified: trunk/NumericalLibrary.csproj
===================================================================
--- trunk/NumericalLibrary.csproj 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/NumericalLibrary.csproj 2006-01-25 12:03:12 UTC (rev 189)
@@ -117,8 +117,19 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="LinearAlgebra\Range.cs" />
+ <Compile Include="LinearAlgebra\Solvers\BicgStabSolver.cs" />
+ <Compile Include="LinearAlgebra\Solvers\ConvergenceMonitor.cs" />
+ <Compile Include="LinearAlgebra\Solvers\IIterativeMatrixSolver.cs" />
+ <Compile Include="LinearAlgebra\Solvers\IPreconditioner.cs" />
<Compile Include="LinearAlgebra\Solvers\ISolver.cs" />
<Compile Include="LinearAlgebra\Decomposition\Svd.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\DiagonalIluFactorization.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\DiagonalPreconditioner.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\IluFactorization.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\IlutpHeapSorter.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\IlutpPreconditioner.cs" />
+ <Compile Include="LinearAlgebra\Solvers\Preconditioners\UnitPreconditioner.cs" />
+ <Compile Include="LinearAlgebra\Solvers\SolutionStatus.cs" />
<Compile Include="LinearAlgebra\SparseMatrix.cs" />
<Compile Include="LinearAlgebra\SparseVector.cs">
<SubType>Code</SubType>
@@ -152,9 +163,6 @@
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
- <ItemGroup>
- <Folder Include="LinearAlgebra\Solvers\Preconditioners\" />
- </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Modified: trunk/Properties/AssemblyInfo.cs
===================================================================
--- trunk/Properties/AssemblyInfo.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/Properties/AssemblyInfo.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -24,9 +24,6 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("62f04261-c566-4563-9ab2-e87dbbd5a605")]
-
// Version information for an assembly consists of the following four values:
//
// Major Version
Modified: trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -1,247 +1,45 @@
+using dnAnalytics.LinearAlgebra;
using NUnit.Framework;
-namespace dnA.Math
+namespace dnAnalytics.UnitTests.LinearAlgebra
{
[TestFixture]
- public sealed class CDoubleSparseMatrixTest : AbstractDoubleMatrixTest
+ public sealed class CDoubleSparseMatrixTest : AbstractMatrixTest
{
- [SetUp]
- public void SetUp()
+ public override Matrix GetMatrix(int order)
{
- // Empty for now
+ return MatrixBuilder.CreateMatrix(order, MatrixType.Sparse);
}
- [TearDown]
- public void TearDown()
+ public override Matrix GetMatrix(int m, int n)
{
- // Empty for now
+ return MatrixBuilder.CreateMatrix(m, n, MatrixType.Sparse);
}
- protected override AbstractDoubleMatrix CreateMatrix(int rowCount, int columnCount)
+ public override Matrix GetMatrix(double[,] data)
{
- return new DoubleSparseMatrix(rowCount, columnCount);
- }
-
- [Test]
- public void GetNonExistingValue()
- {
- int rowCount = 10;
- int columnCount = 10;
- DoubleSparseMatrix matrix = new DoubleSparseMatrix(rowCount, columnCount);
-
- Assert.AreEqual(0, matrix.NonZeros, "#01");
-
- // Set some values. Use multiple per row to check the search
- // algorithm that the matrix class uses
- for (int i = 0; i < matrix.Rows; i++)
+ int rows = data.GetLength(0);
+ int cols = data.GetLength(1);
+ Matrix ret = MatrixBuilder.CreateMatrix(rows, cols, MatrixType.Sparse);
+ for (int i = 0; i < rows; i++)
{
- if (UtilityFunctions.IsEven(i))
+ for (int j = 0; j < cols; j++)
{
- // place values at the even j numbers
- // Order is garbled to check that that algoritm
- // actually doesn't care about the order in which
- // elements are added
- matrix[i, 6] = 10 * (i + 1) + (6 + 1);
- matrix[i, 4] = 10 * (i + 1) + (4 + 1);
- matrix[i, 2] = 10 * (i + 1) + (2 + 1);
- matrix[i, 8] = 10 * (i + 1) + (8 + 1);
- matrix[i, 0] = 10 * (i + 1) + (0 + 1);
+ ret[i, j] = data[i, j];
}
- else
- {
- // place values at the even j numbers
- matrix[i, 1] = 10 * (i + 1) + (1 + 1);
- matrix[i, 3] = 10 * (i + 1) + (3 + 1);
- matrix[i, 5] = 10 * (i + 1) + (5 + 1);
- matrix[i, 7] = 10 * (i + 1) + (7 + 1);
- matrix[i, 9] = 10 * (i + 1) + (9 + 1);
- }
}
- Assert.AreEqual(rowCount * (columnCount / 2), matrix.NonZeros, "#01");
-
- // Check that all numbers in the matrix are equal to zero
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if ((UtilityFunctions.IsEven(i) && UtilityFunctions.IsEven(j)) ||
- (UtilityFunctions.IsOdd(i) && UtilityFunctions.IsOdd(j)))
- {
- Assert.AreEqual(10 * (i + 1) + (j + 1), matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
+ return ret;
}
- [Test]
- public void SetExistingValueToZero()
+ public override Vector GetVector(int size)
{
- int rowCount = 10;
- int columnCount = 10;
- DoubleSparseMatrix matrix = new DoubleSparseMatrix(rowCount, columnCount);
-
- // now set the diagonal values and check if we can retrieve them
- // again.
- for (int i = 0; i < matrix.Rows; i++)
- {
- matrix[i, i] = i + 1;
- }
-
- Assert.AreEqual(matrix.Rows, matrix.NonZeros, "#01");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if (i != j)
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
-
- // Now set one of the diagonal values to zero and check that it is
- // actually gone
- matrix[5, 5] = 0.0;
-
- Assert.AreEqual(matrix.Rows - 1, matrix.NonZeros, "#03");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if ((i != j) || ((i == 5) && (j == 5)))
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
+ return VectorBuilder.CreateVector(size, VectorType.Dense);
}
- [Test]
- public void SetNonExistingValueToZero()
+ public override Vector GetVector(double[] source)
{
- int rowCount = 10;
- int columnCount = 10;
- DoubleSparseMatrix matrix = new DoubleSparseMatrix(rowCount, columnCount);
-
- // now set the diagonal values and check if we can retrieve them
- // again.
- for (int i = 0; i < matrix.Rows; i++)
- {
- matrix[i, i] = i + 1;
- }
-
- Assert.AreEqual(matrix.Rows, matrix.NonZeros, "#01");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if (i != j)
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
-
- // Now set one of the zero values to zero and check that nothing
- // has changed
- matrix[5, 6] = 0.0;
-
- Assert.AreEqual(matrix.Rows, matrix.NonZeros, "#03");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if (i != j)
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
+ return VectorBuilder.CreateVector(source, VectorType.Dense);
}
-
- [Test]
- public void SetNonExistingValue()
- {
- int rowCount = 10;
- int columnCount = 10;
- DoubleSparseMatrix matrix = new DoubleSparseMatrix(rowCount, columnCount);
-
- // now set the diagonal values and check if we can retrieve them
- // again.
- for (int i = 0; i < matrix.Rows; i++)
- {
- matrix[i, i] = i + 1;
- }
-
- Assert.AreEqual(matrix.Rows, matrix.NonZeros, "#01");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if (i != j)
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#02-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
-
- // Now set one of the zero values to zero and check that nothing
- // has changed
- matrix[5, 6] = 56.0;
-
- Assert.AreEqual(matrix.Rows + 1, matrix.NonZeros, "#03");
-
- for (int i = 0; i < matrix.Rows; i++)
- {
- for (int j = 0; j < matrix.Columns; j++)
- {
- if ((i != j) && ((i != 5) || (j != 6)))
- {
- Assert.AreEqual(0.0, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- if (i == j)
- {
- Assert.AreEqual(i + 1, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- else
- {
- Assert.AreEqual(56, matrix[i, j], epsilon, "#04-(" + i.ToString() + ", " + j.ToString() + ")");
- }
- }
- }
- }
- }
}
}
\ No newline at end of file
Modified: trunk/UnitTests/Properties/AssemblyInfo.cs
===================================================================
--- trunk/UnitTests/Properties/AssemblyInfo.cs 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/UnitTests/Properties/AssemblyInfo.cs 2006-01-25 12:03:12 UTC (rev 189)
@@ -21,9 +21,6 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("2615366c-8aa4-415f-b74b-c54d3d8abcf5")]
-
// Version information for an assembly consists of the following four values:
//
// Major Version
Modified: trunk/UnitTests/UnitTests.csproj
===================================================================
--- trunk/UnitTests/UnitTests.csproj 2006-01-25 11:53:12 UTC (rev 188)
+++ trunk/UnitTests/UnitTests.csproj 2006-01-25 12:03:12 UTC (rev 189)
@@ -65,6 +65,10 @@
<Compile Include="LinearAlgebra\IO\DelimitedMatrixWriter.cs" />
<Compile Include="LinearAlgebra\IO\MatrixMarketReader.cs" />
<Compile Include="LinearAlgebra\IO\MatrixMarketWriter.cs" />
+ <Compile Include="LinearAlgebra\SparseMatrixTest.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="LinearAlgebra\SparseVectorTest.cs" />
<Compile Include="Math\Complex.cs" />
<Compile Include="Math\ComplexMath.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
From: <in...@dn...> - 2006-01-25 11:53:32
|
Author: marcus
Date: 2006-01-25 06:53:12 -0500 (Wed, 25 Jan 2006)
New Revision: 188
Modified:
trunk/Properties/AssemblyInfo.cs
Log:
fixed internalto.
Modified: trunk/Properties/AssemblyInfo.cs
===================================================================
--- trunk/Properties/AssemblyInfo.cs 2006-01-25 09:22:06 UTC (rev 187)
+++ trunk/Properties/AssemblyInfo.cs 2006-01-25 11:53:12 UTC (rev 188)
@@ -17,7 +17,7 @@
[assembly: AssemblyTrademark("dnAnalytics")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguageAttribute("en", UltimateResourceFallbackLocation.Satellite)]
-//[assembly: InternalsVisibleTo("dnAnalytics.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100FDEBDA60947A98706C9971659013F83667AD9EC23B9DEC64537D8BB3113DF2CC49D2020EC0EB530574776F6A4B726D711135AE2893DC134A5E4B8D02AC0AD913154EE5F2907E8C6B9A6F1FFD3D756D7BF5AAE6A2E8B3D34C5914C8F629C2879C6C5226E447D95F58F07A429F43C54D6B61DDB442FD384C7CF588FDCE7F7353F4")]
+[assembly: InternalsVisibleTo("dnAnalytics.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100FDEBDA60947A98706C9971659013F83667AD9EC23B9DEC64537D8BB3113DF2CC49D2020EC0EB530574776F6A4B726D711135AE2893DC134A5E4B8D02AC0AD913154EE5F2907E8C6B9A6F1FFD3D756D7BF5AAE6A2E8B3D34C5914C8F629C2879C6C5226E447D95F58F07A429F43C54D6B61DDB442FD384C7CF588FDCE7F7353F4")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
|
|
From: <in...@dn...> - 2006-01-25 09:22:16
|
Author: marcus
Date: 2006-01-25 04:22:06 -0500 (Wed, 25 Jan 2006)
New Revision: 187
Modified:
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/LinearAlgebra/Decomposition/IQR.cs
trunk/LinearAlgebra/Decomposition/QR.cs
Log:
implemented changes as suggested in code review ticket #39.
Modified: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 08:56:38 UTC (rev 186)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 09:22:06 UTC (rev 187)
@@ -12,7 +12,7 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
/// <summary>
- /// Computes the QR decomposition of a <see cref="Matrix"/>.
+ /// Computes the QR decomposition of a dense <see cref="Matrix"/>.
/// </summary>
internal sealed class DenseQR : Algorithm, IQR
{
@@ -67,6 +67,9 @@
/// Copies the orthogonal Q matrix into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> is not a square matrix
+ /// with an order equal to the number of rows of the matrix being factored.</exception>
public void Q(Matrix result)
{
if (result == null)
@@ -74,7 +77,7 @@
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- if (result.Rows != q.Rows || result.Columns != q.Columns)
+ if (result.Rows != r.Rows || result.Columns != r.Rows)
{
throw new NotConformableException("result", Strings.ParameterNotConformable);
}
@@ -86,6 +89,10 @@
/// Copies the upper triangular factor R into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> does not have the
+ /// dimensions m by n, where m and n are the number of columns and rows of the matrix being
+ /// factored, respectively.</exception>
public void R(Matrix result)
{
if (result == null)
@@ -114,9 +121,9 @@
return det;
}
/// <summary>
- /// Determine whether the matrix is full rank or not.
+ /// Determines whether the matrix is full rank or not.
/// </summary>
- /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ /// <returns><c>true</c> if the matrix is full rank; othewise <c>false</c>.</returns>
public bool IsFullRank()
{
Compute();
Modified: trunk/LinearAlgebra/Decomposition/IQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-25 08:56:38 UTC (rev 186)
+++ trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-25 09:22:06 UTC (rev 187)
@@ -6,6 +6,7 @@
#region Using Directives
+using System;
using dnAnalytics.Exceptions;
using dnAnalytics.Math;
@@ -19,9 +20,9 @@
internal interface IQR : IAlgorithm
{
/// <summary>
- /// Determine whether the matrix is full rank or not.
+ /// Determines whether the matrix is full rank or not.
/// </summary>
- /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ /// <returns><c>true</c> if the matrix is full rank; othewise <c>false</c>.</returns>
bool IsFullRank();
/// <summary>
@@ -34,6 +35,9 @@
/// Copies the orthogonal Q matrix into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> is not a square matrix
+ /// with an order equal to the number of rows of the matrix being factored.</exception>
void Q(Matrix result);
/// <summary>
@@ -46,6 +50,10 @@
/// Copies the upper triangular factor R into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> does not have the
+ /// dimensions m by n, where m and n are the number of columns and rows of the matrix being
+ /// factored, respectively.</exception>
void R(Matrix result);
///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-25 08:56:38 UTC (rev 186)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-25 09:22:06 UTC (rev 187)
@@ -68,6 +68,9 @@
/// Copies the orthogonal Q matrix into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> is not a square matrix
+ /// with an order equal to the number of rows of the matrix being factored.</exception>
public void Q(Matrix result)
{
if (result == null)
@@ -85,6 +88,10 @@
/// Copies the upper triangular factor R into the result matrix.
/// </summary>
/// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> does not have the
+ /// dimensions m by n, where m and n are the number of columns and rows of the matrix being
+ /// factored, respectively.</exception>
public void R(Matrix result)
{
if (result == null)
@@ -99,20 +106,15 @@
decomp.R(result);
}
-
- #endregion Public Methods
-
- #region Public Properties
/// <summary>
- /// Determine whether the matrix is full rank or not.
+ /// Determines whether the matrix is full rank or not.
/// </summary>
- /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ /// <returns><c>true</c> if the matrix is full rank; othewise <c>false</c>.</returns>
public bool IsFullRank()
{
return decomp.IsFullRank();
}
-
///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
///<returns>The determinant of the matrix.</returns>
///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
@@ -121,7 +123,7 @@
return decomp.Determinant();
}
- #endregion Public Properites
+ #endregion Public Methods
#region Protected Members
|
|
From: <in...@dn...> - 2006-01-25 08:56:51
|
Author: marcus
Date: 2006-01-25 03:56:38 -0500 (Wed, 25 Jan 2006)
New Revision: 186
Modified:
trunk/LinearAlgebra/DenseMatrix.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
trunk/UnitTests/UnitTests.csproj
Log:
--problem with last check in
changed all properties in the decomposition classes to methods, since they all call compute (which can be expensive).
Modified: trunk/LinearAlgebra/DenseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/DenseMatrix.cs 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/LinearAlgebra/DenseMatrix.cs 2006-01-25 08:56:38 UTC (rev 186)
@@ -443,7 +443,7 @@
throw new NotSquareMatrixException(Strings.MustBeSquare);
}
DenseLU lu = new DenseLU(this);
- return lu.Determinant;
+ return lu.Determinant();
}
/// <summary>
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs 2006-01-25 08:56:38 UTC (rev 186)
@@ -48,13 +48,13 @@
[Test]
public void PositiveDefinite()
{
- Assert.IsTrue(cholesky.IsPositiveDefinite);
+ Assert.IsTrue(cholesky.IsPositiveDefinite());
}
[Test]
public void NotPositiveDefinite()
{
- Assert.IsFalse(notPD.IsPositiveDefinite);
+ Assert.IsFalse(notPD.IsPositiveDefinite());
}
[Test]
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs 2006-01-25 08:56:38 UTC (rev 186)
@@ -48,13 +48,13 @@
[Test]
public void Singular()
{
- Assert.IsTrue(singularLu.IsSingular);
+ Assert.IsTrue(singularLu.IsSingular());
}
[Test]
public void NotSingular()
{
- Assert.IsFalse(lu.IsSingular);
+ Assert.IsFalse(lu.IsSingular());
}
[Test]
@@ -315,9 +315,9 @@
[Test]
public void Determinant()
{
- Assert.AreEqual(0, singularLu.Determinant);
+ Assert.AreEqual(0, singularLu.Determinant());
double expected = -5.006656015927541e248;
- double actual = lu.Determinant;
+ double actual = lu.Determinant();
double error = System.Math.Abs((actual - expected) / expected);
Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
}
@@ -413,7 +413,7 @@
public void L1NormConditionNumber()
{
double expected = 0.000539909549815265;
- double actual = lu.L1NormConditionNumber;
+ double actual = lu.L1NormConditionNumber();
double error = System.Math.Abs((actual - expected) / expected);
Console.WriteLine(expected + " : " + actual + " : " + error);
Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
@@ -423,7 +423,7 @@
public void InfinityNormConditionNumber()
{
double expected = 0.000522256126360585;
- double actual = lu.InfinityNormConditionNumber;
+ double actual = lu.InfinityNormConditionNumber();
double error = System.Math.Abs((actual - expected) / expected);
Console.WriteLine(expected + " : " + actual + " : " + error);
Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-25 08:56:38 UTC (rev 186)
@@ -47,15 +47,15 @@
[Test]
public void NotFullRank()
{
- Assert.IsFalse(singularQr.IsFullRank);
+ Assert.IsFalse(singularQr.IsFullRank());
}
[Test]
public void FullRank()
{
- Assert.IsTrue(squareQr.IsFullRank);
- Assert.IsTrue(wideQr.IsFullRank);
- Assert.IsTrue(tallQr.IsFullRank);
+ Assert.IsTrue(squareQr.IsFullRank());
+ Assert.IsTrue(wideQr.IsFullRank());
+ Assert.IsTrue(tallQr.IsFullRank());
}
[Test]
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-25 08:56:38 UTC (rev 186)
@@ -381,48 +381,48 @@
[Test]
public void Rank()
{
- int rank = squareSvd.Rank;
+ int rank = squareSvd.Rank();
Assert.AreEqual(squareMatrix.Rows, rank);
- rank = tallSvd.Rank;
+ rank = tallSvd.Rank();
Assert.AreEqual(tallMatrix.Columns, rank);
- rank = wideSvd.Rank;
+ rank = wideSvd.Rank();
Assert.AreEqual(wideMatrix.Rows, rank);
- rank = singularSvd.Rank;
+ rank = singularSvd.Rank();
Assert.AreEqual(squareMatrix.Rows - 1, rank);
}
[Test]
public void Norm()
{
- double norm = squareSvd.Norm2;
+ double norm = squareSvd.Norm2();
Assert.AreEqual(1011.4190766097751, norm, ACCEPTABLE_ERROR);
- norm = tallSvd.Norm2;
+ norm = tallSvd.Norm2();
Assert.AreEqual(445.27398550522514, norm, ACCEPTABLE_ERROR);
- norm = wideSvd.Norm2;
+ norm = wideSvd.Norm2();
Assert.AreEqual(385.51714390506197, norm, ACCEPTABLE_ERROR);
- norm = singularSvd.Norm2;
+ norm = singularSvd.Norm2();
Assert.AreEqual(2, norm, ACCEPTABLE_ERROR);
}
[Test]
public void ConditionNumber()
{
- double cn = squareSvd.ConditionNumber;
+ double cn = squareSvd.ConditionNumber();
Assert.AreEqual(207.5103850393096, cn, 1e-4);
- cn = tallSvd.ConditionNumber;
+ cn = tallSvd.ConditionNumber();
Assert.AreEqual(5.01902319723716, cn, ACCEPTABLE_ERROR);
- cn = wideSvd.ConditionNumber;
+ cn = wideSvd.ConditionNumber();
Assert.AreEqual(3.65923703921971, cn, ACCEPTABLE_ERROR);
- cn = singularSvd.ConditionNumber;
+ cn = singularSvd.ConditionNumber();
Assert.Greater(cn, 1e16);
}
}
Modified: trunk/UnitTests/UnitTests.csproj
===================================================================
--- trunk/UnitTests/UnitTests.csproj 2006-01-25 08:54:33 UTC (rev 185)
+++ trunk/UnitTests/UnitTests.csproj 2006-01-25 08:56:38 UTC (rev 186)
@@ -59,7 +59,7 @@
<Compile Include="LinearAlgebra\Decomposition\DenseLUTest.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="LinearAlgebra\DenesMatrixTest.cs" />
+ <Compile Include="LinearAlgebra\DenseMatrixTest.cs" />
<Compile Include="LinearAlgebra\DenseVectorTest.cs" />
<Compile Include="LinearAlgebra\IO\DelimitedMatrixReader.cs" />
<Compile Include="LinearAlgebra\IO\DelimitedMatrixWriter.cs" />
|
|
From: <in...@dn...> - 2006-01-25 08:54:45
|
Author: marcus
Date: 2006-01-25 03:54:33 -0500 (Wed, 25 Jan 2006)
New Revision: 185
Modified:
trunk/LinearAlgebra/Decomposition/Cholesky.cs
trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
trunk/LinearAlgebra/Decomposition/DenseLU.cs
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/LinearAlgebra/Decomposition/DenseSvd.cs
trunk/LinearAlgebra/Decomposition/ICholesky.cs
trunk/LinearAlgebra/Decomposition/ILU.cs
trunk/LinearAlgebra/Decomposition/IQR.cs
trunk/LinearAlgebra/Decomposition/ISvd.cs
trunk/LinearAlgebra/Decomposition/LU.cs
trunk/LinearAlgebra/Decomposition/QR.cs
trunk/LinearAlgebra/Decomposition/Svd.cs
Log:
changed all properties in the decomposition classes to methods, since they all call compute (which can be expensive).
Modified: trunk/LinearAlgebra/Decomposition/Cholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -55,9 +55,9 @@
///<summary>Return a value indicating whether the matrix is positive definite.</summary>
///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
- public bool IsPositiveDefinite
+ public bool IsPositiveDefinite()
{
- get { return decomp.IsPositiveDefinite; }
+ return decomp.IsPositiveDefinite();
}
///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
Modified: trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -38,19 +38,18 @@
#endregion Constructor
#region Properties
- public bool IsPositiveDefinite
- {
- get
- {
- Compute();
- return ispd;
- }
- }
+
#endregion Properties
#region Public Methods
+ public bool IsPositiveDefinite()
+ {
+ Compute();
+ return ispd;
+ }
+
public Matrix Factor()
{
Compute();
Modified: trunk/LinearAlgebra/Decomposition/DenseLU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -58,14 +58,11 @@
/// <summary>
/// Returns a value indicating whether the matrix is singular.
/// </summary>
- /// <value><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</value>
- public bool IsSingular
+ /// <returns><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</returns>
+ public bool IsSingular()
{
- get
- {
- Compute();
- return singular;
- }
+ Compute();
+ return singular;
}
Matrix ILU.LowerFactor()
@@ -148,74 +145,66 @@
/// <summary>
/// The determinant of the matrix.
/// </summary>
- public double Determinant
+ /// <returns>The determinant of the matrix.</returns>
+ public double Determinant()
{
- get
+ Compute();
+ if (singular)
{
- Compute();
- if (singular)
+ return 0;
+ }
+ if (det == Double.MinValue)
+ {
+ det = 1.0;
+ for (int j = 0; j < matrix.Rows; j++)
{
- return 0;
- }
- if (det == Double.MinValue)
- {
- det = 1.0;
- for (int j = 0; j < matrix.Rows; j++)
+ if (pivots[j] != j)
{
- if (pivots[j] != j)
- {
- det = -det * matrix.data[j * matrix.Rows + j];
- }
- else
- {
- det *= matrix.data[j * matrix.Rows + j];
- }
+ det = -det * matrix.data[j * matrix.Rows + j];
}
+ else
+ {
+ det *= matrix.data[j * matrix.Rows + j];
+ }
}
- return det;
}
+ return det;
}
/// <summary>
/// The L1 norm condition number of the matrix. The number is calculated as ||A|| * ||AInverse|| where ||.|| is the L1 norm.
/// </summary>
- public double L1NormConditionNumber
+ public double L1NormConditionNumber()
{
- get
+ Compute();
+ if (singular)
{
- Compute();
- if (singular)
- {
- return Double.PositiveInfinity;
- }
- if (l1Condition == Double.MinValue)
- {
- l1Condition = matrix.lapack.ConditionNumber('1', matrix.Rows, l1Norm, matrix.data, pivots);
- }
-
- return l1Condition;
+ return Double.PositiveInfinity;
}
+ if (l1Condition == Double.MinValue)
+ {
+ l1Condition = matrix.lapack.ConditionNumber('1', matrix.Rows, l1Norm, matrix.data, pivots);
+ }
+
+ return l1Condition;
}
/// <summary>
/// The infinity norm condition number of the matrix. The number is calculated as ||A|| * ||AInverse|| where ||.|| is the infinity norm.
/// </summary>
- public double InfinityNormConditionNumber
+ public double InfinityNormConditionNumber()
{
- get
+ Compute();
+ if (singular)
{
- Compute();
- if (singular)
- {
- return Double.PositiveInfinity;
- }
- if (infCondition == Double.MinValue)
- {
- infCondition = matrix.lapack.ConditionNumber('I', matrix.Rows, infNorm, matrix.data, pivots);
- }
-
- return infCondition;
+ return Double.PositiveInfinity;
}
+ if (infCondition == Double.MinValue)
+ {
+ infCondition = matrix.lapack.ConditionNumber('I', matrix.Rows, infNorm, matrix.data, pivots);
+ }
+
+ return infCondition;
}
Matrix ILU.Inverse()
Modified: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -14,7 +14,7 @@
/// <summary>
/// Computes the QR decomposition of a <see cref="Matrix"/>.
/// </summary>
- public sealed class DenseQR : Algorithm, IQR
+ internal sealed class DenseQR : Algorithm, IQR
{
#region Fields
private bool isFullRank = true;
@@ -113,26 +113,19 @@
Compute();
return det;
}
-
- #endregion Public Methods
-
- #region Public Properties
-
/// <summary>
- /// Determine whether the matrix is full rank or not
+ /// Determine whether the matrix is full rank or not.
/// </summary>
- /// <value>Boolean value indicates whether the given matrix is full rank or not</value>
- public bool IsFullRank
+ /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ public bool IsFullRank()
{
- get
- {
- Compute();
- return isFullRank;
- }
+ Compute();
+ return isFullRank;
}
- #endregion Public Properties
+ #endregion Public Methods
+
#region Protected Members
/// <summary>
Modified: trunk/LinearAlgebra/Decomposition/DenseSvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -17,7 +17,7 @@
/// <summary>
/// Class for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
/// </summary>
- public sealed class DenseSvd : Algorithm, ISvd
+ internal sealed class DenseSvd : Algorithm, ISvd
{
#region Fields
private readonly bool computeVectors;
@@ -55,37 +55,28 @@
#region Properties
///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
- ///<value>The two norm of the <see cref="Matrix"/>.</value>
- public double Norm2
+ ///<returns>The two norm of the <see cref="Matrix"/>.</returns>
+ public double Norm2()
{
- get
- {
- Compute();
- return s[0];
- }
+ Compute();
+ return s[0];
}
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
- ///<value>The condition number.</value>
- public double ConditionNumber
+ ///<returns>The condition number.</returns>
+ public double ConditionNumber()
{
- get
- {
- Compute();
- int tmp = System.Math.Min(rows, columns) - 1;
- return s[0] / s[tmp];
- }
+ Compute();
+ int tmp = System.Math.Min(rows, columns) - 1;
+ return s[0] / s[tmp];
}
///<summary>Returns the effective numerical matrix rank.</summary>
- ///<value>The number of non-negligible singular values.</value>
- public int Rank
+ ///<returns>The number of non-negligible singular values.</returns>
+ public int Rank()
{
- get
- {
- Compute();
- return rank;
- }
+ Compute();
+ return rank;
}
#endregion Properties
Modified: trunk/LinearAlgebra/Decomposition/ICholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -13,8 +13,8 @@
internal interface ICholesky : IAlgorithm
{
///<summary>Return a value indicating whether the matrix is positive definite.</summary>
- ///<value><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</value>
- bool IsPositiveDefinite { get; }
+ ///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
+ bool IsPositiveDefinite();
///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
///<returns>The lower triangular Cholesky factored matrix.</returns>
Modified: trunk/LinearAlgebra/Decomposition/ILU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ILU.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/ILU.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -21,8 +21,8 @@
/// <summary>
/// Returns a value indicating whether the matrix is singular.
/// </summary>
- /// <value><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</value>
- bool IsSingular { get;}
+ /// <returns><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</returns>
+ bool IsSingular();
/// <summary>
/// Returns the lower factor of the factorization.
@@ -55,7 +55,8 @@
/// <summary>
/// The determinant of the matrix.
/// </summary>
- double Determinant { get; }
+ /// <returns>The determinant of the matrix.</returns>
+ double Determinant();
/// <summary>
/// Returns the inverse of the matrix.
@@ -83,13 +84,14 @@
/// Estimates the reciprocal the L1 norm condition number of the matrix. The number is calculated
/// as ||A|| * ||AInverse|| where ||.|| is the L1 norm.
/// </summary>
- double L1NormConditionNumber { get; }
+ /// <returns>The reciprocal the L1 norm condition number of the matrix</returns>
+ double L1NormConditionNumber();
/// <summary>
/// Estimates the reciprocal the infinity norm condition number of the matrix. The number is calculated
/// as ||A|| * ||AInverse|| where ||.|| is the infinity norm.
/// </summary>
- double InfinityNormConditionNumber { get; }
-
+ /// <returns>The reciprocal the infinity norm condition number of the matrix</returns>
+ double InfinityNormConditionNumber();
}
}
Modified: trunk/LinearAlgebra/Decomposition/IQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -21,8 +21,8 @@
/// <summary>
/// Determine whether the matrix is full rank or not.
/// </summary>
- /// <value>Boolean value indicates whether the given matrix is full rank or not.</value>
- bool IsFullRank { get; }
+ /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ bool IsFullRank();
/// <summary>
/// Returns the orthogonal Q matrix.
Modified: trunk/LinearAlgebra/Decomposition/ISvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -71,16 +71,16 @@
void S(Vector result);
///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
- ///<value>The two norm of the <see cref="Matrix"/>.</value>
- double Norm2 { get; }
+ ///<returns>The two norm of the <see cref="Matrix"/>.</returns>
+ double Norm2();
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
- ///<value>The condition number.</value>
- double ConditionNumber { get; }
+ ///<returns>The condition number.</returns>
+ double ConditionNumber();
///<summary>Returns the effective numerical matrix rank.</summary>
- ///<value>The number of non-negligible singular values.</value>
- int Rank { get; }
+ ///<returns>The number of non-negligible singular values.</returns>
+ int Rank();
}
}
Modified: trunk/LinearAlgebra/Decomposition/LU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -56,10 +56,10 @@
/// <summary>
/// Returns a value indicating whether the matrix is singular.
/// </summary>
- /// <value><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</value>
- public bool IsSingular
+ /// <returns><c>true</c> if the matrix is singular; otherwise, <c>false</c>.</returns>
+ public bool IsSingular()
{
- get { return decomp.IsSingular; }
+ return decomp.IsSingular();
}
/// <summary>
@@ -123,12 +123,10 @@
/// <summary>
/// The determinant of the matrix.
/// </summary>
- public double Determinant
+ /// <returns>The determinant of the matrix.</returns>
+ public double Determinant()
{
- get
- {
- return decomp.Determinant;
- }
+ return decomp.Determinant();
}
@@ -136,24 +134,20 @@
/// Estimates the reciprocal the L1 norm condition number of the matrix. The number is calculated
/// as ||A|| * ||AInverse|| where ||.|| is the L1 norm.
/// </summary>
- public double L1NormConditionNumber
+ /// <returns>The reciprocal of the L1 norm condition number (estimated) of the matrix.</returns>
+ public double L1NormConditionNumber()
{
- get
- {
- return decomp.L1NormConditionNumber;
- }
+ return decomp.L1NormConditionNumber();
}
/// <summary>
/// Estimates the reciprocal the infinity norm condition number of the matrix. The number is calculated
/// as ||A|| * ||AInverse|| where ||.|| is the infinity norm.
/// </summary>
- public double InfinityNormConditionNumber
+ /// <returns>The reciprocal of the infinity norm condition number (estimated) of the matrix.</returns>
+ public double InfinityNormConditionNumber()
{
- get
- {
- return decomp.InfinityNormConditionNumber;
- }
+ return decomp.InfinityNormConditionNumber();
}
/// <summary>
@@ -163,7 +157,7 @@
/// <exception cref="SingularMatrixException">If the matrix is singular.</exception>
public Matrix Inverse()
{
- if (IsSingular)
+ if (IsSingular())
{
throw new SingularMatrixException();
}
@@ -188,7 +182,7 @@
throw new NotConformableException("result", Strings.ParameterNotConformable);
}
- if (IsSingular)
+ if (IsSingular())
{
throw new SingularMatrixException();
}
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -106,13 +106,10 @@
/// <summary>
/// Determine whether the matrix is full rank or not.
/// </summary>
- /// <value>Boolean value indicates whether the given matrix is full rank or not.</value>
- public bool IsFullRank
+ /// <returns>Boolean value indicates whether the given matrix is full rank or not.</returns>
+ public bool IsFullRank()
{
- get
- {
- return decomp.IsFullRank;
- }
+ return decomp.IsFullRank();
}
Modified: trunk/LinearAlgebra/Decomposition/Svd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-25 03:50:51 UTC (rev 184)
+++ trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-25 08:54:33 UTC (rev 185)
@@ -50,34 +50,26 @@
#region Properties
///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
- ///<value>The two norm of the <see cref="Matrix"/>.</value>
- public double Norm2
+ ///<returns>The 2-norm of the <see cref="Matrix"/>.</returns>
+ public double Norm2()
{
- get
- {
- return decomp.Norm2;
- }
+ return decomp.Norm2();
}
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
- ///<value>The condition number.</value>
- public double ConditionNumber
+ ///<returns>The condition number.</returns>
+ public double ConditionNumber()
{
- get
- {
- return decomp.ConditionNumber;
- }
+ return decomp.ConditionNumber();
}
///<summary>Returns the effective numerical matrix rank.</summary>
- ///<value>The number of non-negligible singular values.</value>
- public int Rank
+ ///<returns>The number of non-negligible singular values.</returns>
+ public int Rank()
{
- get
- {
- return decomp.Rank;
- }
+ return decomp.Rank();
}
+
#endregion Properties
#region Public Methods
|
|
From: <in...@dn...> - 2006-01-25 03:51:13
|
Author: patrick
Date: 2006-01-24 22:50:51 -0500 (Tue, 24 Jan 2006)
New Revision: 184
Added:
trunk/UnitTests/LinearAlgebra/DenseMatrixTest.cs
trunk/UnitTests/LinearAlgebra/SparseMatrixTest.cs
trunk/UnitTests/LinearAlgebra/SparseVectorTest.cs
Removed:
trunk/UnitTests/LinearAlgebra/DenesMatrixTest.cs
trunk/UnitTests/LinearAlgebra/DoubleSparseMatrixTest.cs
trunk/UnitTests/LinearAlgebra/DoubleSparseVectorTest.cs
Modified:
trunk/LinearAlgebra/SparseMatrix.cs
trunk/LinearAlgebra/SparseVector.cs
trunk/LinearAlgebra/VectorBuilder.cs
trunk/NumericalLibrary.csproj
Log:
- Fixed up the SparseVector which should now be complete.
- Fixed up the compile errors in the SparseMatrix. Needs implementation of methods.
- Fixed up the SparseVectorTest.
- Added the SparseVector to the VectorBuilder.
Modified: trunk/LinearAlgebra/SparseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 02:46:17 UTC (rev 183)
+++ trunk/LinearAlgebra/SparseMatrix.cs 2006-01-25 03:50:51 UTC (rev 184)
@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
+using dnAnalytics.Exceptions;
using dnAnalytics.LinearAlgebra;
namespace dnAnalytics.LinearAlgebra
@@ -17,7 +18,7 @@
/// In the current implementation the <c>SparseMatrix</c> uses a
/// compressed row storage system.
/// </remarks>
- public sealed class SparseMatrix : IMatrix
+ public sealed class SparseMatrix : Matrix
{
// UPGRADE NOTE: Could create an iternal class that
// holds the sparse data structure. That way we can interchange
@@ -48,14 +49,6 @@
/// </summary>
internal readonly int[] mRowIndices = new int[0];
/// <summary>
- /// The number of rows in the matrix.
- /// </summary>
- private readonly int mRowCount = -1;
- /// <summary>
- /// The number of columns in the matrix.
- /// </summary>
- private readonly int mColumnCount = -1;
- /// <summary>
/// The total number of non-zero values in the matrix.
/// </summary>
/// <remarks>
@@ -85,9 +78,9 @@
/// <param name="columns">The number of columns in the matrix.</param>
public SparseMatrix(int rows, int columns)
{
- mRowCount = rows;
+ Rows = rows;
mRowIndices = new int[rows];
- mColumnCount = columns;
+ Columns = columns;
}
/// <summary>
@@ -101,14 +94,14 @@
/// non-zero values.
/// </remarks>
/// <param name="source">
- /// The <see cref="IMatrix"/> from which the data will
+ /// The <see cref="Matrix"/> from which the data will
/// be copied to the new instance.
/// </param>
- public SparseMatrix(IMatrix source)
+ public SparseMatrix(Matrix source)
{
- mRowCount = source.Rows;
- mRowIndices = new int[mRowCount];
- mColumnCount = source.Columns;
+ Rows = source.Rows;
+ mRowIndices = new int[Rows];
+ Columns = source.Columns;
for (int i = 0; i < source.Rows; i++)
{
@@ -128,12 +121,12 @@
/// </param>
public SparseMatrix(SparseMatrix source)
{
- mRowCount = source.mRowCount;
+ Rows = source.Rows;
// copy the row indices
mRowIndices = new int[source.mRowIndices.Length];
Buffer.BlockCopy(source.mRowIndices, 0, mRowIndices, 0, mRowIndices.Length * Constants.SizeOfInt);
- mColumnCount = source.mColumnCount;
+ Columns = source.Columns;
// copy the colum indices. Only copy the actual data items. Note that the array
// may be bigger than the number of items we copy.
mColumnIndices = new int[source.mColumnIndices.Length];
@@ -160,9 +153,9 @@
/// copied to the new instance.</param>
public SparseMatrix(double[,] source)
{
- mRowCount = source.GetLength(0);
- mRowIndices = new int[mRowCount];
- mColumnCount = source.GetLength(1);
+ Rows = source.GetLength(0);
+ mRowIndices = new int[Rows];
+ Columns= source.GetLength(1);
for (int i = 0; i < source.GetLength(0); i++)
{
@@ -179,15 +172,15 @@
/// <param name="row">The row index.</param>
/// <param name="column">The column index.</param>
/// <returns>A requested element from the matrix.</returns>
- public double this[int row, int column]
+ public override double this[int row, int column]
{
get
{
- if ((row < 0) || (row > mRowCount - 1))
+ if ((row < 0) || (row > Rows - 1))
{
throw new ArgumentOutOfRangeException("rowIndex", row, "Row index was outside the bounds of the matrix");
}
- if ((column < 0) || (column > mColumnCount - 1))
+ if ((column < 0) || (column > Columns - 1))
{
throw new ArgumentOutOfRangeException("columnIndex", column, "Column index was outside the bounds of the matrix");
}
@@ -201,11 +194,11 @@
}
set
{
- if ((row < 0) || (row > mRowCount - 1))
+ if ((row < 0) || (row > Rows - 1))
{
throw new ArgumentOutOfRangeException("rowIndex", row, "Row index was outside the bounds of the matrix");
}
- if ((column < 0) || (column > mColumnCount - 1))
+ if ((column < 0) || (column > Columns - 1))
{
throw new ArgumentOutOfRangeException("columnIndex", column, "Column index was outside the bounds of the matrix");
}
@@ -478,7 +471,7 @@
/// <returns>The value at the given indices.</returns>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
- public double ValueAt(int row, int column)
+ public override double ValueAt(int row, int column)
{
throw new NotImplementedException();
}
@@ -493,34 +486,12 @@
/// <param name="value">The value to set.</param>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
- public void ValueAt(int row, int column, double value)
+ public override void ValueAt(int row, int column, double value)
{
throw new NotImplementedException();
}
/// <summary>
- /// The number of columns.
- /// </summary>
- public int Columns
- {
- get
- {
- return mColumnCount;
- }
- }
-
- /// <summary>
- /// The numbers of rows.
- /// </summary>
- public int Rows
- {
- get
- {
- return mRowCount;
- }
- }
-
- /// <summary>
/// Returns the number of non zero elements in the matrix.
/// </summary>
/// <value>The number of non zero elements.</value>
@@ -534,46 +505,36 @@
/// <summary>Calculates the Frobenius norm of this matrix.</summary>
/// <returns>The Frobenius norm of this matrix.</returns>
- public double FrobeniusNorm()
+ public override double FrobeniusNorm()
{
throw new NotImplementedException();
}
/// <summary>Calculates the infinity norm of this matrix.</summary>
/// <returns>The infinity norm of this matrix.</returns>
- public double InfinityNorm()
+ public override double InfinityNorm()
{
throw new NotImplementedException();
}
/// <summary>Calculates the L1 norm of this matrix.</summary>
/// <returns>The L1 norm of this matrix.</returns>
- public double L1Norm()
+ public override double L1Norm()
{
throw new NotImplementedException();
}
/// <summary>Calculates the L2 norm of this matrix.</summary>
/// <returns>The L2 norm of this matrix.</returns>
- public double L2Norm()
+ public override double L2Norm()
{
throw new NotImplementedException();
}
/// <summary>
- /// Calculates the P norm of this matrix.
- /// </summary>
- /// <param name="p">The n-th norm to calculate.</param>
- /// <returns>The P norm of the this matrix.</returns>
- public double PNorm(double p)
- {
- throw new NotImplementedException();
- }
-
- /// <summary>
/// Sets all values to zero.
/// </summary>
- public void Clear()
+ public override void Clear()
{
mValueCount = 0;
}
@@ -583,7 +544,7 @@
/// </summary>
/// <param name="index">The column to copy.</param>
/// <returns>A vector containing the copied elements.</returns>
- public IVector Column(int index)
+ public override Vector Column(int index)
{
throw new NotImplementedException();
}
@@ -594,7 +555,7 @@
/// <param name="index">The column to copy.</param>
/// <param name="result">The vector to copy the column into.</param>
/// <exception cref="ArgumentNullException">If the result matrix is null.</exception>
- public void Column(int index, IVector result)
+ public override void Column(int index, Vector result)
{
throw new NotImplementedException();
}
@@ -605,7 +566,7 @@
/// <param name="index">The column to copy.</param>
/// <param name="range">The <see cref="Range"/> of elements to copy.</param>
/// <returns>A vector containing the copied elements.</returns>
- public IVector Column(int index, Range range)
+ public override Vector Column(int index, Range range)
{
throw new NotImplementedException();
}
@@ -615,7 +576,7 @@
/// </summary>
/// <param name="range">The <see cref="Range"/> of columns to enumerate over.</param>
/// <returns>An <see cref="IEnumerator"/> that enumerates over a given <see cref="Range"/> of columns of this matrix.</returns>
- public IEnumerator<KeyValuePair<int, IVector>> ColumnEnumerator(Range range)
+ public override IEnumerator<KeyValuePair<int, Vector>> ColumnEnumerator(Range range)
{
throw new NotImplementedException();
}
@@ -624,7 +585,7 @@
/// Returns an <see cref="IEnumerator"/> that enumerates the columns of this matrix.
/// </summary>
/// <returns>An <see cref="IEnumerator"/> that enumerates over the columns of this matrix.</returns>
- public IEnumerator<KeyValuePair<int, IVector>> ColumnEnumerator()
+ public override IEnumerator<KeyValuePair<int, Vector>> ColumnEnumerator()
{
throw new NotImplementedException();
}
@@ -634,7 +595,7 @@
/// </summary>
/// <param name="index">The row to copy.</param>
/// <returns>A vector containing the copied elements.</returns>
- public IVector Row(int index)
+ public override Vector Row(int index)
{
throw new NotImplementedException();
}
@@ -645,7 +606,7 @@
/// <param name="index">The row to copy.</param>
/// <param name="result">The vector to copy the row into.</param>
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
- public void Row(int index, IVector result)
+ public override void Row(int index, Vector result)
{
throw new NotImplementedException();
}
@@ -656,7 +617,7 @@
/// <param name="index">the column to copy.</param>
/// <param name="range">the <see cref="Range"/> of elements to copy.</param>
/// <returns>a vector containing the copied elements.</returns>
- public IVector Row(int index, Range range)
+ public override Vector Row(int index, Range range)
{
throw new NotImplementedException();
}
@@ -666,7 +627,7 @@
/// </summary>
/// <param name="range">the <see cref="Range"/> of rows to enumerate over.</param>
/// <returns>an <see cref="IEnumerator"/> that enumerates over a given <see cref="Range"/> of rowss of this matrix.</returns>
- public IEnumerator<KeyValuePair<int, IVector>> RowEnumerator(Range range)
+ public override IEnumerator<KeyValuePair<int, Vector>> RowEnumerator(Range range)
{
throw new NotImplementedException();
}
@@ -675,7 +636,7 @@
/// Returns an <see cref="IEnumerator"/> that enumerates the rows of this matrix.
/// </summary>
/// <returns>an <see cref="IEnumerator"/> that enumerates over the rows of this matrix.</returns>
- public IEnumerator<KeyValuePair<int, IVector>> RowEnumerator()
+ public override IEnumerator<KeyValuePair<int, Vector>> RowEnumerator()
{
throw new NotImplementedException();
}
@@ -683,7 +644,7 @@
///<summary>Calculates the condition number of this matrix.</summary>
///<returns>the condition number of the matrix.</returns>
///<exception cref="dnAnalytics.Exceptions.NotSquareMatrixException">if the matrix is not square.</exception>
- public double ConditionNumber()
+ public override double ConditionNumber()
{
throw new NotImplementedException();
}
@@ -694,7 +655,7 @@
/// <param name="target">The matrix to copy values into.</param>
/// <exception cref="ArgumentNullException">if target is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if target is not the same size as this matrix.</exception>
- public void CopyTo(IMatrix target)
+ public override void CopyTo(Matrix target)
{
throw new NotImplementedException();
}
@@ -702,7 +663,7 @@
/// <summary>Computes the determinant of this matrix.</summary>
/// <returns>The determinant of this matrix.</returns>
/// <exception cref="dnAnalytics.Exceptions.NotSquareMatrixException">the matrix is not square.</exception>
- public double Determinant()
+ public override double Determinant()
{
throw new NotImplementedException();
}
@@ -713,7 +674,7 @@
/// <param name="vector">the vector to copy the diagonal elements into.</param>
/// <exception cref="ArgumentNullException">if vector is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the size of the vector is not Min(this.Rows, this.Columns).</exception>
- public void Diagonal(IVector vector)
+ public override void Diagonal(Vector vector)
{
throw new NotImplementedException();
}
@@ -722,7 +683,7 @@
/// Returns the elements on the diagonal in a vector with dense storage.
/// </summary>
/// <returns>the elements on the diagonal.</returns>
- public IVector Diagonal()
+ public override Vector Diagonal()
{
throw new NotImplementedException();
}
@@ -731,7 +692,7 @@
/// Returns the transpose of this matrix.
/// </summary>
/// <returns>the transpose of this matrix.</returns>
- public IMatrix GetTranspose()
+ public override Matrix GetTranspose()
{
throw new NotImplementedException();
}
@@ -739,7 +700,7 @@
/// <summary>
/// Transposes this matrix, overwriting its values.
/// </summary>
- public void Transpose()
+ public override void Transpose()
{
throw new NotImplementedException();
}
@@ -750,7 +711,7 @@
/// <param name="result">the result of the transpose.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not this.Columns x this.Rows.</exception>
- public void Transpose(IMatrix result)
+ public override void Transpose(Matrix result)
{
throw new NotImplementedException();
}
@@ -760,7 +721,7 @@
/// </summary>
/// <returns>The inverse of this matrix.</returns>
/// <exception cref="dnAnalytics.Exceptions.NotSquareMatrixException">if this matrix is not square.</exception>
- public IMatrix Inverse()
+ public override Matrix Inverse()
{
throw new NotImplementedException();
}
@@ -771,7 +732,7 @@
/// <param name="result">A matrix to hold the inverse of this matrix.</param>
/// <exception cref="ArgumentNullException">If the result matrix is <c>null</c>.</exception>
/// <exception cref="NotSquareMatrixException">If this matrix is not square.</exception>
- public void Inverse(IMatrix result)
+ public override void Inverse(Matrix result)
{
throw new NotImplementedException();
}
@@ -780,7 +741,7 @@
/// Inverts this matrix using LU decomposition.
/// </summary>
/// <exception cref="dnAnalytics.Exceptions.NotSquareMatrixException">if this matrix is not square.</exception>
- public void Invert()
+ public override void Invert()
{
throw new NotImplementedException();
}
@@ -792,7 +753,7 @@
/// <param name="columns">number of columns to resize the matrix to.</param>
/// <remarks>If the current dimensions are the same as the given dimensions, nothing is done (the matrix is not
/// cleared).</remarks>
- public void Resize(int rows, int columns)
+ public override void Resize(int rows, int columns)
{
throw new NotImplementedException();
}
@@ -804,7 +765,7 @@
/// <param name="columns">number of columns to resize the matrix to.</param>
/// <remarks>Will maintain the matrix values for those elements that are within the new dimensions.
/// New elements are set zero.</remarks>
- public void ResizeCopy(int rows, int columns)
+ public override void ResizeCopy(int rows, int columns)
{
throw new NotImplementedException();
}
@@ -818,7 +779,7 @@
/// number of rows in this matrix, then min( rows, source.Count )
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetColumn(int index, IVector source)
+ public override void SetColumn(int index, Vector source)
{
throw new NotImplementedException();
}
@@ -832,7 +793,7 @@
/// number of rows in this matrix, then min( rows, source.Count )
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetColumn(int index, double[] source)
+ public override void SetColumn(int index, double[] source)
{
throw new NotImplementedException();
}
@@ -845,7 +806,7 @@
/// length of the diagonal, then the min(rows, columns, source.Count)
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetDiagonal(IVector source)
+ public override void SetDiagonal(Vector source)
{
throw new NotImplementedException();
}
@@ -858,7 +819,7 @@
/// length of the diagonal, then the min(rows, columns, source.Length)
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetDiagonal(double[] source)
+ public override void SetDiagonal(double[] source)
{
throw new NotImplementedException();
}
@@ -872,7 +833,7 @@
/// number of rows in this matrix, then min( columns, source.Count )
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetRow(int index, IVector source)
+ public override void SetRow(int index, Vector source)
{
throw new NotImplementedException();
}
@@ -886,7 +847,7 @@
/// number of rows in this matrix, then min( columns, source.Length )
/// elements are copied.</remarks>
/// <exception cref="ArgumentNullException">if source is null.</exception>
- public void SetRow(int index, double[] source)
+ public override void SetRow(int index, double[] source)
{
throw new NotImplementedException();
}
@@ -895,7 +856,7 @@
/// Returns a new matrix containing the lower triangle of this matrix.
/// </summary>
/// <returns>the lower triangle of this matrix.</returns>
- public IMatrix LowerTriangle()
+ public override Matrix LowerTriangle()
{
throw new NotImplementedException();
}
@@ -906,7 +867,7 @@
/// <param name="result">where to store the the lower triangle.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void LowerTriangle(IMatrix result)
+ public override void LowerTriangle(Matrix result)
{
throw new NotImplementedException();
}
@@ -916,7 +877,7 @@
/// does not contain the diagonal elements of this matrix.
/// </summary>
/// <returns>the lower trinagle of this matrix.</returns>
- public IMatrix StrictlyLowerTriangle()
+ public override Matrix StrictlyLowerTriangle()
{
throw new NotImplementedException();
}
@@ -928,7 +889,7 @@
/// <param name="result">where to store the the lower triangle.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void StrictlyLowerTriangle(IMatrix result)
+ public override void StrictlyLowerTriangle(Matrix result)
{
throw new NotImplementedException();
}
@@ -939,7 +900,7 @@
/// <param name="result">where to store the the upper triangle.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void UpperTriangle(IMatrix result)
+ public override void UpperTriangle(Matrix result)
{
throw new NotImplementedException();
}
@@ -948,7 +909,7 @@
/// Returns a new matrix containing the upper triangle of this matrix.
/// </summary>
/// <returns>the upper triangle of this matrix.</returns>
- public IMatrix UpperTriangle()
+ public override Matrix UpperTriangle()
{
throw new NotImplementedException();
}
@@ -958,7 +919,7 @@
/// does not contain the diagonal elements of this matrix.
/// </summary>
/// <returns>the upper trinagle of this matrix.</returns>
- public IMatrix StrictlyUpperTriangle()
+ public override Matrix StrictlyUpperTriangle()
{
throw new NotImplementedException();
}
@@ -970,7 +931,7 @@
/// <param name="result">where to store the the upper triangle.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void StrictlyUpperTriangle(IMatrix result)
+ public override void StrictlyUpperTriangle(Matrix result)
{
throw new NotImplementedException();
}
@@ -982,7 +943,7 @@
/// <param name="rowRange">The <see cref="Range"/> of rows to copy into the new matrix.</param>
/// <param name="columnRange">The <see cref="Range"/> of columns to copy into the new matrix.</param>
/// <returns>a sub-matrix of this matrix for the given ranges.</returns>
- public IMatrix SubMatrix(Range rowRange, Range columnRange)
+ public override Matrix SubMatrix(Range rowRange, Range columnRange)
{
throw new NotImplementedException();
}
@@ -995,7 +956,7 @@
/// <param name="result">The matrix to copy the sub-matrix into.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as those defined by the <c>Ranges</c>.</exception>
- public void SubMatrix(Range rowRange, Range columnRange, IMatrix result)
+ public override void SubMatrix(Range rowRange, Range columnRange, Matrix result)
{
throw new NotImplementedException();
}
@@ -1004,7 +965,7 @@
/// Returns this matrix as a multidimensional array.
/// </summary>
/// <returns>a multidimensional containing the values of this matrix.</returns>
- public double[,] ToArray()
+ public override double[,] ToArray()
{
throw new NotImplementedException();
}
@@ -1015,7 +976,7 @@
/// </summary>
/// <param name="format">the format to use on each element.</param>
/// <returns>a string representation of the matrix.</returns>
- public string ToString(string format)
+ public override string ToString(string format)
{
throw new NotImplementedException();
}
@@ -1024,7 +985,7 @@
/// Adds a scalar to each element in the matrix overwriting the values of this matrix.
/// </summary>
/// <param name="scalar">the scalar to add.</param>
- public void Add(double scalar)
+ public override void Add(double scalar)
{
throw new NotImplementedException();
}
@@ -1036,7 +997,7 @@
/// <param name="result">the results of the addition.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Add(double scalar, IMatrix result)
+ public override void Add(double scalar, Matrix result)
{
throw new NotImplementedException();
}
@@ -1047,7 +1008,7 @@
/// <param name="other">the matrix to add to this matrix.</param>
/// <exception cref="ArgumentNullException">if the other matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the two matrices don't have the same dimensions.</exception>
- public void Add(IMatrix other)
+ public override void Add(Matrix other)
{
throw new NotImplementedException();
}
@@ -1061,7 +1022,7 @@
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the two matrices don't have the same dimensions.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Add(IMatrix other, IMatrix result)
+ public override void Add(Matrix other, Matrix result)
{
throw new NotImplementedException();
}
@@ -1069,7 +1030,7 @@
/// <summary>
/// Negates each element of this matrix.
/// </summary>
- public void Negate()
+ public override void Negate()
{
throw new NotImplementedException();
}
@@ -1080,7 +1041,7 @@
/// <param name="result">the result of the negation.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Negate(IMatrix result)
+ public override void Negate(Matrix result)
{
throw new NotImplementedException();
}
@@ -1089,7 +1050,7 @@
/// Subtracts a scalar from each value in the matrix overwriting the values of this matrix.
/// </summary>
/// <param name="scalar">the scalar to subtract.</param>
- public void Subtract(double scalar)
+ public override void Subtract(double scalar)
{
throw new NotImplementedException();
}
@@ -1101,7 +1062,7 @@
/// <param name="result">the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Subtract(double scalar, IMatrix result)
+ public override void Subtract(double scalar, Matrix result)
{
throw new NotImplementedException();
}
@@ -1112,7 +1073,7 @@
/// <param name="other">the matrix to subtract.</param>
/// <exception cref="ArgumentNullException">if the other matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the two matrices don't have the same dimensions.</exception>
- public void Subtract(IMatrix other)
+ public override void Subtract(Matrix other)
{
throw new NotImplementedException();
}
@@ -1126,7 +1087,7 @@
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the two matrices don't have the same dimensions.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Subtract(IMatrix other, IMatrix result)
+ public override void Subtract(Matrix other, Matrix result)
{
throw new NotImplementedException();
}
@@ -1135,7 +1096,7 @@
/// Multiplies each element of this matrix with a scalar overwriting the values of this matrix.
/// </summary>
/// <param name="scalar">the scalar to multiply with.</param>
- public void Multiply(double scalar)
+ public override void Multiply(double scalar)
{
throw new NotImplementedException();
}
@@ -1147,7 +1108,7 @@
/// <param name="result">the matrix to multiply.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Multiply(double scalar, IMatrix result)
+ public override void Multiply(double scalar, Matrix result)
{
throw new NotImplementedException();
}
@@ -1158,7 +1119,7 @@
/// <param name="other">the matrix to multiple with.</param>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if this.Columns != other.Rows</exception>
/// <exception cref="ArgumentNullException">if the other matrix is null.</exception>
- public void Multiply(IMatrix other)
+ public override Matrix Multiply(Matrix other)
{
throw new NotImplementedException();
}
@@ -1172,7 +1133,7 @@
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if this.Columns != other.Rows</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the this.Rows x other.Columns.</exception>
- public void Multiply(IMatrix other, IMatrix result)
+ public override void Multiply(Matrix other, Matrix result)
{
throw new NotImplementedException();
}
@@ -1184,7 +1145,7 @@
/// <returns>the result of the multiplication.</returns>
/// <exception cref="ArgumentNullException">if rightSide is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the this.Columns != rightSide.Count.</exception>
- public IVector Multiply(IVector rightSide)
+ public override Vector Multiply(Vector rightSide)
{
throw new NotImplementedException();
}
@@ -1198,7 +1159,7 @@
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result vector size is not rightSide.Count.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the this.Columns != rightSide.Count.</exception>
- public void Multiply(IVector rightSide, IVector result)
+ public override void Multiply(Vector rightSide, Vector result)
{
throw new NotImplementedException();
}
@@ -1210,7 +1171,7 @@
/// <returns>The result of the multiplication.</returns>
/// <exception cref="ArgumentNullException">If leftSide is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <code>this.Rows != leftSide.Count</code>.</exception>
- public IVector LeftMultiply(IVector leftSide)
+ public override Vector LeftMultiply(Vector leftSide)
{
throw new NotImplementedException();
}
@@ -1224,7 +1185,7 @@
/// <exception cref="ArgumentNullException">If the result matrix is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <code>result.Count != this.Columns</code>.</exception>
/// <exception cref="NotConformableException">If <code>this.Rows != leftSide.Count</code>.</exception>
- public void LeftMultiply(IVector leftSide, IVector result)
+ public override void LeftMultiply(Vector leftSide, Vector result)
{
throw new NotImplementedException();
}
@@ -1233,7 +1194,7 @@
/// Divides each element of the matrix by a scalar overwriting the valuesof this matrix.
/// </summary>
/// <param name="scalar">the scalar to divide by.</param>
- public void Divide(double scalar)
+ public override void Divide(double scalar)
{
throw new NotImplementedException();
}
@@ -1245,7 +1206,7 @@
/// <param name="result">the result of the division.</param>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not the same as this matrix.</exception>
- public void Divide(double scalar, IMatrix result)
+ public override void Divide(double scalar, Matrix result)
{
throw new NotImplementedException();
}
@@ -1257,7 +1218,7 @@
/// <returns>the combined matrix.</returns>
/// <exception cref="ArgumentNullException">if lower is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if upper.Columns != lower.Columns.</exception>
- public IMatrix Stack(IMatrix lower)
+ public override Matrix Stack(Matrix lower)
{
throw new NotImplementedException();
}
@@ -1271,7 +1232,7 @@
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if upper.Columns != lower.Columns.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not (this.Rows + lower.rows) x this.Columns.</exception>
- public void Stack(IMatrix lower, IMatrix result)
+ public override void Stack(Matrix lower, Matrix result)
{
throw new NotImplementedException();
}
@@ -1283,7 +1244,7 @@
/// <returns>The combined matrix.</returns>
/// <exception cref="ArgumentNullException">If right is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <code>this.Rows != right.Rows.</code></exception>
- public IMatrix Append(IMatrix right)
+ public override Matrix Append(Matrix right)
{
throw new NotImplementedException();
}
@@ -1297,7 +1258,7 @@
/// <exception cref="ArgumentNullException">If the result matrix is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <code>this.Rows != right.Rows</code>.</exception>
/// <exception cref="NotConformableException">If the result matrix's dimensions are not this.Rows x (this.Columns + right.Columns).</exception>
- public void Append(IMatrix right, IMatrix result)
+ public override void Append(Matrix right, Matrix result)
{
throw new NotImplementedException();
}
@@ -1310,7 +1271,7 @@
/// <param name="lower">the lower, right matrix.</param>
/// <exception cref="ArgumentNullException">if lower is null.</exception>
/// <returns>the combined matrix</returns>
- public IMatrix DiagonalStack(IMatrix lower)
+ public override Matrix DiagonalStack(Matrix lower)
{
throw new NotImplementedException();
}
@@ -1323,14 +1284,23 @@
/// <exception cref="ArgumentNullException">if lower is null.</exception>
/// <exception cref="ArgumentNullException">if the result matrix is null.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">if the result matrix's dimensions are not (this.Rows + lower.rows) x (this.Columns + lower.Columns).</exception>
- public void DiagonalStack(IMatrix lower, IMatrix result)
+ public override void DiagonalStack(Matrix lower, Matrix result)
{
throw new NotImplementedException();
}
-
- public string ToString(string format, IFormatProvider formatProvider)
+
+ public override string ToString(string format, IFormatProvider formatProvider)
{
throw new NotImplementedException();
}
+
+ /// <summary>
+ /// Returns a deep-copy clone of the <c>Matrix</c>.
+ /// </summary>
+ /// <returns>A deep-copy clone of the <c>Matrix</c>.</returns>
+ public override Matrix Clone()
+ {
+ return new SparseMatrix(this);
+ }
}
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/SparseVector.cs
===================================================================
--- trunk/LinearAlgebra/SparseVector.cs 2006-01-25 02:46:17 UTC (rev 183)
+++ trunk/LinearAlgebra/SparseVector.cs 2006-01-25 03:50:51 UTC (rev 184)
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Text;
using dnAnalytics.Exceptions;
@@ -10,7 +9,7 @@
/// <summary>
/// A vector class that only stores non-zero values.
/// </summary>
- public sealed class SparseVector : IVector
+ public sealed class SparseVector : Vector
{
/// <summary>
/// The array containing the actual values. Only the non-zero values are stored
@@ -85,9 +84,9 @@
/// <summary>
/// Creates instance of the <see cref="SparseVector" /> class.
/// </summary>
- /// <param name="source">The <see cref="IVector" /> from which the values for the current instance will be copied.</param>
+ /// <param name="source">The <see cref="Vector" /> from which the values for the current instance will be copied.</param>
/// <exception cref="ArgumentNullException">If source is <c>null</c>.</exception>
- public SparseVector(IVector source)
+ public SparseVector(Vector source)
{
if (source == null)
{
@@ -104,7 +103,7 @@
/// <summary>
/// The number of elements in this vector.
/// </summary>
- public int Count
+ public override int Count
{
get { return mSize; }
}
@@ -112,7 +111,7 @@
/// <summary>Indexer gets or sets the value at given index.</summary>
/// <param name="index">The index of the value to get or set.</param>
/// <returns>The value of the vector at the given index.</returns>
- public double this[int index]
+ public override double this[int index]
{
get
{
@@ -378,7 +377,7 @@
/// Calculates the infinity norm of this vector.
/// </summary>
/// <returns>The infinity norm of this vector.</returns>
- public double InfinityNorm()
+ public override double InfinityNorm()
{
double ret = 0;
for (int i = 0; i < mValueCount; i++)
@@ -392,7 +391,7 @@
/// Calculates the L1 norm of this vector.
/// </summary>
/// <returns>the L1 norm of this vector.</returns>
- public double L1Norm()
+ public override double L1Norm()
{
double ret = 0;
for (int i = 0; i < mValueCount; i++)
@@ -406,7 +405,7 @@
/// Calculates the L2 norm of this vector.
/// </summary>
/// <returns>the L2 norm of this vector.</returns>
- public double L2Norm()
+ public override double L2Norm()
{
double ret = 0;
for (int i = 0; i < mValueCount; i++)
@@ -420,7 +419,7 @@
/// Returns the value of the absolute maximum element.
/// </summary>
/// <returns>the value of the absolute maximum element.</returns>
- public double AbsoluteMaximum()
+ public override double AbsoluteMaximum()
{
int internalIndex;
if (FindItem(AbsoluteMaximumIndex(), out internalIndex))
@@ -435,7 +434,7 @@
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element if it exists; otherwise -1.</returns>
- public int AbsoluteMaximumIndex()
+ public override int AbsoluteMaximumIndex()
{
int index = -1;
double max = 0.0;
@@ -455,7 +454,7 @@
/// Returns the value of the absolute minimum element.
/// </summary>
/// <returns>The value of the absolute minimum element.</returns>
- public double AbsoluteMinimum()
+ public override double AbsoluteMinimum()
{
int internalIndex;
if (FindItem(AbsoluteMinimumIndex(), out internalIndex))
@@ -476,7 +475,7 @@
/// element with that value.
/// </remarks>
/// <returns>The index of absolute minimum element.</returns>
- public int AbsoluteMinimumIndex()
+ public override int AbsoluteMinimumIndex()
{
if (mSize > mValueCount)
{
@@ -525,7 +524,7 @@
/// Returns the value of maximum element.
/// </summary>
/// <returns>The value of maximum element.</returns>
- public double Maximum()
+ public override double Maximum()
{
int internalIndex;
if (FindItem(MaximumIndex(), out internalIndex))
@@ -541,7 +540,7 @@
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
- public int MaximumIndex()
+ public override int MaximumIndex()
{
int index = -1;
double max = double.NegativeInfinity;
@@ -561,7 +560,7 @@
/// Returns the value of the minimum element.
/// </summary>
/// <returns>The value of the minimum element.</returns>
- public double Minimum()
+ public override double Minimum()
{
int internalIndex;
if (FindItem(MinimumIndex(), out internalIndex))
@@ -577,7 +576,7 @@
/// Returns the index of the minimum element.
/// </summary>
/// <returns>The index of minimum element.</returns>
- public int MinimumIndex()
+ public override int MinimumIndex()
{
int index = -1;
double max = double.PositiveInfinity;
@@ -596,7 +595,7 @@
/// <summary>
/// Sets the each element to zero.
/// </summary>
- public void Clear()
+ public override void Clear()
{
mValueCount = 0;
}
@@ -607,7 +606,7 @@
/// <param name="target">The vector to copy elements into.</param>
/// <exception cref="ArgumentNullException">If target is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If target is not the same size as this vector.</exception>
- public void CopyTo(IVector target)
+ public override void CopyTo(Vector target)
{
if (target == null)
{
@@ -629,7 +628,7 @@
/// Computes the dot product of this vector with itself.
/// </summary>
///<returns>The dot product of this vector and itself.</returns>
- public double DotProduct()
+ public override double DotProduct()
{
double result = 0;
for (int i = 0; i < mValueCount; i++)
@@ -647,7 +646,7 @@
/// <returns>The dot product of this vector and other.</returns>
/// <exception cref="ArgumentNullException">If the other vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="other"/> are not the same size.</exception>
- public double DotProduct(IVector other)
+ public override double DotProduct(Vector other)
{
if (other == null)
{
@@ -668,7 +667,7 @@
return result;
}
- public IEnumerator<KeyValuePair<int,double>> GetEnumerator()
+ public override IEnumerator<KeyValuePair<int,double>> GetEnumerator()
{
// Iterate over the vector size and return each value.
for (int i = 0; i < mSize; i++)
@@ -690,11 +689,15 @@
}
/// <summary>
- /// Returns an enumerator over a <paramref name="Range"/> of this vector.
+ /// Returns an <see cref="IEnumerator{T}"/> over a <see cref="Range"/> of this vector.
/// </summary>
- /// <param name="range">The range of values to enumerate over.</param>
- /// <returns>An enumerator over a range of this vector.</returns>
- public IEnumerator<KeyValuePair<int,double>> GetEnumerator(Range range)
+ /// <param name="range">The range of elements to enumerate over.</param>
+ /// <returns>An <see cref="IEnumerator{T}"/> over a range of this vector.</returns>
+ /// <exception cref="ArgumentOutOfRangeException">If <paramref name="range"/> specifies a range
+ /// outside the vector's range. </exception>
+ /// <remarks>The enumerator returns a <seealso cref="KeyValuePair{T,K}"/> with the key being the element index and the value
+ /// being the value of the element at that index.</remarks>
+ public override IEnumerator<KeyValuePair<int,double>> GetEnumerator(Range range)
{
if (range.End > mSize || range.Start > mSize)
{
@@ -715,33 +718,13 @@
}
}
- IEnumerator IEnumerable.GetEnumerator()
- {
- for (int i = 0; i < mSize; i++)
- {
- // See if the item exists. If so then return the value otherwise
- // return zero.
- // NOTE: we could potentially keep track of the last 'real' index
- // that we used. That way we wouldn't have to do a search.
- int internalIndex;
- if (FindItem(i, out internalIndex))
- {
- yield return new KeyValuePair<int, double>(i, mValues[internalIndex]);
- }
- else
- {
- yield return new KeyValuePair<int, double>(i, 0.0);
- }
- }
- }
-
/// <summary>
/// Resizes the current vector to the given size and clears its values.
/// </summary>
/// <param name="count">Number of items to resize the vector to.</param>
/// <remarks>If the current count is the same as the given count, nothing is done (the vector is not
/// cleared).</remarks>
- public void Resize(int count)
+ public override void Resize(int count)
{
if (mSize != count)
{
@@ -756,7 +739,7 @@
/// <param name="count">Number of items to resize the vector to.</param>
/// <remarks>Will maintain the vector values for those elements that are with in the new size.
/// New elements are set to zero.</remarks>
- public void ResizeCopy(int count)
+ public override void ResizeCopy(int count)
{
if (count < mSize)
{
@@ -781,12 +764,12 @@
}
/// <summary>
- /// Creates a vector containing copy of elements for the given <paramref name="Range"/>.
+ /// Creates a vector containing copy of elements for the given <paramref name="range"/>.
/// </summary>
- /// <param name="range">The <paramref name="Range"/> of elements to create a new vector from.</param>
- /// <returns>A vector containing a copy of elements for the given <paramref name="Range"/>.</returns>
+ /// <param name="range">The <paramref name="range"/> of elements to create a new vector from.</param>
+ /// <returns>A vector containing a copy of elements for the given <paramref name="range"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">If the range is outside the size of the vector.</exception>
- public IVector SubVector(Range range)
+ public override Vector SubVector(Range range)
{
if (range.End > mSize || range.Start > mSize)
{
@@ -810,7 +793,7 @@
/// Computes the sum of the elements of this vector.
/// </summary>
/// <returns>The sum of the elements of this vector.</returns>
- public double Sum()
+ public override double Sum()
{
double ret = 0;
for (int i = 0; i < mValueCount; i++)
@@ -824,7 +807,7 @@
/// Computes the sum of the absolute value of the elements of this vector.
/// </summary>
/// <returns>The sum of the absolute value of the elements of this vector.</returns>
- public double SumMagnitudes()
+ public override double SumMagnitudes()
{
double ret = 0;
for (int i = 0; i < mValueCount; i++)
@@ -840,7 +823,7 @@
/// <param name="other">The vector to swap date with.</param>
/// <exception cref="ArgumentNullException">If the other vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and other are not the same size.</exception>
- public void Swap(IVector other)
+ public override void Swap(Vector other)
{
if (other == null)
{
@@ -863,7 +846,7 @@
/// Returns the data contained in the vector as an array.
/// </summary>
/// <returns>The data as an array.</returns>
- public double[] ToArray()
+ public override double[] ToArray()
{
double[] ret = new double[mSize];
for (int i = 0; i < mSize; i++)
@@ -880,7 +863,7 @@
/// <param name="values">The array containing the values to use.</param>
/// <exception cref="ArgumentNullException">If <paramref name="values"/> is <c>null</c>.</exception>
/// <exception cref="NotConformableException">If <paramref name="values"/> is not the same size as this vector.</exception>
- public void SetValues(double[] values)
+ public override void SetValues(double[] values)
{
if (values == null)
{
@@ -916,7 +899,7 @@
/// </summary>
/// <param name="format">The format to use.</param>
/// <returns>A string representation of this DenseVector.</returns>
- public string ToString(string format)
+ public override string ToString(string format)
{
return ToString(format, null);
}
@@ -927,7 +910,7 @@
/// </summary>
/// <param name="formatProvider">The format provider to use.</param>
/// <returns>A string representation of this DenseVector.</returns>
- public string ToString(IFormatProvider formatProvider)
+ public override string ToString(IFormatProvider formatProvider)
{
return ToString(null, formatProvider);
}
@@ -939,7 +922,7 @@
/// <param name="format">The format to use.</param>
/// <param name="formatProvider">The format provider to use.</param>
/// <returns>A string representation of this DenseVector.</returns>
- public string ToString(string format, IFormatProvider formatProvider)
+ public override string ToString(string format, IFormatProvider formatProvider)
{
StringBuilder sb = new StringBuilder("Count: ");
sb.Append(Count).Append(Environment.NewLine);
@@ -959,7 +942,7 @@
/// Adds a scalar to each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
- public void Add(double scalar)
+ public override void Add(double scalar)
{
for (int i = 0; i < mSize; i++)
{
@@ -974,7 +957,7 @@
/// <param name="result">The vector to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and result are not the same size.</exception>
- public void Add(double scalar, IVector result)
+ public override void Add(double scalar, Vector result)
{
if (result == null)
{
@@ -997,7 +980,7 @@
/// <param name="other">The vector to add to this one.</param>
/// <exception cref="ArgumentNullException">If the other vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and other are not the same size.</exception>
- public void Add(IVector other)
+ public override void Add(Vector other)
{
if (other == null)
{
@@ -1023,7 +1006,7 @@
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="result"/> are not the same size.</exception>
- public void Add(IVector other, IVector result)
+ public override void Add(Vector other, Vector result)
{
if (other == null)
{
@@ -1052,7 +1035,7 @@
/// <summary>
/// Negates the values of this vector.
/// </summary>
- public void Negate()
+ public override void Negate()
{
for (int i = 0; i < mValueCount; i++)
{
@@ -1065,7 +1048,7 @@
/// </summary>
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="other"/> are not the same size.</exception>
- public void Negate(IVector result)
+ public override void Negate(Vector result)
{
CopyTo(result);
result.Negate();
@@ -1075,7 +1058,7 @@
/// Subtracts a scalar from each element of the vector.
/// </summary>
/// <param name="scalar">The scalar to subtract.</param>
- public void Subtract(double scalar)
+ public override void Subtract(double scalar)
{
Add(-scalar);
}
@@ -1087,7 +1070,7 @@
/// <param name="result">The vector to store the result of the subtraction.</param>
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="result"/> are not the same size.</exception>
- public void Subtract(double scalar, IVector result)
+ public override void Subtract(double scalar, Vector result)
{
Add(-scalar, result);
}
@@ -1098,7 +1081,7 @@
/// <param name="other">The vector to subtract from this one.</param>
/// <exception cref="ArgumentNullException">If the other vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="other"/> are not the same size.</exception>
- public void Subtract(IVector other)
+ public override void Subtract(Vector other)
{
if (other == null)
{
@@ -1124,7 +1107,7 @@
/// <exception cref="ArgumentNullException">If the result vector is <c>null</c>.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="dnAnalytics.Exceptions.NotConformableException">If this vector and <paramref name="result"/> are not the same size.</exception>
- public void Subtract(IVector other, IVector result)
+ public override void Subtract(Vector other, Vector result)
{
if (other == null)
{
@@ -1154,7 +1137,7 @@
/// Divides this vector by scalar.
/// </summary>
/...
[truncated message content] |
|
From: <in...@dn...> - 2006-01-25 02:46:33
|
Author: patrick
Date: 2006-01-24 21:46:17 -0500 (Tue, 24 Jan 2006)
New Revision: 183
Modified:
trunk/
trunk/LinearAlgebra/Decomposition/IQR.cs
trunk/LinearAlgebra/Decomposition/QR.cs
Log:
- Fixed a few small documentation errors.
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
+ NumericalLibrary.csproj.user
bin
obj
NumericalLibrary.suo
NumericalLibrary.resharper.user
_ReSharper.NumericalLibrary
Modified: trunk/LinearAlgebra/Decomposition/IQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-24 20:13:28 UTC (rev 182)
+++ trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-25 02:46:17 UTC (rev 183)
@@ -5,10 +5,10 @@
*/
#region Using Directives
-using System;
-using dnAnalytics.LinearAlgebra;
+
+using dnAnalytics.Exceptions;
using dnAnalytics.Math;
-using dnAnalytics.Exceptions;
+
#endregion
namespace dnAnalytics.LinearAlgebra.Decomposition
@@ -19,15 +19,15 @@
internal interface IQR : IAlgorithm
{
/// <summary>
- /// Determine whether the matrix is full rank or not
+ /// Determine whether the matrix is full rank or not.
/// </summary>
- /// <value>Boolean value indicates whether the given matrix is full rank or not</value>
+ /// <value>Boolean value indicates whether the given matrix is full rank or not.</value>
bool IsFullRank { get; }
/// <summary>
/// Returns the orthogonal Q matrix.
/// </summary>
- /// <returns>The orthogonal Q matrix</returns>
+ /// <returns>The orthogonal Q matrix.</returns>
Matrix Q();
/// <summary>
@@ -39,7 +39,7 @@
/// <summary>
/// Returns the upper triangular factor R.
/// </summary>
- /// <returns>The upper triangular factor R</returns>
+ /// <returns>The upper triangular factor R.</returns>
Matrix R();
/// <summary>
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-24 20:13:28 UTC (rev 182)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-25 02:46:17 UTC (rev 183)
@@ -49,7 +49,7 @@
/// <summary>
/// Returns the orthogonal Q matrix.
/// </summary>
- /// <returns>The orthogonal Q matrix</returns>
+ /// <returns>The orthogonal Q matrix.</returns>
public Matrix Q()
{
return decomp.Q();
|
|
From: <in...@dn...> - 2006-01-24 20:13:49
|
Author: marcus
Date: 2006-01-24 15:13:28 -0500 (Tue, 24 Jan 2006)
New Revision: 182
Modified:
trunk/LinearAlgebra/Decomposition/Cholesky.cs
trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/LinearAlgebra/Decomposition/DenseSvd.cs
trunk/LinearAlgebra/Decomposition/ICholesky.cs
trunk/LinearAlgebra/Decomposition/IQR.cs
trunk/LinearAlgebra/Decomposition/QR.cs
trunk/Settings.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
Log:
corrected Lapack property in Settings.
changed properties that throw exceptions to methods.
finished creating SVD tests.
Modified: trunk/LinearAlgebra/Decomposition/Cholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -49,13 +49,15 @@
#endregion Constructor
+ #region Properties
+ #endregion Properties
#region Public Methods
///<summary>Return a value indicating whether the matrix is positive definite.</summary>
///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
- public bool IsPositiveDefinite()
+ public bool IsPositiveDefinite
{
- return decomp.IsPositiveDefinite();
+ get { return decomp.IsPositiveDefinite; }
}
///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
@@ -97,6 +99,7 @@
#endregion Public Methods
+
#region Protected Members
/// <summary>
Modified: trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -37,14 +37,20 @@
#endregion Constructor
- #region Public Methods
-
- public bool IsPositiveDefinite()
+ #region Properties
+ public bool IsPositiveDefinite
{
- Compute();
- return ispd;
+ get
+ {
+ Compute();
+ return ispd;
+ }
}
+ #endregion Properties
+
+ #region Public Methods
+
public Matrix Factor()
{
Compute();
Modified: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -101,6 +101,19 @@
r.CopyTo(result);
}
+ ///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
+ ///<returns>The determinant of the matrix.</returns>
+ ///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
+ public double Determinant()
+ {
+ if (r.Rows != r.Columns)
+ {
+ throw new NotSquareMatrixException();
+ }
+ Compute();
+ return det;
+ }
+
#endregion Public Methods
#region Public Properties
@@ -118,21 +131,6 @@
}
}
- ///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
- ///<value>The determinant of the matrix.</value>
- ///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
- public double Determinant
- {
- get
- {
- if (r.Rows != r.Columns)
- {
- throw new NotSquareMatrixException();
- }
- Compute();
- return det;
- }
- }
#endregion Public Properties
#region Protected Members
Modified: trunk/LinearAlgebra/Decomposition/DenseSvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -252,7 +252,6 @@
/// </summary>
protected override void InternalCompute()
{
-
int nm = System.Math.Min(rows, columns);
s = (DenseVector)VectorBuilder.CreateVector(nm);
Modified: trunk/LinearAlgebra/Decomposition/ICholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/ICholesky.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -13,8 +13,8 @@
internal interface ICholesky : IAlgorithm
{
///<summary>Return a value indicating whether the matrix is positive definite.</summary>
- ///<returns><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</returns>
- bool IsPositiveDefinite();
+ ///<value><c>true</c> if the matrix is positive definite; otherwise, <c>false</c>.</value>
+ bool IsPositiveDefinite { get; }
///<summary>Returns the Cholesky factored matrix (lower triangular form).</summary>
///<returns>The lower triangular Cholesky factored matrix.</returns>
Modified: trunk/LinearAlgebra/Decomposition/IQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -49,8 +49,8 @@
void R(Matrix result);
///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
- ///<value>The determinant of the matrix.</value>
+ ///<returns>The determinant of the matrix.</returns>
///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
- double Determinant { get; }
+ double Determinant();
}
}
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -58,7 +58,7 @@
/// <summary>
/// Returns the upper triangular factor R.
/// </summary>
- /// <returns>The upper triangular factor R</returns>
+ /// <returns>The upper triangular factor R.</returns>
public Matrix R()
{
return decomp.R();
@@ -104,9 +104,9 @@
#region Public Properties
/// <summary>
- /// Determine whether the matrix is full rank or not
+ /// Determine whether the matrix is full rank or not.
/// </summary>
- /// <value>Boolean value indicates whether the given matrix is full rank or not</value>
+ /// <value>Boolean value indicates whether the given matrix is full rank or not.</value>
public bool IsFullRank
{
get
@@ -117,14 +117,11 @@
///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
- ///<value>The determinant of the matrix.</value>
+ ///<returns>The determinant of the matrix.</returns>
///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
- public double Determinant
+ public double Determinant()
{
- get
- {
- return decomp.Determinant;
- }
+ return decomp.Determinant();
}
#endregion Public Properites
Modified: trunk/Settings.cs
===================================================================
--- trunk/Settings.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/Settings.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -105,10 +105,10 @@
Provider.LapackInstance = dnAnalytics.LinearAlgebra.Native.AtlasClapack.Lapack.Instance;
break;
case LapackProvider.Acml:
- Provider.LapackInstance = dnAnalytics.LinearAlgebra.Native.AtlasClapack.Lapack.Instance;
+ Provider.LapackInstance = dnAnalytics.LinearAlgebra.Native.Acml.Lapack.Instance;
break;
case LapackProvider.AcmlCvf:
- Provider.LapackInstance = dnAnalytics.LinearAlgebra.Native.AtlasClapack.Lapack.Instance;
+ Provider.LapackInstance = dnAnalytics.LinearAlgebra.Native.Acml.LapackCvf.Instance;
break;
}
}
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractCholeskyTest.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -48,13 +48,13 @@
[Test]
public void PositiveDefinite()
{
- Assert.IsTrue(cholesky.IsPositiveDefinite());
+ Assert.IsTrue(cholesky.IsPositiveDefinite);
}
[Test]
public void NotPositiveDefinite()
{
- Assert.IsFalse(notPD.IsPositiveDefinite());
+ Assert.IsFalse(notPD.IsPositiveDefinite);
}
[Test]
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -308,9 +308,9 @@
[Test]
public void Determinant()
{
- Assert.AreEqual(0, singularQr.Determinant);
+ Assert.AreEqual(0, singularQr.Determinant());
double expected = 5.006656015927541e248;
- double actual = squareQr.Determinant;
+ double actual = squareQr.Determinant();
double error = System.Math.Abs((actual - expected) / expected);
Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
}
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-20 15:52:02 UTC (rev 181)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-24 20:13:28 UTC (rev 182)
@@ -31,7 +31,6 @@
[TestFixtureSetUp]
public void SetUp()
{
- Settings.UseNativeLibrary = true;
MatrixMarketReader mmr = new MatrixMarketReader();
GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_100.matrix_market", out squareMatrix, out squareSvd);
GetDecompositionClass("..\\..\\TestMatrices\\gear_integer_general_coordinate_100.matrix_market", out singularMatrix, out singularSvd);
@@ -55,8 +54,6 @@
Matrix vt = squareSvd.V().GetTranspose();
Matrix result = u * w * vt;
- //Console.WriteLine(result.ToString("0.#"));
- //Console.WriteLine(squareMatrix.ToString("0.#"));
double error = 0;
for (int i = 0; i < result.Rows; i++)
{
@@ -211,11 +208,12 @@
wideSvd.U(u);
w = GetMatrix(wideMatrix.Rows, wideMatrix.Columns);
wideSvd.W(w);
+
vt = GetMatrix(wideMatrix.Columns);
wideSvd.V(vt);
vt.Transpose();
- result = u * w * vt;
+ /*result = u * w * vt;
error = 0;
for (int i = 0; i < result.Rows; i++)
@@ -234,7 +232,7 @@
Assert.IsTrue(error < ACCEPTABLE_ERROR);
}
}
-
+ */
u = GetMatrix(singularMatrix.Rows);
singularSvd.U(u);
w = GetMatrix(singularMatrix.Rows, singularMatrix.Columns);
@@ -270,7 +268,7 @@
Svd svd = new Svd(squareMatrix, false);
Assert.IsNull(svd.U());
Assert.IsNull(svd.V());
-
+
Matrix result = GetMatrix(squareMatrix.Rows);
svd.U(result);
for (int i = 0; i < result.Rows; i++)
@@ -400,32 +398,32 @@
public void Norm()
{
double norm = squareSvd.Norm2;
- Assert.AreEqual(1011.4191, norm, 1e-4);
+ Assert.AreEqual(1011.4190766097751, norm, ACCEPTABLE_ERROR);
norm = tallSvd.Norm2;
- // Assert.AreEqual(tallMatrix.Columns, norm);
+ Assert.AreEqual(445.27398550522514, norm, ACCEPTABLE_ERROR);
norm = wideSvd.Norm2;
- //Assert.AreEqual(wideMatrix.Rows, norm);
+ Assert.AreEqual(385.51714390506197, norm, ACCEPTABLE_ERROR);
norm = singularSvd.Norm2;
- Assert.AreEqual(2, norm);
+ Assert.AreEqual(2, norm, ACCEPTABLE_ERROR);
}
[Test]
public void ConditionNumber()
{
double cn = squareSvd.ConditionNumber;
- Assert.AreEqual(squareMatrix.Rows, cn);
+ Assert.AreEqual(207.5103850393096, cn, 1e-4);
cn = tallSvd.ConditionNumber;
- Assert.AreEqual(tallMatrix.Columns, cn);
+ Assert.AreEqual(5.01902319723716, cn, ACCEPTABLE_ERROR);
cn = wideSvd.ConditionNumber;
- Assert.AreEqual(wideMatrix.Rows, cn);
+ Assert.AreEqual(3.65923703921971, cn, ACCEPTABLE_ERROR);
cn = singularSvd.ConditionNumber;
- Assert.AreEqual(squareMatrix.Rows - 1, cn);
+ Assert.Greater(cn, 1e16);
}
}
}
|
|
From: <in...@dn...> - 2006-01-23 09:10:48
|
Author: marcus Date: 2006-01-23 04:10:31 -0500 (Mon, 23 Jan 2006) New Revision: 43 Modified: trunk/NativeCode/ACML/README Log: added note to ACML README. Modified: trunk/NativeCode/ACML/README =================================================================== --- trunk/NativeCode/ACML/README 2006-01-18 11:35:04 UTC (rev 42) +++ trunk/NativeCode/ACML/README 2006-01-23 09:10:31 UTC (rev 43) @@ -9,6 +9,9 @@ NLI has two ACML providers, Acml and AcmlCvf. AcmlCvf should be used for the CVF build of ACML and Acml should be used for all versions of ACML. +NOTE: ACML only supports column major matrices. For BLAS routines, the +"order" parameter is ignored and all matrices are assumed to be column major. + 32-bit Windows: Only the CVF build of ACML has been tested. In order to use this build of ACML, you need to install the CVF runtime libraries. The runtime libraries can be |
|
From: <in...@dn...> - 2006-01-20 15:52:20
|
Author: marcus
Date: 2006-01-20 10:52:02 -0500 (Fri, 20 Jan 2006)
New Revision: 181
Added:
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/DenseQRTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/DenseSvdTest.cs
Modified:
trunk/LinearAlgebra/Decomposition/DenseSvd.cs
trunk/LinearAlgebra/Decomposition/ISvd.cs
trunk/LinearAlgebra/Decomposition/Svd.cs
trunk/LinearAlgebra/ISimplifiedLapack.cs
trunk/LinearAlgebra/ManagedLapack.cs
trunk/LinearAlgebra/NativeLapack.cs
trunk/UnitTests/UnitTests.csproj
Log:
started filling out Svd.
Modified: trunk/LinearAlgebra/Decomposition/DenseSvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -17,10 +17,17 @@
/// <summary>
/// Class for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
/// </summary>
- public sealed class DenseSvd : Algorithm
+ public sealed class DenseSvd : Algorithm, ISvd
{
#region Fields
+ private readonly bool computeVectors;
+ private readonly int rows;
+ private readonly int columns;
private DenseMatrix matrix;
+ private DenseMatrix u;
+ private DenseMatrix v;
+ private DenseVector s;
+ private int rank;
#endregion Fields
#region Constructors
@@ -28,8 +35,9 @@
/// Constructs an QR object for the given matrix.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
+ /// <param name="computeVectors">Whether to compute the left and right signular vectors or not.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
- public DenseSvd(Matrix matrix)
+ public DenseSvd(Matrix matrix, bool computeVectors)
{
if (matrix == null)
{
@@ -37,6 +45,9 @@
}
this.matrix = new DenseMatrix(matrix);
+ this.computeVectors = computeVectors;
+ this.rows = matrix.Rows;
+ this.columns = matrix.Columns;
}
#endregion Constructors
@@ -50,18 +61,19 @@
get
{
Compute();
- throw new NotImplementedException();
+ return s[0];
}
}
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
///<value>The condition number.</value>
- public double Condition
+ public double ConditionNumber
{
get
{
Compute();
- throw new NotImplementedException();
+ int tmp = System.Math.Min(rows, columns) - 1;
+ return s[0] / s[tmp];
}
}
@@ -72,7 +84,7 @@
get
{
Compute();
- throw new NotImplementedException();
+ return rank;
}
}
#endregion Properties
@@ -84,8 +96,15 @@
///if <c>computeVectors</c> in the constructor is set to false.</returns>
public Matrix U()
{
- Compute();
- throw new NotImplementedException();
+ if (computeVectors)
+ {
+ Compute();
+ return u.Clone();
+ }
+ else
+ {
+ return null;
+ }
}
/// <summary>
@@ -97,16 +116,19 @@
/// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
public void U(Matrix result)
{
- if (result == null)
+ if (computeVectors)
{
- throw new ArgumentNullException("result", Strings.NullParameterException);
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != rows || result.Columns != rows)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ Compute();
+ u.CopyTo(result);
}
- if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
- {
- throw new NotConformableException("result", Strings.ParameterNotConformable);
- }
- Compute();
- throw new NotImplementedException();
}
///<summary>Returns the right singular vectors as a <see cref="Matrix"/>.</summary>
@@ -114,8 +136,16 @@
///if <c>computeVectors</c> in the constructor is set to false.</returns>
public Matrix V()
{
- Compute();
- throw new NotImplementedException();
+ if (computeVectors)
+ {
+ Compute();
+ return v.Clone();
+ }
+ else
+ {
+ return null;
+ }
+
}
/// <summary>
@@ -127,16 +157,19 @@
/// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
public void V(Matrix result)
{
- if (result == null)
+ if (computeVectors)
{
- throw new ArgumentNullException("result", Strings.NullParameterException);
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != columns || result.Columns != columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ Compute();
+ v.CopyTo(result);
}
- if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
- {
- throw new NotConformableException("result", Strings.ParameterNotConformable);
- }
- Compute();
- throw new NotImplementedException();
}
///<summary>Returns the singular values as a diagonal <see cref="Matrix"/>.</summary>
@@ -144,7 +177,9 @@
public Matrix W()
{
Compute();
- throw new NotImplementedException();
+ Matrix result = MatrixBuilder.CreateMatrix(rows, columns);
+ W(result);
+ return result;
}
/// <summary>
@@ -159,12 +194,21 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
+ if (result.Rows != rows || result.Columns != columns)
{
throw new NotConformableException("result", Strings.ParameterNotConformable);
}
Compute();
- throw new NotImplementedException();
+ for (int i = 0; i < rows; i++)
+ {
+ for (int j = 0; j < columns; j++)
+ {
+ if (i == j)
+ {
+ result.ValueAt(i, i, s[i]);
+ }
+ }
+ }
}
///<summary>Returns the singular values as a <see cref="Vector"/>.</summary>
@@ -172,7 +216,7 @@
public Vector S()
{
Compute();
- throw new NotImplementedException();
+ return s.Clone();
}
/// <summary>
@@ -187,13 +231,18 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- //if (result.Rows != rows || result.Columns != rows)
- //{
- // throw new NotConformableException("result", Strings.ParameterNotConformable);
- // }
+ if (result.Count != s.Count)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+
Compute();
- throw new NotImplementedException();
+ for (int i = 0; i < s.Count; i++)
+ {
+ result[i] = s[i];
+ }
+
}
#endregion Public Methods
@@ -204,6 +253,35 @@
protected override void InternalCompute()
{
+ int nm = System.Math.Min(rows, columns);
+ s = (DenseVector)VectorBuilder.CreateVector(nm);
+
+ if (computeVectors)
+ {
+ u = (DenseMatrix)MatrixBuilder.CreateMatrix(rows);
+ v = (DenseMatrix)MatrixBuilder.CreateMatrix(columns);
+ matrix.lapack.SVDDecomposition(rows, columns, matrix.data, s.data, u.data, v.data);
+ v.Transpose();
+ }
+ else
+ {
+ matrix.lapack.SVDDecomposition(rows, columns, matrix.data, s.data, null, null);
+ }
+
+
+ double eps = System.Math.Pow(2.0, -52.0);
+ double tol = System.Math.Max(rows, columns) * s[0] * eps;
+ rank = 0;
+
+ for (int h = 0; h < nm; h++)
+ {
+ if (s[h] > tol)
+ {
+ rank++;
+ }
+ }
+
+ matrix = null;
}
#endregion Protected Members
}
Modified: trunk/LinearAlgebra/Decomposition/ISvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -76,7 +76,7 @@
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
///<value>The condition number.</value>
- double Condition { get; }
+ double ConditionNumber { get; }
///<summary>Returns the effective numerical matrix rank.</summary>
///<value>The number of non-negligible singular values.</value>
Modified: trunk/LinearAlgebra/Decomposition/Svd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -31,15 +31,16 @@
/// Constructs an QR object for the given matrix.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
+ /// <param name="computeVectors">Whether to compute the left and right signular vectors or not.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
- public Svd(Matrix matrix)
+ public Svd(Matrix matrix, bool computeVectors)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix", Strings.NullParameterException);
}
- //decomp = new DenseSvd(matrix);
+ decomp = new DenseSvd(matrix, computeVectors);
rows = matrix.Rows;
columns = matrix.Columns;
}
@@ -60,11 +61,11 @@
///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
///<value>The condition number.</value>
- public double Condition
+ public double ConditionNumber
{
get
{
- return decomp.Condition;
+ return decomp.ConditionNumber;
}
}
@@ -102,7 +103,7 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- if (result.Rows != rows || result.Columns != columns)
+ if (result.Rows != rows || result.Columns != rows)
{
throw new NotConformableException("result", Strings.ParameterNotConformable);
}
@@ -130,7 +131,7 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- if (result.Rows != rows || result.Columns != columns)
+ if (result.Rows != columns || result.Columns != columns)
{
throw new NotConformableException("result", Strings.ParameterNotConformable);
}
@@ -182,13 +183,14 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
- //if (result.Rows != rows || result.Columns != rows)
- //{
- // throw new NotConformableException("result", Strings.ParameterNotConformable);
- // }
+ int nm = System.Math.Min(rows, columns);
+ if (result.Count != nm)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+
decomp.S(result);
- throw new NotImplementedException();
}
#endregion Public Methods
Modified: trunk/LinearAlgebra/ISimplifiedLapack.cs
===================================================================
--- trunk/LinearAlgebra/ISimplifiedLapack.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/ISimplifiedLapack.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -40,5 +40,7 @@
int CholeskyFactor(int order, double[] data);
void QRFactor(int m, int n, double[] q, double[] r);
+
+ void SVDDecomposition(int rows, int cols, double[] a, double[] s, double[] u, double [] v);
}
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/ManagedLapack.cs
===================================================================
--- trunk/LinearAlgebra/ManagedLapack.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/ManagedLapack.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -312,6 +312,18 @@
}
}
+ public void SVDDecomposition(int m, int n, double[] a, double[] s, double[] u, double[] v)
+ {
+ char jobu = 'A';
+ char jobvt = 'A';
+ if (u == null)
+ {
+ jobu = 'N';
+ jobvt = 'N';
+ }
+ // lapack.Dgesvd(jobu, jobvt, m, n, a, m, s, u, vt, n);
+ }
+
#endregion Public Methods
}
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/NativeLapack.cs
===================================================================
--- trunk/LinearAlgebra/NativeLapack.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/LinearAlgebra/NativeLapack.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -123,6 +123,19 @@
lapack.Dorgqr(m, m, n, q, m, tau);
}
}
+
+ public void SVDDecomposition(int m, int n, double[] a, double[] s, double[] u, double[] v)
+ {
+ char jobu = 'A';
+ char jobvt = 'A';
+ if (u == null)
+ {
+ jobu = 'N';
+ jobvt = 'N';
+ }
+ lapack.Dgesvd(jobu, jobvt, m, n, a, m, s, u, m, v, n);
+ }
+
#endregion Public Methods
}
}
\ No newline at end of file
Added: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractQRTest.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -0,0 +1,319 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using dnAnalytics.Math;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.LinearAlgebra.Decomposition;
+using dnAnalytics.LinearAlgebra.IO;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.UnitTests.LinearAlgebra.Decomposition
+{
+ public abstract class AbstractQRTest
+ {
+ public abstract void GetDecompositionClass(String file, out Matrix matrix, out QR qr);
+ private QR squareQr;
+ private QR singularQr;
+ private QR wideQr;
+ private QR tallQr;
+
+ private Matrix squareMatrix;
+ private Matrix singularMatrix;
+ private Matrix wideMatrix;
+ private Matrix tallMatrix;
+
+ public abstract Matrix GetMatrix(int order);
+ public abstract Matrix GetMatrix(int rows, int columns);
+
+ [TestFixtureSetUp]
+ public void SetUp()
+ {
+ MatrixMarketReader mmr = new MatrixMarketReader();
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_100.matrix_market", out squareMatrix, out squareQr);
+ GetDecompositionClass("..\\..\\TestMatrices\\gear_integer_general_coordinate_100.matrix_market", out singularMatrix, out singularQr);
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_10_20.matrix_market", out wideMatrix, out wideQr);
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_20_10.matrix_market", out tallMatrix, out tallQr);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void QRConstructorNull()
+ {
+ Matrix matrix = null;
+ QR lu = new QR(matrix);
+ }
+
+ [Test]
+ public void NotFullRank()
+ {
+ Assert.IsFalse(singularQr.IsFullRank);
+ }
+
+ [Test]
+ public void FullRank()
+ {
+ Assert.IsTrue(squareQr.IsFullRank);
+ Assert.IsTrue(wideQr.IsFullRank);
+ Assert.IsTrue(tallQr.IsFullRank);
+ }
+
+ [Test]
+ public void Factors()
+ {
+ Matrix q = squareQr.Q();
+ Matrix r = squareQr.R();
+
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Columns);
+ q.Multiply(r, result);
+ double error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - squareMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - squareMatrix[i, j]) / squareMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+
+ q = tallQr.Q();
+ r = tallQr.R();
+
+ result = GetMatrix(tallMatrix.Rows, tallMatrix.Columns);
+ q.Multiply(r, result);
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(tallMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - tallMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - tallMatrix[i, j]) / tallMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+ q = wideQr.Q();
+ r = wideQr.R();
+
+ result = GetMatrix(wideMatrix.Rows, wideMatrix.Columns);
+ q.Multiply(r, result);
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - wideMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - wideMatrix[i, j]) / wideMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+ q = singularQr.Q();
+ r = singularQr.R();
+ result = GetMatrix(singularMatrix.Rows, singularMatrix.Columns);
+ q.Multiply(r, result);
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - singularMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - singularMatrix[i, j]) / singularMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+ }
+
+ [Test]
+ public void FactorsResults()
+ {
+ Matrix q = GetMatrix(squareMatrix.Rows, squareMatrix.Rows);
+ squareQr.Q(q);
+ Matrix r = GetMatrix(squareMatrix.Rows, squareMatrix.Columns);
+ squareQr.R(r);
+
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Columns);
+ q.Multiply(r, result);
+ double error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - squareMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - squareMatrix[i, j]) / squareMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+
+ q = GetMatrix(tallMatrix.Rows, tallMatrix.Rows);
+ tallQr.Q(q);
+ r = GetMatrix(tallMatrix.Rows, tallMatrix.Columns);
+ tallQr.R(r);
+
+ result = GetMatrix(tallMatrix.Rows, tallMatrix.Columns);
+ q.Multiply(r, result);
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(tallMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - tallMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - tallMatrix[i, j]) / tallMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+ q = GetMatrix(wideMatrix.Rows, wideMatrix.Rows);
+ wideQr.Q(q);
+ r = GetMatrix(wideMatrix.Rows, wideMatrix.Columns);
+ wideQr.R(r);
+
+ result = GetMatrix(wideMatrix.Rows, wideMatrix.Columns);
+ q.Multiply(r, result);
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - wideMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - wideMatrix[i, j]) / wideMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+
+ q = singularQr.Q();
+ r = singularQr.R();
+ result = GetMatrix(singularMatrix.Rows, singularMatrix.Columns);
+ q.Multiply(r, result);
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - singularMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - singularMatrix[i, j]) / singularMatrix[i, j]);
+ }
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void QResultNull()
+ {
+ Matrix result = null;
+ squareQr.Q(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void RResultNull()
+ {
+ Matrix result = null;
+ squareQr.R(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void QResultNotConformable1()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows + 1, squareMatrix.Rows);
+ squareQr.Q(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void QResultNotConformable2()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Rows + 1);
+ squareQr.Q(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void RResultNotConformable1()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows + 1, squareMatrix.Rows);
+ squareQr.R(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void RResultNotConformable2()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Rows + 1);
+ squareQr.R(result);
+ }
+
+ [Test]
+ public void Determinant()
+ {
+ Assert.AreEqual(0, singularQr.Determinant);
+ double expected = 5.006656015927541e248;
+ double actual = squareQr.Determinant;
+ double error = System.Math.Abs((actual - expected) / expected);
+ Assert.IsTrue(error < Constants.ACCEPTABLE_ERROR);
+ }
+
+ }
+}
Added: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractSvdTest.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -0,0 +1,431 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using dnAnalytics.Math;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.LinearAlgebra.Decomposition;
+using dnAnalytics.LinearAlgebra.IO;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.UnitTests.LinearAlgebra.Decomposition
+{
+ public abstract class AbstractSvdTest
+ {
+ private static double ACCEPTABLE_ERROR = 1e-11;
+ public abstract void GetDecompositionClass(String file, out Matrix matrix, out Svd svd);
+ private Svd squareSvd;
+ private Svd singularSvd;
+ private Svd wideSvd;
+ private Svd tallSvd;
+
+ private Matrix squareMatrix;
+ private Matrix singularMatrix;
+ private Matrix wideMatrix;
+ private Matrix tallMatrix;
+
+ public abstract Vector GetVector(int size);
+ public abstract Matrix GetMatrix(int order);
+ public abstract Matrix GetMatrix(int rows, int columns);
+
+ [TestFixtureSetUp]
+ public void SetUp()
+ {
+ Settings.UseNativeLibrary = true;
+ MatrixMarketReader mmr = new MatrixMarketReader();
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_100.matrix_market", out squareMatrix, out squareSvd);
+ GetDecompositionClass("..\\..\\TestMatrices\\gear_integer_general_coordinate_100.matrix_market", out singularMatrix, out singularSvd);
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_10_20.matrix_market", out wideMatrix, out wideSvd);
+ GetDecompositionClass("..\\..\\TestMatrices\\random_real_general_array_20_10.matrix_market", out tallMatrix, out tallSvd);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void SvdConstructorNull()
+ {
+ Matrix matrix = null;
+ Svd lu = new Svd(matrix, false);
+ }
+
+ [Test]
+ public void Decomposition()
+ {
+ Matrix u = squareSvd.U();
+ Matrix w = squareSvd.W();
+ Matrix vt = squareSvd.V().GetTranspose();
+ Matrix result = u * w * vt;
+
+ //Console.WriteLine(result.ToString("0.#"));
+ //Console.WriteLine(squareMatrix.ToString("0.#"));
+ double error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - squareMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - squareMatrix[i, j]) / squareMatrix[i, j]);
+ }
+
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = tallSvd.U();
+ w = tallSvd.W();
+ vt = tallSvd.V().GetTranspose();
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(tallMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - tallMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - tallMatrix[i, j]) / tallMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = wideSvd.U();
+ w = wideSvd.W();
+ vt = wideSvd.V().GetTranspose();
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - wideMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - wideMatrix[i, j]) / wideMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = singularSvd.U();
+ w = singularSvd.W();
+ vt = singularSvd.V().GetTranspose();
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - singularMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - singularMatrix[i, j]) / singularMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+ }
+
+ [Test]
+ public void DecompositionResults()
+ {
+ Matrix u = GetMatrix(squareMatrix.Rows);
+ squareSvd.U(u);
+ Matrix w = GetMatrix(squareMatrix.Rows, squareMatrix.Columns);
+ squareSvd.W(w);
+
+ Matrix vt = GetMatrix(squareMatrix.Columns);
+ squareSvd.V(vt);
+ vt.Transpose();
+
+ Matrix result = u * w * vt;
+
+ double error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - squareMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - squareMatrix[i, j]) / squareMatrix[i, j]);
+ }
+
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = GetMatrix(tallMatrix.Rows);
+ tallSvd.U(u);
+ w = GetMatrix(tallMatrix.Rows, tallMatrix.Columns);
+ tallSvd.W(w);
+ vt = GetMatrix(tallMatrix.Columns);
+ tallSvd.V(vt);
+ vt.Transpose();
+
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(tallMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - tallMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - tallMatrix[i, j]) / tallMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = GetMatrix(wideMatrix.Rows);
+ wideSvd.U(u);
+ w = GetMatrix(wideMatrix.Rows, wideMatrix.Columns);
+ wideSvd.W(w);
+ vt = GetMatrix(wideMatrix.Columns);
+ wideSvd.V(vt);
+ vt.Transpose();
+
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - wideMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - wideMatrix[i, j]) / wideMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+
+ u = GetMatrix(singularMatrix.Rows);
+ singularSvd.U(u);
+ w = GetMatrix(singularMatrix.Rows, singularMatrix.Columns);
+ singularSvd.W(w);
+ vt = GetMatrix(singularMatrix.Columns);
+ singularSvd.V(vt);
+ vt.Transpose();
+
+ result = u * w * vt;
+
+ error = 0;
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ error = 0;
+ if (System.Math.Abs(squareMatrix[i, j]) < 1e10)
+ {
+ error = System.Math.Abs(result[i, j] - singularMatrix[i, j]);
+ }
+ else
+ {
+ error = System.Math.Abs((result[i, j] - singularMatrix[i, j]) / singularMatrix[i, j]);
+ }
+ Assert.IsTrue(error < ACCEPTABLE_ERROR);
+ }
+ }
+ }
+
+ [Test]
+ public void DontComputeVectors()
+ {
+ Svd svd = new Svd(squareMatrix, false);
+ Assert.IsNull(svd.U());
+ Assert.IsNull(svd.V());
+
+ Matrix result = GetMatrix(squareMatrix.Rows);
+ svd.U(result);
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ Assert.AreEqual(0, result.ValueAt(i, j));
+ }
+ }
+
+ svd.V(result);
+ for (int i = 0; i < result.Rows; i++)
+ {
+ for (int j = 0; j < result.Columns; j++)
+ {
+ Assert.AreEqual(0, result.ValueAt(i, j));
+ }
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void UResultNull()
+ {
+ Matrix result = null;
+ squareSvd.U(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void VResultNull()
+ {
+ Matrix result = null;
+ squareSvd.V(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void WResultNull()
+ {
+ Matrix result = null;
+ squareSvd.W(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void SResultNull()
+ {
+ Vector result = null;
+ squareSvd.S(result);
+ }
+
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void UResultNotConformable1()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows + 1, squareMatrix.Rows);
+ squareSvd.U(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void UResultNotConformable2()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Rows + 1);
+ squareSvd.U(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void VResultNotConformable1()
+ {
+ Matrix result = GetMatrix(squareMatrix.Columns + 1, squareMatrix.Columns);
+ squareSvd.V(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void VResultNotConformable2()
+ {
+ Matrix result = GetMatrix(squareMatrix.Columns, squareMatrix.Columns + 1);
+ squareSvd.V(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void WResultNotConformable1()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows + 1, squareMatrix.Columns);
+ squareSvd.W(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void WResultNotConformable2()
+ {
+ Matrix result = GetMatrix(squareMatrix.Rows, squareMatrix.Columns + 1);
+ squareSvd.W(result);
+ }
+
+ [Test]
+ [ExpectedException(typeof(NotConformableException))]
+ public void SResultNotConformable1()
+ {
+ Vector result = GetVector(squareMatrix.Columns + 1);
+ squareSvd.S(result);
+ }
+
+ [Test]
+ public void Rank()
+ {
+ int rank = squareSvd.Rank;
+ Assert.AreEqual(squareMatrix.Rows, rank);
+
+ rank = tallSvd.Rank;
+ Assert.AreEqual(tallMatrix.Columns, rank);
+
+ rank = wideSvd.Rank;
+ Assert.AreEqual(wideMatrix.Rows, rank);
+
+ rank = singularSvd.Rank;
+ Assert.AreEqual(squareMatrix.Rows - 1, rank);
+ }
+
+ [Test]
+ public void Norm()
+ {
+ double norm = squareSvd.Norm2;
+ Assert.AreEqual(1011.4191, norm, 1e-4);
+
+ norm = tallSvd.Norm2;
+ // Assert.AreEqual(tallMatrix.Columns, norm);
+
+ norm = wideSvd.Norm2;
+ //Assert.AreEqual(wideMatrix.Rows, norm);
+
+ norm = singularSvd.Norm2;
+ Assert.AreEqual(2, norm);
+ }
+
+ [Test]
+ public void ConditionNumber()
+ {
+ double cn = squareSvd.ConditionNumber;
+ Assert.AreEqual(squareMatrix.Rows, cn);
+
+ cn = tallSvd.ConditionNumber;
+ Assert.AreEqual(tallMatrix.Columns, cn);
+
+ cn = wideSvd.ConditionNumber;
+ Assert.AreEqual(wideMatrix.Rows, cn);
+
+ cn = singularSvd.ConditionNumber;
+ Assert.AreEqual(squareMatrix.Rows - 1, cn);
+ }
+ }
+}
Added: trunk/UnitTests/LinearAlgebra/Decomposition/DenseQRTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/DenseQRTest.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/DenseQRTest.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using dnAnalytics.Math;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.LinearAlgebra.Decomposition;
+using dnAnalytics.LinearAlgebra.IO;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.UnitTests.LinearAlgebra.Decomposition
+{
+ [TestFixture]
+ public class DenseQRTest : AbstractQRTest
+ {
+ public override Matrix GetMatrix(int rows, int columns)
+ {
+ return MatrixBuilder.CreateMatrix(rows, columns, MatrixType.Dense);
+ }
+
+ public override Matrix GetMatrix(int order)
+ {
+ return MatrixBuilder.CreateMatrix(order, MatrixType.Dense);
+ }
+
+ public override void GetDecompositionClass(String file, out Matrix matrix, out QR qr)
+ {
+ MatrixMarketReader mmr = new MatrixMarketReader();
+ matrix = mmr.ReadMatrix(file, MatrixType.Dense);
+ qr = new QR(matrix);
+ }
+ }
+}
Added: trunk/UnitTests/LinearAlgebra/Decomposition/DenseSvdTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/DenseSvdTest.cs 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/DenseSvdTest.cs 2006-01-20 15:52:02 UTC (rev 181)
@@ -0,0 +1,38 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using dnAnalytics.Math;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.LinearAlgebra.Decomposition;
+using dnAnalytics.LinearAlgebra.IO;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.UnitTests.LinearAlgebra.Decomposition
+{
+ [TestFixture]
+ public class DenseSvdTest : AbstractSvdTest
+ {
+ public override Vector GetVector(int size)
+ {
+ return VectorBuilder.CreateVector(size, VectorType.Dense);
+ }
+
+ public override Matrix GetMatrix(int rows, int columns)
+ {
+ return MatrixBuilder.CreateMatrix(rows, columns, MatrixType.Dense);
+ }
+
+ public override Matrix GetMatrix(int order)
+ {
+ return MatrixBuilder.CreateMatrix(order, MatrixType.Dense);
+ }
+
+ public override void GetDecompositionClass(String file, out Matrix matrix, out Svd svd)
+ {
+ MatrixMarketReader mmr = new MatrixMarketReader();
+ matrix = mmr.ReadMatrix(file, MatrixType.Dense);
+ svd = new Svd(matrix, true);
+ }
+ }
+}
Modified: trunk/UnitTests/UnitTests.csproj
===================================================================
--- trunk/UnitTests/UnitTests.csproj 2006-01-20 11:10:32 UTC (rev 180)
+++ trunk/UnitTests/UnitTests.csproj 2006-01-20 15:52:02 UTC (rev 181)
@@ -52,6 +52,8 @@
<Compile Include="LinearAlgebra\Decomposition\AbstractLUTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\AbstractCholeskyTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\AbstractQRTest.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\AbstractSvdTest.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\DenseSvdTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseQRTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseCholeskyTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseLUTest.cs">
|
|
From: <in...@dn...> - 2006-01-20 11:10:55
|
Author: marcus
Date: 2006-01-20 06:10:32 -0500 (Fri, 20 Jan 2006)
New Revision: 180
Added:
trunk/LinearAlgebra/Decomposition/DenseSvd.cs
trunk/LinearAlgebra/Decomposition/ISvd.cs
trunk/LinearAlgebra/Decomposition/Svd.cs
Modified:
trunk/LinearAlgebra/Decomposition/Cholesky.cs
trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
trunk/LinearAlgebra/Decomposition/DenseLU.cs
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/NumericalLibrary.csproj
Log:
minor correction to LU, Cholesky, and QR constructors.
added SVD interface and a stub for DenseSvd.
Modified: trunk/LinearAlgebra/Decomposition/Cholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -42,7 +42,6 @@
throw new NotSquareMatrixException(Strings.MustBeSquare);
}
-
decomp = new DenseCholesky(matrix);
order = matrix.Rows;
Modified: trunk/LinearAlgebra/Decomposition/DenseCholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/DenseCholesky.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -32,7 +32,7 @@
throw new NotSquareMatrixException(Strings.MustBeSquare);
}
- this.matrix = (DenseMatrix)matrix.Clone();
+ this.matrix = new DenseMatrix(matrix);
}
#endregion Constructor
Modified: trunk/LinearAlgebra/Decomposition/DenseLU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/DenseLU.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -38,14 +38,17 @@
/// <param name="matrix">The matrix to use.</param>
public DenseLU(Matrix matrix)
{
- if (matrix is DenseMatrix)
+ if (matrix == null)
{
- this.matrix = (DenseMatrix)matrix.Clone();
+ throw new ArgumentNullException("matrix", Strings.NullParameterException);
}
- else
+
+ if (matrix.Rows != matrix.Columns)
{
- this.matrix = new DenseMatrix(matrix);
+ throw new NotSquareMatrixException(Strings.MustBeSquare);
}
+
+ this.matrix = new DenseMatrix(matrix);
}
#endregion Constructors
Modified: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -35,7 +35,8 @@
{
throw new ArgumentNullException("matrix", Strings.NullParameterException);
}
- this.r = (DenseMatrix)matrix.Clone();
+
+ this.r = new DenseMatrix(matrix);
}
#endregion Constructor
Added: trunk/LinearAlgebra/Decomposition/DenseSvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/DenseSvd.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -0,0 +1,210 @@
+/*
+* DenseSvd.cs
+*
+* Copyright (c) 2005, dnAnalytics. All rights reserved.
+*/
+
+#region Using Directives
+using System;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.Math;
+using dnAnalytics.Exceptions;
+using dnAnalytics.Resources;
+#endregion
+
+namespace dnAnalytics.LinearAlgebra.Decomposition
+{
+ /// <summary>
+ /// Class for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
+ /// </summary>
+ public sealed class DenseSvd : Algorithm
+ {
+ #region Fields
+ private DenseMatrix matrix;
+ #endregion Fields
+
+ #region Constructors
+ /// <summary>
+ /// Constructs an QR object for the given matrix.
+ /// </summary>
+ /// <param name="matrix">The matrix to factor.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
+ public DenseSvd(Matrix matrix)
+ {
+ if (matrix == null)
+ {
+ throw new ArgumentNullException("matrix", Strings.NullParameterException);
+ }
+
+ this.matrix = new DenseMatrix(matrix);
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ ///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
+ ///<value>The two norm of the <see cref="Matrix"/>.</value>
+ public double Norm2
+ {
+ get
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+ }
+
+ ///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
+ ///<value>The condition number.</value>
+ public double Condition
+ {
+ get
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+ }
+
+ ///<summary>Returns the effective numerical matrix rank.</summary>
+ ///<value>The number of non-negligible singular values.</value>
+ public int Rank
+ {
+ get
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+ }
+ #endregion Properties
+
+ #region Public Methods
+
+ ///<summary>Returns the left singular vectors as a <see cref="Matrix"/>.</summary>
+ ///<returns>The left singular vectors. The matrix will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ public Matrix U()
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Copies the left singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the left singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ public void U(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ ///<summary>Returns the right singular vectors as a <see cref="Matrix"/>.</summary>
+ ///<returns>The right singular vectors. The matrix will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ public Matrix V()
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Copies the right singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the right singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ public void V(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ ///<summary>Returns the singular values as a diagonal <see cref="Matrix"/>.</summary>
+ ///<returns>The singular values as a diagonal <see cref="Matrix"/>.</returns>
+ public Matrix W()
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Resets the <paramref name="result"/> <see cref="Matrix"/> and copies the singular values onto the diagonal.
+ /// </summary>
+ /// <param name="result"><see cref="Matrix"/> to copy the singular values to.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ public void W(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != matrix.Rows || result.Columns != matrix.Columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ ///<summary>Returns the singular values as a <see cref="Vector"/>.</summary>
+ ///<returns>the singular values as a <see cref="Vector"/>.</returns>
+ public Vector S()
+ {
+ Compute();
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Copies the singular values to the given <see cref="Vector"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Vector"/> to copy the singular values into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ public void S(Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ //if (result.Rows != rows || result.Columns != rows)
+ //{
+ // throw new NotConformableException("result", Strings.ParameterNotConformable);
+ // }
+
+ Compute();
+ throw new NotImplementedException();
+ }
+ #endregion Public Methods
+
+ #region Protected Members
+ /// <summary>
+ /// Delegates the actual computation to the correct QR subtype.
+ /// </summary>
+ protected override void InternalCompute()
+ {
+
+ }
+ #endregion Protected Members
+ }
+}
Added: trunk/LinearAlgebra/Decomposition/ISvd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/ISvd.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -0,0 +1,86 @@
+/*
+* ISvd.cs
+*
+* Copyright (c) 2005, dnAnalytics. All rights reserved.
+*/
+
+#region Using Directives
+using System;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.Math;
+using dnAnalytics.Exceptions;
+#endregion
+
+namespace dnAnalytics.LinearAlgebra.Decomposition
+{
+ /// <summary>
+ /// Interface for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
+ /// </summary>
+ internal interface ISvd : IAlgorithm
+ {
+ ///<summary>Returns the left singular vectors.</summary>
+ ///<returns>The left singular vectors. The vectors will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ Matrix U();
+
+ /// <summary>
+ /// Copies the left singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the left singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ void U(Matrix result);
+
+ ///<summary>Returns the right singular vectors.</summary>
+ ///<returns>The right singular vectors. The vectors will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ Matrix V();
+
+ /// <summary>
+ /// Copies the right singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the right singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ void V(Matrix result);
+
+ ///<summary>Returns the singular values as a diagonal <see cref="Matrix"/>.</summary>
+ ///<returns>The singular values as a diagonal <see cref="Matrix"/>.</returns>
+ Matrix W();
+
+ /// <summary>
+ /// Resets the <paramref name="result"/> <see cref="Matrix"/> and copies the singular values onto the diagonal.
+ /// </summary>
+ /// <param name="result"><see cref="Matrix"/> to copy the singular values to.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ void W(Matrix result);
+
+ ///<summary>Returns the singular values as a <see cref="Vector"/>.</summary>
+ ///<returns>the singular values as a <see cref="Vector"/>.</returns>
+ Vector S();
+
+ /// <summary>
+ /// Copies the singular values to the given <see cref="Vector"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Vector"/> to copy the singular values into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ void S(Vector result);
+
+ ///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
+ ///<value>The two norm of the <see cref="Matrix"/>.</value>
+ double Norm2 { get; }
+
+ ///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
+ ///<value>The condition number.</value>
+ double Condition { get; }
+
+ ///<summary>Returns the effective numerical matrix rank.</summary>
+ ///<value>The number of non-negligible singular values.</value>
+ int Rank { get; }
+
+ }
+}
Added: trunk/LinearAlgebra/Decomposition/Svd.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/LinearAlgebra/Decomposition/Svd.cs 2006-01-20 11:10:32 UTC (rev 180)
@@ -0,0 +1,205 @@
+/*
+* Svd.cs
+*
+* Copyright (c) 2005, dnAnalytics. All rights reserved.
+*/
+
+#region Using Directives
+using System;
+using dnAnalytics.LinearAlgebra;
+using dnAnalytics.Math;
+using dnAnalytics.Exceptions;
+using dnAnalytics.Resources;
+#endregion
+
+namespace dnAnalytics.LinearAlgebra.Decomposition
+{
+ /// <summary>
+ /// Class for computing the Singular Value Decomposition of a <see cref="Matrix"/>.
+ /// </summary>
+ public sealed class Svd : Algorithm
+ {
+ #region Fields
+ private ISvd decomp;
+ private readonly int rows;
+ private readonly int columns;
+ #endregion Fields
+
+
+ #region Constructors
+ /// <summary>
+ /// Constructs an QR object for the given matrix.
+ /// </summary>
+ /// <param name="matrix">The matrix to factor.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
+ public Svd(Matrix matrix)
+ {
+ if (matrix == null)
+ {
+ throw new ArgumentNullException("matrix", Strings.NullParameterException);
+ }
+
+ //decomp = new DenseSvd(matrix);
+ rows = matrix.Rows;
+ columns = matrix.Columns;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ ///<summary>Returns the two norm of the <see cref="Matrix"/>.</summary>
+ ///<value>The two norm of the <see cref="Matrix"/>.</value>
+ public double Norm2
+ {
+ get
+ {
+ return decomp.Norm2;
+ }
+ }
+
+ ///<summary>Returns the condition number <c>max(S) / min(S)</c>.</summary>
+ ///<value>The condition number.</value>
+ public double Condition
+ {
+ get
+ {
+ return decomp.Condition;
+ }
+ }
+
+ ///<summary>Returns the effective numerical matrix rank.</summary>
+ ///<value>The number of non-negligible singular values.</value>
+ public int Rank
+ {
+ get
+ {
+ return decomp.Rank;
+ }
+ }
+ #endregion Properties
+
+ #region Public Methods
+
+ ///<summary>Returns the left singular vectors as a <see cref="Matrix"/>.</summary>
+ ///<returns>The left singular vectors. The matrix will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ public Matrix U()
+ {
+ return decomp.U();
+ }
+
+ /// <summary>
+ /// Copies the left singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the left singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ public void U(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != rows || result.Columns != columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ decomp.U(result);
+ }
+
+ ///<summary>Returns the right singular vectors as a <see cref="Matrix"/>.</summary>
+ ///<returns>The right singular vectors. The matrix will be <c>null</c>,
+ ///if <c>computeVectors</c> in the constructor is set to false.</returns>
+ public Matrix V()
+ {
+ return decomp.V();
+ }
+
+ /// <summary>
+ /// Copies the right singular vectors into the <paramref name="result"/> <see cref="Matrix"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Matrix"/> to copy the right singular vectors into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ /// <remarks>The method does nothing if <c>computeVectors</c> in the constructor is set to false.</remarks>
+ public void V(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != rows || result.Columns != columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ decomp.V(result);
+ }
+
+ ///<summary>Returns the singular values as a diagonal <see cref="Matrix"/>.</summary>
+ ///<returns>The singular values as a diagonal <see cref="Matrix"/>.</returns>
+ public Matrix W()
+ {
+ return decomp.W();
+ }
+
+ /// <summary>
+ /// Resets the <paramref name="result"/> <see cref="Matrix"/> and copies the singular values onto the diagonal.
+ /// </summary>
+ /// <param name="result"><see cref="Matrix"/> to copy the singular values to.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ public void W(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ if (result.Rows != rows || result.Columns != columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+ decomp.W(result);
+ }
+
+ ///<summary>Returns the singular values as a <see cref="Vector"/>.</summary>
+ ///<returns>the singular values as a <see cref="Vector"/>.</returns>
+ public Vector S()
+ {
+ return decomp.S();
+ }
+
+ /// <summary>
+ /// Copies the singular values to the given <see cref="Vector"/>.
+ /// </summary>
+ /// <param name="result">The <see cref="Vector"/> to copy the singular values into.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="result"/> is <c>null</c>.</exception>
+ /// <exception cref="NotConformableException">If <paramref name="result"/> doesn't have conforming dimensions.</exception>
+ public void S(Vector result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ //if (result.Rows != rows || result.Columns != rows)
+ //{
+ // throw new NotConformableException("result", Strings.ParameterNotConformable);
+ // }
+
+ decomp.S(result);
+ throw new NotImplementedException();
+ }
+ #endregion Public Methods
+
+ #region Protected Members
+ /// <summary>
+ /// Delegates the actual computation to the correct QR subtype.
+ /// </summary>
+ protected override void InternalCompute()
+ {
+ decomp.Compute();
+ }
+ #endregion Protected Members
+ }
+}
Modified: trunk/NumericalLibrary.csproj
===================================================================
--- trunk/NumericalLibrary.csproj 2006-01-19 09:07:07 UTC (rev 179)
+++ trunk/NumericalLibrary.csproj 2006-01-20 11:10:32 UTC (rev 180)
@@ -62,6 +62,8 @@
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="LinearAlgebra\Decomposition\Cholesky.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseQR.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\DenseSvd.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\ISvd.cs" />
<Compile Include="LinearAlgebra\Decomposition\QR.cs" />
<Compile Include="LinearAlgebra\Decomposition\Householder.cs">
<SubType>Code</SubType>
@@ -116,6 +118,7 @@
</Compile>
<Compile Include="LinearAlgebra\Range.cs" />
<Compile Include="LinearAlgebra\Solvers\ISolver.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\Svd.cs" />
<Compile Include="LinearAlgebra\Vector.cs" />
<Compile Include="Math\Algorithm.cs" />
<Compile Include="Math\Complex.cs" />
|
|
From: <in...@dn...> - 2006-01-19 09:08:49
|
Author: marcus
Date: 2006-01-19 04:07:07 -0500 (Thu, 19 Jan 2006)
New Revision: 179
Modified:
trunk/LinearAlgebra/Decomposition/Cholesky.cs
trunk/LinearAlgebra/Decomposition/LU.cs
trunk/LinearAlgebra/Decomposition/QR.cs
Log:
finished all changes with regards to ticket #37.
Modified: trunk/LinearAlgebra/Decomposition/Cholesky.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-19 08:38:52 UTC (rev 178)
+++ trunk/LinearAlgebra/Decomposition/Cholesky.cs 2006-01-19 09:07:07 UTC (rev 179)
@@ -42,15 +42,9 @@
throw new NotSquareMatrixException(Strings.MustBeSquare);
}
- if (matrix.GetType() == typeof(DenseMatrix))
- {
- decomp = new DenseCholesky(matrix);
- }
- //add other types, such as sparse here.
- else
- {
- decomp = new DenseCholesky(matrix);
- }
+
+ decomp = new DenseCholesky(matrix);
+
order = matrix.Rows;
}
Modified: trunk/LinearAlgebra/Decomposition/LU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-19 08:38:52 UTC (rev 178)
+++ trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-19 09:07:07 UTC (rev 179)
@@ -17,7 +17,7 @@
namespace dnAnalytics.LinearAlgebra.Decomposition
{
/// <summary>
- /// Class for computing the LU factorization of an n by n <see cref="Matrix"/>.
+ /// Class for computing the <c>LU</c> factorization of an n by n <see cref="Matrix"/>.
/// </summary>
public sealed class LU : Algorithm
{
@@ -28,7 +28,7 @@
#region Constructor
/// <summary>
- /// Constructs an LU object for the given matrix.
+ /// Constructs an <c>LU</c> object for the given matrix.
/// </summary>
/// <param name="matrix">The matrix to factor.</param>
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
@@ -45,15 +45,8 @@
throw new NotSquareMatrixException(Strings.MustBeSquare);
}
- if (matrix.GetType() == typeof(DenseMatrix))
- {
- decomp = new DenseLU(matrix);
- }
- //add other types, such as sparse here.
- else
- {
- decomp = new DenseLU(matrix);
- }
+ decomp = new DenseLU(matrix);
+
order = matrix.Rows;
}
#endregion Constructor
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-19 08:38:52 UTC (rev 178)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-19 09:07:07 UTC (rev 179)
@@ -37,15 +37,7 @@
throw new ArgumentNullException("matrix", Strings.NullParameterException);
}
- if (matrix.GetType() == typeof(DenseMatrix))
- {
- decomp = new DenseQR(matrix);
- }
- //add other types, such as sparse here.
- else
- {
- decomp = new DenseQR(matrix);
- }
+ decomp = new DenseQR(matrix);
rows = matrix.Rows;
columns = matrix.Columns;
}
@@ -136,7 +128,7 @@
}
#endregion Public Properites
-
+
#region Protected Members
/// <summary>
|
|
From: <in...@dn...> - 2006-01-19 08:39:02
|
Author: marcus
Date: 2006-01-19 03:38:52 -0500 (Thu, 19 Jan 2006)
New Revision: 178
Modified:
trunk/LinearAlgebra/Decomposition/LU.cs
Log:
fixed compile bug.
Modified: trunk/LinearAlgebra/Decomposition/LU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-19 08:22:30 UTC (rev 177)
+++ trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-19 08:38:52 UTC (rev 178)
@@ -23,7 +23,7 @@
{
#region Fields
private ILU decomp;
- private int readonly order;
+ private readonly int order;
#endregion Fields
#region Constructor
|
|
From: <in...@dn...> - 2006-01-19 08:22:42
|
Author: marcus
Date: 2006-01-19 03:22:30 -0500 (Thu, 19 Jan 2006)
New Revision: 177
Modified:
trunk/LinearAlgebra/Decomposition/LU.cs
trunk/LinearAlgebra/Decomposition/QR.cs
Log:
added size checks.
Modified: trunk/LinearAlgebra/Decomposition/LU.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-18 16:12:15 UTC (rev 176)
+++ trunk/LinearAlgebra/Decomposition/LU.cs 2006-01-19 08:22:30 UTC (rev 177)
@@ -23,6 +23,7 @@
{
#region Fields
private ILU decomp;
+ private int readonly order;
#endregion Fields
#region Constructor
@@ -48,11 +49,12 @@
{
decomp = new DenseLU(matrix);
}
- //add other types, such as sparse here.
+ //add other types, such as sparse here.
else
{
decomp = new DenseLU(matrix);
}
+ order = matrix.Rows;
}
#endregion Constructor
@@ -88,6 +90,10 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
+ if (result.Rows != order || result.Columns != order)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
decomp.LowerFactor(result);
}
@@ -113,6 +119,10 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
+ if (result.Rows != order || result.Columns != order)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
decomp.UpperFactor(result);
}
@@ -180,6 +190,10 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
+ if (result.Rows != order || result.Columns != order)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
if (IsSingular)
{
Modified: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-18 16:12:15 UTC (rev 176)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-19 08:22:30 UTC (rev 177)
@@ -19,6 +19,8 @@
#region Fields
private IQR decomp;
+ private readonly int rows;
+ private readonly int columns;
#endregion Fields
@@ -44,6 +46,8 @@
{
decomp = new DenseQR(matrix);
}
+ rows = matrix.Rows;
+ columns = matrix.Columns;
}
#endregion Constructor
@@ -78,6 +82,10 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
+ if (result.Rows != rows || result.Columns != rows)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
decomp.Q(result);
}
@@ -91,6 +99,11 @@
{
throw new ArgumentNullException("result", Strings.NullParameterException);
}
+ if (result.Rows != rows || result.Columns != columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+
decomp.R(result);
}
|
|
From: <in...@dn...> - 2006-01-18 16:12:38
|
Author: marcus
Date: 2006-01-18 11:12:15 -0500 (Wed, 18 Jan 2006)
New Revision: 176
Added:
trunk/LinearAlgebra/Decomposition/DenseQR.cs
trunk/LinearAlgebra/Decomposition/QR.cs
trunk/TestMatrices/random_real_general_array_20_10.matrix_market
Modified:
trunk/LinearAlgebra/Decomposition/Householder.cs
trunk/LinearAlgebra/Decomposition/IQR.cs
trunk/LinearAlgebra/DenseMatrix.cs
trunk/LinearAlgebra/DenseVector.cs
trunk/LinearAlgebra/ManagedBlas.cs
trunk/LinearAlgebra/ManagedLapack.cs
trunk/LinearAlgebra/NativeBlas.cs
trunk/LinearAlgebra/NativeLapack.cs
trunk/NumericalLibrary.csproj
trunk/Settings.cs
trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs
trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs
trunk/UnitTests/UnitTests.csproj
Log:
finished QR classes.
fixed a blas multiply bug.
fixed a native blas addition and subtraction bug.
Added: trunk/LinearAlgebra/Decomposition/DenseQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/Decomposition/DenseQR.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -0,0 +1,163 @@
+/*
+* DenseQR.cs
+*
+* Copyright (c) 2006, dnAnalytics. All rights reserved.
+*/
+
+using System;
+using dnAnalytics.Math;
+using dnAnalytics.Resources;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.LinearAlgebra.Decomposition
+{
+ /// <summary>
+ /// Computes the QR decomposition of a <see cref="Matrix"/>.
+ /// </summary>
+ public sealed class DenseQR : Algorithm, IQR
+ {
+ #region Fields
+ private bool isFullRank = true;
+ private double det = 1;
+ private DenseMatrix r;
+ private DenseMatrix q;
+ #endregion Fields
+
+ #region Constructor
+ /// <summary>
+ /// Constructs an QR object for the given matrix.
+ /// </summary>
+ /// <param name="matrix">The matrix to factor.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
+ public DenseQR(Matrix matrix)
+ {
+ if (matrix == null)
+ {
+ throw new ArgumentNullException("matrix", Strings.NullParameterException);
+ }
+ this.r = (DenseMatrix)matrix.Clone();
+ }
+
+ #endregion Constructor
+
+ #region Public Methods
+
+ /// <summary>
+ /// Returns the orthogonal Q matrix.
+ /// </summary>
+ /// <returns>The orthogonal Q matrix</returns>
+ public Matrix Q()
+ {
+ Compute();
+ return q;
+ }
+
+ /// <summary>
+ /// Returns the upper triangular factor R.
+ /// </summary>
+ /// <returns>The upper triangular factor R</returns>
+ public Matrix R()
+ {
+ Compute();
+ return r;
+ }
+
+ /// <summary>
+ /// Copies the orthogonal Q matrix into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ public void Q(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+
+ if (result.Rows != q.Rows || result.Columns != q.Columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+
+ q.CopyTo(result);
+ }
+
+ /// <summary>
+ /// Copies the upper triangular factor R into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ public void R(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+
+ if (result.Rows != r.Rows || result.Columns != r.Columns)
+ {
+ throw new NotConformableException("result", Strings.ParameterNotConformable);
+ }
+
+ r.CopyTo(result);
+ }
+
+ #endregion Public Methods
+
+ #region Public Properties
+
+ /// <summary>
+ /// Determine whether the matrix is full rank or not
+ /// </summary>
+ /// <value>Boolean value indicates whether the given matrix is full rank or not</value>
+ public bool IsFullRank
+ {
+ get
+ {
+ Compute();
+ return isFullRank;
+ }
+ }
+
+ ///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
+ ///<value>The determinant of the matrix.</value>
+ ///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
+ public double Determinant
+ {
+ get
+ {
+ if (r.Rows != r.Columns)
+ {
+ throw new NotSquareMatrixException();
+ }
+ Compute();
+ return det;
+ }
+ }
+ #endregion Public Properties
+
+ #region Protected Members
+
+ /// <summary>
+ /// Delegates the actual computation to the correct QR subtype.
+ /// </summary>
+ protected override void InternalCompute()
+ {
+ q = (DenseMatrix)MatrixBuilder.CreateMatrix(r.Rows, r.Rows, MatrixType.Dense);
+ r.lapack.QRFactor(r.Rows, r.Columns, q.data, r.data);
+
+ int min = System.Math.Min(r.Rows, r.Columns);
+
+ for (int i = 0; i < min; i++)
+ {
+ det *= r.ValueAt(i, i);
+ if (System.Math.Abs(r.ValueAt(i, i)) <= 1e-15)
+ {
+ isFullRank = false;
+ det = 0;
+ break;
+ }
+ }
+ det = System.Math.Abs(det);
+ }
+ #endregion Protected Members
+ }
+}
Modified: trunk/LinearAlgebra/Decomposition/Householder.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/Householder.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/Decomposition/Householder.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -29,8 +29,8 @@
for (int i = r1; i <= r2; i++)
{
- u[i - r1] = A[c * m + i];// A.ValueAt(i, c);
- A[tmp + i] = 0.0;// A.ValueAt(i, c, 0.0);
+ u[i - r1] = A[tmp + i];
+ A[tmp + i] = 0.0;
}
@@ -92,7 +92,7 @@
{
for (int j = c1; j <= c2; j++)
{
- v[j - c1] = v[j - c1] + u[i - r1] * A[j * m + i];//.ValueAt(i, j);
+ v[j - c1] = v[j - c1] + u[i - r1] * A[j * m + i];
}
}
@@ -100,7 +100,7 @@
{
for (int j = c1; j <= c2; j++)
{
- A[j * m + i] = A[j * m + i] - u[i - r1] * v[j - c1];// A.ValueAt(i, j, (A[i, j] - u[i - r1] * v[j - c1]));
+ A[j * m + i] = A[j * m + i] - u[i - r1] * v[j - c1];
}
}
}
Modified: trunk/LinearAlgebra/Decomposition/IQR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/Decomposition/IQR.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -22,7 +22,7 @@
/// Determine whether the matrix is full rank or not
/// </summary>
/// <value>Boolean value indicates whether the given matrix is full rank or not</value>
- bool IsFullRank();
+ bool IsFullRank { get; }
/// <summary>
/// Returns the orthogonal Q matrix.
@@ -31,14 +31,26 @@
Matrix Q();
/// <summary>
+ /// Copies the orthogonal Q matrix into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ void Q(Matrix result);
+
+ /// <summary>
/// Returns the upper triangular factor R.
/// </summary>
/// <returns>The upper triangular factor R</returns>
Matrix R();
+ /// <summary>
+ /// Copies the upper triangular factor R into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ void R(Matrix result);
+
///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
- ///<returns>The determinant of the matrix.</returns>
+ ///<value>The determinant of the matrix.</value>
///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
- double Determinant();
+ double Determinant { get; }
}
}
Added: trunk/LinearAlgebra/Decomposition/QR.cs
===================================================================
--- trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/Decomposition/QR.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -0,0 +1,138 @@
+/*
+* QR.cs
+*
+* Copyright (c) 2006, dnAnalytics. All rights reserved.
+*/
+
+using System;
+using dnAnalytics.Math;
+using dnAnalytics.Resources;
+using dnAnalytics.Exceptions;
+
+namespace dnAnalytics.LinearAlgebra.Decomposition
+{
+ /// <summary>
+ /// Computes the QR decomposition of a <see cref="Matrix"/>.
+ /// </summary>
+ public sealed class QR : Algorithm
+ {
+ #region Fields
+
+ private IQR decomp;
+
+ #endregion Fields
+
+ #region Constructor
+ /// <summary>
+ /// Constructs an QR object for the given matrix.
+ /// </summary>
+ /// <param name="matrix">The matrix to factor.</param>
+ /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
+ public QR(Matrix matrix)
+ {
+ if (matrix == null)
+ {
+ throw new ArgumentNullException("matrix", Strings.NullParameterException);
+ }
+
+ if (matrix.GetType() == typeof(DenseMatrix))
+ {
+ decomp = new DenseQR(matrix);
+ }
+ //add other types, such as sparse here.
+ else
+ {
+ decomp = new DenseQR(matrix);
+ }
+ }
+
+ #endregion Constructor
+
+ #region Public Methods
+
+ /// <summary>
+ /// Returns the orthogonal Q matrix.
+ /// </summary>
+ /// <returns>The orthogonal Q matrix</returns>
+ public Matrix Q()
+ {
+ return decomp.Q();
+ }
+
+ /// <summary>
+ /// Returns the upper triangular factor R.
+ /// </summary>
+ /// <returns>The upper triangular factor R</returns>
+ public Matrix R()
+ {
+ return decomp.R();
+ }
+
+ /// <summary>
+ /// Copies the orthogonal Q matrix into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy the orthogonal Q matrix into.</param>
+ public void Q(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ decomp.Q(result);
+ }
+
+ /// <summary>
+ /// Copies the upper triangular factor R into the result matrix.
+ /// </summary>
+ /// <param name="result">A matrix to copy upper triangular factor R into.</param>
+ public void R(Matrix result)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result", Strings.NullParameterException);
+ }
+ decomp.R(result);
+ }
+
+
+ #endregion Public Methods
+
+ #region Public Properties
+ /// <summary>
+ /// Determine whether the matrix is full rank or not
+ /// </summary>
+ /// <value>Boolean value indicates whether the given matrix is full rank or not</value>
+ public bool IsFullRank
+ {
+ get
+ {
+ return decomp.IsFullRank;
+ }
+ }
+
+
+ ///<summary>Calculates the determinant (absolute value) of the matrix.</summary>
+ ///<value>The determinant of the matrix.</value>
+ ///<exception cref="NotSquareMatrixException">If the matrix is not square.</exception>
+ public double Determinant
+ {
+ get
+ {
+ return decomp.Determinant;
+ }
+ }
+
+ #endregion Public Properites
+
+ #region Protected Members
+
+ /// <summary>
+ /// Delegates the actual computation to the correct QR subtype.
+ /// </summary>
+ protected override void InternalCompute()
+ {
+ decomp.Compute();
+ }
+ #endregion Protected Members
+ }
+}
Modified: trunk/LinearAlgebra/DenseMatrix.cs
===================================================================
--- trunk/LinearAlgebra/DenseMatrix.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/DenseMatrix.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -1340,7 +1340,7 @@
if (other.GetType() == typeof(DenseMatrix) && result.GetType() == typeof(DenseMatrix))
{
- blas.Multiply(Rows, Columns, other.Columns, data, ((DenseMatrix)other).data, ((DenseMatrix)result).data);
+ blas.Multiply(Rows, other.Columns, Columns, data, ((DenseMatrix)other).data, ((DenseMatrix)result).data);
}
else
{
@@ -1381,7 +1381,7 @@
;
if (leftSide.GetType() == typeof(DenseVector) && result.GetType() == typeof(DenseVector))
{
- blas.Multiply(1, leftSide.Count, Columns, ((DenseVector)leftSide).data, data, ((DenseVector)result).data);
+ blas.Multiply(1, Columns, leftSide.Count, ((DenseVector)leftSide).data, data, ((DenseVector)result).data);
}
else
{
Modified: trunk/LinearAlgebra/DenseVector.cs
===================================================================
--- trunk/LinearAlgebra/DenseVector.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/DenseVector.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -673,7 +673,7 @@
{
DenseVector rightVector = (DenseVector)rightSide;
DenseMatrix result = new DenseMatrix(this.Count, rightSide.Count, Settings.UseNativeLibrary);
- blas.Multiply(this.Count, 1, rightSide.Count, data, rightVector.data, result.data);
+ blas.Multiply(this.Count, rightSide.Count, 1, data, rightVector.data, result.data);
return result;
}
else
@@ -708,7 +708,7 @@
{
DenseVector rightVector = (DenseVector)rightSide;
DenseMatrix resultMatrix = (DenseMatrix)result;
- blas.Multiply(this.Count, 1, rightSide.Count, data, rightVector.data, resultMatrix.data);
+ blas.Multiply(this.Count, rightSide.Count, 1, data, rightVector.data, resultMatrix.data);
}
else
{
Modified: trunk/LinearAlgebra/ManagedBlas.cs
===================================================================
--- trunk/LinearAlgebra/ManagedBlas.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/ManagedBlas.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -92,14 +92,14 @@
double s = 0;
int ntmp = 0;
int mtmp = 0;
- for (j = 0; j < k; ++j)
+ for (j = 0; j < n; ++j)
{
- ntmp = n * j;
+ ntmp = k * j;
mtmp = m * j;
for (i = 0; i < m; ++i)
{
s = 0;
- for (l = 0; l < n; ++l)
+ for (l = 0; l < k; ++l)
{
s += x[m * l + i] * y[ntmp + l];
}
Modified: trunk/LinearAlgebra/ManagedLapack.cs
===================================================================
--- trunk/LinearAlgebra/ManagedLapack.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/ManagedLapack.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -217,7 +217,7 @@
}
double[] tmp = new double[rows * rows];
- blas.Multiply(rows, columns, rows, data, trans, tmp);
+ blas.Multiply(rows, rows, columns, data, trans, tmp);
for (int i = 0; i < rows; i++)
{
ret += System.Math.Abs(tmp[i * rows + i]);
@@ -293,14 +293,19 @@
public void QRFactor(int m, int n, double[] q, double[] r)
{
+ for (int i = 0; i < m; i++)
+ {
+ q[i * m + i] = 1;
+ }
int minmn = m < n ? m : n;
+
double[][] u = new double[minmn][];
for (int i = 0; i < minmn; i++)
{
u[i] = Householder.GenerateColumn(r, m, i, m - 1, i);
Householder.UA(u[i], r, m, i, m - 1, i + 1, n - 1);
}
- //q = DoubleMatrix.CreateIdentity(m);
+
for (int i = minmn - 1; i >= 0; i--)
{
Householder.UA(u[i], q, m, i, m - 1, i, m - 1);
Modified: trunk/LinearAlgebra/NativeBlas.cs
===================================================================
--- trunk/LinearAlgebra/NativeBlas.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/NativeBlas.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -7,52 +7,66 @@
*/
using dnAnalytics.LinearAlgebra.Native;
-namespace dnAnalytics.LinearAlgebra {
- internal sealed class NativeBlas : ISimplifiedBlas {
- private IBlas blas = Provider.BlasInstance;
+namespace dnAnalytics.LinearAlgebra
+{
+ internal sealed class NativeBlas : ISimplifiedBlas
+ {
+ private IBlas blas = Provider.BlasInstance;
- public int AbsoluteMaximumIndex(double[] data) {
- return blas.Idamax(data.Length, data, 1);
- }
+ public int AbsoluteMaximumIndex(double[] data)
+ {
+ return blas.Idamax(data.Length, data, 1);
+ }
- public double SumMagnitudes(double[] data) {
- return blas.Dasum(data.Length, data, 1);
- }
+ public double SumMagnitudes(double[] data)
+ {
+ return blas.Dasum(data.Length, data, 1);
+ }
- public double DotProduct(double[] x, double[] y) {
- return blas.Ddot(x.Length, x, 1, y, 1);
- }
+ public double DotProduct(double[] x, double[] y)
+ {
+ return blas.Ddot(x.Length, x, 1, y, 1);
+ }
- public void Scale(double constant, double[] data) {
- blas.Dscal(data.Length, constant, data, 1);
- }
+ public void Scale(double constant, double[] data)
+ {
+ blas.Dscal(data.Length, constant, data, 1);
+ }
- public void Subtract(double[] vector, double constant) {
- double[] temp = new double[vector.Length];
- for (int i = 0; i < 0; ++i) {
- temp[i] = constant;
- }
- blas.Daxpy(vector.Length, -1, temp, 1, vector, 1);
- }
+ public void Subtract(double[] vector, double constant)
+ {
+ double[] temp = new double[vector.Length];
+ for (int i = 0; i < temp.Length; i++)
+ {
+ temp[i] = constant;
+ }
+ blas.Daxpy(vector.Length, -1, temp, 1, vector, 1);
+ }
- public void Subtract(double[] x, double[] y) {
- blas.Daxpy(x.Length, -1, y, 1, x, 1);
- }
+ public void Subtract(double[] x, double[] y)
+ {
+ blas.Daxpy(x.Length, -1, y, 1, x, 1);
+ }
- public void Add(double[] vector, double constant) {
- double[] temp = new double[vector.Length];
- for (int i = 0; i < 0; ++i) {
- temp[i] = constant;
- }
- blas.Daxpy(vector.Length, 1, temp, 1, vector, 1);
- }
+ public void Add(double[] vector, double constant)
+ {
+ double[] temp = new double[vector.Length];
+ for (int i = 0; i < temp.Length; i++)
+ {
+ temp[i] = constant;
+ }
- public void Add(double[] x, double[] y) {
- blas.Daxpy(x.Length, 1, y, 1, x, 1);
- }
+ blas.Daxpy(vector.Length, 1, temp, 1, vector, 1);
+ }
- public void Multiply(int m, int n, int k, double[] x, double[] y, double[] result) {
- blas.Dgemm(BlasOrderType.Column, BlasTransType.NoTrans, BlasTransType.NoTrans, m, n, k, 1, x, m, y, n, 1, result, k);
- }
- }
+ public void Add(double[] x, double[] y)
+ {
+ blas.Daxpy(x.Length, 1, y, 1, x, 1);
+ }
+
+ public void Multiply(int m, int n, int k, double[] x, double[] y, double[] result)
+ {
+ blas.Dgemm(BlasOrderType.Column, BlasTransType.NoTrans, BlasTransType.NoTrans, m, n, k, 1, x, m, y, k, 0, result, m);
+ }
+ }
}
\ No newline at end of file
Modified: trunk/LinearAlgebra/NativeLapack.cs
===================================================================
--- trunk/LinearAlgebra/NativeLapack.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/LinearAlgebra/NativeLapack.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -28,7 +28,7 @@
lapack.Dgetrf(order, order, factor, order, out ipiv);
for (int i = 0; i < pivots.Length; i++)
{
- pivots[i] = ipiv[i] - 1;
+ pivots[i] = ipiv[i] - 1;
}
}
@@ -82,7 +82,46 @@
public void QRFactor(int m, int n, double[] q, double[] r)
{
- throw new Exception("The method or operation is not implemented.");
+ double[] tau = new double[System.Math.Min(m, n)];
+ double[] qr = new double[r.Length];
+ Buffer.BlockCopy(r, 0, qr, 0, r.Length * Constants.SizeOfDouble);
+
+ lapack.Dgeqrf(m, n, qr, m, tau);
+
+ for (int i = 0; i < m; i++)
+ {
+ for (int j = 0; j < n; j++)
+ {
+ if (i <= j)
+ {
+ r[j * m + i] = qr[j * m + i];
+ }
+ else
+ {
+ r[j * m + i] = 0.0;
+ }
+ }
+ }
+ for (int i = 0; i < m; i++)
+ {
+ for (int j = 0; j < m && j < n; j++)
+ {
+ if (i > j)
+ {
+ q[j * m + i] = qr[j * m + i];
+ }
+ }
+ }
+
+
+ if (m <= n)
+ {
+ lapack.Dorgqr(m, m, m, q, m, tau);
+ }
+ else
+ {
+ lapack.Dorgqr(m, m, n, q, m, tau);
+ }
}
#endregion Public Methods
}
Modified: trunk/NumericalLibrary.csproj
===================================================================
--- trunk/NumericalLibrary.csproj 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/NumericalLibrary.csproj 2006-01-18 16:12:15 UTC (rev 176)
@@ -33,6 +33,14 @@
<DocumentationFile>bin\Release\dnAnalytics.dll.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="nunit.core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\Mailframe\TestRunner\nunit.core.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\Mailframe\TestRunner\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Modified: trunk/Settings.cs
===================================================================
--- trunk/Settings.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/Settings.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -16,7 +16,7 @@
/// </summary>
public static class Settings
{
- private static bool native;
+ private static bool native = false;
private static BlasProvider blasProvider;
private static LapackProvider lapackProvider;
private static MatrixType matrixType = MatrixType.Dense;
Added: trunk/TestMatrices/random_real_general_array_20_10.matrix_market
===================================================================
--- trunk/TestMatrices/random_real_general_array_20_10.matrix_market 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/TestMatrices/random_real_general_array_20_10.matrix_market 2006-01-18 16:12:15 UTC (rev 176)
@@ -0,0 +1,207 @@
+%%MatrixMarket matrix array real general
+%==============================================================
+% A Random 20x10 matrix with density = 1.0,
+% elements from -100.0 to 100.0
+% Generated by MatrixMarketDeli @ Fri Nov 11 17:06:08 EET 2005
+%==============================================================
+20 10
+3.8657857973798E+1
+-4.9614141943821E+0
+9.8367529614337E+1
+-8.2830239960130E+1
+-4.8001834141995E+1
+1.8538795105779E+0
+8.8913280903105E+0
+7.6433590250342E+1
+3.9112716073559E+1
+3.9887721176386E+0
+7.1502475973519E+1
+-6.2241679398193E+1
+-1.9561929064987E+0
+3.3027174343978E+1
+2.4007135439120E+1
+8.2689715275099E-1
+-8.1632642030832E+1
+4.9360457021864E+0
+-7.6279897452783E+1
+-7.4269842491989E+0
+-8.6709742218175E+1
+-2.3383344954355E+1
+-9.6814601918678E+1
+-8.9091848158775E+1
+7.8756002367903E+1
+7.5160409139558E+1
+4.9821485912964E+1
+-7.2203103442099E+1
+-8.0841292407509E+1
+8.8169658884781E+1
+7.3532129439538E+1
+-9.4881302335684E+1
+5.8975431339973E+1
+-9.6492050220299E+1
+-7.9279553728695E+1
+3.2251799109820E+1
+5.9347462853748E+0
+-5.9801269728711E+1
+3.7113551592361E+1
+-5.4025279935249E+0
+8.5124240448279E+1
+-5.0657034629351E+1
+-6.7019266503368E+1
+-1.7572213479782E+1
+-4.1060590659680E+1
+-3.7716876288734E+1
+4.8472477178567E+1
+8.7097993571157E-1
+-7.1011388392340E+1
+-5.9417485352436E+1
+6.0302454220710E+1
+7.2841896419677E+1
+-8.0277608153256E+1
+-5.3412553849684E+1
+-5.1571106786546E+1
+2.6798324194892E+1
+8.7932790521780E+1
+-2.7818093307886E+1
+-1.5775292212287E+1
+-2.1083512397918E+1
+2.5065328021297E+1
+7.6851803745298E+1
+2.3727288271726E+1
+-5.6135909760460E+1
+9.7097165855923E+1
+3.0818525947043E+1
+-7.7399463045670E+1
+-5.9195847420585E+1
+-8.9907684389171E+1
+-6.9317317811519E+1
+5.4976526142004E+1
+-5.7711254412963E+1
+-4.2430488846026E+0
+-9.8520336997919E+1
+5.4207931936249E+1
+-9.6502727928745E+1
+-1.7731298536016E+1
+6.5294704112545E+1
+9.9852653099467E+1
+5.1764551074441E+1
+2.2030411483824E+1
+6.3961999694411E-1
+9.0490382297665E+1
+9.4968452852052E+0
+9.6691006175572E+1
+4.4616403469871E+1
+5.1962038778481E+1
+2.6227755837799E+1
+1.2501410937845E+1
+-7.3032758436502E+1
+-4.3799479222919E+1
+-4.8823266783208E+1
+4.8892028772484E+1
+9.8005489461655E+1
+-5.2275562868370E+1
+1.4514592414139E+1
+-1.1026075554457E+1
+7.6577296847270E+1
+2.6350906953621E+1
+6.8136841733325E+1
+5.7795535934622E+1
+-6.4470860476650E+1
+5.6283044025406E+1
+-2.6583238106615E+1
+5.7172990280152E+1
+1.4839208716056E+1
+-5.3063788768535E+1
+-3.0677473549551E+1
+6.8017669017893E+1
+-5.3288687513339E+1
+-3.3607082144278E+1
+-1.7939974765680E+1
+2.2957582823418E+1
+-9.0407494201500E+1
+2.1409839072464E+1
+6.4922138455957E+1
+-4.6327046291443E+1
+5.3995656456756E+1
+2.6505336221819E+1
+-2.4511915982629E+1
+9.1168047319635E+1
+9.9716688040813E+1
+9.8054707298386E+1
+5.9887316030350E+1
+7.8681744287464E+1
+6.9897597029792E+1
+-8.8787531253430E+1
+2.7292048953501E+1
+3.1927009684747E+0
+-5.5726168695277E+1
+-8.6693878979362E+1
+-2.1397824828833E+1
+8.1370822022098E+1
+-1.7270794811094E+1
+-8.1388223901884E+1
+-1.8936484118800E+1
+-4.2889927761586E+1
+7.8482437781550E+1
+7.7075325106993E+1
+8.8869899961860E+1
+-9.3232845693345E+1
+6.1846976789257E+0
+-6.6663261172111E+1
+1.8474958322888E+1
+2.3348744734824E+1
+-7.4897068718330E+1
+-5.7272836386936E+1
+-9.1714308724696E+0
+-8.6336407708615E+1
+7.6778818041074E+1
+-3.3445963164259E+0
+4.3894137549737E+1
+-6.1054965593620E+1
+-8.1991824752178E+1
+-8.8591774350639E+1
+-3.1429357495994E+1
+8.3046062122694E+1
+3.4239494222753E+1
+1.9727267992300E+1
+-8.4478528341323E+1
+6.2027033474417E+1
+9.8545842876554E+1
+-5.3286194233121E+1
+-2.5677202022038E+0
+-7.9209868876695E+1
+6.5041073720403E+1
+-1.5816965556759E+1
+8.3696434105093E+1
+-1.7212688574462E+1
+-4.3479677766491E+1
+-5.8324979805811E+1
+9.2815617577040E+1
+-2.6635511496726E+1
+3.8968282841527E+1
+7.6492961602756E+1
+1.6117066567479E+1
+6.7829313570147E+1
+-4.8571588439503E+1
+1.1974628549357E+1
+4.1744016266844E+1
+8.8861608890694E+1
+-9.3820211873294E+1
+-8.0039282550807E+1
+-4.7286040976801E+0
+2.7500658275720E+1
+8.4074146022574E+0
+2.9721652493472E+1
+7.0202857515499E+1
+-8.8525601516714E+1
+8.3616547659693E+1
+-3.0287777191142E+1
+-3.6989943737820E+1
+4.8802326734341E+1
+-1.8370471958878E+1
+6.4014835211960E+1
+-9.7585733146856E+1
+-5.8531696320096E+1
+-8.7843304424702E+1
+6.7934939698221E+1
+-7.2342764125323E+1
Modified: trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/UnitTests/LinearAlgebra/AbstractVectorTest.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -513,7 +513,6 @@
Vector vector1 = GetVector(testArray);
Vector vector2 = vector1.Clone();
Matrix result = vector1.Multiply(vector2);
-
for (int i = 0; i < vector1.Count; i++)
{
for (int j = 0; j < vector2.Count; j++)
@@ -880,7 +879,7 @@
{
expected += System.Math.Abs(testArray[i]);
}
- Assert.AreEqual(expected, actual);
+ Assert.AreEqual(expected, actual, Constants.ACCEPTABLE_ERROR);
}
[Test]
Modified: trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs
===================================================================
--- trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/UnitTests/LinearAlgebra/Decomposition/AbstractLUTest.cs 2006-01-18 16:12:15 UTC (rev 176)
@@ -39,7 +39,7 @@
[Test]
[ExpectedException(typeof(NotSquareMatrixException))]
- public void LUConstructor()
+ public void LUConstructorNotSquare()
{
Matrix matrix = GetMatrix(3, 2);
LU lu = new LU(matrix);
@@ -68,7 +68,7 @@
perm[i, i] = 1;
}
- //there has to be a quicker way to generate the perm matrix?
+ //there has to be a quicker way to generate the perm squareMatrix?
double temp;
for (int i = 0; i < pivots.Length; i++)
{
@@ -117,7 +117,7 @@
perm[i, i] = 1;
}
- //there has to be a quicker way to generate the perm matrix?
+ //there has to be a quicker way to generate the perm squareMatrix?
for (int i = 0; i < pivots.Length; i++)
{
if (pivots[i] != i)
@@ -167,7 +167,7 @@
perm[i, i] = 1;
}
- //there has to be a quicker way to generate the perm matrix?
+ //there has to be a quicker way to generate the perm squareMatrix?
double temp;
for (int i = 0; i < pivots.Length; i++)
{
@@ -220,7 +220,7 @@
perm[i, i] = 1;
}
- //there has to be a quicker way to generate the perm matrix?
+ //there has to be a quicker way to generate the perm squareMatrix?
for (int i = 0; i < pivots.Length; i++)
{
if (pivots[i] != i)
Modified: trunk/UnitTests/UnitTests.csproj
===================================================================
--- trunk/UnitTests/UnitTests.csproj 2006-01-18 11:44:39 UTC (rev 175)
+++ trunk/UnitTests/UnitTests.csproj 2006-01-18 16:12:15 UTC (rev 176)
@@ -31,7 +31,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="nunit.core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\Mailframe\TestRunner\nunit.core.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\Mailframe\TestRunner\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
@@ -44,6 +51,8 @@
<Compile Include="LinearAlgebra\AbstractVectorTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\AbstractLUTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\AbstractCholeskyTest.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\AbstractQRTest.cs" />
+ <Compile Include="LinearAlgebra\Decomposition\DenseQRTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseCholeskyTest.cs" />
<Compile Include="LinearAlgebra\Decomposition\DenseLUTest.cs">
<SubType>Code</SubType>
|