Ejemplo n.º 1
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
			ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            Random2 rand = new Random2();
            double std = param.GetParam<double>("Standard deviation").Value;
            int[] inds = param.GetParam<int[]>("Columns").Value;
            List<int> mainInds = new List<int>();
            List<int> numInds = new List<int>();
            foreach (int ind in inds){
                if (ind < mdata.ColumnCount){
                    mainInds.Add(ind);
                } else{
                    numInds.Add(ind - mdata.ColumnCount);
                }
            }
            foreach (int j in mainInds){
                for (int i = 0; i < mdata.RowCount; i++){
                    mdata.Values.Set(i, j, mdata.Values.Get(i, j) + (float) rand.NextGaussian(0, std));
                }
            }
            foreach (int j in numInds){
                for (int i = 0; i < mdata.RowCount; i++){
                    mdata.NumericColumns[j][i] += (float) rand.NextGaussian(0, std);
                }
            }
        }
Ejemplo n.º 2
0
        private static bool ReplaceMissingsByGaussianForOneColumn(double width, double shift, IMatrixData data, int colInd,
                                                                  Random2 r)
        {
            List <float> allValues = new List <float>();

            for (int i = 0; i < data.RowCount; i++)
            {
                float x = data.Values[i, colInd];
                if (!float.IsNaN(x) && !float.IsInfinity(x))
                {
                    allValues.Add(x);
                }
            }
            double stddev;
            double mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out stddev);

            if (double.IsNaN(mean) || double.IsInfinity(mean) || double.IsNaN(stddev) || double.IsInfinity(stddev))
            {
                return(false);
            }
            double m = mean - shift * stddev;
            double s = stddev * width;

            for (int i = 0; i < data.RowCount; i++)
            {
                if (float.IsNaN(data.Values[i, colInd]) || float.IsInfinity(data.Values[i, colInd]))
                {
                    data.Values[i, colInd]    = (float)r.NextGaussian(m, s);
                    data.IsImputed[i, colInd] = true;
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
 private static void BalancedPermutations(int[] inds1, int[] inds2, out int[] inds1Out, out int[] inds2Out,
                                          Random2 r2)
 {
     PermBasedFdrUtil.BalancedPermutations(new[] { inds1, inds2 }, out int[][] out1, r2);
     inds1Out = out1[0];
     inds2Out = out1[1];
 }
 public static string ReplaceMissingsByGaussianWholeMatrix(double width, double shift, IMatrixData data, int[] colInds)
 {
     List<float> allValues = new List<float>();
     for (int i = 0; i < data.RowCount; i++){
         foreach (int t in colInds){
             float x = GetValue(data, i, t);
             if (!float.IsNaN(x) && !float.IsInfinity(x)){
                 allValues.Add(x);
             }
         }
     }
     double stddev;
     double mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out stddev);
     if (double.IsNaN(mean) || double.IsInfinity(mean) || double.IsNaN(stddev) || double.IsInfinity(stddev)){
         return "Imputation failed since mean and standard deviation could not be calculated.";
     }
     double m = mean - shift*stddev;
     double s = stddev*width;
     Random2 r = new Random2();
     for (int i = 0; i < data.RowCount; i++){
         foreach (int colInd in colInds){
             float x = GetValue(data, i, colInd);
             if (float.IsNaN(x) || float.IsInfinity(x)){
                 if (colInd < data.ColumnCount){
                     data.Values.Set(i, colInd, (float) r.NextGaussian(m, s));
                     data.IsImputed[i, colInd] = true;
                 } else{
                     data.NumericColumns[colInd - data.ColumnCount][i] = r.NextGaussian(m, s);
                 }
             }
         }
     }
     return null;
 }
Ejemplo n.º 5
0
        public static void ReplaceMissingsByGaussianWholeMatrix(double width, double shift, IMatrixData data, int[] colInds)
        {
            List <float> allValues = new List <float>();

            for (int i = 0; i < data.RowCount; i++)
            {
                foreach (int t in colInds)
                {
                    float x = data.Values[i, t];
                    if (!float.IsNaN(x) && !float.IsInfinity(x))
                    {
                        allValues.Add(x);
                    }
                }
            }
            double  stddev;
            double  mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out stddev);
            double  m    = mean - shift * stddev;
            double  s    = stddev * width;
            Random2 r    = new Random2();

            for (int i = 0; i < data.RowCount; i++)
            {
                foreach (int t in colInds)
                {
                    if (float.IsNaN(data.Values[i, t]) || float.IsInfinity(data.Values[i, t]))
                    {
                        data.Values[i, t]    = (float)r.NextGaussian(m, s);
                        data.IsImputed[i, t] = true;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// функција која се грижи за поставување на непријателите зависно од тоа за кој левел се работи.
        /// </summary>
        public void placeEvilMinionsGM()
        {
            int LR = Random.Next(2); // 0 за да дојде од лево и 1 за да дојде од десно на играчот.

            switch (GM)
            {
            case GameMode.Easy: {
                int RandomXX = Random2.Next(PositionRIGHT, PositionRIGHT + 200);
                PositionRIGHT += 300;
                FromRight      = true;
                FromLeft       = false;
                X              = RandomXX;
            }
            break;

            case GameMode.Medium: {
                if (LR == 0)
                {
                    int RandomX = Random2.Next(Math.Abs(PositionLEFT), Math.Abs(PositionLEFT - 500));
                    RandomX   = -RandomX;
                    FromLeft  = true;
                    FromRight = false;
                    X         = RandomX;
                }
                else if (LR == 1)
                {
                    int RandomXX = Random2.Next(PositionRIGHT, PositionRIGHT + 200);
                    PositionRIGHT += 300;
                    FromRight      = true;
                    FromLeft       = false;
                    X              = RandomXX;
                }
            }
            break;

            case GameMode.Hard: {
                if (LR == 0)
                {
                    int RandomX = Random2.Next(Math.Abs(PositionLEFT), Math.Abs(PositionLEFT - 500));
                    RandomX   = -RandomX;
                    FromLeft  = true;
                    FromRight = false;
                    X         = RandomX;
                }
                else if (LR == 1)
                {
                    int RandomXX = Random2.Next(PositionRIGHT, PositionRIGHT + 200);
                    PositionRIGHT += 300;
                    FromRight      = true;
                    FromLeft       = false;
                    X              = RandomXX;
                }
            }
            break;

            default:
                break;
            }
        }
Ejemplo n.º 7
0
 private static void BalancedPermutationsSubgroups(List <int[]> preserve1, List <int[]> preserve2, out int[] inds1Out,
                                                   out int[] inds2Out, Random2 r2)
 {
     PermBasedFdrUtil.BalancedPermutationsSubgroups(new[] { preserve1.ToArray(), preserve2.ToArray() }, out int[][] out1,
                                                    r2);
     inds1Out = out1[0];
     inds2Out = out1[1];
 }
Ejemplo n.º 8
0
        private void RandomDownloadFolder_Click(object sender, RoutedEventArgs e)
        {
            Config  cfg    = new Config();
            JObject config = cfg.Load();

            config[download_folder] = Random2.RandomString(int.Parse(new InputBox("랜덤 길이 지정", "설정", "").ShowDialog()));
            cfg.Save(config);
            FolderName.Content = config.StringValue(download_folder);
        }
Ejemplo n.º 9
0
 public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
     ref IDocumentData[] documents, ProcessInfo processInfo)
 {
     int nrows = param.GetParam<int>("Number of rows").Value;
     nrows = Math.Min(nrows, mdata.RowCount);
     Random2 rand = new Random2(7);
     int[] rows = ArrayUtils.SubArray(rand.NextPermutation(mdata.RowCount), nrows);
     PerseusPluginUtils.FilterRows(mdata, param, rows);
 }
Ejemplo n.º 10
0
        static string Get(string key)
        {
            var value = Preferences2.Get(key, null);

            if (string.IsNullOrWhiteSpace(value))
            {
                value = Random2.GenerateRandomString(DeviceIdRLength, _Constants.DigitsLetters);
                Preferences2.Set(key, value);
            }
            return(value);
        }
        private static void RandomizeConstantRegion(int[] o, int startInd, int endInd)
        {
            int     len = endInd - startInd;
            Random2 r   = new Random2(7);

            int[] p        = r.NextPermutation(len);
            int[] permuted = new int[len];
            for (int i = 0; i < len; i++)
            {
                permuted[i] = o[startInd + p[i]];
            }
            Array.Copy(permuted, 0, o, startInd, len);
        }
Ejemplo n.º 12
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            int nrows = param.GetParam <int>("Number of rows").Value;

            if (nrows >= mdata.RowCount)
            {
                return;
            }
            Random2 rand = new Random2(7);

            int[] inds = rand.NextPermutation(mdata.RowCount).SubArray(nrows);
            mdata.ExtractRows(inds);
        }
 public static void ReplaceMissingsByGaussianByColumn(double width, double shift, IMatrixData data, int[] colInds)
 {
     List<int> invalidMain = new List<int>();
     Random2 r = new Random2();
     foreach (int colInd in colInds){
         bool success = ReplaceMissingsByGaussianForOneColumn(width, shift, data, colInd, r);
         if (!success){
             if (colInd < data.ColumnCount){
                 invalidMain.Add(colInd);
             }
         }
     }
     if (invalidMain.Count > 0){
         data.ExtractColumns(ArrayUtils.Complement(invalidMain, data.ColumnCount));
     }
 }
        public static string ReplaceMissingsByGaussianWholeMatrix(double width, double shift, IMatrixData data, int[] colInds)
        {
            List <float> allValues = new List <float>();

            for (int i = 0; i < data.RowCount; i++)
            {
                foreach (int t in colInds)
                {
                    float x = GetValue(data, i, t);
                    if (!float.IsNaN(x) && !float.IsInfinity(x))
                    {
                        allValues.Add(x);
                    }
                }
            }
            double stddev;
            double mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out stddev);

            if (double.IsNaN(mean) || double.IsInfinity(mean) || double.IsNaN(stddev) || double.IsInfinity(stddev))
            {
                return("Imputation failed since mean and standard deviation could not be calculated.");
            }
            double  m = mean - shift * stddev;
            double  s = stddev * width;
            Random2 r = new Random2(7);

            for (int i = 0; i < data.RowCount; i++)
            {
                foreach (int colInd in colInds)
                {
                    float x = GetValue(data, i, colInd);
                    if (float.IsNaN(x) || float.IsInfinity(x))
                    {
                        if (colInd < data.ColumnCount)
                        {
                            data.Values.Set(i, colInd, (float)r.NextGaussian(m, s));
                            data.IsImputed[i, colInd] = true;
                        }
                        else
                        {
                            data.NumericColumns[colInd - data.ColumnCount][i] = r.NextGaussian(m, s);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 15
0
        public static void ReplaceMissingsByGaussianByColumn(double width, double shift, IMatrixData data, int[] colInds)
        {
            List <int> valid = new List <int>();
            Random2    r     = new Random2();

            foreach (int colInd in colInds)
            {
                bool success = ReplaceMissingsByGaussianForOneColumn(width, shift, data, colInd, r);
                if (success)
                {
                    valid.Add(colInd);
                }
            }
            if (valid.Count != data.ColumnCount)
            {
                data.ExtractColumns(valid.ToArray());
            }
        }
        public static void ReplaceMissingsByGaussianByColumn(double width, double shift, IMatrixData data, int[] colInds)
        {
            List <int> invalidMain = new List <int>();
            Random2    r           = new Random2(7);

            foreach (int colInd in colInds)
            {
                bool success = ReplaceMissingsByGaussianForOneColumn(width, shift, data, colInd, r);
                if (!success)
                {
                    if (colInd < data.ColumnCount)
                    {
                        invalidMain.Add(colInd);
                    }
                }
            }
            if (invalidMain.Count > 0)
            {
                data.ExtractColumns(ArrayUtils.Complement(invalidMain, data.ColumnCount));
            }
        }
        private static bool ReplaceMissingsByGaussianForOneColumn(double width, double shift, IMatrixData data, int colInd,
                                                                  Random2 r)
        {
            List <double> allValues = new List <double>();

            for (int i = 0; i < data.RowCount; i++)
            {
                double x = GetValue(data, i, colInd);
                if (!double.IsNaN(x) && !double.IsInfinity(x))
                {
                    allValues.Add(x);
                }
            }
            double mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out double stddev);

            if (double.IsNaN(mean) || double.IsInfinity(mean) || double.IsNaN(stddev) || double.IsInfinity(stddev))
            {
                return(false);
            }
            double m = mean - shift * stddev;
            double s = stddev * width;

            for (int i = 0; i < data.RowCount; i++)
            {
                double x = GetValue(data, i, colInd);
                if (double.IsNaN(x) || double.IsInfinity(x))
                {
                    if (colInd < data.ColumnCount)
                    {
                        data.Values.Set(i, colInd, r.NextGaussian(m, s));
                        data.IsImputed[i, colInd] = true;
                    }
                    else
                    {
                        data.NumericColumns[colInd - data.ColumnCount][i] = r.NextGaussian(m, s);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 18
0
        /// Detects pyramid or hole (if any) at the given coordinates in the <see cref="grid" />, and randomly switches
        /// between pyramid and hole, based on <see cref="probabilityP" /> and <see cref="probabilityQ" /> parameters
        /// (or switches anyway, if forceSwitch is on).
        /// </summary>
        public void RandomlySwitchFourCells(bool forceSwitch)
        {
            uint randomNumber1   = Random1.NextUInt32();
            var  centerX         = (int)(randomNumber1 & (GridWidth - 1));
            var  centerY         = (int)((randomNumber1 >> 16) & (GridHeight - 1));
            int  centerIndex     = GetIndexFromXY(centerX, centerY);
            uint randomNumber2   = Random2.NextUInt32();
            uint randomVariable1 = randomNumber2 & ((1 << 16) - 1);
            uint randomVariable2 = (randomNumber2 >> 16) & ((1 << 16) - 1);
            int  rightNeighbourIndex;
            int  bottomNeighbourIndex;
            // Get neighbor indexes:
            int rightNeighbourX  = (centerX < GridWidth - 1) ? centerX + 1 : 0;
            int rightNeighbourY  = centerY;
            int bottomNeighbourX = centerX;
            int bottomNeighbourY = (centerY < GridHeight - 1) ? centerY + 1 : 0;

            rightNeighbourIndex  = rightNeighbourY * GridWidth + rightNeighbourX;
            bottomNeighbourIndex = bottomNeighbourY * GridWidth + bottomNeighbourX;
            // We check our own {dx,dy} values, and the right neighbor's dx, and bottom neighbor's dx.
            if (
                // If we get the pattern {01, 01} we have a pyramid:
                ((GetGridDx(centerIndex) && !GetGridDx(rightNeighbourIndex)) &&
                 (GetGridDy(centerIndex) && !GetGridDy(bottomNeighbourIndex)) &&
                 (forceSwitch || randomVariable1 < IntegerProbabilityP)) ||
                // If we get the pattern {10, 10} we have a hole:
                ((!GetGridDx(centerIndex) && GetGridDx(rightNeighbourIndex)) &&
                 (!GetGridDy(centerIndex) && GetGridDy(bottomNeighbourIndex)) &&
                 (forceSwitch || randomVariable2 < IntegerProbabilityQ))
                )
            {
                // We make a hole into a pyramid, and a pyramid into a hole.
                SetGridDx(centerIndex, !GetGridDx(centerIndex));
                SetGridDy(centerIndex, !GetGridDy(centerIndex));
                SetGridDx(rightNeighbourIndex, !GetGridDx(rightNeighbourIndex));
                SetGridDy(bottomNeighbourIndex, !GetGridDy(bottomNeighbourIndex));
            }
        }
Ejemplo n.º 19
0
        public CurrentUser?GetCurrentUser()
        {
            var hasCurrentUser = currentUser != null;

#if DEBUG
            var read_cache = Random2.Next(100) % 2 == 0;
            hasCurrentUser = read_cache && hasCurrentUser;
#endif
            CurrentUser?result;
            if (hasCurrentUser)
            {
                result = currentUser?.Clone();
            }
            else
            {
                Func <ValueTask <CurrentUser?> > func = GetCurrentUserAsync;
                result = func.RunSync();
            }
#if DEBUG
            logger.LogDebug("read_cache: {0}, PhoneNumber: {1}", read_cache, result?.ToStringHideMiddleFour());
#endif
            return(result);
        }
Ejemplo n.º 20
0
        public void ProcessData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables,
                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            Random2 rand = new Random2(7);
            double  std  = param.GetParam <double>("Standard deviation").Value;

            int[]      inds     = param.GetParam <int[]>("Columns").Value;
            List <int> mainInds = new List <int>();
            List <int> numInds  = new List <int>();

            foreach (int ind in inds)
            {
                if (ind < mdata.ColumnCount)
                {
                    mainInds.Add(ind);
                }
                else
                {
                    numInds.Add(ind - mdata.ColumnCount);
                }
            }
            foreach (int j in mainInds)
            {
                for (int i = 0; i < mdata.RowCount; i++)
                {
                    mdata.Values.Set(i, j, mdata.Values.Get(i, j) + rand.NextGaussian(0, std));
                }
            }
            foreach (int j in numInds)
            {
                for (int i = 0; i < mdata.RowCount; i++)
                {
                    mdata.NumericColumns[j][i] += rand.NextGaussian(0, std);
                }
            }
        }
Ejemplo n.º 21
0
    public static void Main()
    {
        Random2 rnd = new Random2();

        Byte[] bytes = new Byte[10000];
        int[]  total = new int[101];
        rnd.NextBytes(bytes, 0, 101);

        // Calculate how many of each value we have.
        foreach (var value in bytes)
        {
            total[value]++;
        }

        // Display the results.
        for (int ctr = 0; ctr < total.Length; ctr++)
        {
            Console.Write("{0,3}: {1,-3}   ", ctr, total[ctr]);
            if ((ctr + 1) % 5 == 0)
            {
                Console.WriteLine();
            }
        }
    }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates permutations of group memberships of data points.
        /// </summary>
        /// <param name="inds">Original group memberships. Length = number of groups. Each sub-array contains indices
        /// of original group members.</param>
        /// <param name="indsOut">Scrambled groups</param>
        /// <param name="r2">Random number generator used for creating the permutations</param>
        public static void BalancedPermutations(int[][] inds, out int[][] indsOut, Random2 r2)
        {
            //Permute indices within groups
            int[][] inds1 = new int[inds.Length][];
            for (int i = 0; i < inds.Length; i++)
            {
                inds1[i] = ArrayUtils.SubArray(inds[i], r2.NextPermutation(inds[i].Length));
            }
            //Permute order of groups
            inds1 = ArrayUtils.SubArray(inds1, r2.NextPermutation(inds1.Length));
            List <int>[] newInds = new List <int> [inds1.Length];
            for (int i = 0; i < inds1.Length; i++)
            {
                newInds[i] = new List <int>();
            }
            int index = 0;

            foreach (int[] ig in inds1)
            {
                foreach (int ind in ig)
                {
                    //It has to be inds[index] here since otherwise for sided two-sample tests the group size will be swapped
                    while (newInds[index].Count >= inds[index].Length)
                    {
                        index = (index + 1) % inds1.Length;
                    }
                    newInds[index].Add(ind);
                    index = (index + 1) % inds1.Length;
                }
            }
            indsOut = new int[inds1.Length][];
            for (int i = 0; i < inds1.Length; i++)
            {
                indsOut[i] = newInds[i].ToArray();
            }
        }
Ejemplo n.º 23
0
 private static void RandomizeConstantRegion(int[] o, int startInd, int endInd)
 {
     int len = endInd - startInd;
     Random2 r = new Random2();
     int[] p = r.NextPermutation(len);
     int[] permuted = new int[len];
     for (int i = 0; i < len; i++){
         permuted[i] = o[startInd + p[i]];
     }
     Array.Copy(permuted, 0, o, startInd, len);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 当前是否装有 Xposed 框架
        /// </summary>
        /// <returns></returns>
        public static bool IsXposedExists()
        {
            var classLoader = Java.Lang.ClassLoader.SystemClassLoader;

            if (classLoader == null)
            {
                throw new NullReferenceException("Java.Lang.ClassLoader.SystemClassLoader is null.");
            }

            try
            {
                var xpHelperObj = classLoader.LoadClass(XPOSED_HELPERS)?.NewInstance();
            }
            catch (Java.Lang.InstantiationException e)
            {
                e.PrintStackTraceWhenDebug();
                return(true);
            }
            catch (Java.Lang.IllegalAccessException e)
            {
                e.PrintStackTraceWhenDebug();
                return(true);
            }
            catch (Java.Lang.ClassNotFoundException e)
            {
                e.PrintStackTraceWhenDebug();
            }

            try
            {
                var xpBridgeObj = classLoader.LoadClass(XPOSED_BRIDGE)?.NewInstance();
            }
            catch (Java.Lang.InstantiationException e)
            {
                e.PrintStackTraceWhenDebug();
                return(true);
            }
            catch (Java.Lang.IllegalAccessException e)
            {
                e.PrintStackTraceWhenDebug();
                return(true);
            }
            catch (Java.Lang.ClassNotFoundException e)
            {
                e.PrintStackTraceWhenDebug();
            }

            try
            {
                throw new Java.Lang.Exception(Random2.GenerateRandomString(Random2.Next(5, 10)));
                // 通过主动抛出异常,检查堆栈信息来判断是否存在XP框架。
            }
            catch (Java.Lang.Exception e)
            {
                var hasFind = e.GetStackTrace()
                              .Any(x => x.ClassName != null &&
                                   x.ClassName.Contains(XPOSED_BRIDGE, StringComparison.OrdinalIgnoreCase));
                if (hasFind)
                {
                    return(true);
                }
            }

            return(false);
        }
        private static bool ReplaceMissingsByGaussianForOneColumn(double width, double shift, IMatrixData data, int colInd,
			Random2 r)
        {
            List<float> allValues = new List<float>();
            for (int i = 0; i < data.RowCount; i++){
                float x = GetValue(data, i, colInd);
                if (!float.IsNaN(x) && !float.IsInfinity(x)){
                    allValues.Add(x);
                }
            }
            double stddev;
            double mean = ArrayUtils.MeanAndStddev(allValues.ToArray(), out stddev);
            if (double.IsNaN(mean) || double.IsInfinity(mean) || double.IsNaN(stddev) || double.IsInfinity(stddev)){
                return false;
            }
            double m = mean - shift*stddev;
            double s = stddev*width;
            for (int i = 0; i < data.RowCount; i++){
                float x = GetValue(data, i, colInd);
                if (float.IsNaN(x) || float.IsInfinity(x)){
                    if (colInd < data.ColumnCount){
                        data.Values.Set(i, colInd, (float) r.NextGaussian(m, s));
                        data.IsImputed[i, colInd] = true;
                    } else{
                        data.NumericColumns[colInd - data.ColumnCount][i] = r.NextGaussian(m, s);
                    }
                }
            }
            return true;
        }
Ejemplo n.º 26
0
        public void StartTestChangeST()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = grid.ActualWidth;
            var height = grid.ActualHeight;

            const int step   = 20;
            var       labels = new TextBlock[step * 2];

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            var texts = new string[] { "dOpe", "Dope", "doPe", "dopE" };

            Action loop = null;

            loop = () =>
            {
                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }

                var now = sw.ElapsedMilliseconds;

                //60hz, 16ms to build the frame
                while (sw.ElapsedMilliseconds - now < 16)
                {
                    if (processed > max)
                    {
                        (absolute.Children[processed % max] as TextBlock).Text = texts[(int)Math.Floor(rand.NextDouble() * 4)];
                    }
                    else
                    {
                        var label = new TextBlock()
                        {
                            Text       = "Dope",
                            Foreground = new SolidColorBrush(Color.FromArgb(0xFF, (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255)))
                        };

                        label.RenderTransform = new RotateTransform()
                        {
                            Angle = rand.NextDouble() * 360
                        };

                        Canvas.SetLeft(label, rand.NextDouble() * width);
                        Canvas.SetTop(label, rand.NextDouble() * height);

                        absolute.Children.Add(label);
                    }

                    processed++;

                    if (sw.ElapsedMilliseconds - prevMs > 500)
                    {
                        var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                        prevTicks     = sw.ElapsedTicks;
                        prevProcessed = processed;

                        if (processed > max)
                        {
                            dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                            avgSum    += r;
                            avgN++;
                        }

                        prevMs = sw.ElapsedMilliseconds;
                    }
                }

                _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop());
            };

            sw.Start();

            _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop());
        }
Ejemplo n.º 27
0
        void StartTestReuseST()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = absolute.ActualWidth;
            var height = absolute.ActualHeight;

            const int step   = 20;
            var       labels = new TextBlock[step * 2];

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            Action loop = null;

            Stack <TextBlock> _cache = new Stack <TextBlock>();

            loop = () =>
            {
                var now = sw.ElapsedMilliseconds;

                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }

                //60hz, 16ms to build the frame
                while (sw.ElapsedMilliseconds - now < 16)
                {
                    var label = _cache.Count == 0 ? new TextBlock()
                    {
                        Foreground = new SolidColorBrush()
                    } : _cache.Pop();

                    label.Text = "Dope";
                    (label.Foreground as SolidColorBrush).Color = Color.FromArgb(0xFF, (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255));

                    label.RenderTransform = new RotateTransform()
                    {
                        Angle = rand.NextDouble() * 360
                    };

                    Canvas.SetLeft(label, rand.NextDouble() * width);
                    Canvas.SetTop(label, rand.NextDouble() * height);

                    if (processed > max)
                    {
                        _cache.Push(absolute.Children[0] as TextBlock);
                        absolute.Children.RemoveAt(0);
                    }

                    absolute.Children.Add(label);

                    processed++;

                    if (sw.ElapsedMilliseconds - prevMs > 500)
                    {
                        var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                        prevTicks     = sw.ElapsedTicks;
                        prevProcessed = processed;

                        if (processed > max)
                        {
                            dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                            avgSum    += r;
                            avgN++;
                        }

                        prevMs = sw.ElapsedMilliseconds;
                    }
                }

                _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop());
            };

            sw.Start();

            _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => loop());
        }
Ejemplo n.º 28
0
        //void StartTestGridST()
        //{
        //    var rand = new Random2(0);

        //    breakTest = false;

        //    var width = grid.Width;
        //    var height = grid.Height;

        //    const int step = 20;
        //    var labels = new Label[step * 2];

        //    var processed = 0;

        //    long prevTicks = 0;
        //    long prevMs = 0;
        //    int prevProcessed = 0;
        //    double avgSum = 0;
        //    int avgN = 0;
        //    var sw = new Stopwatch();

        //    Action loop = null;

        //    loop = () =>
        //    {
        //        if (breakTest)
        //        {
        //            var avg = avgSum / avgN;
        //            dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
        //            return;
        //        }

        //        var now = sw.ElapsedMilliseconds;

        //        //60hz, 16ms to build the frame
        //        while (sw.ElapsedMilliseconds - now < 16)
        //        {
        //            var label = new Label()
        //            {
        //                Text = "Dope",
        //                TextColor = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()),
        //                Rotation = rand.NextDouble() * 360,
        //                TranslationX = rand.NextDouble() * width,
        //                TranslationY = rand.NextDouble() * height
        //            };


        //            if (processed > max)
        //            {
        //                grid.Children.RemoveAt(0);
        //            }

        //            grid.Children.Add(label);

        //            processed++;

        //            if (sw.ElapsedMilliseconds - prevMs > 500)
        //            {

        //                var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
        //                prevTicks = sw.ElapsedTicks;
        //                prevProcessed = processed;

        //                if (processed > max)
        //                {
        //                    dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
        //                    avgSum += r;
        //                    avgN++;
        //                }

        //                prevMs = sw.ElapsedMilliseconds;
        //            }
        //        }

        //        Device.BeginInvokeOnMainThread(loop);
        //    };

        //    sw.Start();

        //    Device.BeginInvokeOnMainThread(loop);
        //}

        void StartTestBindings()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = absolute.ActualWidth;
            var height = absolute.ActualHeight;

            const int step   = 20;
            var       labels = new TextBlock[step * 2];

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            var source = Enumerable.Range(0, max).Select(i => new BindingItem()
            {
                Color = Colors.Red
            }).ToArray();

            items.ItemsSource = source;

            Action loop    = null;
            var    current = 0;

            loop = () =>
            {
                var now = sw.ElapsedMilliseconds;

                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }

                //60hz, 16ms to build the frame
                while (sw.ElapsedMilliseconds - now < 16)
                {
                    var index = current++ % source.Length;

                    source[index].Color    = Color.FromArgb(0xFF, (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255), (byte)(rand.NextDouble() * 255));
                    source[index].Rotation = rand.NextDouble() * 360;
                    source[index].Top      = rand.NextDouble() * height;
                    source[index].Left     = rand.NextDouble() * width;

                    processed++;

                    if (sw.ElapsedMilliseconds - prevMs > 500)
                    {
                        var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                        prevTicks     = sw.ElapsedTicks;
                        prevProcessed = processed;

                        if (processed > max)
                        {
                            dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                            avgSum    += r;
                            avgN++;
                        }

                        prevMs = sw.ElapsedMilliseconds;
                    }
                }

                _ = Dispatcher.RunIdleAsync(_ => loop());
            };

            sw.Start();

            _ = Dispatcher.RunIdleAsync(_ => loop());
        }
