本文整理汇总了Java中org.jblas.DoubleMatrix.put方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.put方法的具体用法?Java DoubleMatrix.put怎么用?Java DoubleMatrix.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jblas.DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeQ
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
protected DoubleMatrix computeQ(DoubleMatrix Y, DoubleMatrix F, DoubleMatrix G, DoubleMatrix Coef) {
DoubleMatrix Q = DoubleMatrix.zeros(numStates,numStates);
double rateOutByBirth, rateOutByMigration, totalRate;
for (int k = 0; k < numStates; k++) /* k row */
{
double colSum = 0.0, diag;
if (Y.get(k) > 0) {
for (int l = 0; l < numStates; l++)
{
rateOutByBirth = F.get(l,k) * Coef.get(l) / Y.get(k);
//rateOutByBirth = F.get(l,k) / Y.get(k);
rateOutByMigration = G.get(l,k) / (Y.get(k));
totalRate = rateOutByBirth + rateOutByMigration;
Q.put(k, l, totalRate);
colSum += totalRate;
}
diag = Q.get(k,k);
Q.put(k,k,diag-colSum);
}
// else skip and leave row k with zero values
// Q.put(k, l, 0.0);
}
return Q;
}
示例2: loadDataSet
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public static Pair<List<DoubleMatrix>, double[]> loadDataSet(BufferedReader stream, final int size, final int numAttributes) throws Exception
{
// read LibSVM data
double[] label_list = new double[size];
List<DoubleMatrix> data_list = new ArrayList<>(size);
for(int label_idx = 0; label_idx < size; ++label_idx)
{
String[] data = stream.readLine().trim().split("\\s+");
label_list[label_idx] = Double.parseDouble(data[numAttributes]);
DoubleMatrix feature_vector = DoubleMatrix.zeros(numAttributes);
for (int idx = 0; idx < numAttributes; ++idx)
{
feature_vector.put(idx, Double.parseDouble(data[idx]));
assert(feature_vector.get(idx) >= 0.0 && feature_vector.get(idx) <= 1.0);
}
data_list.add(feature_vector);
}
return new DMPair(data_list, label_list);
}
示例3: fillOutputVector
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
protected void fillOutputVector(DoubleMatrix output,
MultitaggerTrainingSentence sentence, int position) {
for(int i=0; i<output.length; i++) {
output.put(i, 0.0);
}
this.inputItem = sentence.getItems().get(position);
for(int c=0; c<K; c++) {
String cat = this.inputItem.getCat(c);
Integer ind = this.index.get(cat);
if(ind == null) {
ind = this.index.get(MISSING);
}
output.put(ind, this.inputItem.getProb(c));
}
}
示例4: computeHighDimDistances
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private DoubleMatrix computeHighDimDistances(DoubleMatrix dataHighDim, BiFunction<DoubleMatrix, DoubleMatrix, Double> distHighDim) {
DoubleMatrix dists = new DoubleMatrix((dataHighDim.rows * (dataHighDim.rows - 1)) / 2);
for (int i = 0; i < dataHighDim.rows - 1; i++) {
DoubleMatrix x1 = dataHighDim.get(new PointRange(i), new AllRange());
for (int j = i + 1; j < dataHighDim.rows; j++) {
DoubleMatrix x2 = dataHighDim.get(new PointRange(j), new AllRange());
double dist = distHighDim.apply(x1, x2);
int idx = this.compactIndex(i, j);
dists.put(idx, dist);
}
}
/* Normalize the distances s.t. the largest is 1. */
this.scaling = 1 / dists.max();
dists.muli(this.scaling);
return dists;
}
示例5: fillOutputVector
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
protected void fillOutputVector(DoubleMatrix output,
MultitaggerTrainingSentence sentence, int position) {
String cat = sentence.getItems().get(position).getCat(0);
Integer ind = this.index.get(cat);
if(ind == null) {
ind = this.index.get(MISSING);
cat = MISSING;
}
for(int i=0; i<this.getOutputDimension(); i++) {
output.put(i, 0);
}
DoubleMatrix vec = this.getFeatureVector(cat);
for(int i=this.dimension*ind; i<this.dimension*(ind+1); i++) {
int j = i - this.dimension*ind;
this.outputVector.put(i, vec.get(j));
}
this.inputFeatureIndex = ind;
}
示例6: testSimpleMatrix
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Test
public void testSimpleMatrix() {
// Setting elements
DoubleMatrix mat = new DoubleMatrix(2, 2);
mat.put(0, 0, 2.3);
mat.put(1, 0, 42.42);
mat.put(0, 1, 3.14);
mat.put(1, 1, 3.91992);
Assert.assertEquals(mat.get(0, 0), 2.3, Math.ulp(2.3));
Assert.assertEquals(mat.get(1, 0), 42.42, Math.ulp(42.42));
Assert.assertEquals(mat.get(0, 1), 3.14, Math.ulp(3.14));
Assert.assertEquals(mat.get(1, 1), 3.91992, Math.ulp(3.91992));
// Matrix multiplied with its transpose should be symmetric.
DoubleMatrix symMat = mat.mmul(mat.transpose());
for (int i = 0; i < symMat.rows; i++) {
for (int j = 0; j < symMat.columns; j++) {
Assert.assertEquals(symMat.get(i, j), symMat.get(j, i), Math.ulp(symMat.get(i, j)));
}
}
}
示例7: updateLineProbs
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
protected boolean updateLineProbs(int tsPoint, double dt) {
DoubleMatrix A = stateProbabilities.getLineageStateSum();
DoubleMatrix Y = ts.getYs()[tsPoint];
DoubleMatrix F = ts.getFs()[tsPoint];
DoubleMatrix G = ts.getGs()[tsPoint];
DoubleMatrix mul = Y.sub(A).div(Y);
/*
* (before: If there is more state probability in a deme than individuals
* return the false flag indicating an error)
* Fix coefficient to [0,1] range
*/
if(mul.min()<0 || mul.max() > 1) {
//System.out.println("Y<A t: "+t+" Y "+Y+" A: "+A+" -- fixing --");
for(int i=0; i < mul.length; i++) {
final double v = mul.get(i);
if (v < 0.0) { mul.put(i, 0.0); }
if (v > 1.0) { mul.put(i, 1.0); }
}
}
if (Double.isNaN(mul.get(0)))
{ System.out.println("NaN"); return true; }
DoubleMatrix QT = computeQTrans(Y, F, G, mul);
// dP(i)/dt = Q*Pi , i lineage, Pi column vector
// dP(i)/dt = Pi*QT, QT=trans(Q); Pi,dPi row vectors
// transposed version more efficient due to jblas column-major layout
// We need the state probabilities as row vectors
/* Compute lineage probabilities */
DoubleMatrix newP = matrixExponential(QT, dt);
// Update extant probabilities: p*Q
stateProbabilities.mulExtantProbabilities(newP, true);
return false;
}
示例8: computeQTrans
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
protected DoubleMatrix computeQTrans(DoubleMatrix Y, DoubleMatrix F, DoubleMatrix G, DoubleMatrix Coef) {
DoubleMatrix Q = DoubleMatrix.zeros(numStates,numStates);
double rateOutByBirth, rateOutByMigration, totalRate;
for (int k = 0; k < numStates; k++)
{
double rowSum = 0.0;
for (int l = 0; l < numStates; l++)
{
if (k != l)
{ // off-diagonal
if (Y.get(k) > 0)
{
rateOutByBirth = F.get(l,k) * Coef.get(l) / Y.get(k); // Birth in other deme (Backwards in time)
rateOutByMigration = G.get(l,k) / (Y.get(k)); // State change of lineages (Backwards in time)
totalRate = rateOutByBirth + rateOutByMigration;
Q.put(k, l, totalRate);
rowSum += totalRate;
}
else
{ // diagonal
Q.put(k, l, 0.0);
}
}
}
Q.put(k,k,-rowSum);
}
return Q;
}
示例9: computeLambdaSum
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public double computeLambdaSum(int t, int childIdx1, int childIdx2) {
double lambda;
DoubleMatrix F,Y;
Y = ts.getYs()[t];
F = ts.getFs()[t];
DoubleMatrix pa, pvec1, pvec2;
pvec1 = stateProbabilities.getStateProbsFromIndex(childIdx1);
pvec2 = stateProbabilities.getStateProbsFromIndex(childIdx2);
/* previous version */
DoubleMatrix coalRates = DoubleMatrix.zeros(numStates, numStates);
for (int k = 0; k < numStates; k++) {
for (int l = 0; l < numStates; l++) {
final double Yk = Y.get(k);
final double Yl = Y.get(l);
//System.out.println("numStates="+numStates+"dim:"+F.rows+", "+F.columns);
lambda = F.get(k,l) / (Yk*Yl)
* (pvec1.get(k) * pvec2.get(l)
+ pvec1.get(l) * pvec2.get(k));
coalRates.put(k, l, lambda);
}
}
lambda = coalRates.sum();
pa = coalRates.rowSums().div(lambda).transpose(); // row-vector
/* pa := new state probabilities of the lineage dt after coalescing */
return lambda;
}
示例10: processSampleEvent
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
protected void processSampleEvent(int interval) {
int sampleState;
List<Node> incomingLines = intervals.getLineagesAdded(interval);
for (Node l : incomingLines) {
/* uses pre-computed nodeNrToState */
sampleState = nodeNrToState[l.getNr()]; /* suceeds if node is a leaf, otherwise state=-1 */
DoubleMatrix sVec = DoubleMatrix.zeros(1,numStates); // row-vector
sVec.put(sampleState, 1.0);
stateProbabilities.addLineage(l.getNr(),sVec);
}
}
示例11: getState
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private DoubleMatrix getState() {
DoubleMatrix result = new DoubleMatrix(board.length, 1);
for (int i = 0; i < board.length; i++) {
result.put(i, board[i].value);
}
return result;
}
示例12: setSegmentOutput
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private void setSegmentOutput(DoubleMatrix output, DoubleMatrix embedding, double prob, int segIndex) {
int[] indices = this.segmentIndices.get(segIndex);
LinearLayer map = this.mappingFunctions.get(segIndex);
DoubleMatrix result = map.output(embedding);
output.put(indices, result);
output.put(indices[indices.length-1]+1, prob);
}
开发者ID:ramusa2,项目名称:CandCNFPerceptronParser,代码行数:8,代码来源:ContextSensitiveFirstClassifierLookupLayer.java
示例13: updateParameters
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public void updateParameters(DoubleMatrix outputGradient,
double learningRate) {
for(int c=0; c<K; c++) {
DoubleMatrix embed = this.catEmbeddings.get(this.currentCatIDs[c]);
for(int w=0; w<this.D; w++) {
embed.put(w, embed.get(w) + outputGradient.get(w+1)*learningRate); // w+1: skip prob feature
}
}
}
示例14: stringToDoubleMatrix
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
private final static DoubleMatrix stringToDoubleMatrix(String input, int startPos) {
String[] toks = input.trim().split("\\s+");
double[] arr = new double[toks.length - startPos];
for(int i=startPos; i<toks.length; i++) {
arr[i-startPos] = Double.parseDouble(toks[i]);
}
DoubleMatrix vec = new DoubleMatrix(arr.length, 1);
for(int i=0; i<vec.length; i++) {
vec.put(i, arr[i]);
}
return vec;
}
示例15: loadWeightsFromFile
import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
@Override
public void loadWeightsFromFile(File file) {
Scanner sc = null;
try {
sc = new Scanner(file);
String line;
while(sc.hasNextLine()) {
line = sc.nextLine().trim();
if(!line.isEmpty()) {
String[] toks = line.split("\\s+");
if(toks.length == this.dimension+1) {
DoubleMatrix weights = new DoubleMatrix(this.dimension, 1);
for(int i=1; i<toks.length; i++) {
weights.put(i-1, Double.parseDouble(toks[i]));
}
this.lookupTable.put(toks[0], weights);
}
else {
System.out.println("Malformed weights file; dimensionality does not match " +
"(expected "+this.dimension+" outputs, " +
"read "+(toks.length-1)+" weights).\nAborting.");
sc.close();
return;
}
}
}
sc.close();
} catch (FileNotFoundException e) {
System.out.println("Failed to load lookup layer weights from: "+file.getPath());
}
}