本文整理汇总了Java中org.apache.commons.math3.linear.RealVector.getEntry方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.getEntry方法的具体用法?Java RealVector.getEntry怎么用?Java RealVector.getEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.RealVector
的用法示例。
在下文中一共展示了RealVector.getEntry方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sim
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
if (r1.getDimension() != r2.getDimension()) {
return 0;
}
double min = 0.0;
double sum = 0.0;
for (int i = 0; i < r1.getDimension(); ++i) {
if (r1.getEntry(i) > r2.getEntry(i)) {
min += r2.getEntry(i);
} else {
min += r1.getEntry(i);
}
sum += r1.getEntry(i) + r2.getEntry(i);
}
if (sum == 0) {
return 0;
}
double result = 2 * min / sum;
return Math.abs(result);
}
示例2: sim
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
if (r1.getDimension() != r2.getDimension()) {
return 0;
}
double alpha = 0.99;
double divergence = 0.0;
for (int i = 0; i < r1.getDimension(); ++i) {
if (r1.getEntry(i) > 0.0 && r2.getEntry(i) > 0.0) {
divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / ((1 - alpha) * r1.getEntry(i) + alpha * r2.getEntry(i)));
}
}
double result = (1 - (divergence / Math.sqrt(2 * Math.log(2))));
return Math.abs(result);
}
示例3: sim
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
if (r1.getDimension() != r2.getDimension()) {
return 0;
}
double min = 0.0;
double max = 0.0;
for (int i = 0; i <r1.getDimension(); ++i) {
if (r1.getEntry(i) > r2.getEntry(i)) {
min +=r2.getEntry(i);
max += r1.getEntry(i);
} else {
min += r1.getEntry(i);
max += r2.getEntry(i);
}
}
if (max == 0) {
return 0;
}
return Math.abs(min / max);
}
示例4: computeParameterStdErrors
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Calculates the standard errors of the regression parameters.
* @param betaVar the variance of the beta parameters
* @throws DataFrameException if this operation fails
*/
private void computeParameterStdErrors(RealVector betaVar) {
try {
final int offset = hasIntercept() ? 1 : 0;
if (hasIntercept()) {
final double interceptVariance = betaVar.getEntry(0);
final double interceptStdError = Math.sqrt(interceptVariance);
this.intercept.data().setDouble(0, Field.STD_ERROR, interceptStdError);
}
for (int i = 0; i < regressors.size(); i++) {
final double betaVar_i = betaVar.getEntry(i + offset);
final double betaStdError = Math.sqrt(betaVar_i);
this.betas.data().setDouble(i, Field.STD_ERROR, betaStdError);
}
} catch (Exception ex) {
throw new DataFrameException("Failed to calculate regression coefficient standard errors", ex);
}
}
示例5: sim
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public double sim(RealVector r1, RealVector r2, boolean sparse) {
if (r1.getDimension() != r2.getDimension()) {
return 0;
}
double divergence = 0.0;
double avr = 0.0;
for (int i = 0; i < r1.getDimension(); ++i) {
avr = (r1.getEntry(i) + r2.getEntry(i)) / 2;
if (r1.getEntry(i) > 0.0 && avr > 0.0) {
divergence += r1.getEntry(i) * Math.log(r1.getEntry(i) / avr);
}
}
for (int i = 0; i < r2.getDimension(); ++i) {
avr = (r1.getEntry(i) + r2.getEntry(i)) / 2;
if (r2.getEntry(i) > 0.0 && avr > 0.0) {
divergence += r1.getEntry(i) * Math.log(r2.getEntry(i) / avr);
}
}
double result = 1 - (divergence / (2 * Math.sqrt(2 * Math.log(2))));
return Math.abs(result);
}
示例6: thetaPred
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
private static double thetaPred(RealVector sumLogDens, RealVector thetas) {
int thetaIndex = sumLogDens.getMaxIndex();
double pred;
if (thetaIndex == -1 || // NaN for all theta dists
sumLogDens.getMaxValue() == sumLogDens.getMinValue()) { // uniform dist
pred = Double.NaN;
} else {
pred = thetas.getEntry(thetaIndex);
}
return pred;
}
示例7: ProjectiveMapping
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Constructor for more than 4 point pairs, finds a least-squares solution
* for the homography parameters.
* NOTE: this is UNFINISHED code!
* @param P sequence of points (source)
* @param Q sequence of points (target)
* @param dummy unused (only to avoid duplicate signature)
*/
public ProjectiveMapping(Point2D[] P, Point2D[] Q, boolean dummy) {
final int n = P.length;
double[] ba = new double[2 * n];
double[][] Ma = new double[2 * n][];
for (int i = 0; i < n; i++) {
double x = P[i].getX();
double y = P[i].getY();
double u = Q[i].getX();
double v = Q[i].getY();
ba[2 * i + 0] = u;
ba[2 * i + 1] = v;
Ma[2 * i + 0] = new double[] { x, y, 1, 0, 0, 0, -u * x, -u * y };
Ma[2 * i + 1] = new double[] { 0, 0, 0, x, y, 1, -v * x, -v * y };
}
RealMatrix M = MatrixUtils.createRealMatrix(Ma);
RealVector b = MatrixUtils.createRealVector(ba);
DecompositionSolver solver = new SingularValueDecomposition(M).getSolver();
RealVector h = solver.solve(b);
a00 = h.getEntry(0);
a01 = h.getEntry(1);
a02 = h.getEntry(2);
a10 = h.getEntry(3);
a11 = h.getEntry(4);
a12 = h.getEntry(5);
a20 = h.getEntry(6);
a21 = h.getEntry(7);
a22 = 1;
}
示例8: solveFToF
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public float[] solveFToF(float[] b) {
RealVector bVec = new ArrayRealVector(b.length);
for (int i = 0; i < b.length; i++) {
bVec.setEntry(i, b[i]);
}
RealVector resultVec = solver.solve(bVec);
float[] result = new float[resultVec.getDimension()];
for (int i = 0; i < result.length; i++) {
result[i] = (float) resultVec.getEntry(i);
}
return result;
}
示例9: computeParameterSignificance
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Computes the T-stats and the P-Value for all regression parameters
*/
private void computeParameterSignificance(RealVector betaVector) {
try {
final double residualDF = frame.rows().count() - (regressors.size() + 1);
final TDistribution distribution = new TDistribution(residualDF);
final double interceptParam = betaVector.getEntry(0);
final double interceptStdError = intercept.data().getDouble(0, Field.STD_ERROR);
final double interceptTStat = interceptParam / interceptStdError;
final double interceptPValue = distribution.cumulativeProbability(-Math.abs(interceptTStat)) * 2d;
final double interceptCI = interceptStdError * distribution.inverseCumulativeProbability(1d - alpha / 2d);
this.intercept.data().setDouble(0, Field.PARAMETER, interceptParam);
this.intercept.data().setDouble(0, Field.T_STAT, interceptTStat);
this.intercept.data().setDouble(0, Field.P_VALUE, interceptPValue);
this.intercept.data().setDouble(0, Field.CI_LOWER, interceptParam - interceptCI);
this.intercept.data().setDouble(0, Field.CI_UPPER, interceptParam + interceptCI);
final int offset = hasIntercept() ? 1 : 0;
for (int i=0; i<regressors.size(); ++i) {
final C regressor = regressors.get(i);
final double betaParam = betaVector.getEntry(i + offset);
final double betaStdError = betas.data().getDouble(regressor, Field.STD_ERROR);
final double tStat = betaParam / betaStdError;
final double pValue = distribution.cumulativeProbability(-Math.abs(tStat)) * 2d;
final double betaCI = betaStdError * distribution.inverseCumulativeProbability(1d - alpha / 2d);
this.betas.data().setDouble(regressor, Field.PARAMETER, betaParam);
this.betas.data().setDouble(regressor, Field.T_STAT, tStat);
this.betas.data().setDouble(regressor, Field.P_VALUE, pValue);
this.betas.data().setDouble(regressor, Field.CI_LOWER, betaParam - betaCI);
this.betas.data().setDouble(regressor, Field.CI_UPPER, betaParam + betaCI);
}
} catch (Exception ex) {
throw new DataFrameException("Failed to compute regression coefficient t-stats and p-values", ex);
}
}
示例10: run
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public void run() {
mixDens[featureIdx] = new BlockRealMatrix(nBetas,nThetas);
for(int j = 0; j < nThetas;j++) {
double theta = thetas.getEntry(j);
RealVector betaDens = new ArrayRealVector(nBetas);
for (int k = 0; k < nBetas; k++) {
double beta = betas.getEntry(k);
double lowerBound = FastMath.max(0, (beta - 1 + theta) / theta);
if (Double.isNaN(lowerBound)) lowerBound = 0;
double upperBound = FastMath.min(1,beta/theta);
if (Double.isNaN(upperBound)) upperBound = 1;
double step = (upperBound-lowerBound)/(nPoints-1);
RealVector dens = new ArrayRealVector(nPoints);
RealVector points = new ArrayRealVector(nPoints);
RealVector allTumorDens = new ArrayRealVector(nPoints);
RealVector allNormalDens = new ArrayRealVector(nPoints);
RealVector allNormalDensRev = new ArrayRealVector(nPoints);
// tumor
for (int l = 0; l < nPoints; l++) {
double tumorValue = lowerBound + l * step;
points.setEntry(l, tumorValue);
if (tumorValue == 0) tumorValue = 0.0001;
if (tumorValue == 1) tumorValue = 0.9999;
allTumorDens.setEntry(l,tumorDist.density(tumorValue));
}
// adjust the densities
double calProb = tumorDist.probability(lowerBound,upperBound);
double estProb = CancerLocator.integSimpson(points,allTumorDens);
if (estProb!=0) {
allTumorDens.mapMultiplyToSelf(calProb/estProb);
}
else {
allTumorDens.mapAddToSelf(1.0/allTumorDens.getDimension());
}
// normal
RealVector normalPoints = new ArrayRealVector(nPoints);
for (int l = 0; l < nPoints; l++) {
double normalValue = (beta-theta*points.getEntry(l))/(1-theta);
normalPoints.setEntry(nPoints-l-1,normalValue);
if (normalValue == 0) normalValue = 0.0001;
if (normalValue == 1) normalValue = 0.9999;
double normalDens = normalDist.density(normalValue);
allNormalDens.setEntry(l,normalDens);
allNormalDensRev.setEntry(nPoints-l-1,normalDens);
}
calProb = normalDist.probability((beta-theta*upperBound)/(1-theta),(beta-theta*lowerBound)/(1-theta));
estProb = CancerLocator.integSimpson(normalPoints, allNormalDensRev);
if (estProb!=0) {
allNormalDens.mapMultiplyToSelf(calProb/estProb);
}
else {
allNormalDens.mapAddToSelf(1.0/allNormalDens.getDimension());
}
//mixture
for (int l = 0; l < nPoints; l++) {
dens.setEntry(l,allTumorDens.getEntry(l)*allNormalDens.getEntry(l));
}
betaDens.setEntry(k,CancerLocator.integSimpson(points,dens));
}
double normTerm = CancerLocator.integSimpson(betas,betaDens); //normalization term
if (normTerm!=0) {
betaDens.mapDivideToSelf(normTerm);
}
else {
betaDens.mapAddToSelf(1.0/betaDens.getDimension());
}
mixDens[featureIdx].setColumnVector(j, betaDens);
}
}