Ejemplo n.º 29
0
        void StartTestMT2()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = absolute.Width;
            var height = absolute.Height;

            const int step = 75;

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            var bankA = new Label[step];
            var bankB = new Label[step];

            Action <Label[]> addLabels = (Label[] labels) =>
            {
                for (int k = 0; k < step; k++)
                {
                    var label = new Label()
                    {
                        Text      = "Dope",
                        TextColor = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()),
                        Rotation  = rand.NextDouble() * 360
                    };

                    AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.PositionProportional);
                    AbsoluteLayout.SetLayoutBounds(label, new Rectangle(rand.NextDouble(), rand.NextDouble(), 80, 24));

                    labels[k] = label;
                }
            };

            addLabels(bankA);
            addLabels(bankB);

            var bank = bankA;

            Action loop = null;

            var  i    = 0;
            Task task = null;

            loop = () =>
            {
                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }

                if (processed > max)
                {
                    absolute.Children.RemoveAt(0);
                }

                absolute.Children.Add(bank[i]);
                i++;

                if (i == step)
                {
                    if (task != null && task.Status != TaskStatus.RanToCompletion)
                    {
                        task.Wait();
                    }
                    task = Task.Run(() => addLabels(bank));
                    if (bank == bankA)
                    {
                        bank = bankB;
                    }
                    else
                    {
                        bank = bankA;
                    }
                    i = 0;
                }

                processed++;

                if (sw.ElapsedMilliseconds - prevMs > 500)
                {
                    var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                    prevTicks     = sw.ElapsedTicks;
                    prevProcessed = processed;

                    if (processed > max)
                    {
                        dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                        avgSum    += r;
                        avgN++;
                    }

                    prevMs = sw.ElapsedMilliseconds;
                }

                Device.BeginInvokeOnMainThread(loop);
            };

            sw.Start();


            Device.BeginInvokeOnMainThread(loop);
        }
