public void OnDrawFrame(Javax.Microedition.Khronos.Opengles.IGL10 gl)
        {
            Java.Util.Random r = new Java.Util.Random();

            gl.GlClearColor(r.NextFloat(), r.NextFloat(), r.NextFloat(), 1);
            gl.GlClear(Javax.Microedition.Khronos.Opengles.GL10.GlColorBufferBit);
        }
示例#2
0
        /**
         * Returns a matrix where all the elements are selected independently from
         * a uniform distribution between 0 and 1 inclusive.
         *
         * @param numRow Number of rows in the new matrix.
         * @param numCol Number of columns in the new matrix.
         * @param randJava.Util.Random number generator used to fill the matrix.
         * @return The randomly generated matrix.
         */
        public static DMatrixRMaj rectangle(int numRow, int numCol, Java.Util.Random rand)
        {
            DMatrixRMaj mat = new DMatrixRMaj(numRow, numCol);

            fillUniform(mat, 0, 1, rand);

            return(mat);
        }
示例#3
0
        /// <summary>
        /// Creates a real valued diagonal matrix of the specified type
        /// </summary>
        ///

        /*
         * public static SimpleMatrix diag(Type type, params double[] vals)
         * {
         *      SimpleMatrix M = new SimpleMatrix(vals.Length, vals.Length, type);
         *      for (int i = 0; i < vals.Length; i++)
         *      {
         *              M.set(i, i, vals[i]);
         *      }
         *      return M;
         * }*/

        /// <summary>
        /// <para>
        /// Creates a new SimpleMatrix with random elements drawn from a uniform distribution from minValue to maxValue.
        /// </para>
        /// </summary>
        /// <param name="numRows"> The number of rows in the new matrix </param>
        /// <param name="numCols"> The number of columns in the new matrix </param>
        /// <param name="minValue"> Lower bound </param>
        /// <param name="maxValue"> Upper bound </param> </param>
        /// <param name="rand"> The random number generator that's used to fill the matrix.  <returns> The new random matrix. </returns>
        /// <seealso cref= RandomMatrices_DDRM#fillUniform(DMatrixRMaj, java.util.Random) </seealso>
        public static SimpleMatrix <W> random_DDRM(int numRows, int numCols, double minValue, double maxValue, Random rand)
        {
            SimpleMatrix <W> ret = new SimpleMatrix <W>(numRows, numCols);

            Java.Util.Random rd = new Java.Util.Random();
            RandomMatrices_DDRM.fillUniform((DMatrixRMaj)ret.mat, minValue, maxValue, rd);
            return(ret);
        }
示例#4
0
        /**
         * Creates aJava.Util.Random symmetric matrix whose values are selected from an uniform distribution
         * from min to max, inclusive.
         *
         * @param Count() Width and height of the matrix.
         * @param min Minimum value an element can have.
         * @param max Maximum value an element can have.
         * @param randJava.Util.Random number generator.
         * @return A symmetric matrix.
         */
        public static DMatrixRMaj symmetric(int length, double min, double max, Java.Util.Random rand)
        {
            DMatrixRMaj A = new DMatrixRMaj(length, length);

            symmetric(A, min, max, rand);

            return(A);
        }
示例#5
0
        /**
         * Returns new bool matrix with true or false values selected with equal probability.
         *
         * @param numRow Number of rows in the new matrix.
         * @param numCol Number of columns in the new matrix.
         * @param randJava.Util.Random number generator used to fill the matrix.
         * @return The randomly generated matrix.
         */
        public static BMatrixRMaj randomBinary(int numRow, int numCol, Java.Util.Random rand)
        {
            BMatrixRMaj mat = new BMatrixRMaj(numRow, numCol);

            setRandomB(mat, rand);

            return(mat);
        }
    //Generate random transaction id
    public string Generate()
    {
        long ticks = System.DateTime.Now.Ticks;

        System.Threading.Thread.Sleep(200);
        Java.Util.Random rnd  = new Java.Util.Random();
        string           rndm = Integer.ToString(rnd.NextInt()) + (System.DateTime.Now.Ticks - ticks / 1000);

        return(rndm);
    }
