本文整理汇总了Java中cern.colt.matrix.DoubleMatrix1D类的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix1D类的具体用法?Java DoubleMatrix1D怎么用?Java DoubleMatrix1D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoubleMatrix1D类属于cern.colt.matrix包,在下文中一共展示了DoubleMatrix1D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuildMatrix4
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
示例2: testBuildMatrix5
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
示例3: testBuildMatrix6
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
示例4: testBuildMatrix7
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
示例5: testBuildMatrix8
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
示例6: Mult
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static DoubleMatrix1D Mult(DoubleMatrix2D M, DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA, EdgeGenerator edgeGen) {
// z = alpha * A * y + beta*z
for (int i = 0; i < z.size(); z.set(i,z.get(i)*beta),i++);
for (int j = 0; j < M.columns(); j++) {
for (int i = (edgeGen==null)?j:edgeGen.first(j); i < M.rows(); i = (edgeGen==null)?i+1:edgeGen.next(j,i)) {
int r = i;
int c = j;
if (transposeA) {
r = j;
c = i;
}
z.set(r, z.getQuick(r) + M.getQuick(i,j)*y.getQuick(c)*alpha);
}
}
return z;
}
示例7: allocateCacheArray
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的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);
}
}
}
示例8: MetaPathInstanceCnt
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
public MetaPathInstanceCnt(MetaPath metaPath,List<List<DoubleMatrix1D>> interMats) {
this.metaPath = metaPath;
this.interMats = interMats;
doc_num = interMats.get(0).size();
label_map = new HashMap<Integer, Integer>();
Set<String> types = new HashSet<String>();
int cnt = 0;
for(int i = 0; i < metaPath.path.size(); i++)
{
String type = metaPath.path.get(i);
if (!types.contains(type))
{
types.add(type);
label_map.put(i, cnt);
cnt ++;
} else {
for (int j = 0; j < i; j++)
if (metaPath.path.get(j).equals(type))
{
label_map.put(i, label_map.get(j));
break;
}
}
}
}
示例9: getVertexNum
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
public static int getVertexNum(List<List<DoubleMatrix1D>> interMats, boolean self_cycle, Map<Integer, Integer> label_map)
{
int num = 0;
Set<Integer> visited = new HashSet<Integer>();
for (int i = 0; i < interMats.size(); i++)
{
int idx = label_map.get(i);
if (! visited.contains(idx)){
num += interMats.get(i).size();
visited.add(idx);
}
}
if (!self_cycle)
{
num += interMats.get(interMats.size() - 1).get(0).size();
}
return num;
}
示例10: matrixSum
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static public DoubleMatrix1D matrixSum (List<DoubleMatrix1D> mat, int dim) {
DenseDoubleMatrix1D maxVector = null;
if (dim == 2) { // row sum valuse
maxVector = new ColtDenseVector(mat.size());
} else if(dim == 1) { // column sum value
maxVector = new ColtDenseVector(mat.get(0).size());
}
for (int i = 0; i < mat.size(); ++i) {
for (int j = 0; j < mat.get(i).size(); ++j) {
if (dim == 2) {
maxVector.setQuick(i, maxVector.getQuick(i) + mat.get(i).getQuick(j));
} else if (dim == 1) {
maxVector.setQuick(j, maxVector.getQuick(j) + mat.get(i).getQuick(j));
}
}
}
return maxVector;
}
示例11: SparseMultSparseTranspose
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static public List<DoubleMatrix1D> SparseMultSparseTranspose(List<DoubleMatrix1D> A,
List<DoubleMatrix1D> B) {
int m = A.size();
int n = A.get(0).size();
int p = B.size();
List<DoubleMatrix1D> C = null;
if (C==null) {
C = new ArrayList<DoubleMatrix1D>();
for (int i = 0; i < m; ++i) {
C.add(new ColtSparseVector(p));
}
}
if (B.get(0).size() != n)
throw new IllegalArgumentException("Matrix2D inner dimensions must agree.");
for (int i = 0; i < m; ++i) {
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
A.get(i).getNonZeros(indexList, valueList);
for (int j = 0; j < p; ++j) {
if (B.get(j).size() != A.get(i).size())
throw new IllegalArgumentException("Matrix2D inner dimensions must agree.");
double sum = 0.0;
for (int k = 0; k < indexList.size(); ++k) {
int index = indexList.get(k);
double value1 = valueList.get(k);
double value2 = B.get(j).getQuick(index);
if (value1 != 0 || value2 != 0) {
sum += value1 * value2;
}
}
C.get(i).setQuick(j, sum);
}
}
return C;
}
示例12: SparseTransposeMultSparse
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static public List<DoubleMatrix1D> SparseTransposeMultSparse(List<DoubleMatrix1D> A,
List<DoubleMatrix1D> B) {
// List<DoubleMatrix1D> AT = new ArrayList<DoubleMatrix1D>();
// for (int i = 0; i < A.get(0).size(); ++i) {
// AT.add(new ColtSparseVector(A.size()));
// }
// for (int i = 0; i < A.size(); ++i) {
// IntArrayList indexList = new IntArrayList();
// DoubleArrayList valueList = new DoubleArrayList();
// A.get(i).getNonZeros(indexList, valueList);
// for (int k = 0; k < indexList.size(); ++k) {
// int index = indexList.get(k);
// double value = valueList.get(k);
// AT.get(index).set(i, value);
// }
// }
List<DoubleMatrix1D> AT = getSparseTranspose(A);
List<DoubleMatrix1D> C = SparseMultSparse(AT, B);
AT = null;
return C;
}
示例13: getSparseTranspose
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static public List<DoubleMatrix1D> getSparseTranspose(List<DoubleMatrix1D> A) {
List<DoubleMatrix1D> AT = new ArrayList<DoubleMatrix1D>();
for (int i = 0; i < A.get(0).size(); ++i) {
AT.add(new ColtSparseVector(A.size()));
}
for (int i = 0; i < A.size(); ++i) {
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
A.get(i).getNonZeros(indexList, valueList);
for (int k = 0; k < indexList.size(); ++k) {
int index = indexList.get(k);
double value = valueList.get(k);
AT.get(index).set(i, value);
}
}
return AT;
}
示例14: productQuick
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
static public double productQuick(DoubleMatrix1D v1, DoubleMatrix1D v2) {
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
v1.getNonZeros(indexList, valueList);
double prod = 0.0;
for (int i = 0; i < indexList.size(); ++i) {
double temp = v2.getQuick(indexList.getQuick(i));
if (temp != 0.0) {
prod += valueList.getQuick(i) * temp;
}
}
// for (int i = 0; i < v1.size(); ++i) {
// double temp1 = v1.getQuick(i);
// double temp2 = v2.getQuick(i);
// if (temp1 != 0.0 || temp2 != 0.0) {
// prod += temp1 * temp2;
// }
// }
return prod;
}
示例15: computeCosineSimilarity
import cern.colt.matrix.DoubleMatrix1D; //导入依赖的package包/类
public static double computeCosineSimilarity(IntArrayList indexA, DoubleArrayList valueA, DoubleMatrix1D B, DoubleArrayList valueB)
{
double sim = -1;
double num = 0;
double den = 0;
double den_1 = 0;
double den_2 = 0;
num = Matrix2DUtil.productQuick(indexA, valueA, B);
den_1 = Matrix2DUtil.getSqrSum(valueA);
den_2 = Matrix2DUtil.getSqrSum(valueB);
den = Math.sqrt(den_1) * Math.sqrt(den_2);
if(den == 0)
return 0;
sim = num/den;
return sim;
}