コード例 #1
0
ファイル: SimpleMatrix.cs プロジェクト: lulzzz/BraneCloud
        /**
         * <p>
         * Creates a new vector which is drawn from a multivariate normal distribution with zero mean
         * and the provided covariance.
         * </p>
         *
         * @see CovarianceRandomDraw_DDRM
         *
         * @param covariance Covariance of the multivariate normal distribution
         * @return Vector randomly drawn from the distribution
         */
        public static SimpleMatrix <T> randomNormal(SimpleMatrix <T> covariance, IMersenneTwister random)
        {
            SimpleMatrix <T> found = new SimpleMatrix <T>(covariance.numRows(), 1);

            var m    = covariance.getMatrix();
            var bits = covariance.bits();

            if (bits == 64)
            {
                // Check type here to make sure
                if (typeof(T) != typeof(DMatrixRMaj))
                {
                    throw new InvalidOperationException("This operation is only valid for type DMatrixRMaj.");
                }

                var draw = new CovarianceRandomDraw_DDRM(random, m as DMatrixRMaj);
                draw.next(found.getMatrix() as DMatrixRMaj);
            }
            else if (bits == 32)
            {
                // Check type here to make sure
                if (typeof(T) != typeof(FMatrixRMaj))
                {
                    throw new InvalidOperationException("This operation is only valid for type FMatrixRMaj.");
                }

                var draw = new CovarianceRandomDraw_FDRM(random, m as FMatrixRMaj);
                draw.next(found.getMatrix() as FMatrixRMaj);
            }
            else // Unknown data type
            {
                throw new InvalidOperationException("Unknown data type: must be double (64 bits) or float (32 bits).");
            }
            return(found);
        }
コード例 #2
0
        /// <summary>
        /// <para>
        /// Creates a new vector which is drawn from a multivariate normal distribution with zero mean
        /// and the provided covariance.
        /// </para>
        /// </summary>
        /// <param name="covariance"> Covariance of the multivariate normal distribution </param>
        /// <returns> Vector randomly drawn from the distribution </returns>
        /// <seealso cref= CovarianceRandomDraw_DDRM </seealso>
        public static SimpleMatrix <W> randomNormal(SimpleMatrix <W> covariance, Random random)
        {
            SimpleMatrix <W> found = new SimpleMatrix <W>(covariance.numRows(), 1, covariance.getType());

            switch (found.getType().tipo)
            {
            case Types.DDRM:
            {
                CovarianceRandomDraw_DDRM draw = new CovarianceRandomDraw_DDRM(random, (DMatrixRMaj)covariance.mat);

                draw.next((DMatrixRMaj)found.mat);
            }
            break;

            //case MatrixType.FDRM:
            //	{
            //		CovarianceRandomDraw_FDRM draw = new CovarianceRandomDraw_FDRM(random, (FMatrixRMaj)covariance.Matrix);

            //		draw.next((FMatrixRMaj)found.mat);
            //	}
            //	break;

            default:
                throw new System.ArgumentException("Matrix type is currently not supported");
            }

            return(found);
        }
コード例 #3
0
        /**
         * <p>
         * Creates a new vector which is drawn from a multivariate normal distribution with zero mean
         * and the provided covariance.
         * </p>
         *
         * @see CovarianceRandomDraw_DDRM
         *
         * @param covariance Covariance of the multivariate normal distribution
         * @return Vector randomly drawn from the distribution
         */
        public static SimpleMatrixD randomNormal(SimpleMatrixD covariance, IMersenneTwister random)
        {
            SimpleMatrixD found = new SimpleMatrixD(covariance.numRows(), 1);

            var draw = new CovarianceRandomDraw_DDRM(random, covariance.getMatrix());

            draw.next(found.getMatrix());

            return(found);
        }