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


Java DoubleMatrix1D.getQuick方法代码示例

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


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

示例1: dsymv

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

示例2: 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;
	}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:22,代码来源:Matrix2DUtil.java

示例3: 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

示例4: sort

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
Sorts the matrix slices into ascending order, according to the <i>natural ordering</i> of the matrix values in the given <tt>[row,column]</tt> position.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
To sort ranges use sub-ranging views. To sort by other dimensions, use dice views. To sort descending, use flip views ...
<p>
The algorithm compares two 2-d slices at a time, determinining whether one is smaller, equal or larger than the other.
Comparison is based on the cell <tt>[row,column]</tt> within a slice.
Let <tt>A</tt> and <tt>B</tt> be two 2-d slices. Then we have the following rules
<ul>
<li><tt>A &lt;  B  iff A.get(row,column) &lt;  B.get(row,column)</tt>
<li><tt>A == B iff A.get(row,column) == B.get(row,column)</tt>
<li><tt>A &gt;  B  iff A.get(row,column) &gt;  B.get(row,column)</tt>
</ul>

@param matrix the matrix to be sorted.
@param row the index of the row inducing the order.
@param column the index of the column inducing the order.
@return a new matrix view having slices sorted by the values of the slice view <tt>matrix.viewRow(row).viewColumn(column)</tt>.
		<b>Note that the original matrix is left unaffected.</b>
