本文整理汇总了Java中org.apache.commons.math3.linear.RealMatrix.getColumn方法的典型用法代码示例。如果您正苦于以下问题:Java RealMatrix.getColumn方法的具体用法?Java RealMatrix.getColumn怎么用?Java RealMatrix.getColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.RealMatrix
的用法示例。
在下文中一共展示了RealMatrix.getColumn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CancerPrediction
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public CancerPrediction(RealMatrix dens, RealVector thetas, boolean cancerPos) {
int nTheta = dens.getColumnDimension();
int nType = dens.getRowDimension();
thetaPreds = new double[nType];
maxDens = new Double[nType];
double[] baseDens = dens.getColumn(0); // the likelihoods if the sample is normal
for (int i=0; i<nType; i++) {
RealVector rowDens;
if (cancerPos) {
rowDens = dens.getRowVector(i).getSubVector(1,nTheta - 1);
thetaPreds[i] = thetaPred(rowDens, thetas.getSubVector(1,nTheta-1));
}
else {
rowDens = dens.getRowVector(i);
thetaPreds[i] = thetaPred(rowDens, thetas);
}
maxDens[i] = rowDens.getMaxValue();
}
//sort type by maxDens-baseDens
typeRanks = new Integer[nType];
for(int i=0 ; i < nType; i++ ) typeRanks[i] = i;
Arrays.sort(typeRanks, (i1, i2) -> { // descending
return Double.compare(maxDens[i2]-baseDens[i2], maxDens[i1]-baseDens[i1]); // log scale
});
bestTheta = thetaPreds[typeRanks[0]];
bestDens = maxDens[typeRanks[0]];
bestRatio = bestDens-baseDens[typeRanks[0]]; // log scale
}
示例2: solve
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
private double[] solve(float tc, float m, float w, Range range) {
kernel.set_tcmw(tc, m, w);
kernel.execute(range);
final float[] result = kernel.getResult();
double[][] _A = new double[4][4];
double[] _b = new double[4];
_A[0][0] = N;
/*
A = [[ N, result[fi], result[gi], result[hi] ],
[ result[fi], result[fi2], result[figi], result[fihi] ],
[ result[gi], result[figi], result[gi2], result[gihi] ],
[ result[hi], result[fihi], result[gihi], result[hi2] ]]
b = [ sum_yi, sum_yi_fi, sum_yi_gi, sum_yi_hi ]
*/
for (int i = 0; i < N; i++) {
int offset = i * v;
_A[0][1] += result[offset + FI];
_A[0][2] += result[offset + GI];
_A[0][3] += result[offset + HI];
_A[1][0] += result[offset + FI];
_A[1][1] += result[offset + FI2];
_A[1][2] += result[offset + FIGI];
_A[1][3] += result[offset + FIHI];
_A[2][0] += result[offset + GI];
_A[2][1] += result[offset + FIGI];
_A[2][2] += result[offset + GI2];
_A[2][3] += result[offset + GIHI];
_A[3][0] += result[offset + HI];
_A[3][1] += result[offset + FIHI];
_A[3][2] += result[offset + GIHI];
_A[3][3] += result[offset + HI2];
_b[0] += result[offset + YI];
_b[1] += result[offset + YIFI];
_b[2] += result[offset + YIGI];
_b[3] += result[offset + YIHI];
}
RealMatrix A = new Array2DRowRealMatrix(_A, false);
RealMatrix b = new Array2DRowRealMatrix(new double[][]{_b}, false).transpose();
RealMatrix At = A.transpose();
RealMatrix x = MatrixUtils.inverse(At.multiply(A)).multiply(At).multiply(b);
return x.getColumn(0);
}
示例3: giveMeFFT
import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
/**
*Devuelve la energía de fourier de los acelerómetros
* importante el orden del df
* 1ºGyro
* 2ºAcell
* @param df
* @return
*/
private List giveMeFFT(DataFrame df){
List retList = new ArrayList();
//http://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/transform/FastFourierTransformer.html
//http://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/transform/DftNormalization.html
//http://jakevdp.github.io/blog/2013/08/28/understanding-the-fft/
double[][] miMatrix = (double[][]) df.toArray(double[][].class);
RealMatrix rm = new Array2DRowRealMatrix(miMatrix);
double logaritmo;
double[] x = rm.getColumn(3);// accel-x
double[] y = rm.getColumn(4);// accel-y
double[] z = rm.getColumn(5);// accel-z
if(!ArithmeticUtils.isPowerOfTwo(df.length())){
logaritmo = Math.log(x.length)/Math.log(2);
x = Arrays.copyOf(x, (int) Math.pow(2, Math.ceil(logaritmo)));
y = Arrays.copyOf(y, (int) Math.pow(2, Math.ceil(logaritmo)));
z = Arrays.copyOf(z, (int) Math.pow(2, Math.ceil(logaritmo)));
}
FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
Complex[] X = fft.transform(x, TransformType.FORWARD);
Complex[] Y = fft.transform(y, TransformType.FORWARD);
Complex[] Z = fft.transform(z, TransformType.FORWARD);
double sumX = 0;
double sumY = 0;
double sumZ = 0;
for (int i = 0; i < df.length(); i++) {
sumX += Math.pow(X[i].abs(), 2);
sumY += Math.pow(Y[i].abs(), 2);
sumZ += Math.pow(Z[i].abs(), 2);
}
retList.add(sumX/df.length());
retList.add(sumY/df.length());
retList.add(sumZ/df.length());
return retList;
}