示例#7
0
        public static DMatrixRBlock createRandom(int numRows, int numCols,
                                                 double min, double max, Random rand)
        {
            DMatrixRBlock ret = new DMatrixRBlock(numRows, numCols);

            Java.Util.Random rd = new Java.Util.Random();
            RandomMatrices_DDRM.fillUniform(ret, min, max, rd);

            return(ret);
        }
示例#8
0
        /**
         * <p>
         * Sets each element in the bool matrix to true or false with equal probability
         * </p>
         *
         * @param mat The matrix who is to be randomized. Modified.
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static void setRandomB(BMatrixRMaj mat, Java.Util.Random rand)
        {
            bool[] d    = mat.data;
            int    size = mat.NumElements;


            for (int i = 0; i < size; i++)
            {
                d[i] = rand.NextBoolean();
            }
        }
示例#9
0
        /**
         * <p>
         * Sets each element in the matrix to a value drawn from an Gaussian distribution with the specified mean and
         * standard deviation
         * </p>
         *
         * @param mat The matrix who is to be randomized. Modified.
         * @param mean Mean value in the distribution
         * @param stdev Standard deviation in the distribution
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static void fillGaussian(DMatrixD1 mat, double mean, double stdev, Java.Util.Random rand)
        {
            double[] d    = mat.getData();
            int      size = mat.NumElements;

            Java.Util.Random random2 = new Java.Util.Random();
            for (int i = 0; i < size; i++)
            {
                d[i] = mean + stdev * (double)random2.NextGaussian();
            }
        }
        public static byte[] GetRandomByteArray(int nLength)
        {
            byte[] data   = new byte[nLength];
            var    rmByte = new Java.Util.Random(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());

            for (int i = 0; i < nLength; i++)
            {
                // 该方法的作用是生成一个随机的int值,该值介于[0,n)的区间,也就是0到n之间的随机int值,包含0而不包含n
                data[i] = (byte)rmByte.NextInt(256);
            }
            return(data);
        }
示例#11
0
        /**
         * Creates a newJava.Util.Random symmetric matrix that will have the specified real eigenvalues.
         *
         * @param num Dimension of the resulting matrix.
         * @param randJava.Util.Random number generator.
         * @param eigenvalues Set of real eigenvalues that the matrix will have.
         * @return AJava.Util.Random matrix with the specified eigenvalues.
         */
        public static DMatrixRMaj symmetricWithEigenvalues(int num, Java.Util.Random rand, double[] eigenvalues)
        {
            DMatrixRMaj V = RandomMatrices_DDRM.orthogonal(num, num, rand);
            DMatrixRMaj D = CommonOps_DDRM.diag(eigenvalues);

            DMatrixRMaj temp = new DMatrixRMaj(num, num);

            CommonOps_DDRM.mult(V, D, temp);
            CommonOps_DDRM.multTransB(temp, V, D);

            return(D);
        }
