当前位置: 首页>>代码示例>>Java>>正文


Java DoubleMatrix1D.size方法代码示例

本文整理汇总了Java中cern.colt.matrix.DoubleMatrix1D.size方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix1D.size方法的具体用法?Java DoubleMatrix1D.size怎么用?Java DoubleMatrix1D.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cern.colt.matrix.DoubleMatrix1D的用法示例。


在下文中一共展示了DoubleMatrix1D.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeLogMi

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
static boolean computeLogMi(FeatureGenerator featureGen, double lambda[], 
        DoubleMatrix2D Mi_YY,
        DoubleMatrix1D Ri_Y, boolean takeExp,boolean reuseM, boolean initMDone) {
    
    if (reuseM && initMDone) {
        Mi_YY = null;
    } else {
        initMDone = false;
    }
    if (Mi_YY != null) Mi_YY.assign(0);
    Ri_Y.assign(0);
    initMDone = computeLogMiInitDone(featureGen,lambda,Mi_YY,Ri_Y,0);
    if (takeExp) {
        for(int r = Ri_Y.size()-1; r >= 0; r--) {
            Ri_Y.setQuick(r,expE(Ri_Y.getQuick(r)));
            if (Mi_YY != null)
                for(int c = Mi_YY.columns()-1; c >= 0; c--) {
                    Mi_YY.setQuick(r,c,expE(Mi_YY.getQuick(r,c)));
                }
        }
    }
    return initMDone;
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:24,代码来源:Trainer.java

示例2: computeCosineSimilarity

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public static double computeCosineSimilarity(DoubleMatrix1D a, DoubleMatrix1D b)
{
	double sim = -1;
	if (a.size() != b.size())
	{
		System.err.println("mismatched size");
		return -1;
	}
	
	double num = 0;
	double den = 0;
	double den_1 = 0;
	double den_2 = 0;

	num = Matrix2DUtil.productQuick(a, b);
	den_1 = Matrix2DUtil.getSqrSum(a);
	den_2 = Matrix2DUtil.getSqrSum(b);
	den = Math.sqrt(den_1) * Math.sqrt(den_2);
	if(den == 0)
		return 0;
	sim = num/den;
	return sim;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:24,代码来源:SimilarityMeasures.java

示例3: computeJaccardSimilarity

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public static double computeJaccardSimilarity(DoubleMatrix1D a, DoubleMatrix1D b)
{
	double sim = -1;
	if(a.size() != b.size())
		return sim;
	double num = 0;
	double den = 0;
	num = Matrix2DUtil.productQuick(a, b);
	den = Matrix2DUtil.getSqrSum(a) + Matrix2DUtil.getSqrSum(b);
	

	if((den-num) == 0)
		return 0;
	sim = num/(den - num);
	return sim;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:17,代码来源:SimilarityMeasures.java

示例4: prepareRR1

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
private static <O> void prepareRR1(int L, DoubleMatrix1D w, DoubleMatrix2D gt, DoubleMatrix2D q, int N, Stream<? extends IdxPref> prefs, DoubleUnaryOperator confidence, double lambda) {
    int K = w.size();

    double[][] x = new double[K + N][K];
    double[] y = new double[K + N];
    double[] c = new double[K + N];
    for (int k = 0; k < K; k++) {
        gt.viewColumn(k).toArray(x[k]);
        y[k] = 0.0;
        c[k] = 1.0;
    }
    int[] j = {K};
    prefs.forEach(iv -> {
        q.viewRow(iv.v1).toArray(x[j[0]]);
        double Cui = confidence.applyAsDouble(iv.v2);
        y[j[0]] = (Cui * iv.v2) / (Cui - 1);
        c[j[0]] = Cui - 1;
        j[0]++;
    });
    
    doRR1(L, w, x, y, c, lambda);
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:23,代码来源:PZTFactorizer.java

示例5: getRecommendation

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
@Override
public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) {
    DoubleMatrix1D pu;

    pu = factorization.getUserVector(uidx2user(uidx));
    if (pu == null) {
        return new FastRecommendation(uidx, new ArrayList<>());
    }

    IntDoubleTopN topN = new IntDoubleTopN(min(maxLength, factorization.numItems()));

    DoubleMatrix1D r = factorization.getItemMatrix().zMult(pu, null);
    for (int iidx = 0; iidx < r.size(); iidx++) {
        if (filter.test(iidx)) {
            topN.add(iidx, r.getQuick(iidx));
        }
    }

    topN.sort();

    List<Tuple2id> items = topN.reverseStream()
            .collect(toList());

    return new FastRecommendation(uidx, items);
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:26,代码来源:MFRecommender.java

示例6: zMult

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
 * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>.
 * <tt>z[i] = alpha*Sum(A[i,j] * y[j]) + beta*z[i], i=0..A.rows()-1, j=0..y.size()-1</tt>.
 * Where <tt>A == this</tt>.
 * @param y the source vector.
 * @param z the vector where results are to be stored.
 * 
 * @throws IllegalArgumentException if <tt>A.columns() != y.size() || A.rows() > z.size())</tt>.
 */
protected void zMult(final DoubleMatrix1D y, final DoubleMatrix1D z, cern.colt.list.IntArrayList nonZeroIndexes, DoubleMatrix1D[] allRows, final double alpha, final double beta) {
	if (columns != y.size() || rows > z.size())	
		throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort());

	z.assign(cern.jet.math.Functions.mult(beta/alpha));
	for (int i = indexes.length; --i >= 0; ) {
		if (indexes[i] != null) {
			for (int k = indexes[i].size(); --k >= 0; ) {
				int j = indexes[i].getQuick(k);
				double value = values[i].getQuick(k);
				z.setQuick(i,z.getQuick(i) + value * y.getQuick(j));
			}
		}
	}
		
	z.assign(cern.jet.math.Functions.mult(alpha));
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:27,代码来源:RCMDoubleMatrix2D.java

示例7: logMult

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public static DoubleMatrix1D logMult(DoubleMatrix2D M, DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) {
        // z = alpha * A * y + beta*z
        double lalpha = 0;
        if (alpha != 1)
            lalpha = Math.log(alpha);
        if (beta != 0) {
            if (beta != 1) {
                double lbeta = Math.log(beta);
                for (int i = 0; i < z.size(); z.set(i,z.get(i)+lbeta),i++);
            }
        } else {
            z.assign(RobustMath.LOG0);
        }
        // in log domain this becomes: 
        logMult.M = M;
        logMult.z = z;
        logMult.lalpha = lalpha;
        logMult.transposeA = transposeA;
        logMult.y = y;
        logMult.cnt=0;
        M.forEachNonZero(logMult);
//      System.out.println("Matrix "+M.size()+" "+M.columns()+ " "+logMult.cnt);
        return z;
    }
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:25,代码来源:RobustMath.java

示例8: createSuccessors

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
private void createSuccessors(DoubleMatrix1D miRow){
    SegmentState successor;
    double succG, succH;
    
    if(labelConstraints != null){
        nextLabelsOnPath = (CloneableIntSet) labelsOnPath.clone();
        if(y != -1 && labelConstraints.conflicting(y))
            nextLabelsOnPath.add(y);
    }    
    for(int yi = miRow.size() - 1; yi >= 0; yi--){
        double val = miRow.getQuick(yi);
        if(val == 0 ||  
                (labelConstraints != null && prevPos() >= 0 && !labelConstraints.valid(labelsOnPath, yi, y))){
                                continue;
        }
        succG = (pos == -1 ? val + g : val+Ri[succPos][succEll].get(yi) + g);
        succH = context[succPos + 1].getEntry(yi).solns[0].score;
        if(Double.compare((succG + succH + delta), lowerBound) >= 0){
            successor = new SegmentState(succPos, succEll, yi, succH, succG, this, nextLabelsOnPath);
            states.add(successor);
        }
    }
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:24,代码来源:SegmentAStar.java

示例9: dtrmv

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public void dtrmv(boolean isUpperTriangular, boolean transposeA, boolean isUnitTriangular, DoubleMatrix2D A, DoubleMatrix1D x) {
	if (transposeA) {
		A = A.viewDice();
		isUpperTriangular = !isUpperTriangular;
	}
	
	Property.DEFAULT.checkSquare(A);
	int size = A.rows();
	if (size != x.size()) {
		throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort());
	}
	    
	DoubleMatrix1D b = x.like();
	DoubleMatrix1D y = x.like();
	if (isUnitTriangular) {
		y.assign(1);
	}
	else {
		for (int i = 0; i < size; i++) {
			y.setQuick(i, A.getQuick(i,i));
		}
	}
	
	for (int i = 0; i < size; i++) {
		double sum = 0;
		if (!isUpperTriangular) {
			for (int j = 0; j < i; j++) {
				sum += A.getQuick(i,j) * x.getQuick(j);
			}
			sum += y.getQuick(i) * x.getQuick(i);
		}
		else {
			sum += y.getQuick(i) * x.getQuick(i);
			for (int j = i + 1; j < size; j++) {
				sum += A.getQuick(i,j) * x.getQuick(j);			}
		}
		b.setQuick(i,sum);
	}
	x.assign(b);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:41,代码来源:SeqBlas.java

示例10: multOuter

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
 * Outer product of two vectors; Sets <tt>A[i,j] = x[i] * y[j]</tt>.
 *
 * @param x the first source vector.
 * @param y the second source vector.
 * @param A the matrix to hold the results. Set this parameter to <tt>null</tt> to indicate that a new result matrix shall be constructed.
 * @return A (for convenience only).
 * @throws IllegalArgumentException	if <tt>A.rows() != x.size() || A.columns() != y.size()</tt>.
 */
public DoubleMatrix2D multOuter(DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix2D A) {
	int rows = x.size();
	int columns = y.size();
	if (A==null) A = x.like2D(rows,columns);
	if (A.rows() != rows || A.columns() != columns) throw new IllegalArgumentException();
	
	for (int row = rows; --row >= 0; ) A.viewRow(row).assign(y);
	
	for (int column = columns; --column >= 0; ) A.viewColumn(column).assign(x, cern.jet.math.Functions.mult);
	return A;
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:21,代码来源:Algebra.java

示例11: viewSample

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
Constructs and returns a sampling view with a size of <tt>round(matrix.size() * fraction)</tt>.
Samples "without replacement" from the uniform distribution.
@param matrix any matrix.
@param rowFraction the percentage of rows to be included in the view.
@param columnFraction the percentage of columns to be included in the view.
@param randomGenerator a uniform random number generator; set this parameter to <tt>null</tt> to use a default generator seeded with the current time.
@return the sampling view.
@throws IllegalArgumentException if <tt>! (0 <= rowFraction <= 1 && 0 <= columnFraction <= 1)</tt>.
@see cern.jet.random.sampling.RandomSampler
*/
public static DoubleMatrix1D viewSample(DoubleMatrix1D matrix, double fraction, RandomEngine randomGenerator) {
	// check preconditions and allow for a little tolerance
	double epsilon = 1e-09;
	if (fraction < 0 - epsilon || fraction > 1 + epsilon) throw new IllegalArgumentException();
	if (fraction < 0) fraction = 0;
	if (fraction > 1) fraction = 1;

	// random generator seeded with current time
	if (randomGenerator==null) randomGenerator = new cern.jet.random.engine.MersenneTwister((int) System.currentTimeMillis());

	int ncols = (int) Math.round(matrix.size() * fraction);
	int max = ncols;
	long[] selected = new long[max]; // sampler works on long's, not int's

	// sample 
	int n = ncols;
	int N = matrix.size();
	cern.jet.random.sampling.RandomSampler.sample(n,N,n,0,selected,0,randomGenerator);
	int[] selectedCols = new int[n];
	for (int i=0; i<n; i++) selectedCols[i] = (int) selected[i];

	return matrix.viewSelection(selectedCols);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:35,代码来源:Statistic.java

示例12: laplacianScore

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public int[] laplacianScore(int numK, String type, double[] weights) {
		if (this.fMat == null) {
			logger.warning("No feature loaded");
			return null;
		}
		System.out.println("computeLaplacian");
		computeLaplacian(numK, type);
		DoubleMatrix2D diagSum = new SparseDoubleMatrix2D(fMat.rows(), fMat.rows()); 
		for (int i = 0; i < fMat.rows(); ++i) {
			diagSum.setQuick(i, i, sumRow[i]);
		}
		diagSum.trimToSize();

		DenseDoubleMatrix1D  onesVector = new DenseDoubleMatrix1D (fMat.rows());
		onesVector.assign(1);
		DenseDoubleMatrix1D  zerosVector = new DenseDoubleMatrix1D (fMat.rows());
		zerosVector.assign(0);

		// f = f - \frac{f^T D 1}{1^T D 1} 1
		System.out.println("compute weight");
//		DoubleMatrix1D[] trans_vec = new DoubleMatrix1D[fMat.columns()];
//		for (int i = 0; i < fMat.columns(); i++)
//		{
//			trans_vec[i] = fMat.viewColumn(i).copy();
//		}
		for (int i = 0; i < fMat.columns(); ++i) {
			if (i % 100 == 0)
				System.out.println("have handle " + i + " feature");
			DoubleMatrix1D colVector = null;
//			colVector = trans_vec[i];
			colVector = fMat.viewColumn(i).copy();
			DoubleMatrix1D tempVector = null;
			
			// potential problem: diagSum.zMult(onesVector, tempVector) will lead tempVector as null!!
			tempVector = diagSum.zMult(onesVector, tempVector);
			double temp1 = colVector.zDotProduct(tempVector);
			double temp2 = onesVector.zDotProduct(onesVector);
			
			for (int j = 0; j < colVector.size(); ++j) {
				double temp3 = colVector.getQuick(j);
				double temp4 = temp3 - temp1/temp2;
				colVector.setQuick(j, temp4);
			}
			
			Laplacian.zMult(colVector, tempVector);
			temp1 = colVector.zDotProduct(tempVector);
			diagSum.zMult(colVector, tempVector);
			temp2 = colVector.zDotProduct(tempVector);
			
			lScore.insert(i, temp1/(temp2+Double.MIN_VALUE));
			weights[i] = temp1/(temp2+Double.MIN_VALUE);
		}
		int[] sortedIndices = MaxHeap.heapSort(lScore);
		//reverse array
//		sortedIndices = lScore.getIndices();
//		double[] scores = lScore.getValues();
//		for (double score: scores)
//				System.out.print(score + " ");
//		System.out.println();
		return sortedIndices;
		
	}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:63,代码来源:LaplacianScore.java

示例13: DenseMultDenseTranspose

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
static public List<DoubleMatrix1D> DenseMultDenseTranspose(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 ColtDenseVector(p));
		}
	}
	if (B.get(0).size() != n)
		throw new IllegalArgumentException("Matrix2D inner dimensions must agree.");
	for (int i = 0; i < m; ++i) {
		DoubleMatrix1D vector1 = A.get(i);
		for (int j = 0; j < p; ++j) {
			DoubleMatrix1D vector2 = B.get(j);

			if (vector2.size() != vector1.size())
				throw new IllegalArgumentException("Matrix2D inner dimensions must agree.");
			double sum = 0.0;
			for (int k = 0; k < vector1.size(); ++k) {
				sum += vector1.get(k) * vector2.get(k);
			}
			C.get(i).setQuick(j, sum);
		}	
	}
	return C;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:31,代码来源:Matrix2DUtil.java

示例14: inverseDense

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
static public List<DoubleMatrix1D> inverseDense(List<DoubleMatrix1D> A) {
	List<DoubleMatrix1D> C = null;
	
	DoubleMatrix2D A1 = new DenseDoubleMatrix2D(A.size(), A.get(0).size());
	for (int i = 0; i < A.size(); ++i) {
		DoubleMatrix1D vector = A.get(0);
		for (int j = 0; j < vector.size(); ++j ) {
			A1.set(i, j, vector.get(j));
		}
	}
	
	double tol = 0.001;
	for (int i = 0; i < A.size(); ++i) {
		A1.set(i, i, A1.get(i, i) + tol);
	}
	
	Algebra algebra = new Algebra();
	DoubleMatrix2D C1 = algebra.inverse(A1);
	
	C = new ArrayList<DoubleMatrix1D>();
	for (int i = 0; i < A.size(); ++i) {
		C.add(new ColtDenseVector(A.get(0).size()));
	}
	for (int i = 0; i < C1.rows(); ++i) {
		for (int j = 0; j < C1.columns(); ++j ) {
			C.get(i).set(j, C1.get(i, j));
		}
	}
	return C;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:31,代码来源:Matrix2DUtil.java

示例15: inverseSparse

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
static public List<DoubleMatrix1D> inverseSparse(List<DoubleMatrix1D> A) {
	
	// TODO: optimize this code
	
	List<DoubleMatrix1D> C = null;
	
	DoubleMatrix2D A1 = new SparseDoubleMatrix2D(A.size(), A.get(0).size());
	for (int i = 0; i < A.size(); ++i) {
		DoubleMatrix1D vector = A.get(i);
		for (int j = 0; j < vector.size(); ++j ) {
			A1.set(i, j, vector.get(j));
		}
	}
	double tol = 0.001;
	for (int i = 0; i < A.size(); ++i) {
		A1.set(i, i, A1.get(i, i) + tol);
	}
	Algebra algebra = new Algebra();
	DoubleMatrix2D C1 = algebra.inverse(A1);
	
	C = new ArrayList<DoubleMatrix1D>();
	for (int i = 0; i < A.size(); ++i) {
		C.add(new ColtSparseVector(A.get(0).size()));
	}
	for (int i = 0; i < C1.rows(); ++i) {
		for (int j = 0; j < C1.columns(); ++j ) {
			C.get(i).set(j, C1.get(i, j));
		}
	}
	return C;
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:32,代码来源:Matrix2DUtil.java


注:本文中的cern.colt.matrix.DoubleMatrix1D.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。