[ 
https://issues.apache.org/jira/browse/MATH-226?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12631578#action_12631578
 ] 

Stuart Siegel commented on MATH-226:
------------------------------------

Thanks for the very speedy reply and thanks for commons-math, it has proven to 
be very helpful.

> CorrelatedRandomVectorGenerator generates invariant samples
> -----------------------------------------------------------
>
>                 Key: MATH-226
>                 URL: https://issues.apache.org/jira/browse/MATH-226
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 1.2
>         Environment: WIN32
>            Reporter: Stuart Siegel
>
> For the following code sample, the output is:
> 1.0,3.9432161557722925,16.66859790068678,1.0743673824292688,
> 1.0,-1.4103098147521094,-2.670854139636077,1.8368602953644368,
> 1.0,0.230029048125738,12.67864233710285,0.1124537698401884,
> Why is the first column of each row fixed at 1.0?
> Here is the code that generated this:
> import org.apache.commons.math.linear.RealMatrix;
> import org.apache.commons.math.linear.RealMatrixImpl;
> import org.apache.commons.math.random.CorrelatedRandomVectorGenerator;
> import org.apache.commons.math.random.GaussianRandomGenerator;
> import org.apache.commons.math.random.JDKRandomGenerator;
> public class TestMath {
>       public static void sampler(double[] mean, double[][] cov, double[][] s) 
> {
>               RealMatrix covRM = new RealMatrixImpl(cov);
>               try {
>                       CorrelatedRandomVectorGenerator sg = new 
> CorrelatedRandomVectorGenerator(
>                                       mean, covRM, 0.00001, new 
> GaussianRandomGenerator(
>                                                       new 
> JDKRandomGenerator()));
>                       for (int i = 0; i < s.length; i++) {
>                               s[i] = sg.nextVector();
>                       }
>               } catch (Exception e) {
>                       e.printStackTrace();
>                       System.exit(-1);
>               }
>       }
>       static void print(double[][] s) {
>               for (int r = 0; r < s.length; r++) {
>                       for (int c = 0; c < s[r].length; c++)
>                               System.out.print(s[r][c] + ",");
>                       System.out.println();
>               }
>       }
>       public static void main(String[] args) {
>               double[] mean = { 1, 1, 10, 1 };
>               double[][] cov = { { 1, 3, 2, 6 }, { 3, 13, 16, 2 }, { 2, 16, 
> 38, -1 },
>                               { 6, 2, -1, 197 } };
>               
>               double[][] s = new double[3][4];
>               TestMath.sampler(mean, cov, s);
>               TestMath.print(s);
>               
>       }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to