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


Java Vector.getElement方法代码示例

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


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

示例1: setParameters

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Setter for parameters
 * @param parameters
 * Parameters of the Dirichlet distribution, must be at least 2-dimensional
 * and each element must be positive.
 */
public void setParameters(
    final Vector parameters)
{

    final int N = parameters.getDimensionality();

    if( N < 2 )
    {
        throw new IllegalArgumentException( "Dimensionality must be >= 2" );
    }

    for( int i = 0; i < N; i++ )
    {
        if( parameters.getElement(i) <= 0.0 )
        {
            throw new IllegalArgumentException(
                "All parameter elements must be > 0.0" );
        }
    }
    this.parameters = parameters;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:28,代码来源:MultivariatePolyaDistribution.java

示例2: logEvaluate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public double logEvaluate(
    final Vector input)
{
    Vector xn = input.scale( 1.0 / input.norm1() );

    Vector a = this.getParameters();
    input.assertSameDimensionality( a );

    double logsum = 0.0;
    final int K = a.getDimensionality();
    for( int i = 0; i < K; i++ )
    {
        double xi = xn.getElement(i);
        if( (xi <= 0.0) || (1.0 <= xi) )
        {
            throw new IllegalArgumentException(
                "Expected all inputs to be (0.0,infinity): " + input );
        }
        double ai = a.getElement(i);
        logsum += (ai-1.0) * Math.log( xi );
    }

    logsum -= MathUtil.logMultinomialBetaFunction( a );
    return logsum;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:27,代码来源:DirichletDistribution.java

示例3: testGetSteadyStateDistribution

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Test of getSteadyStateDistribution method, of class MarkovChain.
 */
public void testGetSteadyStateDistribution()
{
    System.out.println("getSteadyStateDistribution");
    MarkovChain instance = this.createInstance();

    Vector phat = instance.getSteadyStateDistribution();

    EigenDecompositionRightMTJ evd = EigenDecompositionRightMTJ.create(
        (DenseMatrix) instance.getTransitionProbability() );

    Vector p = evd.getEigenVectorsRealPart().getColumn(0);
    // We do the manual sum (instead of norm1) in case the EVD found
    // the negative of the eigenvector.
    double sum = 0.0;
    for( int i = 0; i < p.getDimensionality(); i++ )
    {
        sum += p.getElement(i);
    }
    p.scaleEquals( 1.0/sum );

    System.out.println( "P: " + p );
    System.out.println( "Phat: " + phat );
    assertTrue( p.equals( phat, TOLERANCE ) );
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:28,代码来源:MarkovChainTest.java

示例4: differentiate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public Vector differentiate( Vector input )
{
    this.GRADIENT_EVALUATIONS++;            
    Vector gradient = VectorFactory.getDefault().createVector(
        input.getDimensionality() );
    for( int i = 0; i < input.getDimensionality()-1; i++ )
    {
        double xi = input.getElement( i );
        double xip1 = input.getElement( i+1 );
        double gi = -2.0*(1.0-xi) - 400.0*(xip1-xi*xi)*xi;
        double gip1 = 200.0*(xip1-xi*xi);
        gradient.setElement( i, gradient.getElement(i) + gi );
        gradient.setElement( i+1, gradient.getElement(i+1) + gip1 );
    }
    
    return gradient;
    
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:19,代码来源:FunctionMinimizerTestHarness.java

示例5: setInitialProbability

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Setter for initialProbability
 * @param initialProbability
 * Initial probability Vector over the states.  Each entry must be
 * nonnegative and the Vector must sum to 1.
 */
public void setInitialProbability(
    Vector initialProbability)
{
    final int k = initialProbability.getDimensionality();
    double sum = 0.0;
    for( int i = 0; i < k; i++ )
    {
        double value = initialProbability.getElement(i);
        if( value < 0.0 )
        {
            throw new IllegalArgumentException(
                "Initial Probabilities must be >= 0.0" );
        }
        sum += value;
    }
    if( sum != 1.0 )
    {
        initialProbability.scaleEquals(1.0/sum);
    }
    this.initialProbability = initialProbability;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:28,代码来源:MarkovChain.java

示例6: getSteadyStateDistribution

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Returns the steady-state distribution of the state distribution.
 * This is also the largest eigenvector of the transition-probability
 * matrix, which has an eigenvalue of 1.
 * @return
 * Steady-state probability distribution of state distribution.
 */
public Vector getSteadyStateDistribution()
{
    final double tolerance = 1e-5;
    final int maxIterations = 100;
    Vector p = EigenvectorPowerIteration.estimateEigenvector(
        this.initialProbability, this.transitionProbability,
        tolerance, maxIterations );

    // We do the manual sum (instead of norm1) in case the EVD found
    // the negative of the eigenvector.
    double sum = 0.0;
    for( int i = 0; i < p.getDimensionality(); i++ )
    {
        sum += p.getElement(i);
    }
    p.scaleEquals( 1.0/sum );
    return p;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:26,代码来源:MarkovChain.java

示例7: setParameters

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Setter for parameters
 * @param parameters
 * Parameters of the Dirichlet distribution, must be at least 2-dimensional
 * and each element must be positive.
 */
public void setParameters(
    final Vector parameters)
{

    final int N = parameters.getDimensionality();

    if( N < 2 )
    {
        throw new IllegalArgumentException( "Dimensionality must be >= 2" );
    }
    
    for( int i = 0; i < N; i++ )
    {
        if( parameters.getElement(i) <= 0.0 )
        {
            throw new IllegalArgumentException(
                "All parameter elements must be > 0.0" );
        }
    }

    this.parameters = parameters;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:29,代码来源:DirichletDistribution.java

示例8: euclideanDistanceSquared

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public double euclideanDistanceSquared(
    Vector other )
{
    this.assertSameDimensionality( other );
    
    double sumSquared = 0.0;
    double[] values = this.getArray();
    int M = this.getDimensionality();
    for( int i = 0; i < M; i++ )
    {
        double delta = values[i] - other.getElement( i );
        sumSquared += delta*delta;
    }
    
    return sumSquared;
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:18,代码来源:DenseVector.java

示例9: normalise

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
private void normalise(Vector mean) {
	for (final double[] data : this) {
		for (int i = 0; i < data.length; i++) {
			data[i] -= mean.getElement(i);
		}
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:8,代码来源:WineDataset.java

示例10: convertFromVector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public void convertFromVector(
    final Vector parameters)
{
    parameters.assertDimensionalityEquals(1);
    this.value = (long) parameters.getElement(0);
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:8,代码来源:MutableLong.java

示例11: convertToVector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Converts a given list of terms to a vector by counting the occurrence of
 * each term.
 *
 * @param   terms
 *      The terms to count.
 * @param   termIndex
 *      The term index to use to map terms to their vector indices.
 * @param   vectorFactory
 *      The vector factory to use to create the vector.
 * @return
 *      The bag-of-words vector representation of the terms, which is the
 *      count of how many times each term occurs in the document.
 */
public static Vector convertToVector(
    final Iterable<? extends Termable> terms,
    final TermIndex termIndex,
    final VectorFactory<?> vectorFactory)
{
    // Create the vector to store the result.
    final Vector result = vectorFactory.createVector(
        termIndex.getTermCount());

    for (Termable termable : terms)
    {
        final Term term = termable.asTerm();
        int index = termIndex.getIndex(term);

        if (index >= 0)
        {
            final double count = result.getElement(index);
            result.setElement(index, count + 1);
        }
        // TODO: Ideally we would somehow handle all of the "unknown"
        // elements also. Perhaps by using the first vector element for
        // unknowns.
    }

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

示例12: applyUpdate

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Apply the update for the Projectron. This function is put here so that
 * it can be overriden by the Projectron++ implementation, which also
 * enforces a margin.
 *
 * @param   target
 *      The target to update.
 * @param   input
 *      The input value.
 * @param   actual
 *      The actual label.
 * @param   margin
 *      The margin on the input.
 * @param   kernelInputInput
 *      The kernel function k(input, input).
 * @param   delta
 *      The value delta computed by the Projectron.
 * @param   d
 *      The vector d that represents the coefficients for the projection.
 */
protected void applyUpdate(
    final DefaultKernelBinaryCategorizer<InputType> target,
    final InputType input,
    final double actual,
    final double margin,
    final double kernelInputInput,
    final double delta,
    final Vector d)
{
    if (delta <= this.getEta())
    {
        // Get the supports.
        final int size = target.getExampleCount();
        
        // Use the projection of the example point onto the others.
        for (int i = 0; i < size; i++)
        {
            final DefaultWeightedValue<InputType> support = target.get(i);
            final double oldWeight = support.getWeight();
            final double newWeight = oldWeight + d.getElement(i) * actual;
            support.setWeight(newWeight);
        }
    }
    else
    {
        // Add a new support.
        target.add(input, actual);
    }
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:50,代码来源:Projectron.java

示例13: convertFromVector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public void convertFromVector(
    Vector parameters)
{
    parameters.assertDimensionalityEquals( this.getDistributionCount() );
    for( int k = 0; k < parameters.getDimensionality(); k++ )
    {
        this.priorWeights[k] = parameters.getElement(k);
    }
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:11,代码来源:MultivariateMixtureDensityModel.java

示例14: convertFromVector

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public void convertFromVector(
    final Vector parameters )
{
    parameters.assertDimensionalityEquals(2);
    double a = parameters.getElement(0);
    double b = parameters.getElement(1);

    this.setMinSupport( Math.min(a,b) );
    this.setMaxSupport( Math.max(a, b) );
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:12,代码来源:UniformDistribution.java

示例15: testComputeParameterGradient

import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
 * Test of computeParameterGradient method, of class FactorizationMachine.
 */
@Test
public void testComputeParameterGradient()
{
    VectorFactory<?> vf = VectorFactory.getSparseDefault();
    FactorizationMachine instance = new FactorizationMachine();
    Vector input = vf.createVector(0);
    Vector result = instance.computeParameterGradient(input);
    assertEquals(1, result.getDimensionality());
    assertEquals(1.0, result.getElement(0), 0.0);
    
    int d = 3;
    instance.setWeights(VectorFactory.getDenseDefault().createVector(d));
    input = vf.createUniformRandom(d, -10, 10, random);
    result = instance.computeParameterGradient(input);
    assertEquals(1 + d, result.getDimensionality());
    assertEquals(1.0, result.getElement(0), 0.0);
    assertEquals(input, result.subVector(1, d));
    
    int k = 2;
    instance.setFactors(MatrixFactory.getDenseDefault().createUniformRandom(k, d, -10, 10, random));
    input = vf.createUniformRandom(d, -10, 10, random);
    result = instance.computeParameterGradient(input);
    assertEquals(10, result.getDimensionality());
    assertEquals(1.0, result.getElement(0), 0.0);
    assertEquals(input, result.subVector(1, d));
    
    Vector factorGradients = result.subVector(d + 1, d + d * k);
    for (int f = 0; f < k; f++)
    {
        for (int l = 0; l < d; l++)
        {
            double actual = factorGradients.getElement(f * d + l);
            
            double expected = 0.0;
            for (int j = 0; j < d; j++)
            {
                if (j != l)
                {
                    double xl = input.getElement(l);
                    expected += xl * instance.getFactors().getElement(f, j) * input.getElement(j);
                }
            }
            assertEquals(expected, actual, epsilon);
        }
    }
}
 
开发者ID:algorithmfoundry,项目名称:Foundry,代码行数:50,代码来源:FactorizationMachineTest.java


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