示例#1
0
        /// <summary>
        /// Solve SPD(Symmetric positive definite) into vector
        /// </summary>
        /// <param name="b"> vector </param>
        /// <param name="maxConditionNumber"> maximum condition number </param>
        /// <returns> solution vector of SPD </returns>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: public InsightsVector solveSPDIntoVector(InsightsVector b, final double maxConditionNumber)
        public virtual InsightsVector solveSPDIntoVector(InsightsVector b, double maxConditionNumber)
        {
            if (!_valid || b == null || _n != b._m)
            {
                // invalid linear system
                throw new Exception("[InsightsMatrix][solveSPDIntoVector] invalid linear system");
            }
            if (_cholL == null)
            {
                // computing Cholesky Decomposition
                this.computeCholeskyDecomposition(maxConditionNumber);
            }
            if (_cholZero)
            {
                // singular matrix. returning null
                return(null);
            }

            double[] y  = new double[_m];
            double[] bt = new double[_n];
            int      i;
            int      j;

            for (i = 0; i < _m; ++i)
            {
                bt[i] = b._data[i];
            }
            double val;

            for (i = 0; i < _m; ++i)
            {
                val = 0;
                for (j = 0; j < i; ++j)
                {
                    val += _cholL[i][j] * y[j];
                }
                y[i] = bt[i] - val;
            }
            for (i = _m - 1; i >= 0; --i)
            {
                val = 0;
                for (j = i + 1; j < _n; ++j)
                {
                    val += _cholL[i][j] * bt[j];
                }
                bt[i] = y[i] / _cholD[i] - val;
            }
            return(new InsightsVector(bt, false));
        }
示例#2
0
        //=====================================================================
        // END of Getters & Setters
        //=====================================================================
        //=====================================================================
        // Basic Linear Algebra operations
        //=====================================================================

        /// <summary>
        /// Multiply a InsightMatrix (n x m) by a InsightVector (m x 1)
        /// </summary>
        /// <param name="v"> a InsightVector </param>
        /// <returns> a InsightVector of dimension (n x 1) </returns>
        public virtual InsightsVector timesVector(InsightsVector v)
        {
            if (!_valid || !v._valid || _n != v._m)
            {
                throw new Exception("[InsightsMatrix][timesVector] size mismatch");
            }
            double[] data = new double[_m];
            double   dotProduc;

            for (int i = 0; i < _m; ++i)
            {
                InsightsVector rowVector = new InsightsVector(_data[i], false);
                dotProduc = rowVector.dot(v);
                data[i]   = dotProduc;
            }
            return(new InsightsVector(data, false));
        }
        //=====================================================================
        // END of Getters & Setters
        //=====================================================================
        //=====================================================================
        // Basic Linear Algebra operations
        //=====================================================================

        /// <summary>
        /// Perform dot product operation with another vector of the same size
        /// </summary>
        /// <param name="vector"> vector of the same size </param>
        /// <returns> dot product of the two vector </returns>
        public virtual double dot(InsightsVector vector)
        {
            if (!_valid || !vector._valid)
            {
                throw new Exception("[InsightsVector] invalid Vector");
            }
            else if (_m != vector.size())
            {
                throw new Exception("[InsightsVector][dot] invalid vector size.");
            }

            double sumOfProducts = 0;

            for (int i = 0; i < _m; i++)
            {
                sumOfProducts += _data[i] * vector.get(i);
            }
            return(sumOfProducts);
        }