Ejemplo n.º 30
0
        void StartTest()
        {
            VmLocator.OnlineDb.SendPageHit("dopeStart");

            var rand = new Random2(0);

            breakTest = false;

            var width  = absolute.Width;
            var height = absolute.Height;

            retry.IsVisible = back.IsVisible = false;
            stop.IsVisible  = true;

            const int max = 600;

            absolute.Children.Clear();

            var i         = 0;
            var processed = 0;

            var thread = new Thread(() =>
            {
                while (true)
                {
                    if (processed < i - 20)
                    {
                        Thread.Sleep(1);
                        continue;
                    }

                    var label = new Label()
                    {
                        Text      = "Dope",
                        TextColor = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()),
                        Rotation  = rand.NextDouble() * 360
                    };

                    AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.PositionProportional);
                    AbsoluteLayout.SetLayoutBounds(label, new Rectangle(rand.NextDouble(), rand.NextDouble(), 80, 24));

                    absolute.Dispatcher.BeginInvokeOnMainThread(() =>
                    {
                        if (i > max)
                        {
                            absolute.Children.RemoveAt(0);
                        }

                        absolute.Children.Add(label);

                        processed++;
                    });

                    if (breakTest)
                    {
                        break;
                    }

                    i++;
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    stop.IsVisible  = false;
                    retry.IsVisible = back.IsVisible = true;
                });
            });

            thread.IsBackground = true;
            thread.Priority     = ThreadPriority.Lowest;
            thread.Start();

            var sw = new Stopwatch();

            sw.Start();
            long   prevTicks     = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;

            Device.StartTimer(TimeSpan.FromMilliseconds(500), () =>
            {
                if (retry.IsVisible)
                {
                    var avg    = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    VmLocator.OnlineDb.SendPageHit("dopeAvg", avg.ToString("0.00", new NumberFormatInfo()
                    {
                        NumberDecimalSeparator = "."
                    }));
                    return(false);
                }

                var r         = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                dopes.Text    = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                prevTicks     = sw.ElapsedTicks;
                prevProcessed = processed;

                if (i > max)
                {
                    avgSum += r;
                    avgN++;
                }

                return(true);
            });
        }
