Fixed an error in CorrelatedRandomVectorGenerator leading to a component of the generated vector being constant

JIRA: MATH-226

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@696054 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-09-16 21:00:28 +00:00
parent 7684119c58
commit e1e21f2f68
3 changed files with 28 additions and 1 deletions

View File

@ -253,7 +253,7 @@ implements RandomVectorGenerator {
// build the root matrix
root = new RealMatrixImpl(order, rank);
for (int i = 0; i < order; ++i) {
System.arraycopy(b[i], 0, root.getDataRef()[swap[i]], 0, rank);
System.arraycopy(b[i], 0, root.getDataRef()[index[i]], 0, rank);
}
}

View File

@ -39,6 +39,10 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="MATH-226" due-to="Stuart Siegel">
Fixed an error in CorrelatedRandomVectorGenerator leading to a component of
the generated vector being constant.
</action>
<action dev="luc" type="fix" issue="MATH-223" due-to="John Mulcahy">
Greatly improved QR-decomposition speed using transposed matrices internally.
</action>

View File

@ -39,6 +39,29 @@ extends TestCase {
assertEquals(3, generator.getRank());
}
public void testMath226()
throws DimensionMismatchException, NotPositiveDefiniteMatrixException {
double[] mean = { 1, 1, 10, 1 };
double[][] cov = {
{ 1, 3, 2, 6 },
{ 3, 13, 16, 2 },
{ 2, 16, 38, -1 },
{ 6, 2, -1, 197 }
};
RealMatrix covRM = new RealMatrixImpl(cov, false);
JDKRandomGenerator jg = new JDKRandomGenerator();
jg.setSeed(5322145245211l);
NormalizedRandomGenerator rg = new GaussianRandomGenerator(jg);
CorrelatedRandomVectorGenerator sg =
new CorrelatedRandomVectorGenerator(mean, covRM, 0.00001, rg);
for (int i = 0; i < 10; i++) {
double[] generated = sg.nextVector();
assertTrue(Math.abs(generated[0] - 1) > 0.1);
}
}
public void testRootMatrix() {
RealMatrix b = generator.getRootMatrix();
RealMatrix bbt = b.multiply(b.transpose());