当前位置: 首页>>代码示例>>C#>>正文


C# Vector.Norm方法代码示例

本文整理汇总了C#中Vector.Norm方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Norm方法的具体用法?C# Vector.Norm怎么用?C# Vector.Norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.Norm方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reflection

        /// <summary>
        /// Householder Reflection: Evaluate symmetric orthogonal Q such that Q*v = -sigma*||v||*e1 
        /// </summary>
        public static Matrix Reflection(Vector v)
        {
            double sigma = v[0] >= 0 ? 1 : -1;

            Vector u = v.Clone();
            u[0] += sigma * v.Norm();

            Matrix m = Matrix.Identity(v.Length, v.Length);
            m.MultiplyAccumulateInplace(u.TensorMultiply(u), -2d / u.ScalarMultiply(u));

            return m;
        }
开发者ID:AdrianCNewman,项目名称:mathnet-iridium,代码行数:15,代码来源:Orthogonal.cs

示例2: Calculate

        internal void Calculate(IEnumerable<INuclei> Nucleis,int problemDimensionality, int nucleisCount)
        {
            Helpers.CalculateSimpliceCentroidFromFacets(Nucleis, nucleisCount -1 , ref Center);
            INuclei nuclei = Nucleis.First();

            //now calculate the radious and store it.
            Vector v = new Vector(problemDimensionality);
            for (int i = 0; i<problemDimensionality; i++)
                v[i] = Center[i] - nuclei.Coordinates[i];

            this.Radious = v.Norm();
        }
开发者ID:pabloinigoblasco,项目名称:nd-voronoi-sharp,代码行数:12,代码来源:HyperSphereConstraint.cs

示例3: Compute

 public double Compute(Vector x, Vector y)
 {
     return x.Dot(y) / (x.Norm() * y.Norm());
 }
开发者ID:al-main,项目名称:CloudyBank,代码行数:4,代码来源:CosineSimilarity.cs