Ejemplo n.º 31
0
        void StartTestGridST()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = grid.Width;
            var height = grid.Height;

            const int step   = 20;
            var       labels = new Label[step * 2];

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            Action loop = null;

            loop = () =>
            {
                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }

                var now = sw.ElapsedMilliseconds;

                //60hz, 16ms to build the frame
                while (sw.ElapsedMilliseconds - now < 16)
                {
                    var label = new Label()
                    {
                        Text         = "Dope",
                        TextColor    = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()),
                        Rotation     = rand.NextDouble() * 360,
                        TranslationX = rand.NextDouble() * width,
                        TranslationY = rand.NextDouble() * height
                    };


                    if (processed > max)
                    {
                        grid.Children.RemoveAt(0);
                    }

                    grid.Children.Add(label);

                    processed++;

                    if (sw.ElapsedMilliseconds - prevMs > 500)
                    {
                        var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                        prevTicks     = sw.ElapsedTicks;
                        prevProcessed = processed;

                        if (processed > max)
                        {
                            dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                            avgSum    += r;
                            avgN++;
                        }

                        prevMs = sw.ElapsedMilliseconds;
                    }
                }

                Device.BeginInvokeOnMainThread(loop);
            };

            sw.Start();

            Device.BeginInvokeOnMainThread(loop);
        }
