本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D类的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D类的具体用法?Java DoubleMatrix2D怎么用?Java DoubleMatrix2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleMatrix2D类属于cern.colt.matrix包,在下文中一共展示了DoubleMatrix2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSparseMatrix
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
private DoubleMatrix2D createSparseMatrix(int M, int R, double sparcityPercentage) {
// TODO: add varying scale factor.
// Create sparse matrix.
DoubleMatrix2D D = DoubleFactory2D.sparse.random(M, R);
double[] rowSums = new double[M];
for (int m = 0; m < M; m++) {
for (int r = 0; r < R; r++) {
if (rand.nextDouble() < sparcityPercentage) {
D.set(m, r, 0);
}
rowSums[m] += D.get(m, r);
}
}
// Normalise rows.
for (int m = 0; m < M; m++) {
for (int r = 0; r < R; r++) {
double val = D.get(m, r);
D.set(m, r, val/rowSums[m]);
}
}
return D;
}
示例2: validierung
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
public void validierung(DoubleArrayList trendbereinigtezeitreihe, DoubleMatrix2D matrixPhi, int p) {
double prognosewert = 0;
double realisierungsWert = trendbereinigtezeitreihe.get(trendbereinigtezeitreihe.size() - 1);
Trendgerade trend = new Trendgerade(new double[1]);
realisierungsWert = realisierungsWert + trend.getValue(p);
// Ein Durchlauf findet den Gewichtungsfaktor Phi und den dazu passenden
// Vergangenheitswert.
// Hier wird der Prognosewert für den Zeitpunkt 0 berechnet
for (int t = 0; t < p; t++) {
prognosewert = prognosewert
+ (matrixPhi.get(t, 0) * trendbereinigtezeitreihe.get(trendbereinigtezeitreihe.size() - (t + 2)));
}
prognosewert = prognosewert + trend.getValue(p);
// Berechnung der prozentualen Abweichung
double h = prognosewert / (realisierungsWert / 100);
// Die Variable abweichung enthält die Abweichung in %, abweichung =1
// --> Die Abweichung beträgt 1%
double abweichung = Math.abs(h - 100);
setAbweichung(abweichung);
}
示例3: getRoots
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Double[] getRoots(final RealPolynomialFunction1D function) {
Validate.notNull(function, "function");
final double[] coeffs = function.getCoefficients();
final int l = coeffs.length - 1;
final DoubleMatrix2D hessian = DoubleFactory2D.dense.make(l, l);
for (int i = 0; i < l; i++) {
hessian.setQuick(0, i, -coeffs[l - i - 1] / coeffs[l]);
for (int j = 1; j < l; j++) {
hessian.setQuick(j, i, 0);
if (i != l - 1) {
hessian.setQuick(i + 1, i, 1);
}
}
}
final double[] d = new EigenvalueDecomposition(hessian).getRealEigenvalues().toArray();
final Double[] result = new Double[d.length];
for (int i = 0; i < d.length; i++) {
result[i] = d[i];
}
return result;
}
示例4: blockDiagonalExponential
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
private static DoubleMatrix2D blockDiagonalExponential(double distance, DoubleMatrix2D mat) {
for (int i = 0; i < mat.rows(); i++) {
if ((i + 1) < mat.rows() && mat.getQuick(i, i + 1) != 0) {
double a = mat.getQuick(i, i);
double b = mat.getQuick(i, i + 1);
double expat = Math.exp(distance * a);
double cosbt = Math.cos(distance * b);
double sinbt = Math.sin(distance * b);
mat.setQuick(i, i, expat * cosbt);
mat.setQuick(i + 1, i + 1, expat * cosbt);
mat.setQuick(i, i + 1, expat * sinbt);
mat.setQuick(i + 1, i, -expat * sinbt);
i++; // processed two entries in loop
} else
mat.setQuick(i, i, Math.exp(distance * mat.getQuick(i, i))); // 1x1 block
}
return mat;
}
示例5: save
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
/**
* Saves a graph to a file
* @see edu.uci.ics.jung.io.GraphFile#save(edu.uci.ics.jung.graph.Graph, java.lang.String)
*/
public void save(Graph<V,E> graph, String filename) {
try {
BufferedWriter writer =
new BufferedWriter(new FileWriter(filename));
DoubleMatrix2D matrix = GraphMatrixOperations.<V,E>graphToSparseMatrix(graph,
mWeightKey);
for (int i=0;i<matrix.rows();i++) {
for (int j=0;j<matrix.columns();j++) {
writer.write(String.format("%4.2f ", matrix.getQuick(i,j)));
}
writer.write("\n");
}
writer.close();
} catch (Exception e) {
throw new RuntimeException("Error saving file: " + filename, e);
}
}
示例6: testBuildMatrix4
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
@Test
public final void testBuildMatrix4()
{
LearnerGraph gr=buildLearnerGraph("A-a->B\nA-b->C\nD-a->C", "testBuildMatrix4",config,converter);
final int size =4*5/2;
DoubleMatrix2D matrix=createIdentity(size);
DoubleMatrix1D row=DoubleFactory1D.dense.make(size, 0);
matrix.setQuick(2, 2, 1);matrix.setQuick(4, 4, 1);matrix.setQuick(5, 5, 1);// pairs with zero total outgoing transitions.
matrix.setQuick(0, 0, 2*2);matrix.setQuick(0, 2, -k);matrix.setQuick(0, 5, -k);row.setQuick(0, 2);
matrix.setQuick(1, 1, 2*2);
matrix.setQuick(3, 3, 2*2);
matrix.setQuick(6, 6, 2*2);
matrix.setQuick(9, 5, -k);row.setQuick(9, 1);
matrix.setQuick(6, 4, -k);row.setQuick(6, 1);
checkBuildMatrix(gr,matrix,row);
}
示例7: testBuildMatrix5
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
@Test
public final void testBuildMatrix5()
{
LearnerGraph gr=buildLearnerGraph("A-a->B\nA-b->C\nD-a->C\nD-b->C","testBuildMatrix5",config,converter);
final int size =4*5/2;
DoubleMatrix2D matrix=createIdentity(size);
DoubleMatrix1D row=DoubleFactory1D.dense.make(size, 0);
matrix.setQuick(2, 2, 1);matrix.setQuick(4, 4, 1);matrix.setQuick(5, 5, 1);// pairs with zero total outgoing transitions.
matrix.setQuick(0, 0, 2*2);matrix.setQuick(0, 2, -k);matrix.setQuick(0, 5, -k);row.setQuick(0, 2);
matrix.setQuick(1, 1, 2*2);
matrix.setQuick(3, 3, 2*2);
matrix.setQuick(6, 6, 2*2);
matrix.setQuick(9, 5, -2*k);row.setQuick(9, 2);
matrix.setQuick(6, 4, -k);matrix.setQuick(6, 5, -k);row.setQuick(6, 2);
matrix.setQuick(9, 9, 2*2);
matrix.setQuick(8, 8, 2*2);
matrix.setQuick(7, 7, 2*2);
matrix.setQuick(6, 6, 2*2);
checkBuildMatrix(gr,matrix,row);
}
示例8: testBuildMatrix6
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
@Test
public final void testBuildMatrix6()
{
LearnerGraph gr=buildLearnerGraph("A-a->B\nA-b->C\nD-a->C\nD-b->C\nD-c->A","testBuildMatrix6",config,converter);
final int size =4*5/2;
DoubleMatrix2D matrix=createIdentity(size);
DoubleMatrix1D row=DoubleFactory1D.dense.make(size, 0);
matrix.setQuick(2, 2, 1);matrix.setQuick(4, 4, 1);matrix.setQuick(5, 5, 1);// pairs with zero total outgoing transitions.
matrix.setQuick(0, 0, 2*2);matrix.setQuick(0, 2, -k);matrix.setQuick(0, 5, -k);row.setQuick(0, 2);
matrix.setQuick(1, 1, 2*2);
matrix.setQuick(3, 3, 2*2);
matrix.setQuick(6, 6, 2*2);
matrix.setQuick(9, 5, -2*k);matrix.setQuick(9, 0, -k);row.setQuick(9, 3);
matrix.setQuick(6, 4, -k);matrix.setQuick(6, 5, -k);row.setQuick(6, 2);
matrix.setQuick(9, 9, 3*2);
matrix.setQuick(8, 8, 3*2);
matrix.setQuick(7, 7, 3*2);
matrix.setQuick(6, 6, 3*2);
checkBuildMatrix(gr,matrix,row);
}
示例9: testBuildMatrix7
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
@Test
public final void testBuildMatrix7()
{
LearnerGraph gr=buildLearnerGraph("A-a->B\nA-b->C\nA-c->C\nD-a->C\nD-b->C\nD-c->A","testBuildMatrix7",config,converter);
final int size =4*5/2;
DoubleMatrix2D matrix=createIdentity(size);
DoubleMatrix1D row=DoubleFactory1D.dense.make(size, 0);
matrix.setQuick(2, 2, 1);matrix.setQuick(4, 4, 1);matrix.setQuick(5, 5, 1);// pairs with zero total outgoing transitions.
matrix.setQuick(0, 0, 3*2);matrix.setQuick(0, 2, -k);matrix.setQuick(0, 5, -2*k);row.setQuick(0, 3);
matrix.setQuick(1, 1, 3*2);
matrix.setQuick(3, 3, 3*2);
matrix.setQuick(6, 6, 3*2);
matrix.setQuick(9, 5, -2*k);matrix.setQuick(9, 0, -k);row.setQuick(9, 3);
matrix.setQuick(6, 4, -k);matrix.setQuick(6, 5, -k);matrix.setQuick(6, 3, -k);row.setQuick(6, 3);
matrix.setQuick(9, 9, 3*2);
matrix.setQuick(8, 8, 3*2);
matrix.setQuick(7, 7, 3*2);
matrix.setQuick(6, 6, 3*2);
checkBuildMatrix(gr,matrix,row);
}
示例10: testBuildMatrix8
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
@Test
public final void testBuildMatrix8()
{
LearnerGraph gr=buildLearnerGraph("A-a->B\nA-b->C\nA-c->C\nD-a->C\nD-b->C\nD-d->C\nD-c->A","testBuildMatrix8",config,converter);
final int size =4*5/2;
DoubleMatrix2D matrix=createIdentity(size);
DoubleMatrix1D row=DoubleFactory1D.dense.make(size, 0);
matrix.setQuick(2, 2, 1);matrix.setQuick(4, 4, 1);matrix.setQuick(5, 5, 1);// pairs with zero total outgoing transitions.
matrix.setQuick(0, 0, 3*2);matrix.setQuick(0, 2, -k);matrix.setQuick(0, 5, -2*k);row.setQuick(0, 3);
matrix.setQuick(1, 1, 3*2);
matrix.setQuick(3, 3, 3*2);
matrix.setQuick(6, 6, 3*2);
matrix.setQuick(9, 5, -3*k);matrix.setQuick(9, 0, -k);row.setQuick(9, 4);
matrix.setQuick(6, 4, -k);matrix.setQuick(6, 5, -k);matrix.setQuick(6, 3, -k);row.setQuick(6, 3);
matrix.setQuick(9, 9, 4*2);
matrix.setQuick(8, 8, 4*2);
matrix.setQuick(7, 7, 4*2);
matrix.setQuick(6, 6, 4*2);
checkBuildMatrix(gr,matrix,row);
}
示例11: computeLogMiTrainMode
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
protected boolean computeLogMiTrainMode(FeatureGenerator featureGen, double lambda[],
DataSequence dataSeq, int i,
DoubleMatrix2D Mi_YY,
DoubleMatrix1D Ri_Y, boolean takeExp, boolean reuseM, boolean initMDone) {
boolean retVal = Trainer.computeLogMi(featureGen,lambda,dataSeq,i,fMi_YY,Ri_Y,false,reuseM,initMDone);
int iterNum = icall;
for (int c = 0; c < Ri_Y.size();c++) {
int loss = (dataSeq.y(i)!=c)?1:0;
Ri_Y.set(c,eta*C*(Ri_Y.get(c)+iterNum*loss));
/*
* don't need loss for this since it is already accounted for in Ri_Y
*/
if (i > 0) {
for (int r = 0; r < Mi_YY.rows(); r++) {
Mi_YY.set(r,c,eta*C*(fMi_YY.get(r,c)));
}
}
}
return retVal;
}
示例12: the
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
/**
Generates and returns the (economy-sized) orthogonal factor <tt>Q</tt>.
@return <tt>Q</tt>
*/
public DoubleMatrix2D getQ () {
cern.jet.math.Functions F = cern.jet.math.Functions.functions;
DoubleMatrix2D Q = QR.like();
//double[][] Q = X.getArray();
for (int k = n-1; k >= 0; k--) {
DoubleMatrix1D QRcolk = QR.viewColumn(k).viewPart(k,m-k);
Q.setQuick(k,k, 1);
for (int j = k; j < n; j++) {
if (QR.getQuick(k,k) != 0) {
DoubleMatrix1D Qcolj = Q.viewColumn(j).viewPart(k,m-k);
double s = QRcolk.zDotProduct(Qcolj);
s = -s / QR.getQuick(k,k);
Qcolj.assign(QRcolk, F.plusMult(s));
}
}
}
return Q;
}
示例13: allocateCacheArray
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
private void allocateCacheArray(DataSequence dataSeq) {
int i = -1, seqLength = dataSeq.length(), ell;
Iter iter = getIter();
Mis = new LogSparseDoubleMatrix2D[seqLength][];
Ris = new LogSparseDoubleMatrix1D[seqLength][];
int size = 0, maxEll = 0;
staticHeapMi.reset();
staticHeapRi.reset();
for(i++; i < seqLength; i++){
iter.start(i, dataSeq);
while((ell = iter.nextEll(i)) > 0 )
maxEll = (maxEll < ell) ? ell : maxEll;
size = (i < maxEll ? i+1: maxEll);
Mis[i] = new LogSparseDoubleMatrix2D[size + 1];
Ris[i] = new LogSparseDoubleMatrix1D[size + 1];
for(int j = 0; j < Mis[i].length; j++){
Mis[i][j] = (DoubleMatrix2D) staticHeapMi.getObject(); //new LogSparseDoubleMatrix2D(numY,numY);
Ris[i][j] = (DoubleMatrix1D) staticHeapRi.getObject(); //new LogSparseDoubleMatrix1D(numY);
}
}
}
示例14: assign
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
/**
* Sets all cells to the state specified by <tt>value</tt>.
* @param value the value to be filled into the cells.
* @return <tt>this</tt> (for convenience only).
*/
public DoubleMatrix2D assign(double value) {
// overriden for performance only
if (value==0) {
for (int i=values.length; --i >= 0; ) values[i]=0;
for (int i=dims.length; --i >= NONZERO; ) dims[i]=0;
//for (int i=diagonal.length; --i >= 0; ) diagonal[i]=0;
//for (int i=upper.length; --i >= 0; ) upper[i]=0;
//for (int i=lower.length; --i >= 0; ) lower[i]=0;
//diagonalNonZeros = 0;
//lowerNonZeros = 0;
//upperNonZeros = 0;
}
else super.assign(value);
return this;
}
示例15: getSumDeviations
import cern.colt.matrix.DoubleMatrix2D; //导入依赖的package包/类
public static double getSumDeviations(DoubleMatrix2D proj, int[] groups) {
int idx = 0;
int currGroup;
double[][] projD = proj.toArray();
do {
double[] avgGroup = new double[proj.columns()];
int grpSize = 0;
currGroup = groups[idx];
while (idx < groups.length && groups[idx] == currGroup) {
avgGroup = MatrixOp.sum(avgGroup, projD[idx]);
idx++;
grpSize++;
}
idx -= grpSize;
MatrixOp.mult(avgGroup, 1.0 / (double) grpSize);
while (idx < groups.length && groups[idx] == currGroup) {
projD[idx] = MatrixOp.diff(projD[idx], avgGroup);
idx++;
}
} while (idx < groups.length);
double sumSqLen = 0;
for (double[] ds : projD) {
sumSqLen += asinh(MatrixOp.mult(ds, ds));
}
return sumSqLen;
}