Exemplo n.º 1
0
        public static void TestHarness_LOOP()
        {
            RandomAugmented random = RandomAugmented.getSeededRandomAugmented();

            ArrayList pool1 = new ArrayList();
            ArrayList pool2 = new ArrayList();

            for (int i = 0; i < 10; ++i)
            {
                pool1.Add(new Point2D(random.NextDouble(), random.NextDouble()));
                pool2.Add(new Point2D(random.NextDouble(), random.NextDouble()));
            }
            double m, c;

            findHull(pool1, pool2, out m, out c);
            ArrayList hull = new ArrayList();

            hull.Add(new Point2D(0, c)); hull.Add(new Point2D(1, m + c));

            GenericChartForm charts = new GenericChartForm();

            charts.setChartCounts(1, 1);
            charts[0].addSeries(new Series("Pool1", ChartType.Point, pool1));
            charts[0].addSeries(new Series("Pool2", ChartType.Point, pool2));
            charts[0].addSeries(new Series("Hull", ChartType.Line, hull));
            charts[0].Refresh();
            charts.ShowDialog();
        }
        public static Color getRandomColour(RandomAugmented random)
        {
            double r = random.NextDouble();
            double g = random.NextDouble();
            double b = random.NextDouble();

            return(Color.FromArgb((int)(255 * r), (int)(255 * g), (int)(255 * b)));
        }
 public static void getRandomBrilliantColour(RandomAugmented random, out double r, out double g, out double b)
 {
     r = g = b = 0.5;
     while
     (
         (isValueNearBottom(r) && isValueNearBottom(g) && isValueNearBottom(b)) ||
         (isValueNearMiddle(r) && isValueNearMiddle(g)) || (isValueNearMiddle(r) && isValueNearMiddle(b)) || (isValueNearMiddle(g) && isValueNearMiddle(b))
     )
     {
         r = random.NextDouble();
         g = random.NextDouble();
         b = random.NextDouble();
     }
 }
        public static void TestHarness()
        {
            RandomAugmented ra = RandomAugmented.getSeededRandomAugmented();

            int N = 4;

            // Create a matrix
            Matrix m = new Matrix(N, N);

            for (int i = 0; i < N; ++i)
            {
                for (int j = i; j < N; ++j)
                {
                    m[i, j] = ra.NextDouble(10);
                    m[j, i] = m[i, j];
                }
            }

            // Space for results
            Matrix eigenvectors = new Matrix(N, N);
            Vector eigenvalues  = new Vector(N);

            // Get values
            calculateEigensystem(m, eigenvectors, eigenvalues);
            sortEigensystem(eigenvectors, eigenvalues);

            Console.WriteLine("Eigenvalues");
            Console.WriteLine(eigenvalues);
            Console.WriteLine("Eigenvectors");
            Console.WriteLine(eigenvectors);

            // Test each eigenpair
            Vector eigenvector = new Vector(N);

            for (int i = 0; i < N; ++i)
            {
                eigenvectors.getColumn(i, eigenvector);

                Console.WriteLine("Eigenpair {0}", i);
                Console.WriteLine(m.multiply(eigenvector));
                Console.WriteLine(eigenvector.multiply(eigenvalues[i]));
            }
        }
Exemplo n.º 5
0
        public double getProb(Vector a, Vector b, double alpha, double epsilon, int N_max)
        {
            // A neat reference to match the document
            int    m = correlation.rows;
            Matrix c = correlation_root;

            // Check that we are not in univariate land....
            if (1 == m)
            {
                return(Distributions.CDistStandardNormal(b[0]) - Distributions.CDistStandardNormal(a[0]));
            }

            // Our variables
            double[] d = new double[m];
            double[] e = new double[m];
            double[] f = new double[m];

            double[] y = new double[m];
            double[] w = new double[m];

            // Initialisation code
            double intsum = 0.0;
            int    N      = 0;
            double varsum = 0.0;

            d[0] = Distributions.CDistStandardNormal(a[0] / c[0, 0]);
            e[0] = Distributions.CDistStandardNormal(b[0] / c[0, 0]);
            f[0] = e[0] - d[0];

            double error = 0.0;

            do
            {
                for (int i = 0; i < m - 1; ++i)
                {
                    w[i] = random.NextDouble();
                }

                for (int i = 1; i < m; ++i)
                {
                    y[i - 1] = Distributions.InvDist_SN(d[i - 1] + w[i - 1] * (e[i - 1] - d[i - 1]));

                    double sum_cij_yj = 0.0;
                    for (int j = 0; j <= i - 1; ++j)
                    {
                        sum_cij_yj += c[i, j] * y[j];
                    }
                    d[i] = Distributions.CDistStandardNormal((a[i] - sum_cij_yj) / c[i, i]);
                    e[i] = Distributions.CDistStandardNormal((b[i] - sum_cij_yj) / c[i, i]);
                    f[i] = (e[i] - d[i]) * f[i - 1];

                    ++N;
                    double delta = (f[m - 1] - intsum) / N;
                    intsum += delta;
                    varsum  = (N - 2) * varsum / N + delta * delta;
                    error   = alpha * Math.Sqrt(varsum);
                }
            } while (error > epsilon && N < N_max);

            if (N >= N_max)
            {
                //System.Console.WriteLine("Exceeded");
                //throw new GenericException("Reached maximum number of iterations");
            }

            return(intsum);
        }