Ejemplo n.º 32
0
        void StartTestChangeST()
        {
            var rand = new Random2(0);

            breakTest = false;

            var width  = grid.Width;
            var height = grid.Height;

            const int step   = 20;
            var       labels = new Label[step * 2];

            var processed = 0;

            long   prevTicks     = 0;
            long   prevMs        = 0;
            int    prevProcessed = 0;
            double avgSum        = 0;
            int    avgN          = 0;
            var    sw            = new Stopwatch();

            var texts = new string[] { "dOpe", "Dope", "doPe", "dopE" };

            Action loop = null;

            loop = () =>
            {
                if (breakTest)
                {
                    var avg = avgSum / avgN;
                    dopes.Text = string.Format("{0:0.00} Dopes/s (AVG)", avg).PadLeft(21);
                    return;
                }


                var now = sw.ElapsedMilliseconds;

                //60hz, 16ms to build the frame
                while (sw.ElapsedMilliseconds - now < 16)
                {
                    var label = new Label()
                    {
                        Text      = "Dope",
                        TextColor = new Color(rand.NextDouble(), rand.NextDouble(), rand.NextDouble()),
                        Rotation  = rand.NextDouble() * 360
                    };

                    AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.PositionProportional);
                    AbsoluteLayout.SetLayoutBounds(label, new Rectangle(rand.NextDouble(), rand.NextDouble(), 80, 24));

                    if (processed > max)
                    {
                        (absolute.Children[processed % max] as Label).Text = texts[(int)Math.Floor(rand.NextDouble() * 4)];
                    }
                    else
                    {
                        absolute.Children.Add(label);
                    }

                    processed++;

                    if (sw.ElapsedMilliseconds - prevMs > 500)
                    {
                        var r = (double)(processed - prevProcessed) / ((double)(sw.ElapsedTicks - prevTicks) / Stopwatch.Frequency);
                        prevTicks     = sw.ElapsedTicks;
                        prevProcessed = processed;

                        if (processed > max)
                        {
                            dopes.Text = string.Format("{0:0.00} Dopes/s", r).PadLeft(15);
                            avgSum    += r;
                            avgN++;
                        }

                        prevMs = sw.ElapsedMilliseconds;
                    }
                }

                Device.BeginInvokeOnMainThread(loop);
            };

            sw.Start();

            Device.BeginInvokeOnMainThread(loop);
        }
