本文整理汇总了Java中no.uib.cipr.matrix.DenseVector.set方法的典型用法代码示例。如果您正苦于以下问题:Java DenseVector.set方法的具体用法?Java DenseVector.set怎么用?Java DenseVector.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类no.uib.cipr.matrix.DenseVector
的用法示例。
在下文中一共展示了DenseVector.set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupGPvalues
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
protected void setupGPvalues() {
setupQmatrix(precisionParameter.getParameterValue(0));
int length = getCorrectFieldLength();
DenseVector StandNorm = new DenseVector(length);
DenseVector MultiNorm = new DenseVector(length);
for (int i=0; i<length;i++){
StandNorm.set(i,MathUtils.nextGaussian());
// StandNorm.set(i,0.1);
}
UpperSPDBandMatrix Qcurrent = new UpperSPDBandMatrix(weightMatrix, 1);
BandCholesky U = new BandCholesky(length,1,true);
U.factor(Qcurrent);
UpperTriangBandMatrix CholeskyUpper = U.getU();
CholeskyUpper.solve(StandNorm,MultiNorm);
for (int i=0; i<length;i++){
popSizeParameter.setParameterValue(i,MultiNorm.get(i));
}
}
示例2: DenseDoubleVector
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Creates a new dense vector with the given size and paste for each entry the given value.
*
* @param size the size of the dense vector
* @param value the value for each entry
*/
public DenseDoubleVector(int size, double value) {
internalVector = new DenseVector(size);
for (int index = 0; index < internalVector.size(); index++) {
internalVector.set(index, value);
}
}
示例3: getSubVector
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* @see ApacheVector#getSubVector(int, int)
*/
@Override
public AbstractVector getSubVector(int index, int n) {
DenseVector subVector = new DenseVector(n);
for (int i = index, j = 0; i < index + n; i++, j++) {
double value = this.vector.get(i);
subVector.set(j, value);
}
return new MtjVector(subVector);
}
示例4: addScoresAndRanks
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Adds ranks and scores obtained from a candidate provider.
*
* @param docFeats all features
* @param resultsAll result entries
*/
private void addScoresAndRanks(Map<String, DenseVector> docFeats,
CandidateEntry[] resultsAll) {
for (CandidateEntry e: resultsAll) {
DenseVector oldVect = docFeats.get(e.mDocId);
int oldSize = oldVect.size();
DenseVector newVect = new DenseVector(oldSize + 2);
newVect.set(0, e.mOrigRank);
newVect.set(1, e.mOrigScore);
for (int vi = 0; vi < oldSize; ++vi)
newVect.set(vi + 2, oldVect.get(vi));
docFeats.replace(e.mDocId, newVect);
}
}
示例5: getFieldScores
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Get TF-IDF scores for one field.
*
* @param fieldIndex an in-memory field index
* @param similObj an object that computes similarity.
* @param arrDocIds an array of document ids.
* @param fieldName a name of the field.
* @param featureId an index/id of the feature.
* @param query an actual query
* @param res a result set to be updated. *
* @throws Exception
*/
private void getFieldScores(InMemForwardIndex fieldIndex,
QueryDocSimilarity similObj,
ArrayList<String> arrDocIds,
String fieldName,
int featureId,
String query,
Map<String,DenseVector> res) throws Exception {
if (null == query) return;
query = query.trim();
if (query.isEmpty()) return;
DocEntry queryEntry = fieldIndex.createDocEntry(query.split("\\s+"));
if (PRINT_SCORES)
System.out.println("InMemIndex Field: '" + fieldName + "' (getFieldScores)");
for (String docId : arrDocIds) {
DocEntry docEntry = fieldIndex.getDocEntry(docId);
if (docEntry == null) {
throw new Exception("Inconsistent data or bug: can't find document with id ='" + docId + "'");
}
float score = similObj.compute(queryEntry, docEntry);
DenseVector v = res.get(docId);
if (v == null) {
throw new Exception(String.format("Bug, cannot retrieve a vector for docId '%s' from the result set", docId));
}
v.set(featureId, score);
if (PRINT_SCORES)
System.out.println(String.format("Doc id %s %s: %g", docId, similObj.getName(), score));
}
}
示例6: getFieldOverallMatchScores
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Get overall match scores for one field.
*
* @param fieldIndex an in-memory field index
* @param fieldId a field identifier
* @param arrDocIds an array of document ids.
* @param fieldName a name of the field.
* @param startFeatureId an index/id of the first feature.
* @param query an actual query
* @param res a result set to be updated. *
* @throws Exception
*/
private void getFieldOverallMatchScores(InMemForwardIndex fieldIndex, int fieldId,
ArrayList<String> arrDocIds,
String fieldName,
int startFeatureId,
String query,
Map<String,DenseVector> res) throws Exception {
if (null == query) return;
query = query.trim();
if (query.isEmpty()) return;
DocEntry queryEntry = fieldIndex.createDocEntry(query.split("\\s+"));
if (PRINT_SCORES)
System.out.println("InMemIndex Field: '" + fieldName + "' (getFieldOverallMatchScores))");
for (String docId : arrDocIds) {
DocEntry docEntry = fieldIndex.getDocEntry(docId);
if (docEntry == null) {
throw new Exception("Inconsistent data or bug: can't find document with id ='" + docId + "'");
}
float score = DistanceFunctions.compOverallMatch(queryEntry, docEntry);
DenseVector v = res.get(docId);
if (v == null) {
throw new Exception(String.format("Bug, cannot retrieve a vector for docId '%s' from the result set", docId));
}
float scoreQueryNorm = score / Math.max(1, queryEntry.mWordIds.length);
int fid = startFeatureId;
if (useOverallMatchFeature(fieldId)) {
if (OVERAL_MATCH_FIELD_FEATURE_QTY != 1) {
throw new RuntimeException("Wrong value of constant OVERAL_MATCH_FIELD_FEATURE_QTY");
}
v.set(fid++, score);
}
if (useOverallMatchFeatureQueryNorm(fieldId)) {
if (OVERAL_MATCH_FIELD_FEATURE_QUERY_NORM_QTY!= 1) {
throw new RuntimeException("Wrong value of constant OVERAL_MATCH_FIELD_FEATURE_QUERY_NORM_QTY");
}
v.set(fid++, scoreQueryNorm);
}
if (PRINT_SCORES) {
if (useOverallMatchFeature(fieldId))
System.out.println(String.format("Doc id %s %s: %g", docId, "OVERALL MATCH", score));
if (useOverallMatchFeatureQueryNorm(fieldId))
System.out.println(String.format("Doc id %s %s: %g", docId, "OVERALL MATCH QUERY-NORM", scoreQueryNorm));
}
}
}
示例7: getFieldLCSScores
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Get LCS scores for one field.
*
* @param fieldIndex an in-memory field index
* @param fieldId a field identifier
* @param arrDocIds an array of document ids.
* @param fieldName a name of the field.
* @param startFeatureId an index/id of the first feature.
* @param query an actual query
* @param res a result set to be updated. *
* @throws Exception
*/
private void getFieldLCSScores(InMemForwardIndex fieldIndex, int fieldId,
ArrayList<String> arrDocIds,
String fieldName,
int startFeatureId,
String query,
Map<String,DenseVector> res) throws Exception {
if (null == query) return;
query = query.trim();
if (query.isEmpty()) return;
DocEntry queryEntry = fieldIndex.createDocEntry(query.split("\\s+"));
boolean useLCSFeature = useLCSFeature(fieldId);
boolean useLCSFeatureQueryNorm = useLCSFeatureQueryNorm(fieldId);
if (PRINT_SCORES)
System.out.println("InMemIndex Field: '" + fieldName + "' (getFieldLCSScores))");
for (String docId : arrDocIds) {
DocEntry docEntry = fieldIndex.getDocEntry(docId);
if (docEntry == null) {
throw new Exception("Inconsistent data or bug: can't find document with id ='" + docId + "'");
}
float score = DistanceFunctions.compLCS(queryEntry.mWordIdSeq, docEntry.mWordIdSeq);
DenseVector v = res.get(docId);
if (v == null) {
throw new Exception(String.format("Bug, cannot retrieve a vector for docId '%s' from the result set", docId));
}
float normScore = score / Math.max(1, queryEntry.mWordIdSeq.length);
int fid = startFeatureId;
if (useLCSFeature) {
v.set(fid++, score);
if (LCS_FIELD_FEATURE_QTY != 1) {
throw new RuntimeException("Bug: wrong value for the constant LCS_FIELD_FEATURE_QTY");
}
}
if (useLCSFeatureQueryNorm) {
v.set(fid++, normScore);
if (LCS_FIELD_FEATURE_QUERY_NORM_QTY != 1) {
throw new RuntimeException("Bug: wrong value for the constant LCS_FIELD_FEATURE_QUERY_NORM_QTY");
}
}
if (PRINT_SCORES) {
if (useLCSFeatureQueryNorm) System.out.println(String.format("Doc id %s %s: %g", docId, "LCS", score));
if (useLCSFeatureQueryNorm) System.out.println(String.format("Doc id %s %s: %g", docId, "LCS (query-norm)", normScore));
}
}
}
示例8: readFeatureWeights
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
/**
* Reads feature weights from a file.
*
* @param fileName input file (in the RankLib format): all weights must be present
* there should be no gaps!
* @return a sparse vector that keeps weights
* @throws Exception
*/
public static DenseVector readFeatureWeights(String fileName) throws Exception {
BufferedReader inFile = new BufferedReader(new FileReader(new File(fileName)));
try {
String line = null;
while ((line = inFile.readLine()) != null) {
line = line.trim();
if (line.isEmpty() || line.startsWith("#")) continue;
String parts0[] = line.split("\\s+");
DenseVector res = new DenseVector(parts0.length);
int ind = 0;
for (String onePart: parts0) {
try {
String parts1[] = onePart.split(":");
if (parts1.length != 2) {
throw new Exception(
String.format(
"The line in file '%s' has a field '%s' without exactly one ':', line: %s", fileName, onePart, line));
}
int partId = Integer.parseInt(parts1[0]);
if (partId != ind + 1) {
throw new Exception(
String.format("Looks like there's a missing feature weight, field %d has id %d", ind + 1, partId));
}
res.set(ind, Double.parseDouble(parts1[1]));
ind++;
} catch (NumberFormatException e) {
throw new Exception(
String.format(
"The line in file '%s' has non-number '%s', line: %s", fileName, onePart, line));
}
}
return res;
}
} finally {
inFile.close();
}
throw new Exception("No features found in '" + fileName + "'");
}
示例9: updateGammaWithCovariates
import no.uib.cipr.matrix.DenseVector; //导入方法依赖的package包/类
@Override
protected void updateGammaWithCovariates(DenseVector currentGamma) {
// Handle betaParameter / designMatrix
if (NEW_APPROACH) {
final int N = currentGamma.size();
double[] update = new double[N];
if (dMatrix != null) {
final int K = dMatrix.getColumnDimension();
if (N != dMatrix.getRowDimension()) {
throw new RuntimeException("Incorrect covariate dimensions (" + N + " != "
+ dMatrix.getRowDimension() + ")");
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K; ++j) {
update[i] += dMatrix.getParameterValue(i, j) * betaParameter.getParameterValue(j);
}
}
}
if (covariates != null) {
if (beta.size() != covariates.size()) {
throw new RuntimeException("beta.size() != covariates.size()");
}
for (int k = 0; k < beta.size(); ++k) {
Parameter b = beta.get(k);
final int J = b.getDimension();
MatrixParameter covariate = covariates.get(k);
if ((J != covariate.getRowDimension()) ||
(N != covariate.getColumnDimension())) { // Note: XML current has covariates transposed
throw new RuntimeException("Incorrect dimensions in " + covariate.getId());
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < J; ++j) {
update[i] += covariate.getParameterValue(j, i) * b.getParameterValue(j);
}
}
}
}
for (int i = 0; i < N; ++i) {
currentGamma.set(i, currentGamma.get(i) - update[i]);
}
} else {
DenseVector currentBeta = new DenseVector(beta.size());
for (int i = 0; i < beta.size(); i++) {
currentBeta.set(i, beta.get(i).getParameterValue(0));
}
//int numMissing = fieldLength - lastObservedIndex;
//DenseVector tempVectCov = new DenseVector(numMissing);
//System.err.println("covariates.size(): " + covariates.size());
//System.err.println("covariates.get(0).getColumnDimension: " + covariates.get(0).getColumnDimension());
//System.err.println("covariates.get(0).getRowDimension: " + covariates.get(0).getRowDimension());
for (int i = 0; i < covariates.size(); i++) {
for (int j = 0; j < covariates.get(i).getColumnDimension(); j++) {
// System.err.println("j: " + j);
// System.err.println("covariates.get(i).getParameterValue(0,j): " + covariates.get(i).getParameterValue(0,j));
currentGamma.set(j, currentGamma.get(j) - covariates.get(i).getParameterValue(0, j) * currentBeta.get(i));
}
}
}
}