示例#12
0
        /**
         * <p>
         * AddsJava.Util.Random values to each element in the matrix from an uniform distribution.<br>
         * <br>
         * a<sub>ij</sub> = a<sub>ij</sub> + U(min,max)<br>
         * </p>
         *
         * @param A The matrix who is to be randomized. Modified
         * @param min The minimum value each element can be.
         * @param max The maximum value each element can be..
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static void addUniform(DMatrixRMaj A, double min, double max, Java.Util.Random rand)
        {
            double[] d    = A.getData();
            int      size = A.NumElements;

            double r = max - min;

            for (int i = 0; i < size; i++)
            {
                d[i] += r * rand.NextDouble() + min;
            }
        }
示例#13
0
        /**
         * <p>
         * Sets each element in the matrix to a value drawn from an uniform distribution from 'min' to 'max' inclusive.
         * </p>
         *
         * @param min The minimum value each element can be.
         * @param max The maximum value each element can be.
         * @param mat The matrix who is to be randomized. Modified.
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static void fillUniform(DMatrixD1 mat, double min, double max, Java.Util.Random rand)
        {
            double[] d    = mat.getData();
            int      size = mat.NumElements;

            double r = max - min;

            for (int i = 0; i < size; i++)
            {
                d[i] = r * rand.NextDouble() + min;
            }
        }
示例#14
0
        /**
         * <p>
         * Creates a randomly generated set of orthonormal vectors.  At most it can generate the same
         * number of vectors as the dimension of the vectors.
         * </p>
         *
         * <p>
         * This is done by creatingJava.Util.Random vectors then ensuring that they are orthogonal
         * to all the ones previously created with reflectors.
         * </p>
         *
         * <p>
         * NOTE: This employs a brute force O(N<sup>3</sup>) algorithm.
         * </p>
         *
         * @param dimen dimension of the space which the vectors will span.
         * @param numVectors How many vectors it should generate.
         * @param rand Used to createJava.Util.Random vectors.
         * @return Array of NJava.Util.Random orthogonal vectors of unit Count().
         */
        // is there a faster algorithm out there? This one is a bit sluggish
        public static DMatrixRMaj[] span(int dimen, int numVectors, Java.Util.Random rand)
        {
            if (dimen < numVectors)
            {
                throw new ArgumentException("The number of vectors must be less than or equal to the dimension");
            }

            DMatrixRMaj[] u = new DMatrixRMaj[numVectors];

            u[0] = RandomMatrices_DDRM.rectangle(dimen, 1, -1, 1, rand);
            NormOps_DDRM.normalizeF(u[0]);

            for (int i = 1; i < numVectors; i++)
            {
                //            System.out.println(" i = "+i);
                DMatrixRMaj a = new DMatrixRMaj(dimen, 1);
                DMatrixRMaj r = RandomMatrices_DDRM.rectangle(dimen, 1, -1, 1, rand);

                for (int j = 0; j < i; j++)
                {
                    // find a vector that is normal to vector j
                    // u[i] = (1/2)*(r + Q[j]*r)
                    a.setTo(r);
                    VectorVectorMult_DDRM.householder(-2.0, u[j], r, a);
                    CommonOps_DDRM.add(r, a, a);
                    CommonOps_DDRM.scale(0.5, a);

                    //                UtilEjml.print(a);

                    DMatrixRMaj t = a;
                    a = r;
                    r = t;

                    // normalize it so it doesn't get too small
                    double val = NormOps_DDRM.normF(r);
                    if (val == 0 || Double.IsNaN(val) || Double.IsInfinity(val))
                    {
                        throw new SystemException("Failed sanity check");
                    }
                    CommonOps_DDRM.divide(r, val);
                }

                u[i] = r;
            }

            return(u);
        }
示例#15
0
        public static List <string> GetListKeyboard(this string param, string aide)
        {
            Java.Util.Random rnd        = new Java.Util.Random();
            List <string>    return_var = param.ToList_OUF();

            for (int i = param.Length; i < 12; i++)
            {
                int element = rnd.NextInt(ALPHABET.Count);
                return_var.Add(ALPHABET[element]);
            }

            for (int i = 0; i < aide.Length; i++)
            {
                return_var.ReplaceWidthWhiteSpace(aide[i].ToString());
            }

            return(return_var);
        }