Ejemplo n.º 33
0
        public void Test1()
        {
            var a = new Random2();

            Assert.True(true);
        }
Ejemplo n.º 34
0
        private static string[][] CalcPermutationBasedFdr(IList <double> pvalsS0, int nperm, IMatrixData data,
                                                          TwoSampleTest test, OneSampleTest test1, TestSide side, int[] colInd1, int[] colInd2, double s0, double threshold,
                                                          List <int[]> colIndsPreserve1, List <int[]> colIndsPreserve2, List <int> validRows, out double[] fdrs, bool paired)
        {
            List <double> pq      = new List <double>();
            List <int>    indices = new List <int>();

            for (int i = 0; i < pvalsS0.Count; i++)
            {
                pq.Add(pvalsS0[i]);
                indices.Add(i);
            }
            Random2 r2 = new Random2(7);

            for (int p = 0; p < nperm; p++)
            {
                int[]  colInd1P   = null;
                int[]  colInd2P   = null;
                bool[] pairedPerm = null;
                if (!paired)
                {
                    if (colIndsPreserve1 != null)
                    {
                        BalancedPermutationsSubgroups(colIndsPreserve1, colIndsPreserve2, out colInd1P, out colInd2P, r2);
                    }
                    else
                    {
                        BalancedPermutations(colInd1, colInd2, out colInd1P, out colInd2P, r2);
                    }
                }
                else
                {
                    pairedPerm = new bool[colInd1.Length];
                    for (int i = 0; i < colInd1.Length / 2; i++)
                    {
                        pairedPerm[i] = true;
                    }
                    pairedPerm = ArrayUtils.SubArray(pairedPerm, r2.NextPermutation(pairedPerm.Length));
                }
                foreach (int row in validRows)
                {
                    double[] vals1;
                    double[] vals2;
                    if (!paired)
                    {
                        vals1 = GetValues(row, colInd1P, data, true);
                        vals2 = GetValues(row, colInd2P, data, true);
                    }
                    else
                    {
                        vals1 = GetValues(row, colInd1, data, false);
                        vals2 = GetValues(row, colInd2, data, false);
                        for (int i = 0; i < pairedPerm.Length; i++)
                        {
                            if (pairedPerm[i])
                            {
                                double tmp = vals2[i];
                                vals2[i] = vals1[i];
                                vals1[i] = tmp;
                            }
                        }
                    }
                    CalcTest(test, test1, paired, vals1, vals2, s0, side, out double _, out double _, out double p1, out double _);
                    pq.Add(p1);
                    indices.Add(-1);
                }
            }
            double[] pv      = pq.ToArray();
            int[]    inds    = indices.ToArray();
            int[]    o       = ArrayUtils.Order(pv);
            double   forw    = 0;
            double   rev     = 0;
            int      lastind = -1;

            fdrs = new double[pvalsS0.Count];
            foreach (int ind in o)
            {
                if (inds[ind] == -1)
                {
                    rev++;
                }
                else
                {
                    forw++;
                    double fdr = Math.Min(1, rev / forw / nperm);
                    fdrs[inds[ind]] = fdr;
                    if (fdr <= threshold)
                    {
                        lastind = (int)Math.Round(forw - 1);
                    }
                }
            }
            string[][] result = new string[pvalsS0.Count][];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new string[0];
            }
            int[] o1 = ArrayUtils.Order(pvalsS0);
            for (int i = 0; i <= lastind; i++)
            {
                result[o1[i]] = new[] { "+" };
            }
            return(result);
        }
