本文整理汇总了Java中org.ejml.simple.SimpleSVD类的典型用法代码示例。如果您正苦于以下问题:Java SimpleSVD类的具体用法?Java SimpleSVD怎么用?Java SimpleSVD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleSVD类属于org.ejml.simple包,在下文中一共展示了SimpleSVD类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PCA
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
PCA(final INDArray X)
{
this._X = X;
this._N = _X.rows();
this._P = _X.columns();
SimpleSVD svd = svd(_X);
this._LOADINGS = Nd4j.create(
svd.getV()
.transpose()
.getMatrix().getData(),
new int[]{_P, _P}, 'r');
// add standard deviations
this._SD = new ArrayList<>();
final double sq = sqrt(_X.rows() - 1);
for (int i = 0; i < _X.columns(); i++)
_SD.add(svd.getW().get(i, i) / sq);
this._SCORES = _X.mmul(_LOADINGS);
}
示例2: getSigmaPoints
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* Returns 2n+k sigma points starting with mean as the first point
*
* @param mean
* @param cov
* @param no
* @param k
* @return
*/
private static List<SimpleMatrix> getSigmaPoints(SimpleMatrix mean, SimpleMatrix cov, int no, int k) {
List<SimpleMatrix> resultVectors = new ArrayList<SimpleMatrix>();
int n = cov.numRows();
SimpleSVD<?> svd = cov.svd(true);
SimpleMatrix U = svd.getU();
SimpleMatrix S = svd.getW();
S = U.mult(MatrixOps.elemSqrt(S)).scale(Math.sqrt(n + k));
for (int i = 0; i < S.numCols(); i++) {
SimpleMatrix columnVector = S.extractVector(false, i);
SimpleMatrix negColumnVector = S.extractVector(false, i).scale(-1);
resultVectors.add(columnVector.plus(mean));
resultVectors.add(negColumnVector.plus(mean));
}
if (k != 0)
resultVectors.add(mean);
return resultVectors;
}
示例3: computeInputs
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
@Override
public List<Double> computeInputs(Cluster cluster) {
List<Double> singularValues = new ArrayList<Double>();
double[][] adjacencyValues = getAdjacencyValues(cluster);
SimpleMatrix adjacencyMatrix = new SimpleMatrix(adjacencyValues);
int numNodes = cluster.getNodes().size();
@SuppressWarnings("rawtypes")
SimpleSVD svd = adjacencyMatrix.svd(); //this svd function guarantees ordering
for (int i = 0; i < 3; i++) {
if (i < numNodes)
singularValues.add(svd.getSingleValue(i));
else
singularValues.add(0.0);
}
return singularValues;
}
示例4: svd
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* Compute a singular value decompositon.
*
* @param X matrix that is going to be decomposed
* @return returns the SVD matrices
*/
public static SimpleSVD svd(INDArray X)
{
return new SimpleMatrix(
X.rows(), X.columns(), true, X.data().asDouble())
.svd(true);
}
示例5: svd
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
private SimpleSVD svd(final INDArray X, final double[] sdevs)
{
final double nsqrt = sqrt(_N);
for (int i = 0; i < sdevs.length; i++)
{
X.getColumn(i).assign(X.getColumn(i).div(sdevs[i] * nsqrt));
}
return new SimpleMatrix(_N, _P, true, X.data().asDouble()).svd(true);
}
示例6: svd_EJML
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* Calculates the compact Singular Value Decomposition of a matrix. The
* Singular Value Decomposition of matrix A is a set of three matrices: U, Σ
* and V such that A = U × Σ × VT. Let A be a m × n matrix, then U is a m ×
* p orthogonal matrix, Σ is a p × p diagonal matrix with positive or null
* elements, V is a p × n orthogonal matrix (hence VT is also orthogonal)
* where p=min(m,n).
*
* @param a Given matrix.
* @return Result U/S/V arrays.
*/
public static Array[] svd_EJML(Array a) {
int m = a.getShape()[0];
int n = a.getShape()[1];
int k = Math.min(m, n);
double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
SimpleMatrix M = new SimpleMatrix(aa);
SimpleSVD svd = M.svd(false);
Array Ua = Array.factory(DataType.DOUBLE, new int[]{m, m});
Array Va = Array.factory(DataType.DOUBLE, new int[]{n, n});
Array Sa = Array.factory(DataType.DOUBLE, new int[]{k});
SimpleBase U = svd.getU();
SimpleBase V = svd.getV();
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
Ua.setDouble(i * m + j, U.get(i, j));
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
Va.setDouble(j * n + i, V.get(i, j));
}
}
for (int i = 0; i < k; i++) {
//Sa.setDouble(i, sv[i]);
Sa.setDouble(i, svd.getSingleValue(i));
}
return new Array[]{Ua, Sa, Va};
}
示例7: whiten
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private SimpleMatrix whiten(SimpleMatrix x) {
// get compact SVD (D matrix is min(m,n) square)
SimpleSVD svd = x.svd(true);
// K should only keep `num_components` columns if performing
// dimensionality reduction
K = svd.getV().mult(svd.getW().invert())
.extractMatrix(0, x.numCols(), 0, num_components);
// K = K.scale(-1); // sklearn returns this version for K; doesn't affect results
// return x.mult(K).scale(Math.sqrt(m)); // sklearn scales the input
return x.mult(K);
}
示例8: split
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* Splits a single component distribution into two components as described in the oKDE-paper.
* @return a TwoComponentDistribution
*/
public TwoComponentDistribution split(double parentWeight){
SimpleSVD<?> svd = mGlobalCovariance.svd(true);
SimpleMatrix S = svd.getW();
SimpleMatrix V = svd.getV();
SimpleMatrix d = S.extractDiag();
double max = MatrixOps.maxVectorElement(d);
int maxIndex = MatrixOps.maxVectorElementIndex(d);
int len = mGlobalCovariance.numRows();
SimpleMatrix M = new SimpleMatrix(len,1);
M.set(maxIndex, 0, 1.0d);
SimpleMatrix dMean = V.mult(M).scale(0.5*Math.sqrt(max));
SimpleMatrix meanSplit1 = mGlobalMean.plus(dMean);
SimpleMatrix meanSplit2 = mGlobalMean.minus(dMean);
SimpleMatrix dyadMean = mGlobalMean.mult(mGlobalMean.transpose());
SimpleMatrix dyadMeanSplit1 = meanSplit1.mult(meanSplit1.transpose());
SimpleMatrix dyadMeanSplit2 = meanSplit2.mult(meanSplit2.transpose());
SimpleMatrix covSplit = mGlobalCovariance.plus(dyadMean).minus(dyadMeanSplit1.plus(dyadMeanSplit2).scale(0.5));
SimpleMatrix[] means = {meanSplit1, meanSplit2};
SimpleMatrix[] covariances = {covSplit, covSplit};
double[] weights = {0.5, 0.5};
TwoComponentDistribution splitDist = null;
try {
splitDist = new TwoComponentDistribution(weights, means, covariances, mBandwidthMatrix);
splitDist.setGlobalWeight(parentWeight*mGlobalWeight);
splitDist.setGlobalCovariance(mGlobalCovariance);
splitDist.setGlobalMean(mGlobalMean);
} catch (TooManyComponentsException e) {
// cant be thrown
}
return splitDist;
}
示例9: fit
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
private void fit(final int K)
{
final INDArray vars = _X.var(0);
INDArray F;
INDArray psis = Nd4j.eye(_P);
double loglik = Double.MIN_VALUE;
double oldLoglik;
int niter = 0;
do
{
oldLoglik = loglik;
final INDArray sqrt_psis = sqrtPsis(psis);
INDArray X = _X.dup();
SimpleSVD svd;
double unexp = .0;
INDArray s, V;
// TODO: CHANGE TO OWN METHOD USING
{
svd = svd
(X, sqrt_psis.data().asDouble());
s = getSingularValues(svd.getW(), K);
V = getRightSingularVectors(svd.getV(), K);
unexp = unexplainedVariance(svd.getW(), K);
}
// update the likelihood
loglik = proploglik(s, unexp, psis);
// update the factor matrix and variances AFTERWARDS
F = factorUpdate(s, V, sqrt_psis);
psis = vcovUpdate(vars, F);
}
while (niter++ < _MAXIT && Math.abs(loglik - oldLoglik) > _THRESHOLD);
// set the member variables to the computed values
this._f = F;
this._psi = psis;
}
示例10: remainderSubspace
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* Replace this with a cross product if too slow..
* @param in an M x N matrix whose rows span a subspace of R^N
* @return an orthogonal basis for the subspace of R^N not spanned by in
*/
public static DenseMatrix64F remainderSubspace(DenseMatrix64F in){
SimpleSVD<SimpleMatrix> svd = new SimpleSVD<SimpleMatrix>(in,false);
SimpleMatrix nullspace = svd.nullSpace();
return nullspace.getMatrix();
}
示例11: extractEpipoles
import org.ejml.simple.SimpleSVD; //导入依赖的package包/类
/**
* <p>
* Extracts the epipoles from an essential or fundamental matrix. The epipoles are extracted
* from the left and right null space of the provided matrix. Note that the found epipoles are
* in homogeneous coordinates. If the epipole is at infinity then z=0
* </p>
*
* <p>
* Left: e<sub>2</sub><sup>T</sup>*F = 0 <br>
* Right: F*e<sub>1</sub> = 0
* </p>
*
* @param F Input: Fundamental or Essential 3x3 matrix. Not modified.
* @param e1 Output: Right epipole in homogeneous coordinates. Can be null. Modified.
* @param e2 Output: Left epipole in homogeneous coordinates. Can be null. Modified.
*/
public static void extractEpipoles( DenseMatrix64F F , Point3D_F64 e1 , Point3D_F64 e2 ) {
SimpleMatrix f = SimpleMatrix.wrap(F);
SimpleSVD svd = f.svd();
SimpleMatrix U = svd.getU();
SimpleMatrix V = svd.getV();
if( e2 != null )
e2.set(U.get(0,2),U.get(1,2),U.get(2,2));
if( e1 != null )
e1.set(V.get(0,2),V.get(1,2),V.get(2,2));
}