本文整理汇总了Java中org.jblas.DoubleMatrix.divi方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.divi方法的具体用法?Java DoubleMatrix.divi怎么用?Java DoubleMatrix.divi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jblas.DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.divi方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateOutput
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
protected DoubleMatrix calculateOutput(DoubleMatrix inputVector,
DoubleMatrix outputVector) {
double max = Double.NEGATIVE_INFINITY;
for(double v : inputVector.data) {
max = Math.max(max, v);
}
double Z = 0.0;
double[] inputData = inputVector.data;
for(int i=0; i<inputData.length; i++) {
double x = Math.exp(inputData[i] - max);
outputVector.put(i, x);
Z += x;
}
outputVector.divi(Z, outputVector);
return outputVector;
}
示例2: learnWhiteningMatrix
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void learnWhiteningMatrix(ArrayList<T> data) {
this.means = getMeans(data);
DoubleMatrix X = new DoubleMatrix(data.size(), this.dimension);
// Center observations w.r.t. their means
int row = 0;
for(T t : data) {
DoubleMatrix x_i = this.getOutput(t);
X.putRow(row++, x_i.subi(means, x_i).transpose());
}
// Sphericize data
DoubleMatrix M = X.transpose().mmul(X);
M.divi(data.size(), M);
DoubleMatrix[] ED = Eigen.symmetricEigenvectors(M);
DoubleMatrix E = ED[0];
DoubleMatrix D = ED[1];
//DoubleMatrix D_invrt = Solve.pinv(sqrt(D));
DoubleMatrix D_invrt = diagPow(D, -0.5);
this.whitener = E.mmul(D_invrt);
this.wasWhitened = true;
checkSampleCovariance(X.mmul(this.whitener));
//DoubleMatrix X_std = X.mmul(E).mmul(D_invrt);
}
示例3: mulExtantProbabilities
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public void mulExtantProbabilities(DoubleMatrix Q, boolean normalise) {
// Update extant probabilities: p*Q
for (int l = 0; l < numExtant; l++) {
DoubleMatrix probs = (extantProbs[l]).mmul(Q);
if (normalise) {
//extantProbs[l] = probs.div(probs.sum());
probs.divi(probs.sum()); /* normalise */
probs.maxi(0.0); /* clamp(0,1) */
probs.mini(1.0);
}
extantProbs[l] = probs;
}
}
示例4: mulExtantProbability
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void mulExtantProbability(int idx, DoubleMatrix Q, boolean normalise) {
DoubleMatrix probs = (extantProbs[idx]).mmul(Q);
if (normalise) {
//extantProbs[l] = probs.div(probs.sum());
probs.divi(probs.sum()); /* normalise */
probs.maxi(0.0); /* clamp(0,1) */
probs.mini(1.0);
}
extantProbs[idx] = probs;
}
示例5: setMinP
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void setMinP(double minP) {
for (int l = 0; l < numExtant; l++) {
DoubleMatrix probs = extantProbs[l];
probs.maxi(minP);
probs.divi(probs.sum()); /* normalise */
// extantProbs[l] = probs;
}
}
示例6: mean_normalization
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public static List<DoubleMatrix> mean_normalization(double[] sum, List<DoubleMatrix> data_list)
{
DoubleMatrix meanVector = new DoubleMatrix(sum);
meanVector.divi(data_list.size());
for(DoubleMatrix data : data_list)
{
data.subi(meanVector);
}
return data_list;
}
示例7: range_normalization
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public static List<DoubleMatrix> range_normalization(double[] min, double[] max, List<DoubleMatrix> data_list)
{
DoubleMatrix minVector = new DoubleMatrix(min);
DoubleMatrix maxVector = new DoubleMatrix(max);
DoubleMatrix range = maxVector.sub(minVector);
for(DoubleMatrix data : data_list)
{
data.divi(range);
}
return data_list;
}
示例8: computeDerivatives
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public void computeDerivatives(double h, double[] ql, double[] dql)
throws MaxCountExceededException, DimensionMismatchException {
int tsPointCurrent = ts.getTimePoint(tsTimes0-h, tsPointLast);
tsPointLast = tsPointCurrent;
DoubleMatrix Y = ts.getYs()[tsPointCurrent];
DoubleMatrix F = ts.getFs()[tsPointCurrent];
DoubleMatrix G = ts.getGs()[tsPointCurrent];
if (forgiveY) Y.maxi(1.0); else Y.maxi(MIN_Y);
int i;
for(i=0; i < numStatesSQ; i++) qdata[i] = ql[i];
DoubleMatrix Q = new DoubleMatrix(numStates,numStates,qdata);
DoubleMatrix Qnorm = Q.dup();
Qnorm.diviRowVector(Q.columnSums());
DoubleMatrix A = Qnorm.mmul(A0);
A.divi(A.sum()); // normalised
A.muli(sumA0); // sum of A = sum(A0)
//A = A.mul(sumA0).div(A.sum());
DoubleMatrix a = A.div(Y); // column vector
// DoubleMatrix dQ = new DoubleMatrix(numStates,numStates,dql);
double dL = 0;
DoubleMatrix FG = F.add(G);
double accum;
int k,l,z;
i=0;
for (z = 0; z < numStates; z++){
for (k = 0; k < numStates; k++){
accum = 0;
for(l=0; l < numStates; l++) {
if (k != l) {
if (Q.get(l,z) > 0) {
accum += FG.get(k,l) * Q.get(l,z)/ Math.max(Q.get(l,z), Y.get(l));
}
if (Q.get(k,z) > 0) {
accum -= FG.get(l,k) * Q.get(k,z)/ Math.max(Q.get(k,z), Y.get(k));
}
}
if (Q.get(k,z) > 0) {
accum -= F.get(k,l) * a.get(l) * Q.get(k,z)/ Math.max(Q.get(k,z), Y.get(k));
}
}
//dQ.put(k,z,accum);
dql[i++] = accum;
}
}
for (k= 0; k < numStates; k++){
for (l =0 ; l < numStates; l++){
if (k == l && A.get(k) >= 1. ){
dL += (A.get(k) / Y.get(k)) * ((A.get(k)-1.) / Y.get(k)) * F.get(k,l) ;
} else {
dL += a.get(k) * a.get(l) * F.get(k,l);
}
}
}
dL = Math.max(dL, 0.);
dql[numStatesSQ] = dL;
}
示例9: solve
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public void solve(double h0, double h1, int lastPoint, STreeLikelihoodODE stlh) {
tsPointLast = lastPoint;
tsTimes0 = stlh.tsTimes0;
ts = stlh.ts;
StateProbabilities sp = stlh.stateProbabilities;
A0 = sp.getLineageStateSum(); // numStates column vector
sumA0 = A0.sum();
numExtant = sp.getNumExtant();
dimensionP = numStates*numExtant;
// initialise arrays
pl0 = new double[dimensionP+1];
pl1 = new double[dimensionP+1];
int idx=0;
DoubleMatrix probs;
// Copy extant to array
sp.copyProbabilitesToArray(pl0); // column = probs
//for(int i = 0; i < numExtant; i++) {
// probs = stlh.extantProbs[i];
// for(int j=0; j < numStates; j++) {
// pl0[idx++] = probs.get(j);
// }
//}
pl0[dimensionP] = 0.0;
//for(int i=0; i <= dimensionP; i++) System.out.print(pl0[i]+ " ");
//System.out.println("");
foi.integrate(this, h0, pl0, h1, pl1);
//System.out.print("pl1=");
//for(int i=0; i <= dimensionP; i++) System.out.print(pl1[i]+ " ");
//System.out.println("");
// copy new state probabilities
idx=0;
//DoubleMatrix A = DoubleMatrix.zeros(numStates);
for(int i = 0; i < numExtant; i++) {
//probs = stlh.extantProbs[i];
probs = sp.getStateProbsFromIndex(i);
//A.addi(probs);
for(int j=0; j < numStates; j++) {
probs.put(j,pl1[idx]);
idx++;
}
probs.maxi(0.0);
probs.divi(probs.sum());
//System.out.println("probs "+i+" "+ stlh.extantProbs[i]);
}
if (stlh.setMinP) {
sp.setMinP(stlh.minP);
}
//System.out.println("Asum="+A.sum()+" A="+A);
logLh = -pl1[idx];
// set lh
return;
}
示例10: processCoalEvent
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
protected double processCoalEvent(int t, int currTreeInterval) {
List<DoubleMatrix> coalVectors = stateProbabilities.getCoalescentVectors(intervals, currTreeInterval);
DoubleMatrix pvec1, pvec2;
pvec1 = coalVectors.get(0);
pvec2 = coalVectors.get(1);
List<Node> parentLines = intervals.getLineagesAdded(currTreeInterval);
if (parentLines.size() > 1) throw new RuntimeException("Unsupported coalescent at non-binary node");
//Add parent to activeLineage and initialise parent's state prob vector
Node parentNode = parentLines.get(0);
//Compute parent lineage state probabilities in p
DoubleMatrix F,Y;
Y = ts.getYs()[t];
F = ts.getFs()[t];
if (forgiveYInput.get()) {
Y.maxi(1.0);
} else { // however, Y_i > 1e-12 by default
Y.maxi(1e-12);
}
double lambda;
/* Compute Lambda Sum */
DoubleMatrix pa;
DoubleMatrix pi_Y = pvec1.div(Y);
pi_Y.reshape(numStates, 1);
DoubleMatrix pj_Y = pvec2.div(Y);
pj_Y.reshape(numStates, 1);
pa = pi_Y.mul(F.mmul(pj_Y));
pa.addi(pj_Y.mul(F.mmul(pi_Y)));
pa.reshape(1,numStates);
lambda = pa.sum();
pa.divi(lambda);
stateProbabilities.addLineage(parentNode.getNr(),pa);
sp[parentNode.getNr() - nrSamples] = (pa);
//Remove child lineages
List<Node> coalLines = intervals.getLineagesRemoved(currTreeInterval);
stateProbabilities.removeLineageNr(coalLines.get(0).getNr() );
stateProbabilities.removeLineageNr(coalLines.get(1).getNr());
if (fsCorrectionsInput.get()) {
doFiniteSizeCorrections(parentNode,pa);
}
return lambda;
}
示例11: create
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public CorrMatrix create(ITable data) {
for (String col : this.colNames) {
if ((data.getSchema().getKind(col) != ContentsKind.Double) &&
(data.getSchema().getKind(col) != ContentsKind.Integer))
throw new InvalidParameterException("Correlation Sketch requires column to be " +
"integer or double: " + col);
}
CorrMatrix corrMatrix = new CorrMatrix(this.colNames);
ITable table;
if (this.samplingRate >= 1)
table = data;
else {
ColumnAndConverterDescription[] ccds = ColumnAndConverterDescription.create(
this.colNames);
ColumnAndConverter[] iCols = data.getLoadedColumns(ccds);
IMembershipSet mm = data.getMembershipSet().sample(this.samplingRate, this.seed);
table = data.compress(mm);
}
int nRows = table.getNumOfRows();
int nCols = this.colNames.length;
// Convert the columns to a DoubleMatrix.
DoubleMatrix mat = BlasConversions.toDoubleMatrix(table, this.colNames);
// The number of non-missing values per column pair
corrMatrix.nonMissing = DoubleMatrix.ones(nCols, nCols).mul(nRows);
for (int row = 0; row < mat.rows; row++) {
for (int i = 0; i < mat.columns; i++) {
if (Double.isNaN(mat.get(row, i))) {
mat.put(row, i, 0); // Set the value to 0 so it doesn't contribute.
corrMatrix.nonMissing.put(i, i, corrMatrix.nonMissing.get(i, i) - 1);
for (int j = i; j < mat.columns; j++) {
if (Double.isNaN(mat.get(row, j))) {
corrMatrix.nonMissing.put(i, j, corrMatrix.nonMissing.get(i, j) - 1);
corrMatrix.nonMissing.put(j, i, corrMatrix.nonMissing.get(j, i) - 1);
}
}
}
}
}
// Since the missing values are set to 0, they don't contribute to the covariance matrix.
DoubleMatrix covMat = mat.transpose().mmul(mat);
// Normalize by the number of *actual* values processed. (Also for the mean!)
covMat.divi(corrMatrix.nonMissing);
DoubleMatrix means = mat.columnSums().divRowVector(corrMatrix.nonMissing.diag());
for (int i = 0; i < this.colNames.length; i++) {
for (int j = i; j < this.colNames.length; j++) {
corrMatrix.put(i, j, covMat.get(i, j));
}
corrMatrix.means[i] = means.get(i);
}
return corrMatrix;
}