示例#16
0
        /**
         * <p>
         * Creates aJava.Util.Random orthogonal or isometric matrix, depending on the number of rows and columns.
         * The number of rows must be more than or equal to the number of columns.
         * </p>
         *
         * @param numRows Number of rows in the generated matrix.
         * @param numCols Number of columns in the generated matrix.
         * @param randJava.Util.Random number generator used to create matrices.
         * @return A new isometric matrix.
         */
        public static DMatrixRMaj orthogonal(int numRows, int numCols, Java.Util.Random rand)
        {
            if (numRows < numCols)
            {
                throw new ArgumentException("The number of rows must be more than or equal to the number of columns");
            }

            DMatrixRMaj[] u = span(numRows, numCols, rand);

            DMatrixRMaj ret = new DMatrixRMaj(numRows, numCols);

            for (int i = 0; i < numCols; i++)
            {
                SubmatrixOps_DDRM.setSubMatrix(u[i], ret, 0, 0, 0, i, numRows, 1);
            }

            return(ret);
        }
        /**
         * Creates a random distribution with the specified mean and covariance.  The references
         * to the variables are not saved, their value are copied.
         *
         * @param rand Used to create the random numbers for the draw. Reference is saved.
         * @param cov The covariance of the distribution.  Not modified.
         */
        public CovarianceRandomDraw_DDRM(Random rand, DMatrixRMaj cov)
        {
            r = new DMatrixRMaj(cov.numRows, 1);
            CholeskyDecompositionInner_DDRM cholesky = new CholeskyDecompositionInner_DDRM(true);

            if (cholesky.inputModified())
            {
                cov = cov.copy();
            }
            if (!cholesky.decompose(cov))
            {
                throw new SystemException("Decomposition failed!");
            }

            A = cholesky.getT();
            //this.rand = rand;
            this.rand = new Java.Util.Random();
        }
示例#18
0
        /**
         * Creates aJava.Util.Random symmetric positive definite matrix.
         *
         * @param width The width of the square matrix it returns.
         * @param randJava.Util.Random number generator used to make the matrix.
         * @return TheJava.Util.Random symmetric  positive definite matrix.
         */
        public static DMatrixRMaj symmetricPosDef(int width, Java.Util.Random rand)
        {
            // This is not formally proven to work.  It just seems to work.
            DMatrixRMaj a = new DMatrixRMaj(width, 1);
            DMatrixRMaj b = new DMatrixRMaj(width, width);

            for (int i = 0; i < width; i++)
            {
                a.set(i, 0, rand.NextDouble());
            }

            CommonOps_DDRM.multTransB(a, a, b);

            for (int i = 0; i < width; i++)
            {
                b.add(i, i, 1);
            }

            return(b);
        }
示例#19
0
        /**
         * Sets the provided square matrix to be aJava.Util.Random symmetric matrix whose values are selected from an uniform distribution
         * from min to max, inclusive.
         *
         * @param A The matrix that is to be modified.  Must be square.  Modified.
         * @param min Minimum value an element can have.
         * @param max Maximum value an element can have.
         * @param randJava.Util.Random number generator.
         */
        public static void symmetric(DMatrixRMaj A, double min, double max, Java.Util.Random rand)
        {
            if (A.numRows != A.numCols)
            {
                throw new ArgumentException("A must be a square matrix");
            }

            double range = max - min;

            int length = A.numRows;

            for (int i = 0; i < length; i++)
            {
                for (int j = i; j < length; j++)
                {
                    double val = rand.NextDouble() * range + min;
                    A.set(i, j, val);
                    A.set(j, i, val);
                }
            }
        }
示例#20
0
        /**
         * <p>
         * Creates aJava.Util.Random matrix which will have the provided singular values.  The Count() of sv
         * is assumed to be the rank of the matrix.  This can be useful for testing purposes when one
         * needs to ensure that a matrix is not singular but randomly generated.
         * </p>
         *
         * @param numRows Number of rows in generated matrix.
         * @param numCols NUmber of columns in generated matrix.
         * @param randJava.Util.Random number generator.
         * @param sv Singular values of the matrix.
         * @return A new matrix with the specified singular values.
         */
        public static DMatrixRMaj singular(int numRows, int numCols,
                                           Java.Util.Random rand, double[] sv)
        {
            DMatrixRMaj U, V, S;

            // speed it up in compact format
            if (numRows > numCols)
            {
                U = RandomMatrices_DDRM.orthogonal(numRows, numCols, rand);
                V = RandomMatrices_DDRM.orthogonal(numCols, numCols, rand);
                S = new DMatrixRMaj(numCols, numCols);
            }
            else
            {
                U = RandomMatrices_DDRM.orthogonal(numRows, numRows, rand);
                V = RandomMatrices_DDRM.orthogonal(numCols, numCols, rand);
                S = new DMatrixRMaj(numRows, numCols);
            }

            int min = Math.Min(numRows, numCols);

            min = Math.Min(min, sv.Count());

            for (int i = 0; i < min; i++)
            {
                S.set(i, i, sv[i]);
            }

            DMatrixRMaj tmp = new DMatrixRMaj(numRows, numCols);

            CommonOps_DDRM.mult(U, S, tmp);
            S.reshape(numRows, numCols);
            CommonOps_DDRM.multTransB(tmp, V, S);

            return(S);
        }