@throws IndexOutOfBoundsException if <tt>row < 0 || row >= matrix.rows() || column < 0 || column >= matrix.columns()</tt>.
*/
public DoubleMatrix3D sort(DoubleMatrix3D matrix, int row, int column) {
	if (row < 0 || row >= matrix.rows()) throw new IndexOutOfBoundsException("row="+row+", matrix="+Formatter.shape(matrix));
	if (column < 0 || column >= matrix.columns()) throw new IndexOutOfBoundsException("column="+column+", matrix="+Formatter.shape(matrix));

	int[] sliceIndexes = new int[matrix.slices()]; // indexes to reorder instead of matrix itself
	for (int i=sliceIndexes.length; --i >= 0; ) sliceIndexes[i] = i;

	final DoubleMatrix1D sliceView = matrix.viewRow(row).viewColumn(column);
	IntComparator comp = new IntComparator() {  
		public int compare(int a, int b) {
			double av = sliceView.getQuick(a);
			double bv = sliceView.getQuick(b);
			if (av!=av || bv!=bv) return compareNaN(av,bv); // swap NaNs to the end
			return av<bv ? -1 : (av==bv ? 0 : 1);
		}
	};

	runSort(sliceIndexes,0,sliceIndexes.length,comp);

	// view the matrix according to the reordered slice indexes
	// take all rows and columns in the original order
	return matrix.viewSelection(sliceIndexes,null,null);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:45,代码来源:Sorting.java

示例5: equals

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
 * Returns whether both given matrices <tt>A</tt> and <tt>B</tt> are equal.
 * The result is <tt>true</tt> if <tt>A==B</tt>. 
 * Otherwise, the result is <tt>true</tt> if and only if both arguments are <tt>!= null</tt>, 
 * have the same size and 
 * <tt>! (Math.abs(A[i] - B[i]) > tolerance())</tt> holds for all indexes.
 * @param   A   the first matrix to compare.
 * @param   B   the second matrix to compare.
 * @return  <tt>true</tt> if both matrices are equal;
 *          <tt>false</tt> otherwise.
 */
public boolean equals(DoubleMatrix1D A, DoubleMatrix1D B) {
	if (A==B) return true;
	if (! (A != null && B != null)) return false;
	int size = A.size();
	if (size != B.size()) return false;

	double epsilon = tolerance();
	for (int i=size; --i >= 0;) {
		//if (!(getQuick(i) == B.getQuick(i))) return false;
		//if (Math.abs(A.getQuick(i) - B.getQuick(i)) > epsilon) return false;
		double x = A.getQuick(i);
		double value = B.getQuick(i);
		double diff = Math.abs(value - x);
		if ((diff!=diff) && ((value!=value && x!=x) || value==x)) diff = 0;
		if (!(diff <= epsilon)) return false;
	}
	return true;
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:30,代码来源:Property.java

示例6: 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

示例7: 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

示例8: SolveSpectralClustering

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
 * Finds the clusters using algorithm version 1.
 * 
 * @param similarityMatrix
 *            the similarity matrix
 * @param numCluster
 *            the number of clusters to construct
 */
public static void SolveSpectralClustering(DenseDoubleMatrix2D similarityMatrix, int numCluster,
        SimilarityMatrixTransformer transformer) {
    for (int r = 0; r < similarityMatrix.rows(); r++) {
        for (int c = 0; c < similarityMatrix.columns(); c++) {
            System.out.print(similarityMatrix.getQuick(r, c) + " ");
        }
        System.out.println();
    }

    DenseDoubleMatrix2D weightedMatrix = transformer.transform(similarityMatrix);
    DenseDoubleMatrix2D laplacianMatrix = getLaplacian(weightedMatrix);
    EigenvalueDecomposition eigenDecomposition = new EigenvalueDecomposition(laplacianMatrix);
    DoubleMatrix2D eigenVectors = eigenDecomposition.getV();
    DoubleMatrix1D eigenValues = eigenDecomposition.getRealEigenvalues();
    System.out.println("EigenValues:");
    EigenValueSortHelper[] eigenvaluesToSort = new EigenValueSortHelper[eigenValues.size()];
    for (int iEigen = 0; iEigen < eigenValues.size(); iEigen++) {
        eigenvaluesToSort[iEigen] = new EigenValueSortHelper(eigenValues.getQuick(iEigen), iEigen);
        System.out.print(eigenValues.getQuick(iEigen) + " ");
    }
    System.out.println();
    Arrays.sort(eigenvaluesToSort);

    for (int iEigen = 0; iEigen < eigenValues.size(); iEigen++) {
        System.out.print(eigenvaluesToSort[iEigen].getIndex() + ":"
                + eigenValues.getQuick(eigenvaluesToSort[iEigen].getIndex()) + " ");
    }
    System.out.println();
    System.out.println("EigenVectors:");
    for (int iEigen = 0; iEigen < eigenVectors.columns(); iEigen++) {
        System.out.print("[");
        for (int r = 0; r < eigenVectors.rows(); r++) {
            System.out.print(eigenVectors.getQuick(r, eigenvaluesToSort[iEigen].getIndex()) + " ");
        }
        System.out.println("]");
    }
}
 
开发者ID:dexyko,项目名称:spectralclustering,代码行数:46,代码来源:SpectralClusteringSolver.java

示例9: FactorizationUserIntentModel

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public FactorizationUserIntentModel(DoubleMatrix1D userVector) {
    Set<Integer> nonZeroFidx = new HashSet<>();
    for (int i = 0; i < userVector.size(); i++) {
        if (userVector.getQuick(i) > 0) {
            nonZeroFidx.add(i);
        }
    }
    this.userVector = userVector;
    this.nonZeroFactors = nonZeroFidx.stream()
            .map(featureData::fidx2feature)
            .collect(Collectors.toSet());
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:13,代码来源:CPLSAIAFactorizationModelFactory.java

示例10: PLSAUserIntentModel

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public PLSAUserIntentModel(DoubleMatrix1D userVector) {
    this.nonZeroFactors = new HashSet<>();
    for (int i = 0; i < userVector.size(); i++) {
        if (userVector.getQuick(i) > 0) {
            nonZeroFactors.add(i);
        }
    }
    this.userVector = userVector;
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:10,代码来源:PLSAIAFactorizationModelFactory.java

示例11: doRR1

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
private static void doRR1(int L, DoubleMatrix1D w, double[][] x, double[] y, double[] c, double lambda) {
    int N = x.length;
    int K = x[0].length;
    
    double[] e = new double[N];
    for (int i = 0; i < N; i++) {
        double pred = 0.0;
        for (int k = 0; k < K; k++) {
            pred += w.getQuick(k) * x[i][k];
        }
        e[i] = y[i] - pred;
    }

    for (int l = 0; l < L; l++) {
        for (int k = 0; k < K; k++) {
            for (int i = 0; i < N; i++) {
                e[i] += w.getQuick(k) * x[i][k];
            }
            double a = 0.0;
            double d = 0.0;
            for (int i = 0; i < N; i++) {
                a += c[i] * x[i][k] * x[i][k];
                d += c[i] * x[i][k] * e[i];
            }
            w.setQuick(k, d / (lambda + a));
            for (int i = 0; i < N; i++) {
                e[i] -= w.getQuick(k) * x[i][k];
            }
        }
    }

}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:33,代码来源:PZTFactorizer.java

示例12: logSumExp

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public static double logSumExp(DoubleMatrix1D logProb) {
    TreeSet<Double> logProbVector = new TreeSet<Double>();
    for ( int lpx = 0; lpx < logProb.size(); lpx++ )
        if (logProb.getQuick(lpx) != RobustMath.LOG0)
            addNoDups(logProbVector,logProb.getQuick(lpx));
    return logSumExp(logProbVector);
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:8,代码来源:RobustMath.java

示例13: LogSparseDoubleMatrix1D

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public LogSparseDoubleMatrix1D(DoubleMatrix1D doubleMatrix) {super(doubleMatrix.size());
  	double val;
   for (int y = 0; y < size(); y++) {
    if ((val = doubleMatrix.getQuick(y)) != 0) 
        super.setQuick(y, map(val));
}
  }
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:8,代码来源:LogSparseDoubleMatrix1D.java

示例14: assign

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
public DoubleMatrix1D assign(DoubleMatrix1D v2, DoubleDoubleFunction func) {
    // TODO..
    for (int row = 0; row < size(); row++) {
        if ((v2.getQuick(row) != 0) || (getQuick(row) != 0))
            set(row,func.apply(get(row), v2.get(row)));
    }
    return this;
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:9,代码来源:LogSparseDoubleMatrix1D.java

示例15: quickSort

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
Sorts the matrix rows into ascending order, according to the <i>natural ordering</i> of the matrix values in the given column.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
To sort ranges use sub-ranging views. To sort columns by rows, use dice views. To sort descending, use flip views ...
<p>
<b>Example:</b> 
<table border="1" cellspacing="0">
  <tr nowrap> 
	<td valign="top"><tt>4 x 2 matrix: <br>
	  7, 6<br>
	  5, 4<br>
	  3, 2<br>
	  1, 0 <br>
	  </tt></td>
	<td align="left" valign="top"> 
	  <p><tt>column = 0;<br>
		view = quickSort(matrix,column);<br>
		System.out.println(view); </tt><tt><br>
		==> </tt></p>
	  </td>
	<td valign="top"> 
	  <p><tt>4 x 2 matrix:<br>
		1, 0<br>
		3, 2<br>
		5, 4<br>
		7, 6</tt><br>
		The matrix IS NOT SORTED.<br>
		The new VIEW IS SORTED.</p>
	  </td>
  </tr>
</table>

@param matrix the matrix to be sorted.
@param column the index of the column inducing the order.
@return a new matrix view having rows sorted by the given column.
		<b>Note that the original matrix is left unaffected.</b>
@throws IndexOutOfBoundsException if <tt>column < 0 || column >= matrix.columns()</tt>.
*/
public DoubleMatrix2D sort(DoubleMatrix2D matrix, int column) {
	if (column < 0 || column >= matrix.columns()) throw new IndexOutOfBoundsException("column="+column+", matrix="+Formatter.shape(matrix));

	int[] rowIndexes = new int[matrix.rows()]; // row indexes to reorder instead of matrix itself
	for (int i=rowIndexes.length; --i >= 0; ) rowIndexes[i] = i;

	final DoubleMatrix1D col = matrix.viewColumn(column);
	IntComparator comp = new IntComparator() {  
		public int compare(int a, int b) {
			double av = col.getQuick(a);
			double bv = col.getQuick(b);
			if (av!=av || bv!=bv) return compareNaN(av,bv); // swap NaNs to the end
			return av<bv ? -1 : (av==bv ? 0 : 1);
		}
	};

	runSort(rowIndexes,0,rowIndexes.length,comp);

	// view the matrix according to the reordered row indexes
	// take all columns in the original order
	return matrix.viewSelection(rowIndexes,null);
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:61,代码来源:Sorting.java


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