示例4: DetermineStatus

        /// <summary>
        /// Determines the status of the iterative calculation based on the stop criteria stored
        /// by the current <see cref="IIterationStopCriterium"/>. Result is set into <c>Status</c> field.
        /// </summary>
        /// <param name="iterationNumber">The number of iterations that have passed so far.</param>
        /// <param name="solutionVector">The vector containing the current solution values.</param>
        /// <param name="sourceVector">The right hand side vector.</param>
        /// <param name="residualVector">The vector containing the current residual vectors.</param>
        /// <remarks>
        /// The individual stop criteria may internally track the progress of the calculation based
        /// on the invocation of this method. Therefore this method should only be called if the 
        /// calculation has moved forwards at least one step.
        /// </remarks>
        public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector)
        {
            if (iterationNumber < 0)
            {
                throw new ArgumentOutOfRangeException("iterationNumber");
            }

            if (residualVector == null)
            {
                throw new ArgumentNullException("residualVector");
            }

            if (_lastIteration >= iterationNumber)
            {
                // We have already stored the actual last iteration number
                // For now do nothing. We only care about the next step.
                return;
            }

            if ((_residualHistory == null) || (_residualHistory.Length != RequiredHistoryLength))
            {
                _residualHistory = new double[RequiredHistoryLength];
            }

            // We always track the residual.
            // Move the old versions one element up in the array.
            for (var i = 1; i < _residualHistory.Length; i++)
            {
                _residualHistory[i - 1] = _residualHistory[i];
            }

            // Store the infinity norms of both the solution and residual vectors
            // These values will be used to calculate the relative drop in residuals later on.
            _residualHistory[_residualHistory.Length - 1] = residualVector.Norm(Double.PositiveInfinity).Real;

            // Check if we have NaN's. If so we've gone way beyond normal divergence.
            // Stop the iteration.
            if (double.IsNaN(_residualHistory[_residualHistory.Length - 1]))
            {
                SetStatusToDiverged();
                return;
            }

            // Check if we are diverging and if so set the status
            if (IsDiverging())
            {
                SetStatusToDiverged();
            }
            else
            {
                SetStatusToRunning();
            }

            _lastIteration = iterationNumber;
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:68,代码来源:DivergenceStopCriterium.cs

示例5: DetermineStatus

        /// <summary>
        /// Determines the status of the iterative calculation based on the stop criteria stored
        /// by the current <see cref="IIterationStopCriterium"/>. Result is set into <c>Status</c> field.
        /// </summary>
        /// <param name="iterationNumber">The number of iterations that have passed so far.</param>
        /// <param name="solutionVector">The vector containing the current solution values.</param>
        /// <param name="sourceVector">The right hand side vector.</param>
        /// <param name="residualVector">The vector containing the current residual vectors.</param>
        /// <remarks>
        /// The individual stop criteria may internally track the progress of the calculation based
        /// on the invocation of this method. Therefore this method should only be called if the 
        /// calculation has moved forwards at least one step.
        /// </remarks>
        public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector)
        {
            if (iterationNumber < 0)
            {
                throw new ArgumentOutOfRangeException("iterationNumber");
            }

            if (solutionVector == null)
            {
                throw new ArgumentNullException("solutionVector");
            }

            if (residualVector == null)
            {
                throw new ArgumentNullException("residualVector");
            }

            if (solutionVector.Count != residualVector.Count)
            {
                throw new ArgumentException(Resources.ArgumentArraysSameLength);
            }

            if (_lastIteration >= iterationNumber)
            {
                // We have already stored the actual last iteration number
                // For now do nothing. We only care about the next step.
                return;
            }

            // Store the infinity norms of both the solution and residual vectors
            var residualNorm = residualVector.Norm(Double.PositiveInfinity);
            var solutionNorm = solutionVector.Norm(Double.PositiveInfinity);

            if (Double.IsNaN(solutionNorm.Real) || Double.IsNaN(residualNorm.Real))
            {
                SetStatusToFailed();
            }
            else
            {
                SetStatusToRunning();
            }

            _lastIteration = iterationNumber;
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:57,代码来源:FailureStopCriterium.cs

示例6: length

 protected static float length(Vector<float> v1)
 {
     return v1.Norm(2);
 }
开发者ID:JohanLarsson,项目名称:HlslEmulator,代码行数:4,代码来源:EmulatorBase.cs

示例7: DetermineStatus

        /// <summary>
        /// Determines the status of the iterative calculation based on the stop criteria stored
        /// by the current <see cref="IIterationStopCriterium"/>. Result is set into <c>Status</c> field.
        /// </summary>
        /// <param name="iterationNumber">The number of iterations that have passed so far.</param>
        /// <param name="solutionVector">The vector containing the current solution values.</param>
        /// <param name="sourceVector">The right hand side vector.</param>
        /// <param name="residualVector">The vector containing the current residual vectors.</param>
        /// <remarks>
        /// The individual stop criteria may internally track the progress of the calculation based
        /// on the invocation of this method. Therefore this method should only be called if the 
        /// calculation has moved forwards at least one step.
        /// </remarks>
        public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector)
        {
            if (iterationNumber < 0)
            {
                throw new ArgumentOutOfRangeException("iterationNumber");
            }

            if (solutionVector == null)
            {
                throw new ArgumentNullException("solutionVector");
            }

            if (sourceVector == null)
            {
                throw new ArgumentNullException("sourceVector");
            }
            
            if (residualVector == null)
            {
                throw new ArgumentNullException("residualVector");
            }

            if (solutionVector.Count != sourceVector.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength, "sourceVector");
            }

            if (solutionVector.Count != residualVector.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength, "residualVector");
            }

            // Store the infinity norms of both the solution and residual vectors
            // These values will be used to calculate the relative drop in residuals
            // later on.
            var residualNorm = residualVector.Norm(Double.PositiveInfinity);
            
            // Check the residuals by calculating:
            // ||r_i|| <= stop_tol * ||b||
            var stopCriterium = ComputeStopCriterium(sourceVector.Norm(Double.PositiveInfinity).Real);

            // First check that we have real numbers not NaN's.
            // NaN's can occur when the iterative process diverges so we
            // stop if that is the case.
            if (double.IsNaN(stopCriterium) || double.IsNaN(residualNorm.Real))
            {
                _iterationCount = 0;
                SetStatusToDiverged();
                return;
            }

            // ||r_i|| <= stop_tol * ||b||
            // Stop the calculation if it's clearly smaller than the tolerance
            var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1;
            if (residualNorm.Real.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude))
            {
                if (_lastIteration <= iterationNumber)
                {
                    _iterationCount = iterationNumber - _lastIteration;
                    if (_iterationCount >= _minimumIterationsBelowMaximum)
                    {
                        SetStatusToConverged();
                    }
                    else
                    {
                        SetStatusToRunning();
                    }
                }
            }
            else
            {
                _iterationCount = 0;
                SetStatusToRunning();
            }

            _lastIteration = iterationNumber;
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:90,代码来源:ResidualStopCriterium.cs

