本文整理汇总了Java中gov.sandia.cognition.math.matrix.Vector.get方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.get方法的具体用法?Java Vector.get怎么用?Java Vector.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gov.sandia.cognition.math.matrix.Vector
的用法示例。
在下文中一共展示了Vector.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
final public Vector solve(
final Vector b)
{
checkSolveDimensions(b);
Vector result = b.clone();
for (int i = 0; i < diagonal.length; ++i)
{
if (diagonal[i] == 0)
{
if (result.get(i) != 0)
{
throw new UnsupportedOperationException("Unable to solve "
+ "Ax=b because b spans different space than A");
}
}
else
{
result.setElement(i, result.get(i) / diagonal[i]);
}
}
return result;
}
示例2: convertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
final public void convertFromVector(
final Vector v)
{
v.assertDimensionalityEquals(this.getNumRows() * this.getNumColumns());
final int numRows = this.getNumRows();
final int numColumns = this.getNumColumns();
for (int i = 0; i < numRows; ++i)
{
for (int j = 0; j < numColumns; ++j)
{
this.rows[i].values[j] = v.get(i + j
* getNumRows());
}
}
}
示例3: copyVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
@Override
final public DenseVector copyVector(
final Vector m)
{
int n = m.getDimensionality();
DenseVector result = new DenseVector(n);
for (int i = 0; i < n; ++i)
{
result.values[i] = m.get(i);
}
return result;
}
示例4: convertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @param parameters {@inheritDoc}
* @throws IllegalArgumentException if input vector doesn't have enough
* elements to cover all elements of this or if the input vector specifies
* non-zero values in off-diagonal elements.
*/
@Override
final public void convertFromVector(
final Vector parameters)
{
parameters.assertDimensionalityEquals(this.getNumRows() * getNumColumns());
final int numRows = this.getNumRows();
final int numColumns = this.getNumColumns();
for (int i = 0; i < numRows; ++i)
{
for (int j = 0; j < numColumns; ++j)
{
if (i == j)
{
diagonal[i] = parameters.get(i * numColumns + j);
}
// this checks that all off-diagonal elements are zero
else if (parameters.get(i * numColumns + j) != 0)
{
throw new IllegalArgumentException("Cannot convert "
+ "diagonal matrix from vector with non-zero element "
+ "that maps to off-diagonal location at " + i
+ ", " + j);
}
}
}
}
示例5: convertFromVector
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* NOTE: Upon ocmpletion this is in the compressed Yale format.
*
* @param parameters {@inheritDoc}
* @throws IllegalArgumentException if parameters does not have the same
* number of elements as this's full size (including all of the zero
* values).
*/
@Override
final public void convertFromVector(
final Vector parameters)
{
parameters.assertDimensionalityEquals(numRows * numCols);
// Count how many non-zero elements there will be at the end
int nnz = 0;
final int d = parameters.getDimensionality();
for (int i = 0; i < d; ++i)
{
if (parameters.get(i) != 0)
{
++nnz;
}
}
// Initialize the compressed Yale format
firstIndicesForRows = new int[numRows + 1];
columnIndices = new int[nnz];
values = new double[nnz];
int idx = 0;
// Fill the data in
for (int i = 0; i < numRows; ++i)
{
rows[i].clear();
firstIndicesForRows[i] = idx;
for (int j = 0; j < numCols; ++j)
{
double val = parameters.get(i + j * numRows);
if (val != 0)
{
columnIndices[idx] = j;
values[idx] = val;
++idx;
}
}
}
firstIndicesForRows[numRows] = idx;
}
示例6: evaluateWithDiscriminant
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* This method implements the evaluation aspect of CosineDelta. That is,
* given an unknownVector, this method should return a discriminant
* value paired with the corresponding most likely category.
* The discriminant value is the score.
*
* @param unknownVector
* @return
*/
@Override
public ValueDiscriminantPair<CategoryType, Double> evaluateWithDiscriminant(
Vector unknownVector)
{
double minDelta = Double.MAX_VALUE;
CategoryType minCat = null;
DefaultWeightedValueDiscriminant<CategoryType> result =
new DefaultWeightedValueDiscriminant<CategoryType>();
for (InputOutputPair<? extends Vector, CategoryType> pair :
learner.trainingSet)
{
Vector knownVector = pair.getInput();
double delta = 0.0;
double dotProduct = 0.0;
double knownLength = 0.0;
double unknownLength = 0.0;
for (int featureIndex = 0;
featureIndex < knownVector.getDimensionality();
featureIndex++)
{
// Scale feature
double known = (knownVector.get(featureIndex) -
featureMeans.get(featureIndex)) /
featureStddev.get(featureIndex);
double unknown = (unknownVector.get(featureIndex) -
featureMeans.get(featureIndex)) /
featureStddev.get(featureIndex);
// Dot product
dotProduct += known * unknown;
// Known length
knownLength += Math.pow(known, 2);
// Unkown length
unknownLength += Math.pow(unknown, 2);
}
// Calculte cosine delta and record result
double preDelta = dotProduct / (Math.sqrt(knownLength) * Math.sqrt(unknownLength));
if (preDelta > 1.0) {
preDelta = 1.0;
}
else if (preDelta < -1.0) {
preDelta = -1.0;
}
delta = Math.acos(preDelta);
if (delta < minDelta)
{
minDelta = delta;
minCat = pair.getOutput();
}
}
result.setValue(minCat);
result.setWeight(minDelta);
return result;
}
示例7: upperTriangularSolve
import gov.sandia.cognition.math.matrix.Vector; //导入方法依赖的package包/类
/**
* Solves Rx = QtransB requiring that R be upper triangular and square.
* Solves by back-subsititution from the bottom-most corner of the
* upper-triangular matrix.
*
* @param R The upper triangular right-side matrix
* @param QtransB The Q-transformed right-side vector
* @return The x from Rx = Qtrans * b.
* @throws IllegalArgumentException if R is not square or if R is not
* upper-triangular (has values below the diagonal).
* @throws UnsupportedOperationException if any diagonal element of R is
* zero (as it does not span the space).
*/
private static Vector upperTriangularSolve(
final Matrix R,
final Vector QtransB)
{
// This should be tested in the solve methods, this is here just to
// make sure no one else calls this w/o checking
if (!R.isSquare())
{
throw new IllegalArgumentException("Called with a non-square "
+ "matrix.");
}
// Test bottom triangle is zero
// And test that all diagonals are non-zero (else you can't solve)
final int numRows = R.getNumRows();
final int numColumns = R.getNumColumns();
for (int i = 0; i < numRows; ++i)
{
// diagonals
if (R.get(i, i) == 0)
{
throw new UnsupportedOperationException("Can't invert matrix "
+ "because it does not span the columns");
}
// lower triangle
for (int j = 0; j < i; ++j)
{
if (R.get(i, j) != 0)
{
throw new IllegalArgumentException("upperTriangleSolve "
+ "passed a non-upper-triangle matrix");
}
}
}
DenseVector result = new DenseVector(numColumns);
// Start from the bottom of the triangle
for (int i = numColumns - 1; i >= 0; --i)
{
// Start w/ the value in B
double v = QtransB.get(i);
// Back substitute all solved parts in
for (int j = i + 1; j < numColumns; ++j)
{
v -= R.get(i, j) * result.values[j];
}
// Solve with the diagonal element
result.values[i] = (v / R.get(i, i));
}
return result;
}