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


Java Vector.unitVector方法代码示例

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


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

示例1: estimateEigenvalue

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Finds the eigenvalue associated with the given Matrix and eigenvector.
 * This is found by noting that the definition of an eigensystem is:
 * lamba*v=A*v.  Therefore, the absolute value of the eigenvalue will be 
 * norm2(A*v), but determining the sign of the eigenvalue takes some minor
 * computation (which we do, so this method works with negative
 * eigenvalues).
 *
 * @param A 
 * Matrix to estimate the eigenvalue of.  May have negative, repeated, 
 * positive, or zero eigenvalues
 * @param v 
 * Eigenvector associated with the unknown eigenvalue
 * @return 
 * Eigenvalue associated with the eigenvector and Matrix
 */
public static double estimateEigenvalue(
    final Matrix A,
    final Vector v )
{
    // Definition of eigenvalue/eigenvector: lamba*ei = A*ei
    Vector vunit = v.unitVector();
    Vector vlambda = A.times( vunit );
    double lambda = vlambda.norm2();

    if (lambda != 0.0)
    {
        Vector vunithat = vlambda.scale( 1.0 / lambda );
        double dp = vunithat.minus( vunit ).norm2();
        double dn = vunithat.plus( vunit ).norm2();
        if (dn < dp)
        {
            lambda *= -1.0;
        }
    }
    return lambda;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:38,代码来源:EigenvectorPowerIteration.java

示例2: testNormalizeWeights

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Test of normalizeWeights method, of class UnitTermWeightNormalizer.
 */
@Test
public void testNormalizeWeights()
{
    Random random = new Random();
    UnitTermWeightNormalizer instance =
        new UnitTermWeightNormalizer();
    
    int dimensionality = 10;
    Vector weights = VectorFactory.getDefault().createUniformRandom(
        dimensionality, 0.0, 1.0, random);
    Vector expected = weights.unitVector();
    instance.normalizeWeights(weights, null, null);
    assertEquals(expected, weights);

    weights.zero();
    expected = weights.clone();
    instance.normalizeWeights(weights, null, null);
    assertEquals(expected, weights);

    weights.setElement(0, 1.0);
    expected = weights.clone();
    instance.normalizeWeights(weights, null, null);
    assertEquals(expected, weights);
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:28,代码来源:UnitTermWeightNormalizerTest.java

示例3: estimateEigenvector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
     * Estimates the eigenvector corresponding to the largest magnitude 
     * eigenvalue.  The eigenvector will be of unit length, unless the
     * input Matrix is all zeros, in which case the method will return
     * an all-zero Vector.  Please note that all eigenvectors are unique to
     * a direction.  That is, sometimes eigenvectors may be a scale factor 
     * of -1.0 to eigenvectors found by other approaches or initial conditions.
     * <BR><BR>
     * This method is appropriate for sparse matrix problems.
     * 
     * 
     * @return Eigenvector corresponding to the largest magnitude eigenvalue.
     * @param initial 
     * Initial estimate of the eigenvector. This is generally a uniform 
     * (constant nonzero) Vector.
     * @param A The matrix to estimate the eigenvectors for. It must be symmetric.
     *      It will be modified by the algorithm.
     * @param stoppingThreshold The stopping threshold for the power iteration algorithm. The 
     *      algorithm will stop its computation of an eigenvector when the
     * @param maxIterations The maximum number of iterations for the power iteration algorithm.
     */
// TODO: Implement the AnytimeAlgorithm interface here.  --krdixon, 2009-07-02
    public static Vector estimateEigenvector(
        final Vector initial,
        final Matrix A,
        final double stoppingThreshold,
        final int maxIterations )
    {
        // This is the brain-dead algorithm called "Power Iteration"
        Vector v = initial.unitVector();

        double normChange;
        int iteration = 0;
        boolean keepGoing = true;
        while (keepGoing)
        {
            final Vector vPrevious = v;
            v = A.times( v );
            v.unitVectorEquals();
            normChange = v.minus( vPrevious ).norm2();
            iteration++;

            if ((normChange <= stoppingThreshold) || (iteration >= maxIterations))
            {
                keepGoing = false;
            }
        }

        return v;
    }
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:51,代码来源:EigenvectorPowerIteration.java


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