示例8: Solve

        /// <summary>
        /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
        /// solution vector and x is the unknown vector.
        /// </summary>
        /// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
        /// <param name="input">The solution vector, <c>b</c></param>
        /// <param name="result">The result vector, <c>x</c></param>
        public void Solve(Matrix matrix, Vector input, Vector result)
        {
            // If we were stopped before, we are no longer
            // We're doing this at the start of the method to ensure
            // that we can use these fields immediately.
            _hasBeenStopped = false;

            // Error checks
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (result.Count != input.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != matrix.RowCount)
            {
                throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
            }

            // Initialize the solver fields
            // Set the convergence monitor
            if (_iterator == null)
            {
                _iterator = Iterator.CreateDefault();
            }

            if (_preconditioner == null)
            {
                _preconditioner = new UnitPreconditioner();
            }

            _preconditioner.Initialize(matrix);

            var d = new DenseVector(input.Count);
            var r = new DenseVector(input);

            var uodd = new DenseVector(input.Count);
            var ueven = new DenseVector(input.Count);

            var v = new DenseVector(input.Count);
            var pseudoResiduals = new DenseVector(input);

            var x = new DenseVector(input.Count);
            var yodd = new DenseVector(input.Count);
            var yeven = new DenseVector(input);

            // Temp vectors
            var temp = new DenseVector(input.Count);
            var temp1 = new DenseVector(input.Count);
            var temp2 = new DenseVector(input.Count);

            // Initialize
            var startNorm = input.Norm(2);

            // Define the scalars
            double alpha = 0;
            double eta = 0;
            double theta = 0;

            var tau = startNorm;
            var rho = tau * tau;

            // Calculate the initial values for v
            // M temp = yEven
            _preconditioner.Approximate(yeven, temp);

            // v = A temp
            matrix.Multiply(temp, v);

            // Set uOdd
            v.CopyTo(ueven);

            // Start the iteration
            var iterationNumber = 0;
//.........这里部分代码省略.........
开发者ID:nrolland,项目名称:mathnet-numerics,代码行数:101,代码来源:TFQMR.cs

示例9: Compute

 public double Compute(Vector x, Vector y)
 {
     double dot = x.Dot(y);
     return dot / (System.Math.Pow(x.Norm(), 2) + System.Math.Pow(y.Norm(), 2) - dot);
 }
开发者ID:al-main,项目名称:CloudyBank,代码行数:5,代码来源:TanimotoCoefficient.cs

示例10: NIPALS

        static void NIPALS(Matrix X, int PCs, Matrix PCmatrix, Vector EigenValues)
        {

            //TODO:
            //Check that PCs<min(X.rows,X.columns)
            //Check that PCMatrix size is (X.columns, PCs) , i.e. (features, lower number of dimensions)
            //Change name of eigenvalues to something more appropriate
            //Check that eigenvalues vector passed in is of size PCs.


            //X is the zero-mean data matrix
            //E is the residual error after i itereations
            int i;
            //PCmatrix = new Matrix(PCs, X.ColumnCount, 0);
            //EigenValues = new Vector(PCs);
            Matrix E = X.Clone();
            Vector u = new Vector(E.RowCount);
            Vector v = new Vector(E.ColumnCount);
            Matrix E_transposed;
            int initialVector = 0;
            //convergence threshold
            const double threshold = 0.0000001;

            //from http://www.vias.org/tmdatanaleng/dd_nipals_algo.html
            for (i = 0; i < PCs; i++)
            {
                //printMatrix(E, "E");
                //1.    u := x(i) 	Select a column vector xi of the matrix X and copy it to the vector u
                //The vector must be such that the self-inner product is not zero 

                double ut_u = 0;
                Boolean valid = false;
                while (!valid && initialVector < E.ColumnCount)
                {
                    u = E.GetColumnVector(initialVector);
                    initialVector++;
                    if (u.ScalarMultiply(u) != 0)
                        valid = true;
                }
                if (!valid)
                    throw new Exception("Could not find " + PCs + " principal components");

                E_transposed = E.Clone();
                E_transposed.Transpose();
                //printMatrix(E_transposed, "E transposed");

                //int step = 1;
                double error = 1;
                while (error > threshold)
                {
                    //  Console.Out.WriteLine("PC " + (i+1) + " Step : " + step++);

                    //2. 	v := (X'u)/(u'u) 	Project the matrix X onto u in order to find the corresponding loading vs
                    //Console.Out.WriteLine("u: " + u.ToColumnMatrix().ToString());
                    ut_u = u.ScalarMultiply(u);
                    if (ut_u == 0)
                        throw new Exception("Principal component results in complex answer");

                    //Console.Out.WriteLine("u'u: " + ut_u);

                    Matrix v_prime = E_transposed.Multiply(u.ToColumnMatrix());
                    //printMatrix(v_prime, "v prime");
                    v = v_prime.GetColumnVector(0) / ut_u;
                    //Console.Out.WriteLine("v: " + v.ToString());

                    //3.    v := v/|v| 	Normalize the loading vector v to length 1
                    v = v.Normalize();
                    //v = v / v.Norm();
                    //Console.Out.WriteLine("v after normalization: " + v.ToString());


                    //4.1 	u_old := u  Store the score vector u into uold 
                    Vector u_old = u.Clone();
                    //Console.Out.WriteLine("u old: " + u_old.ToString());

                    //4.2      u := (Xp)/(v'v) 	and project the matrix X onto v in order to find corresponding score vector u
                    Matrix u_prime = E.Multiply(v.ToColumnMatrix());
                    //Console.Out.WriteLine("u_prime: ");
                    //printMatrix(u_prime);

                    Vector u_primeColumn = u_prime.GetColumnVector(0);
                    //Console.Out.WriteLine("u_primeColumn: " + u_primeColumn.ToString());

                    double v_v = v.ScalarMultiply(v);

                    //Console.Out.WriteLine("v_v: " + v_v);

                    u = u_primeColumn / v_v;
                    //Console.Out.WriteLine("new u: " + u.ToString());

                    //5. 	d := uold-u 	In order to check for the convergence of the process 
                    //calculate the difference vector d as the difference between the previous scores
                    //and the current scores. If the difference |d| is larger than a pre-defined threshold,
                    //then return to step 2.
                    Vector d = u_old.Subtract(u);
                    //Console.Out.WriteLine("d: " + d.ToString());
                    error = d.Norm();
                    //Console.Out.WriteLine("Error: " + error.ToString());

                }
//.........这里部分代码省略.........
开发者ID:ridhi29,项目名称:dataminingproject,代码行数:101,代码来源:NIPALS_PCA.cs

示例11: Kop1

 /// <summary>
 ///     Критерий окончания поиска - норма вектора меньше епсилона и
 /// </summary>
 /// <param name="d"></param>
 /// <returns></returns>
 protected bool Kop1(Vector<double> d)
 {
     return IterationCount <= _maxIterations && !(d.Norm(1) < Eps);
 }
开发者ID:OlegFilimonov,项目名称:optimisation,代码行数:9,代码来源:OptimisationMethod.cs

示例12: Vector_Norm_returns_zero_for_zero_vector

 public void Vector_Norm_returns_zero_for_zero_vector()
 {
     Vector v = new Vector(0.0f, 0.0f, 0.0f);
       float actual = v.Norm();
       Assert.AreEqual(0.0f, actual, EPSILON);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:6,代码来源:VectorTests.cs

示例13: Vector_Norm_returns_correctly_for_pythagorean_quadruple_with_negatives_3

 public void Vector_Norm_returns_correctly_for_pythagorean_quadruple_with_negatives_3()
 {
     Vector v = new Vector(-3.0f, 16.0f, -24.0f);
       float actual = v.Norm();
       Assert.AreEqual(29.0f, actual, EPSILON);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:6,代码来源:VectorTests.cs

示例14: Vector_Norm_returns_correctly_for_pythagorean_quadruple_2

 public void Vector_Norm_returns_correctly_for_pythagorean_quadruple_2()
 {
     Vector v = new Vector(4.0f, 8.0f, 19.0f);
       float actual = v.Norm();
       Assert.AreEqual(21.0f, actual, EPSILON);
 }
开发者ID:EddPorter,项目名称:RayManCS,代码行数:6,代码来源:VectorTests.cs


注:本文中的Vector.Norm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。