示例#21
0
        /**
         * Creates aJava.Util.Random vector that is inside the specified span.
         *
         * @param span The span theJava.Util.Random vector belongs in.
         * @param rand RNG
         * @return AJava.Util.Random vector within the specified span.
         */
        public static DMatrixRMaj insideSpan(DMatrixRMaj[] span, double min, double max, Java.Util.Random rand)
        {
            DMatrixRMaj A = new DMatrixRMaj(span.Count(), 1);

            DMatrixRMaj B = new DMatrixRMaj(span[0].NumElements, 1);

            for (int i = 0; i < span.Count(); i++)
            {
                B.setTo(span[i]);
                double val = rand.NextDouble() * (max - min) + min;
                CommonOps_DDRM.scale(val, B);

                CommonOps_DDRM.add(A, B, A);
            }

            return(A);
        }
示例#22
0
        /**
         * Creates a lower triangular matrix whose values are selected from a uniform distribution.  If hessenberg
         * is greater than zero then a hessenberg matrix of the specified degree is created instead.
         *
         * @param dimen Number of rows and columns in the matrix..
         * @param hessenberg 0 for triangular matrix and &gt; 0 for hessenberg matrix.
         * @param min minimum value an element can be.
         * @param max maximum value an element can be.
         * @param randJava.Util.Random number generator used.
         * @return The randomly generated matrix.
         */
        public static DMatrixRMaj triangularLower(int dimen, int hessenberg, double min, double max, Java.Util.Random rand)
        {
            if (hessenberg < 0)
            {
                throw new SystemException("hessenberg must be more than or equal to 0");
            }

            double range = max - min;

            DMatrixRMaj A = new DMatrixRMaj(dimen, dimen);

            for (int i = 0; i < dimen; i++)
            {
                int end = Math.Min(dimen, i + hessenberg + 1);
                for (int j = 0; j < end; j++)
                {
                    A.set(i, j, rand.NextDouble() * range + min);
                }
            }

            return(A);
        }
