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


Java Vector.norm2方法代码示例

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


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

示例1: evaluate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Evaluate the this function on the provided cluster.
 *
 * @param cluster The cluster to calculate the function on.
 * @return The result of applying this function to the cluster.
 */
public double evaluate(NormalizedCentroidCluster<V> cluster)
{
    double total = 1.0;

    Vector centroid = cluster.getCentroid().convertToVector();
    Vector normalizedCentroid
        = cluster.getNormalizedCentroid().convertToVector();

    //if centroid is 0.0, cosine measure returns 0.0
    if (centroid.norm2() != 0.0)
    {
        total -= centroid.dotProduct(normalizedCentroid) / centroid.norm2();
    }

    total *= cluster.getMembers().size();

    return total;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:25,代码来源:WithinNormalizedCentroidClusterCosineDivergence.java

示例2: testMeasure

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Test of measure method, of class KalmanFilter.
 */
public void testMeasure()
{
    System.out.println("measure");
    KalmanFilter instance = this.createInstance();
    final int N = instance.getModel().getOutputDimensionality();
    final double t = 10.0;
    Vector measurement = VectorFactory.getDefault().createVector(N,t);

    Vector target = VectorFactory.getDefault().copyValues(t/2,t/2);
    MultivariateGaussian belief = instance.createInitialLearnedObject();
    double lastDelta, delta = Double.POSITIVE_INFINITY;
    for( int i = 0; i < 100; i++ )
    {
        lastDelta = delta;
        instance.measure(belief, measurement);
        Vector err = belief.getMean().minus( target );
        delta = err.norm2();
        assertTrue( delta < lastDelta );
    }

}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:25,代码来源:KalmanFilterTest.java

示例3: 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

示例4: test_backtrack

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public boolean test_backtrack(Matrix W, Matrix grad, Matrix prox, double eta){
	Matrix tmp = prox.clone();
       tmp.minusEquals(W);
       Vector tmpvec = tmp.getColumn(0);
	return (
		eval(prox) <= eval(W) + grad.getColumn(0).dotProduct(tmpvec) + 0.5*eta*tmpvec.norm2());
	
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:9,代码来源:LossFunction.java

示例5: initialize

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
protected void initialize(
    final LinearBinaryCategorizer target,
    final Vector input,
    final boolean actualCategory)
{
    final double norm = input.norm2();
    if (norm != 0.0)
    {
        final Vector weights = this.getVectorFactory().copyVector(input);
        final double actual = actualCategory ? +1.0 : -1.0;
        weights.scaleEquals(actual / input.norm2());
        target.setWeights(weights);
    }
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:16,代码来源:OnlineBinaryMarginInfusedRelaxedAlgorithm.java

示例6: initializeAlgorithm

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
protected boolean initializeAlgorithm()
{
    // Figure out if there is enough data to run the algorithm.
    if (CollectionUtil.isEmpty(this.data))
    {
        // Can't run the algorithm on empty data.
        return false;
    }

    this.dataSize = this.data.size();
    this.dataList = CollectionUtil.asArrayList(this.data);
    this.dimensionality = DatasetUtil.getInputDimensionality(this.data);
    this.dataSampleSize = Math.min(dataSize, this.sampleSize);

    // Compute a vector to store the update that gets reused between steps.
    final VectorFactory<?> vectorFactory = VectorFactory.getDenseDefault();
    this.update = vectorFactory.createVector(this.dimensionality);

    // Create initial random weights.
    final double lambda = this.regularizationWeight;
    final double sqrtLambda = Math.sqrt(lambda);
    final double initializationRange =
        1.0 / (this.dimensionality * sqrtLambda);
    final Vector initialWeights =
        vectorFactory.createUniformRandom(this.dimensionality,
            -initializationRange, initializationRange, this.random);
    if (initialWeights.norm2() < (1.0 / sqrtLambda))
    {
        initialWeights.unitVectorEquals();
        initialWeights.scaleEquals(1.0 / sqrtLambda);
    }

    this.result = new LinearBinaryCategorizer(initialWeights, 0.0);

    // Compute a vector to store the update that gets reused between steps.
    this.update = vectorFactory.createVector(this.dimensionality);

    return true;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:41,代码来源:PrimalEstimatedSubGradient.java

示例7: step

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
protected boolean step()
{
    SumSquaredErrorCostFunction.Cache cost = 
        SumSquaredErrorCostFunction.Cache.compute( this.getResult(), this.getData() );
    
    Vector lastParameters = this.lineFunction.getVectorOffset();
    Vector direction = cost.JtJ.solve(cost.Jte);
    double directionNorm = direction.norm2();
    if( directionNorm > STEP_MAX )
    {
        direction.scaleEquals( STEP_MAX / directionNorm );
    }
    
    this.lineFunction.setDirection( direction );
    InputOutputPair<Vector,Double> result = this.getLineMinimizer().minimizeAlongDirection(
        this.lineFunction, cost.parameterCost, cost.Jte );
    this.lineFunction.setVectorOffset( result.getInput() );
    
    this.setResultCost( result.getOutput() );
    
    Vector delta = result.getInput().minus( lastParameters );
    
    this.getResult().convertFromVector( result.getInput() );

    return !MinimizationStoppingCriterion.convergence( 
        result.getInput(), result.getOutput(), cost.Jte, delta, this.getTolerance() );
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:29,代码来源:GaussNewtonAlgorithm.java

示例8: testPerturb

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
     * Test of perturb method, of class 
     * gov.sandia.isrc.learning.vector.VectorizablePerturber.
     */
    public void testPerturb() 
    {    
        System.out.println("perturb");
        
        Vector initialParameters = VectorFactory.getDefault().createUniformRandom( 2, -10, 10, random );
        
        int N = 100;
        ArrayList<Vector> results = new ArrayList<Vector>();
        for( int i = 0; i < N; i++ )
        {
            Vector r = VectorFactory.getDefault().copyValues(
                random.nextGaussian(), random.nextGaussian() );
            Vectorizable s = this.perturber.perturb( r );
            results.add( s.convertToVector() );
        }
        
        MultivariateGaussian estimate =
            MultivariateGaussian.MaximumLikelihoodEstimator.learn( results, 0.0 );

        Matrix diffCov = this.covariance.minus( estimate.getCovariance() );
        Vector diffMean = initialParameters.minus( estimate.getMean() );
        double normMean = diffMean.norm2();
        double normCov = diffCov.normFrobenius();
        double testMax = 1.0 / Math.log( N );
        
        System.out.println("NormMean = " + normMean + ", testMax = " + testMax);
//        assertTrue( normMean <= testMax );
        
        System.out.println("NormCov = " + normCov + ", testMax = " + testMax);
//        assertTrue( normCov <= testMax );
    }
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:36,代码来源:VectorizablePerturberTest.java

示例9: testPerturbVector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
     * Test of perturbVector method, of class 
     * gov.sandia.isrc.learning.vector.VectorizablePerturber.
     */
    public void testPerturbVector() 
    {
        System.out.println("perturbVector");
        
        Vector initialParameters = VectorFactory.getDefault().createUniformRandom( 2, -10, 10, random );
        
        int N = 100;
        ArrayList<Vector> results = new ArrayList<Vector>();
        for( int i = 0; i < N; i++ )
        {
            Vector r = initialParameters.clone();
            Vector s = this.perturber.perturbVector( r );
            results.add( s );
        }
        
        MultivariateGaussian estimate =
            MultivariateGaussian.MaximumLikelihoodEstimator.learn( results, 0.0 );

        Matrix diffCov = this.covariance.minus( estimate.getCovariance() );
        Vector diffMean = initialParameters.minus( estimate.getMean() );
        double normMean = diffMean.norm2();
        double normCov = diffCov.normFrobenius();
        double testMax = 1.0 / Math.log( N );
        
        System.out.println("NormMean = " + normMean + ", testMax = " + testMax);
        assertTrue( normMean <= testMax );
        
        System.out.println("NormCov = " + normCov + ", testMax = " + testMax);
//        assertTrue( normCov <= testMax );
    }
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:35,代码来源:VectorizablePerturberTest.java

示例10: evaluate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public double evaluate(
    Vectorizable first,
    Vectorizable second)
{
    NUM_EVALS++;
    Vector delta = first.convertToVector().minus(
        second.convertToVector());
    return delta.norm2();
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:10,代码来源:KDTreeTest.java

示例11: update

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public void update(
    final LinearBinaryCategorizer target,
    final Vector input,
    final boolean label)
{
    Vector weights = target.getWeights();
    if (weights == null)
    {
        // This is the first example, so initialize the weight vector.
        weights = this.getVectorFactory().createVector(
            input.getDimensionality());
        target.setWeights(weights);
    }
    // else - Use the existing weights.

    // Predict the output as a double (negative values are false, positive
    // are true).
    final double prediction = target.evaluateAsDouble(input);
    final double actual = label ? +1.0 : -1.0;
    final double margin = prediction * actual;


    boolean error = false;
    if (margin <= 0.0)
    {
        // An actual mistake: Use the standard perceptron update rule.
        error = true;
    }
    else
    {
        final double weightNorm = weights.norm2();
        if (margin / weightNorm <= this.getRadius())
        {
            // This is one way to implement this. However, it is not as
            // efficient as the following way with sparse vectors, which
            // is based on the derivation:
            // final Vector change = weights.scale(
            //     -actual * this.getRadius() / weightNorm);
            // change.plusEquals(input);
            // change.scaleEquals(actual);
            // weights.plusEquals(change);

            final double scale = 1.0 - this.getRadius() / weightNorm;
            weights.scaleEquals(scale);
            error = true;
        }
        // else - No margin mistake change.
    }

    if (error)
    {
        if (label)
        {
            weights.plusEquals(input);
        }
        else
        {
            weights.minusEquals(input);
        }
    }
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:63,代码来源:Ballseptron.java

示例12: createCluster

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public NormalizedCentroidCluster<Vectorizable> createCluster(
    final Collection<? extends Vectorizable> members)
{
    if (members.isEmpty())
    {
        // No members to create the cluster from.
        return new NormalizedCentroidCluster<>(null, null, members);
    }

    // We are going to create the centroid of the cluster.
    Vectorizable centroid = null;
    Vector data = null;
    Vectorizable normalizedCentroid = null;
    Vector normalizedData = null;
    for (Vectorizable member : members)
    {
        Vector memberVector = member.convertToVector();
        if (data == null)
        {
            centroid = member.clone();
            data = memberVector.clone();
            normalizedCentroid = member.clone();
            normalizedData = memberVector.norm2() != 0.0
                ? memberVector.scale(1.0 / memberVector.norm2())
                : memberVector;
        }
        else
        {
            data.plusEquals(memberVector);
            if (memberVector.norm2() != 0.0)
            {
                normalizedData.plusEquals(memberVector.scale(1.0
                    / memberVector.norm2()));
            }
        }
    }

    data.scaleEquals(1.0 / (double) members.size());
    normalizedData.scaleEquals(1.0 / (double) members.size());
    centroid.convertFromVector(data);
    normalizedCentroid.convertFromVector(normalizedData);
    return new NormalizedCentroidCluster<>(centroid,
        normalizedCentroid, members);
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:46,代码来源:NormalizedCentroidClusterCreator.java

示例13: step

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
protected boolean step()
{
            
    // These negatives are to compensate because the derivative is the
    // negative of the error.  Since we're computing the derivative, but
    // the descent direction is the negative of the gradient, we need to
    // scale the matrices by -1.0
    Matrix JtJpI = this.bestParametersCost.JtJ.scale( -1.0 );
    Vector Jte = this.bestParametersCost.Jte;
    
    int M = JtJpI.getNumRows();
    for( int i = 0; i < M; i++ )
    {
        // Again, the damping factor is subtracted to compensate for the
        // negative between gradient and direction
        double v = JtJpI.getElement(i, i);
        JtJpI.setElement(i, i, v - this.getDampingFactor() );
    }
    
    // This is the ridge-regression (Tikhonov regularization) step to solve
    // for the parameter change
    Vector trialParameters = JtJpI.solve(Jte);
    trialParameters.plusEquals(this.bestParameters);
    
    // If the trial parameters reduce the cost, then accept them
    this.getResult().convertFromVector( trialParameters );
    SumSquaredErrorCostFunction.Cache trialCost = 
        SumSquaredErrorCostFunction.Cache.compute( this.getResult(), this.getData() ); 
    
    if( trialCost.parameterCost < this.bestParametersCost.parameterCost )
    {
        this.iterationsWithoutImprovement = 0;
        this.dampingFactor /= this.dampingFactorDivisor;
        this.bestParameters = trialParameters;
        
        // Test to see if we're done
        double delta = trialParameters.norm2() *
            (this.bestParametersCost.parameterCost - trialCost.parameterCost);
            
        this.bestParameters = trialParameters;
        this.bestParametersCost = trialCost;
        
        this.setResultCost( this.bestParametersCost.parameterCost );
        
        if( delta < this.getTolerance() )
        {
            return false;
        }
        
    }
    
    // The trial parameters aren't better than the best parameters,
    // so increase the regularization damping factor
    else
    {
        this.dampingFactor *= this.dampingFactorDivisor;
        this.iterationsWithoutImprovement++;
    }
    
    if( this.iterationsWithoutImprovement > this.getMaxIterationsWithoutImprovement() )
    {
        return false;
    }
    
    return true;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:68,代码来源:LevenbergMarquardtEstimation.java

示例14: evaluate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public Double evaluate(
    Vector input )
{
    NUM_EVALS++;
    return input.norm2();
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:7,代码来源:LineMinimizerTestHarness.java

示例15: evaluate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public Double evaluate(Vector input)
{
    this.FUNCTION_EVALUATIONS++;
    return input.norm2();
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:6,代码来源:FunctionMinimizerTestHarness.java


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