本文整理汇总了Java中org.apache.commons.math3.linear.RealVector.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.toArray方法的具体用法?Java RealVector.toArray怎么用?Java RealVector.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.RealVector
的用法示例。
在下文中一共展示了RealVector.toArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: score
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
private NoveltyScores score(final RealMatrix kernelMatrix) {
// projected test samples:
final RealMatrix projectionVectors =
kernelMatrix.transpose().multiply(m_projection);
// differences to the target value:
final RealMatrix diff = projectionVectors.subtract(
MatrixFunctions.ones(kernelMatrix.getColumnDimension(), 1)
.scalarMultiply(m_targetPoints.getEntry(0, 0)));
// distances to the target value:
final RealVector scoresVector = MatrixFunctions.sqrt(MatrixFunctions
.rowSums(MatrixFunctions.multiplyElementWise(diff, diff)));
return new NoveltyScores(scoresVector.toArray(), projectionVectors);
}
示例2: estimateCoefficients
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public SlopeCoefficients estimateCoefficients(final DerivationEquation eq)
throws EstimationException {
final double[][] sourceTriangleMatrix = eq.getCovarianceLowerTriangularMatrix();
// Copy matrix and enhance it to a full matrix as expected by CholeskyDecomposition
// FIXME: Avoid copy job to speed-up the solving process e.g. by extending the CholeskyDecomposition constructor
final int length = sourceTriangleMatrix.length;
final double[][] matrix = new double[length][];
for (int i = 0; i < length; i++) {
matrix[i] = new double[length];
final double[] s = sourceTriangleMatrix[i];
final double[] t = matrix[i];
for (int j = 0; j <= i; j++) {
t[j] = s[j];
}
for (int j = i + 1; j < length; j++) {
t[j] = sourceTriangleMatrix[j][i];
}
}
final RealMatrix coefficients =
new Array2DRowRealMatrix(matrix, false);
try {
final DecompositionSolver solver = new CholeskyDecomposition(coefficients).getSolver();
final RealVector constants = new ArrayRealVector(eq.getConstraints(), true);
final RealVector solution = solver.solve(constants);
return new DefaultSlopeCoefficients(solution.toArray());
} catch (final NonPositiveDefiniteMatrixException e) {
throw new EstimationException("Matrix inversion error due to data is linearly dependent", e);
}
}
示例3: score
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
private NoveltyScores score(final RealMatrix kernelMatrix) {
final RealMatrix projectionVectors =
kernelMatrix.transpose().multiply(m_projection);
// squared euclidean distances to target points:
final RealMatrix squared_distances =
squared_euclidean_distances(projectionVectors, m_targetPoints);
// novelty scores as minimum distance to one of the target points
final RealVector scoreVector = MatrixFunctions
.sqrt(MatrixFunctions.rowMins(squared_distances));
return new NoveltyScores(scoreVector.toArray(), projectionVectors);
}
示例4: simpleNewtonIteration
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public static RealVector simpleNewtonIteration(RealVector currentApprox) {
NewtonMethod method = new NewtonMethod();
double[] temp = currentApprox.toArray();
method.setJacobiMatrix(temp);
method.setEquationSystem(temp);
RealVector vector = method.solveOfEquation();
return vector.add(currentApprox);
}
示例5: getAccuracy
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public static float getAccuracy(LeastSquaresOptimizer.Optimum optimum) {
RealVector standardDeviation = optimum.getSigma(0);
float maximumDeviation = 0;
for (double deviation : standardDeviation.toArray()) {
maximumDeviation = (float) Math.max(maximumDeviation, deviation);
}
return maximumDeviation;
}
示例6: computeTSS
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Computes the Total Sum of Squares for regressand
* @param y the vector with dependent variable observations
* @return the Total Sum of Squares for regressand
*/
protected double computeTSS(RealVector y) {
if (!hasIntercept()) {
return y.dotProduct(y);
} else {
final double[] values = y.toArray();
final double mean = DoubleStream.of(values).average().orElse(Double.NaN);
final double[] demeaned = DoubleStream.of(values).map(v -> v - mean).toArray();
final RealVector demeanedVector = new ArrayRealVector(demeaned);
return demeanedVector.dotProduct(demeanedVector);
}
}
示例7: HomogeneousVector
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Creates a new homogeneous vector from Cartesian
* coordinates.
* @param c Cartesian coordinates.
*/
public HomogeneousVector(RealVector c) {
this(c.toArray());
}