示例#23
0
        /**
         * Creates an upper triangular matrix whose values are selected from a uniform distribution.  If hessenberg
         * is greater than zero then a hessenberg matrix of the specified degree is created instead.
         *
         * @param dimen Number of rows and columns in the matrix..
         * @param hessenberg 0 for triangular matrix and &gt; 0 for hessenberg matrix.
         * @param min minimum value an element can be.
         * @param max maximum value an element can be.
         * @param randJava.Util.Random number generator used.
         * @return The randomly generated matrix.
         */
        public static DMatrixRMaj triangularUpper(int dimen, int hessenberg, double min, double max, Java.Util.Random rand)
        {
            if (hessenberg < 0)
            {
                throw new SystemException("hessenberg must be more than or equal to 0");
            }

            double range = max - min;

            DMatrixRMaj A = new DMatrixRMaj(dimen, dimen);

            for (int i = 0; i < dimen; i++)
            {
                int start = i <= hessenberg ? 0 : i - hessenberg;

                for (int j = start; j < dimen; j++)
                {
                    A.set(i, j, rand.NextDouble() * range + min);
                }
            }

            return(A);
        }
        private void DrawPieChart()
        {
            List <PieEntry> datalist = new List <PieEntry>();

            int[] colors = new int[14];
            for (int i = 0; i < lstPieChartDataValue.Count; i++)
            {
                string expensecategory = lstPieChartDataValue[i].ExpenseCategory;
                double total           = lstPieChartDataValue[i].Total;
                datalist.Add(new PieEntry((float)total, expensecategory));

                switch (expensecategory)
                {
                case "Food and Dining":
                    colors[i] = Android.Graphics.Color.ParseColor("#FFA500");
                    break;

                case "Shopping":
                    colors[i] = Android.Graphics.Color.ParseColor("#40C4FF");
                    break;

                case "Travelling":
                    colors[i] = Android.Graphics.Color.ParseColor("#00BFA5");
                    break;

                case "Entertainment":
                    colors[i] = Android.Graphics.Color.ParseColor("#e49ef0");
                    break;

                case "Medical":
                    colors[i] = Android.Graphics.Color.ParseColor("#FF0000");
                    break;

                case "Personal Care":
                    colors[i] = Android.Graphics.Color.ParseColor("#0EDBDB");
                    break;

                case "Education":
                    colors[i] = Android.Graphics.Color.ParseColor("#1b49f2");
                    break;

                case "Bills and Utilities":
                    colors[i] = Android.Graphics.Color.ParseColor("#006600");
                    break;

                case "Banking":
                    colors[i] = Android.Graphics.Color.ParseColor("#FFAB91");
                    break;

                case "Rent":
                    colors[i] = Android.Graphics.Color.ParseColor("#9E9D24");
                    break;

                case "Taxes":
                    colors[i] = Android.Graphics.Color.ParseColor("#DB32B1");
                    break;

                case "Insurance":
                    colors[i] = Android.Graphics.Color.ParseColor("#AA00FF");
                    break;

                case "Gifts and Donations":
                    colors[i] = Android.Graphics.Color.ParseColor("#8699E3");
                    break;

                case "Other":
                    colors[i] = Android.Graphics.Color.ParseColor("#695e5e");
                    break;
                }
            }
            prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            MikePhil.Charting.Data.PieDataSet pieDataSet = new MikePhil.Charting.Data.PieDataSet(datalist, "");
            pieDataSet.YValuePosition = PieDataSet.ValuePosition.OutsideSlice;
            //pieDataSet.ValueLinePart1OffsetPercentage=100f; /** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */
            pieDataSet.ValueLinePart1Length = 0.4f; /** When valuePosition is OutsideSlice, indicates length of first half of the line */
            pieDataSet.ValueLinePart2Length = 0.4f;
            pieDataSet.SliceSpace           = 0.5f;
            pieDataSet.SelectionShift       = 5f;
            Java.Util.Random rnd = new Java.Util.Random();
            //int[] colors = new int[lstExpenseCategories.Count];
            //for (int i = 0; i < lstExpenseCategories.Count; i++)
            //{
            //    Android.Graphics.Color randomColor = Android.Graphics.Color.Rgb(rnd.NextInt(256), rnd.NextInt(256), rnd.NextInt(256));
            //    colors[i] = randomColor;
            //}


            pieDataSet.SetColors(colors);
            // pieDataSet.SetColors(PieChartColors.piecharcolors.Take(lstExpenseCategories.Count).ToArray());
            // pieDataSet.Colors = ColorTemplate.MaterialColors.Select(c => new Java.Lang.Integer(c)).ToList();
            pieDataSet.ValueTextSize          = 10f;
            pieDataSet.ValueTextColor         = Android.Graphics.Color.Black;
            piechartStats.Description.Enabled = false;
            piechartStats.CenterText          = "";

            Legend l = piechartStats.Legend;

            l.VerticalAlignment   = Legend.LegendVerticalAlignment.Bottom;
            l.HorizontalAlignment = Legend.LegendHorizontalAlignment.Left;
            l.Orientation         = Legend.LegendOrientation.Horizontal;
            l.WordWrapEnabled     = true;
            l.SetDrawInside(false);
            l.Enabled = true;
            piechartStats.SetExtraOffsets(0f, 2f, 0f, 2f);
            piechartStats.SetDrawEntryLabels(false);

            PieData pieData = new PieData(pieDataSet);

            piechartStats.Data = pieData;

            piechartStats.AnimateXY(1000, 1000);
            piechartStats.Invalidate();
            progressBarStats.Visibility = ViewStates.Invisible;
            piechartStats.Visibility    = ViewStates.Visible;
            statsdata.Visibility        = ViewStates.Invisible;
            generatePDF.Visibility      = ViewStates.Visible;
            statstype.Text = "Total expense for the month" + "(" + SelectedMonth.Substring(0, 3) + ")" + " = " + prefs.GetString("CurrencySymbolSelected", "") + lstPieChartDataValue.Sum(x => Convert.ToDouble(x.Total));
        }
 /// <summary>
 /// Returns a randomly initialized tensor with values draft from the
 /// uniform distribution between minValue and maxValue.
 /// </summary>
 public static Edu.Stanford.Nlp.Neural.SimpleTensor Random(int numRows, int numCols, int numSlices, double minValue, double maxValue, Java.Util.Random rand)
 {
     Edu.Stanford.Nlp.Neural.SimpleTensor tensor = new Edu.Stanford.Nlp.Neural.SimpleTensor(numRows, numCols, numSlices);
     for (int i = 0; i < numSlices; ++i)
     {
         tensor.slices[i] = SimpleMatrix.Random(numRows, numCols, minValue, maxValue, rand);
     }
     return(tensor);
 }
