本文整理汇总了Java中gov.sandia.cognition.math.matrix.Vector.scale方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.scale方法的具体用法?Java Vector.scale怎么用?Java Vector.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gov.sandia.cognition.math.matrix.Vector
的用法示例。
在下文中一共展示了Vector.scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: testSetLocalApproximator
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of setLocalApproximator method, of class LocallyWeightedFunction.
*/
public void testSetLocalApproximator()
{
System.out.println( "Function.setLocalApproximator" );
double r = 1.0;
LocallyWeightedFunction<Vector, Vector> instance = this.createFunctionInstance();
Vector input = VectorFactory.getDefault().createUniformRandom( NUM_DIM, -r, r, random );
Vector output = instance.evaluate( input );
Evaluator<? super Vector, ? extends Vector> f = instance.getLocalApproximator();
assertNotNull( f );
Vector input2 = input.scale( Math.random() );
Vector output2 = instance.evaluate( input2 );
Evaluator<? super Vector, ? extends Vector> f2 = instance.getLocalApproximator();
assertNotNull( f2 );
assertNotSame( f2, f );
Vector outputAgain = instance.evaluate( input );
assertEquals( output, outputAgain );
assertNotSame( f, instance.getLocalApproximator() );
}
示例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;
}
示例4: testConvertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of convertFromVector method, of class gov.sandia.isrc.learning.util.function.FeedforwardNeuralNetwork.
*/
public void testConvertFromVector()
{
System.out.println("convertFromVector");
FeedforwardNeuralNetwork instance = this.createRandom();
Vector p1 = instance.convertToVector();
FeedforwardNeuralNetwork clone = instance.clone();
Vector p2 = clone.convertToVector();
assertEquals(p1, p2);
Vector p3 = p1.scale( this.random.nextDouble() );
assertFalse(p3.equals(p1));
instance.convertFromVector(p3);
Vector p4 = instance.convertToVector();
assertEquals(p3, p4);
}
示例5: getFutureStateDistribution
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Simulates the Markov chain into the future, given the transition Matrix
* and the given current state-probability distribution, for the
* given number of time steps into the future.
* @param current
* Current distribution of probabilities of the various states.
* @param numSteps
* Number of steps into the future to simulate.
* @return
* State-probability distribution for numSteps into the future, starting
* from the given state-probability distribution.
*/
public Vector getFutureStateDistribution(
Vector current,
int numSteps )
{
Vector predicted = current;
for( int n = 0; n < numSteps; n++ )
{
predicted = this.transitionProbability.times( predicted );
}
return predicted.scale( 1.0/predicted.norm1() );
}
示例6: evaluate
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Evaluates the Dirichlet PDF about the given input. Note that we
* normalize the given input by its L1 norm to ensure that its entries
* sum to 1.
* @param input
* Input to consider, automatically normalized by its L1 norm without
* side-effect.
* @return
* Dirichlet PDF evaluated about the given (unnormalized) input.
*/
@Override
public Double evaluate(
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 Math.exp(logsum);
}
示例7: testConvertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of convertFromVector method, of class AutoRegressiveMovingAverageFilter.
*/
public void testConvertFromVector()
{
System.out.println( "convertFromVector" );
Vector a = VectorFactory.getDefault().copyValues( -1.0, 2.0 );
Vector b = VectorFactory.getDefault().copyValues( 3.0, -2.0, 1.0 );
AutoRegressiveMovingAverageFilter instance =
new AutoRegressiveMovingAverageFilter( a, b );
Vector result = instance.convertToVector();
Vector r2 = result.scale( random.nextGaussian() );
instance.convertFromVector( r2 );
Vector r2hat = instance.convertToVector();
assertNotSame( r2, r2hat );
assertEquals( r2, r2hat );
try
{
instance.convertFromVector( a.stack( a ) );
fail( "Wrong dimension!" );
}
catch (Exception e)
{
System.out.println( "Good: " + e );
}
}
示例8: testClone
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of clone method, of class gov.sandia.isrc.learning.util.function.FeedforwardNeuralNetwork.
*/
public void testClone()
{
System.out.println("clone");
FeedforwardNeuralNetwork instance = new FeedforwardNeuralNetwork(1, 2, 3, new AtanFunction(1.0));
Vector p = instance.convertToVector();
Vector p2 = VectorFactory.getDefault().createUniformRandom(p.getDimensionality(), -10.0, 10.0, random);
instance.convertFromVector(p2);
System.out.println("Neural Net:\n" + instance);
FeedforwardNeuralNetwork clone = instance.clone();
Vector v1 = instance.convertToVector();
Vector v2 = clone.convertToVector();
assertNotSame(instance, clone);
assertNotSame(v1, v2);
assertEquals(v1, v2);
Vector v1delta = v1.scale(this.random.nextDouble() );
instance.convertFromVector(v1delta);
Vector v12 = instance.convertToVector();
Vector v22 = clone.convertToVector();
assertEquals(v2, v22);
assertEquals(v12, v1delta);
assertFalse(v12.equals(v1));
}
示例9: testClone
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of clone method, of class ThreeLayerFeedforwardNeuralNetwork.
*/
public void testClone()
{
System.out.println("clone");
int numInputs = random.nextInt( 10 ) + 1;
int numHidden = random.nextInt( 10 ) + 1;
int numOutput = random.nextInt( 10 ) + 1;
ThreeLayerFeedforwardNeuralNetwork instance = new ThreeLayerFeedforwardNeuralNetwork(
numInputs, numHidden, numOutput );
ThreeLayerFeedforwardNeuralNetwork clone = instance.clone();
assertNotSame( instance, clone );
assertNotSame( instance.getSquashingFunction(), clone.getSquashingFunction() );
Vector p1 = instance.convertToVector();
Vector p2 = clone.convertToVector();
assertEquals( p1, p2 );
Vector p3 = p2.scale(random.nextGaussian());
clone.convertFromVector(p3);
Vector p4 = clone.convertToVector();
assertEquals( p3, p4 );
// Make sure fiddling with the clone's parameters didn't duff up
// the original instance's parameters.
Vector p5 = instance.convertToVector();
assertEquals( p1, p5 );
}
示例10: testConvertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of convertFromVector method, of class VectorFunctionLinearDiscriminant.
*/
public void testConvertFromVector()
{
System.out.println( "convertFromVector" );
VectorFunctionLinearDiscriminant<?> instance = this.createInstance();
Vector v = instance.convertToVector();
assertNotNull( v );
assertSame( v, instance.getDiscriminant().convertToVector() );
Vector v2 = v.scale( random.nextGaussian() );
instance.convertFromVector( v2 );
assertEquals( v2, instance.convertToVector() );
}
示例11: testSetInitialProbability
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of setInitialProbability method, of class MarkovChain.
*/
public void testSetInitialProbability()
{
System.out.println("setInitialProbability");
MarkovChain instance = this.createInstance();
Vector pi = instance.getInitialProbability();
assertEquals( 1.0, pi.norm1(), TOLERANCE );
Vector p2 = pi.scale(RANDOM.nextDouble());
instance.setInitialProbability(p2);
assertSame( p2, instance.getInitialProbability() );
assertEquals( 1.0, p2.norm1(), TOLERANCE );
}
示例12: testGetFutureStateDistribution
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Test of getFutureStateDistribution method, of class MarkovChain.
*/
public void testGetFutureStateDistribution()
{
System.out.println("getFutureStateDistribution");
MarkovChain instance = this.createInstance();
Vector expected = instance.transitionProbability.times(
instance.getInitialProbability() );
Vector result = instance.getFutureStateDistribution(
instance.getInitialProbability(), 1);
if( !expected.equals( result ) )
{
assertEquals( expected, result );
}
expected = instance.getInitialProbability();
assertEquals( expected, instance.getFutureStateDistribution( instance.getInitialProbability(), -1 ) );
assertEquals( expected, instance.getFutureStateDistribution( instance.getInitialProbability(), 0 ) );
for( int i = 1; i < 100; i++ )
{
expected = instance.getTransitionProbability().times( expected );
expected = expected.scale( 1.0/result.norm1() );
result = instance.getFutureStateDistribution(
instance.getInitialProbability(), i );
if( !expected.equals( result, TOLERANCE ) )
{
assertEquals( expected, result );
}
}
}
示例13: evaluate
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
public Vector evaluate(
Vector input)
{
return input.scale( this.getScaleFactor() );
}
示例14: 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);
}
示例15: learn
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
public Function<DataType> learn(
final Collection<? extends DataType> data)
{
final int dataSize = data.size();
final ArrayList<? extends DataType> dataList =
CollectionUtil.asArrayList(data);
final DenseMatrix kernelMatrix =
new DenseMatrixFactoryMTJ().createMatrix(dataSize, dataSize);
for (int i = 0; i < dataSize; i++)
{
final DataType x = dataList.get(i);
kernelMatrix.setElement(i, i, this.kernel.evaluate(x, x));
for (int j = i + 1; j < dataSize; j++)
{
final DataType y = dataList.get(j);
final double value = this.kernel.evaluate(x, y);
kernelMatrix.setElement(i, j, value);
kernelMatrix.setElement(j, i, value);
}
}
// Center the data, if needed.
final DenseMatrix k;
if (!this.centerData)
{
// When not centering, just use the kernel matrix.
k = kernelMatrix;
}
else
{
// Center the data before applying the analysis.
// Khat = K - 1_m K - K 1_m + 1_m K 1_m
// Where m is the data size
// and 1_m is a m x m with 1/m on the diagonal
// and K is the kernel m x m matrix
final Matrix centeringTerm =
MatrixFactory.getDiagonalDefault().createIdentity(
dataSize, dataSize);
centeringTerm.scaleEquals(1.0 / dataSize);
k = kernelMatrix.clone();
k.minusEquals(centeringTerm.times(kernelMatrix));
k.minusEquals(kernelMatrix.times(centeringTerm));
k.plusEquals(centeringTerm.times(kernelMatrix.times(centeringTerm)));
}
// We can only have up to dataSize components.
final int realComponentCount = Math.min(this.componentCount, dataSize);
// Perform an eigendecomposition on the kernel matrix.
final EigenDecomposition decomposition =
EigenDecompositionRightMTJ.create(k);
// Now we need to take the result from the eigen-decomposition and
// transform it into a form we can use to transform data.
final Matrix components = MatrixFactory.getDenseDefault().createMatrix(
realComponentCount, dataSize);
for (int i = 0; i < realComponentCount; i++)
{
// Get the i-th eigenvector and eigenvalue.
final Vector eigenVector =
decomposition.getEigenVectorsRealPart().getColumn(i);
final double eigenValue = decomposition.getEigenValue(i).getRealPart();
// Create the component by scaling the eigenvector by one over
// the square root of the eigenvalue.
final Vector component = eigenVector.scale(
1.0 / Math.sqrt(Math.abs(eigenValue)));
components.setRow(i, component);
}
// Return the result.
return new Function<DataType>(this.kernel, dataList, components,
this.centerData, kernelMatrix);
}