Ejemplo n.º 35
0
        public void LoadData(IMatrixData mdata, Parameters param, ref IMatrixData[] supplTables, ref IDocumentData[] documents,
                             ProcessInfo processInfo)
        {
            int nrows       = param.GetParam <int>("Number of rows").Value;
            int ncols       = param.GetParam <int>("Number of columns").Value;
            int missingPerc = param.GetParam <int>("Percentage of missing values").Value;
            int ngroups     = param.GetParam <int>("Number of groups").Value;
            ParameterWithSubParams <bool> setSeed = param.GetParamWithSubParams <bool>("Set seed");
            Random2 randy = setSeed.Value? new Random2(setSeed.GetSubParameters().GetParam <int>("Seed").Value) : new Random2();

            ngroups    = Math.Min(ngroups, ncols);
            float[,] m = new float[nrows, ncols];
            ParameterWithSubParams <int> x = param.GetParamWithSubParams <int>("Mode");
            Parameters        subParams    = x.GetSubParameters();
            List <string>     catColNames  = new List <string>();
            List <string[][]> catCols      = new List <string[][]>();

            switch (x.Value)
            {
            case 0:
                for (int i = 0; i < m.GetLength(0); i++)
                {
                    for (int j = 0; j < m.GetLength(1); j++)
                    {
                        if (randy.NextDouble() * 100 < missingPerc)
                        {
                            m[i, j] = float.NaN;
                        }
                        else
                        {
                            m[i, j] = (float)randy.NextGaussian();
                        }
                    }
                }
                break;

            case 1:
                float      dist = (float)subParams.GetParam <double>("Distance").Value;
                string[][] col  = new string[m.GetLength(0)][];
                for (int i = 0; i < m.GetLength(0); i++)
                {
                    bool which = randy.NextDouble() < 0.5;
                    for (int j = 0; j < m.GetLength(1); j++)
                    {
                        if (randy.NextDouble() * 100 < missingPerc)
                        {
                            m[i, j] = float.NaN;
                        }
                        else
                        {
                            m[i, j] = (float)randy.NextGaussian();
                        }
                    }
                    if (which)
                    {
                        m[i, 0] += dist;
                        col[i]   = new[] { "Group1" };
                    }
                    else
                    {
                        col[i] = new[] { "Group2" };
                    }
                }
                catColNames.Add("Grouping");
                catCols.Add(col);
                break;

            case 2:
                double     boxLen  = subParams.GetParam <double>("Box size").Value;
                int        howMany = subParams.GetParam <int>("How many").Value;
                string[][] col1    = new string[m.GetLength(0)][];
                float[,] centers = new float[howMany, m.GetLength(1)];
                for (int i = 0; i < centers.GetLength(0); i++)
                {
                    for (int j = 0; j < centers.GetLength(1); j++)
                    {
                        centers[i, j] = (float)(randy.NextDouble() * boxLen);
                    }
                }
                for (int i = 0; i < m.GetLength(0); i++)
                {
                    int which = (int)(randy.NextDouble() * howMany);
                    for (int j = 0; j < m.GetLength(1); j++)
                    {
                        if (randy.NextDouble() * 100 < missingPerc)
                        {
                            m[i, j] = float.NaN;
                        }
                        else
                        {
                            m[i, j] = (float)randy.NextGaussian() + centers[which, j];
                        }
                    }
                    col1[i] = new[] { "Group" + (which + 1) };
                }
                catColNames.Add("Grouping");
                catCols.Add(col1);
                break;
            }
            List <string> exprColumnNames = new List <string>();

            for (int i = 0; i < ncols; i++)
            {
                exprColumnNames.Add("Column " + (i + 1));
            }
            mdata.Name        = "Random matrix";
            mdata.ColumnNames = exprColumnNames;
            mdata.Values.Set(m);
            mdata.Quality.Set(new float[m.GetLength(0), m.GetLength(1)]);
            mdata.IsImputed.Set(new bool[m.GetLength(0), m.GetLength(1)]);
            mdata.SetAnnotationColumns(new List <string>(), new List <string[]>(), catColNames, catCols, new List <string>(),
                                       new List <double[]>(), new List <string>(), new List <double[][]>());
            mdata.Origin = "Random matrix";
            string[] names = new string[mdata.RowCount];
            for (int i = 0; i < names.Length; i++)
            {
                names[i] = "Row " + (i + 1);
            }
            mdata.AddStringColumn("Name", "Name", names);
            string[][] grouping = new string[ncols][];
            for (int i = 0; i < ncols; i++)
            {
                int ig = (i * ngroups) / ncols + 1;
                grouping[i] = new[] { "Group" + ig };
            }
            mdata.AddCategoryRow("Grouping", "Grouping", grouping);
        }