本文整理汇总了Java中org.jblas.DoubleMatrix.mul方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.mul方法的具体用法?Java DoubleMatrix.mul怎么用?Java DoubleMatrix.mul使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jblas.DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.mul方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sigmoidDerivate
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
/**
* Element-wise derivated sigmoid
* @param x DoubleMatrix
* @return DoubleMatrix sigmoid'()
*/
protected static DoubleMatrix sigmoidDerivate(DoubleMatrix x) {
if (x != null) {
DoubleMatrix ones = DoubleMatrix.ones(x.rows, x.columns);
return x.mul(ones.sub(x));
}
return null;
}
示例2: trainOn
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public double trainOn(MultitaggerTrainingSentence sentence, int i, double learningRate, double cumProbCutoff, int maxK) {
MultitaggerTrainingItem item = sentence.getItems().get(i);
int goldRank = item.getGoldIndex();
if(goldRank < 0) {
return 0.0;
// Can't train on missing categories? (or maybe should return single top category)
}
double firstProb = first.predict(sentence, i);
double continueProb = 1.0-firstProb;
ArrayList<Double> probs = new ArrayList<Double>();
probs.add(firstProb);
ArrayList<Double> cumProbs = new ArrayList<Double>();
cumProbs.add(1.0 - continueProb);
int k = 1;
DoubleMatrix category = this.categoryEmbeddings.getVec(item.getCat(0));
this.history = category.mul(firstProb);
while(continueProb >= cumProbCutoff && k < maxK) {
category = this.categoryEmbeddings.getVec(item.getCat(k));
double laterProb = later.predict(sentence, i, k, history);
probs.add(laterProb);
continueProb *= (1.0 - laterProb);
cumProbs.add(1.0 - continueProb);
this.history.addi(category.mul(cumProbs.get(k)));
k++;
}
return 0.0;
}
示例3: coalesceDown
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private void coalesceDown(int currTreeInterval) {
List<Node> parentLines = mascotInput.get().treeIntervalsInput.get().getLineagesAdded(currTreeInterval);
if (parentLines.size()!=1){
System.err.println("to many lineages, while coalescening down");
System.exit(0);
}
Node parentNode = parentLines.get(0);
if (!parentNode.isRoot()){
DoubleMatrix start = stateProbabilities[parentNode.getNr() - nrSamples];
DoubleMatrix end = stateProbabilitiesDown[parentNode.getParent().getNr() - nrSamples];
DoubleMatrix flow = TransitionProbabilities[parentNode.getNr()];
DoubleMatrix otherSideInfo = end.div(start.transpose().mmul(flow));
// get rid of NaN from division by 0
for (int i = 0; i < otherSideInfo.length; i++)
if (Double.isNaN(otherSideInfo.get(i)))
otherSideInfo.put(i, 0.0);
DoubleMatrix conditional = flow.mmul(otherSideInfo);
conditional = conditional.mul(start);
stateProbabilitiesDown[parentNode.getNr() - nrSamples] = conditional.div(conditional.sum());
// if (!(conditional.get(0) >= 0.0 && conditional.get(0)<=1.0))
// conditional.print();
}else{
// DoubleMatrix d1 = stateProbabilities[parentNode.getLeft().getNr() - nrSamples];
// DoubleMatrix d2 = stateProbabilities[parentNode.getRight().getNr() - nrSamples];
// DoubleMatrix f1 = TransitionProbabilities[parentNode.getLeft().getNr()];
// DoubleMatrix f2 = TransitionProbabilities[parentNode.getLeft().getNr()];
// d1.transpose().mmul(f1).print();
// d2.transpose().mmul(f2).print();
// d1.print();
// d2.print();
// System.out.println();
// f1.print();
// f2.print();
// System.out.println();
// stateProbabilities[parentNode.getNr() - nrSamples].print();
//
// System.out.println();
// System.exit(0);
stateProbabilitiesDown[parentNode.getNr() - nrSamples] = stateProbabilities[parentNode.getNr() - nrSamples];
}
}
示例4: 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;
}