本文整理汇总了Java中org.apache.commons.math3.linear.RealVector.setEntry方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.setEntry方法的具体用法?Java RealVector.setEntry怎么用?Java RealVector.setEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.RealVector
的用法示例。
在下文中一共展示了RealVector.setEntry方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshall
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Vector deserialization.
*/
public static RealVector unmarshall(byte[] bytes, boolean sparse, int dimensions) throws IOException {
RealVector realVector = !sparse ? new ArrayRealVector(dimensions) : new OpenMapRealVector(dimensions);
if (!sparse) {
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
for (int i = 0; i < dimensions; i++) {
realVector.setEntry(i, dis.readDouble());
}
}
}
else {
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
while (true) {
try {
realVector.setEntry(dis.readInt(), dis.readDouble());
}
catch (EOFException e) {
break;
}
}
}
}
return realVector;
}
示例2: MixModel
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public MixModel(MethyModel tumor, MethyModel normal, RealVector thetas, int nBetas, int MYTHREADS) throws InterruptedException {
int nFeatures=tumor.getNaRatio().getDimension();
this.nBetas = nBetas;
RealVector betas = new ArrayRealVector(nBetas);
for (int i=0; i<nBetas; i++) {
betas.setEntry(i,i/(nBetas-1.0));
}
mixDens = new RealMatrix[nFeatures];
ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);
for(int i = 0; i < nFeatures; i++) {
double tumorAlpha = tumor.getAlpha().getEntry(i);
double tumorBeta = tumor.getBeta().getEntry(i);
BetaDistribution tumorDist = new BetaDistribution(tumorAlpha,tumorBeta);
double normalAlpha = normal.getAlpha().getEntry(i);
double normalBeta = normal.getBeta().getEntry(i);
BetaDistribution normalDist = new BetaDistribution(normalAlpha,normalBeta);
Runnable worker = new CalMixDens(tumorDist,normalDist,thetas,betas,nPoints,i,mixDens);
executor.execute(worker);
}
executor.shutdown();
while (!executor.isTerminated()) {
Thread.sleep(10000);
}
}
示例3: sqrt
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public static RealVector sqrt(final RealVector vector) {
final RealVector result = vector.copy();
for (int e = 0; e < result.getDimension(); e++) {
result.setEntry(e, Math.sqrt(result.getEntry(e)));
}
return result;
}
示例4: double2RealVector
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
static public RealVector double2RealVector(double[] x) {
RealVector y = new ArrayRealVector(x.length);
for (int i=0; i<x.length; i++) {
y.setEntry(i, x[i]);
}
return y;
}
示例5: fit
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
@Override
public void fit(List<double[]> X, List<double[]> Y) { // fits n-dimensional data sets with affine model
if (X.size() != Y.size())
throw new IllegalArgumentException("point sequences X, Y must have same length");
this.m = X.size();
this.n = X.get(0).length;
RealMatrix M = MatrixUtils.createRealMatrix(2 * m, 2 * (n + 1));
RealVector b = new ArrayRealVector(2 * m);
// mount matrix M:
int row = 0;
for (double[] x : X) {
for (int j = 0; j < n; j++) {
M.setEntry(row, j, x[j]);
M.setEntry(row, n, 1);
row++;
}
for (int j = 0; j < n; j++) {
M.setEntry(row, j + n + 1, x[j]);
M.setEntry(row, 2 * n + 1, 1);
row++;
}
}
// mount vector b
row = 0;
for (double[] y : Y) {
for (int j = 0; j < n; j++) {
b.setEntry(row, y[j]);
row++;
}
}
SingularValueDecomposition svd = new SingularValueDecomposition(M);
DecompositionSolver solver = svd.getSolver();
RealVector a = solver.solve(b);
A = makeTransformationMatrix(a);
}
示例6: 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;
}
示例7: createY
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
/**
* Creates the Y vector for this regression model
* @return the Y vector for regression model
*/
RealVector createY() {
final int rowCount = frame.rows().count();
final int colIndex = frame.cols().ordinalOf(regressand);
final RealVector y = new ArrayRealVector(rowCount);
for (int i = 0; i < rowCount; ++i) {
y.setEntry(i, frame.data().getDouble(i, colIndex));
}
return y;
}
示例8: nextMVNormal
import org.apache.commons.math3.linear.RealVector; //导入方法依赖的package包/类
public RealVector nextMVNormal(int numdim) {
RealVector x = new ArrayRealVector(numdim);
for (int i=0; i<numdim; i++)
x.setEntry(i, nextGaussian());
return x;
}
示例9: 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);
}
}