Example #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 Color getRandomBrilliantColour(RandomAugmented random)
        {
            double r;
            double g;
            double b;

            getRandomBrilliantColour(random, out r, out g, out b);
            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 double[][] generateEmptyStartupParameters(double[] scales)
        {
            RandomAugmented ra = RandomAugmented.Instance;

            double[][] initial_points = new double[dimensions + 1][];
            for (int i = 0; i < dimensions + 1; ++i)
            {
                initial_points[i] = new double[dimensions];
                for (int j = 0; j < dimensions; ++j)
                {
                    initial_points[i][j] = ra.NextDoubleBalanced(scales[j]);
                }
            }

            return(initial_points);
        }
        public LDASamplerMCSerial(LDASampler lda_sampler, int NUM_THREADS)
        {
            this.lda_sampler = lda_sampler;
            this.NUM_THREADS = NUM_THREADS;

            // Work out the ratio of each doc for our sampling
            {
                int MAX_REPRESENTATION = 100;

                int max_doc_length = 0;
                for (int doc = 0; doc < lda_sampler.NUM_DOCS; ++doc)
                {
                    max_doc_length = Math.Max(max_doc_length, lda_sampler.WORDS_IN_DOCS[doc].Length);
                }

                total_words_in_corpus = 0;
                for (int doc = 0; doc < lda_sampler.NUM_DOCS; ++doc)
                {
                    total_words_in_corpus += lda_sampler.WORDS_IN_DOCS[doc].Length;
                }

                random_mc_orderings = new List <int>();
                for (int doc = 0; doc < lda_sampler.NUM_DOCS; ++doc)
                {
                    int doc_representation = (0 < max_doc_length) ? MAX_REPRESENTATION * lda_sampler.WORDS_IN_DOCS[doc].Length / max_doc_length : 1;
                    if (0 == doc_representation && lda_sampler.WORDS_IN_DOCS[doc].Length > 0)
                    {
                        //Logging.Info("We have had to bump up the representation for doc {0} because it is too small", doc);
                        doc_representation = 1;
                    }
                    for (int i = 0; i < doc_representation; ++i)
                    {
                        random_mc_orderings.Add(doc);
                    }
                }
            }

            random_mt = new RandomAugmented[NUM_THREADS];
            probability_working_buffer = new double[NUM_THREADS][];
            for (int thread = 0; thread < NUM_THREADS; ++thread)
            {
                random_mt[thread] = new RandomAugmented((DateTime.UtcNow.Millisecond * (1 + thread)));
                probability_working_buffer[thread] = new double[lda_sampler.NUM_TOPICS];
            }
        }
        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]));
            }
        }
Example #8
0
        Series doSampleChartSeries(int series_number)
        {
            RandomAugmented random = RandomAugmented.getSeededRandomAugmented();

            Point2D[] points = new Point2D[25];
            for (int i = 0; i < points.Length; ++i)
            {
                //				points[i] = new Point2D((i+1)/1.0, random.NextDouble());
                points[i] = new Point2D(Math.PI * i / (points.Length - 1), series_number * Math.Sin(series_number * Math.PI * i / (points.Length - 1)));
            }

            Series series = new Series("Series #" + series_number, ChartType.Line, points);

            switch (series_number % 5)
            {
            case 0:
                series.charttype = ChartType.Point;
                break;

            case 1:
                series.charttype = ChartType.Line;
                break;

            case 2:
                series.charttype = ChartType.SmoothLine;
                break;

            case 3:
                series.charttype = ChartType.LineAndPoint;
                break;

            case 4:
                series.chartaxis = ChartAxis.Secondary;
                series.charttype = ChartType.SmoothLineAndPoint;
                break;

            default:
                break;
            }

            return(series);
        }
Example #9
0
        public static int[] generateRandomOrder(int num_tuples)
        {
            int[] random_order = new int[num_tuples];
            for (int i = 0; i < num_tuples; ++i)
            {
                random_order[i] = i;
            }

            RandomAugmented random = RandomAugmented.Instance;

            for (int i = 0; i < num_tuples; ++i)
            {
                int r = random.NextInt(num_tuples - 1);
                int t = random_order[i];
                random_order[i] = random_order[r];
                random_order[r] = t;
            }

            return(random_order);
        }
Example #10
0
 public GenzMultivariate(Matrix acorrelation)
 {
     random = RandomAugmented.getSeededRandomAugmented();
     setCorrelation(acorrelation);
 }
 public GenzMultivariate(Matrix acorrelation)
 {
     random = RandomAugmented.Instance;
     setCorrelation(acorrelation);
 }