示例#26
0
        /**
         * <p>
         * Sets each element in the matrix to a value drawn from an Gaussian distribution with the specified mean and
         * standard deviation
         * </p>
         *
         * @param numRow Number of rows in the new matrix.
         * @param numCol Number of columns in the new matrix.
         * @param mean Mean value in the distribution
         * @param stdev Standard deviation in the distribution
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static DMatrixRMaj rectangleGaussian(int numRow, int numCol, double mean, double stdev, Java.Util.Random rand)
        {
            DMatrixRMaj m = new DMatrixRMaj(numRow, numCol);

            fillGaussian(m, mean, stdev, rand);
            return(m);
        }
示例#27
0
 /**
  * Creates aJava.Util.Random diagonal matrix where the diagonal elements are selected from a uniform
  * distribution that goes from min to max.
  *
  * @param N Dimension of the matrix.
  * @param min Minimum value of a diagonal element.
  * @param max Maximum value of a diagonal element.
  * @param randJava.Util.Random number generator.
  * @return AJava.Util.Random diagonal matrix.
  */
 public static DMatrixRMaj diagonal(int N, double min, double max, Java.Util.Random rand)
 {
     return(diagonal(N, N, min, max, rand));
 }
示例#28
0
        /**
         * Creates aJava.Util.Random matrix where all elements are zero but diagonal elements.  Diagonal elements
         * randomly drawn from a uniform distribution from min to max, inclusive.
         *
         * @param numRows Number of rows in the returned matrix..
         * @param numCols Number of columns in the returned matrix.
         * @param min Minimum value of a diagonal element.
         * @param max Maximum value of a diagonal element.
         * @param randJava.Util.Random number generator.
         * @return AJava.Util.Random diagonal matrix.
         */
        public static DMatrixRMaj diagonal(int numRows, int numCols, double min, double max, Java.Util.Random rand)
        {
            if (max < min)
            {
                throw new ArgumentException("The max must be >= the min");
            }

            DMatrixRMaj ret = new DMatrixRMaj(numRows, numCols);

            int N = Math.Min(numRows, numCols);

            double r = max - min;

            for (int i = 0; i < N; i++)
            {
                ret.set(i, i, rand.NextDouble() * r + min);
            }

            return(ret);
        }
示例#29
0
 /**
  * <p>
  * Sets each element in the matrix to a value drawn from an uniform distribution from 0 to 1 inclusive.
  * </p>
  *
  * @param mat The matrix who is to be randomized. Modified.
  * @param randJava.Util.Random number generator used to fill the matrix.
  */
 public static void fillUniform(DMatrixRMaj mat, System.Random rand1)
 {
     Java.Util.Random rand = new Java.Util.Random();
     fillUniform(mat, 0, 1, rand);
 }
示例#30
0
 public static int nextInt(this Java.Util.Random random, int n)
 {
     return(random.NextInt(n));
 }