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


Java VectorUtils.orthogonalizeVectors方法代码示例

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


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

示例1: getNegatedQueryVector

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Creates a vector, including orthogonalizing negated terms.
 * 
 * @param queryTerms List of positive and negative terms.
 * @param split Position in this list of the NOT mark: terms
 * before this are positive, those after this are negative.
 * @return Single query vector, the sum of the positive terms,
 * projected to be orthogonal to all negative terms.
 * @see VectorUtils#orthogonalizeVectors
 */
protected Vector getNegatedQueryVector(FlagConfig flagConfig, String[] queryTerms, int split) {
  int numNegativeTerms = queryTerms.length - split - 1;
  int numPositiveTerms = split;
  logger.log(Level.FINER, "Number of negative terms: {0}", numNegativeTerms);
  logger.log(Level.FINER, "Number of positive terms: {0}", numPositiveTerms);
  ArrayList<Vector> vectorList = new ArrayList<Vector>();
  for (int i = 1; i <= numNegativeTerms; ++i) {
    Vector tmpVector = vecReader.getVector(queryTerms[split + i]);
    if (tmpVector != null) {
      vectorList.add(tmpVector);
    }
  }
  String[] positiveTerms = new String[numPositiveTerms];
  for (int i = 0; i < numPositiveTerms; ++i) {
    positiveTerms[i] = queryTerms[i];
  }
  vectorList.add(getAdditiveQueryVector(flagConfig, positiveTerms));
  VectorUtils.orthogonalizeVectors(vectorList);

  return vectorList.get(vectorList.size() - 1);
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:32,代码来源:CompoundVectorBuilder.java

示例2: testOrthogonalizeVectors

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
@Test
public void testOrthogonalizeVectors() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(null);
  flagConfig.setDimension(3);
  Vector vec1 = new RealVector(new float[] {1, 2, 1});
  Vector vec2 = new RealVector(new float[] {2, 3, 1});
  Vector vec3 = new RealVector(new float[] {2, 1, 1});
  Vector vec4 = new RealVector(new float[] {2, 1, 5});
  ArrayList<Vector> list = new ArrayList<Vector>();
  list.add(vec1);
  list.add(vec2);
  list.add(vec3);
  list.add(vec4);

  VectorUtils.orthogonalizeVectors(list);
  
  assertEquals(1.0, list.get(0).measureOverlap(list.get(0)), TOL);
  assertEquals(1.0, list.get(1).measureOverlap(list.get(1)), TOL);
  assertEquals(1.0, list.get(2).measureOverlap(list.get(2)), TOL);
  assertEquals(0, list.get(0).measureOverlap(list.get(1)), TOL);
  assertEquals(0, list.get(0).measureOverlap(list.get(2)), TOL);
  assertEquals(0, list.get(1).measureOverlap(list.get(2)), TOL);

  // If we try to orthogonalize more vectors than dimensions, we expect degeneracy eventually!
  assertEquals(Float.NaN, ((RealVector) list.get(3)).getCoordinates()[0]);
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:27,代码来源:VectorUtilsTest.java

示例3: getBoundProductQuerySubSpaceFromString

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Method gets a query subspace from a query string of the form:
 * relation1*relation2+relation3*relation4 
 * 
 * The resulting subspace (or binary approximation) will be derived from the bound product of concept1 and r1*r2, and the
 * bound product of the concept vector  and relation r3*r4.
 * 
 * This method facilitates the combination of single or dual predicate paths using the quantum OR operator, or a binary approximation thereof
 * 
 * @param vecReader Vector store reader for input
 * @param queryString Query expression to be turned into vector subspace
 * @return List of vectors that are basis elements for subspace
 */
public static ArrayList<Vector> getBoundProductQuerySubSpaceFromString(
    FlagConfig flagConfig, VectorStore vecReader, Vector conceptVector, String queryString) {
  ArrayList<Vector> disjunctSpace = new ArrayList<Vector>();
  // Split initially at "+" to construct derive components.
  StringTokenizer subspaceTokenizer = new StringTokenizer(queryString,"+");

  while (subspaceTokenizer.hasMoreTokens()) { 
    // Allow for binding of multiple concepts/relations.
    StringTokenizer bindingTokenizer = new StringTokenizer(subspaceTokenizer.nextToken(),"*");
    Vector boundQueryvector = vecReader.getVector(bindingTokenizer.nextToken()).copy();

    while (bindingTokenizer.hasMoreTokens()) {
      boundQueryvector.release(vecReader.getVector(bindingTokenizer.nextToken()));
    }

    Vector copyConceptVector = conceptVector.copy();
    copyConceptVector.release(boundQueryvector);
    disjunctSpace.add(copyConceptVector);  
  }

  if (flagConfig.searchtype() != SearchType.BOUNDMINIMUM) VectorUtils.orthogonalizeVectors(disjunctSpace);
  return disjunctSpace;
}
 
开发者ID:tuxdna,项目名称:semanticvectors-googlecode,代码行数:37,代码来源:CompoundVectorBuilder.java

示例4: testOrthogonalizeVectors

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
@Test
public void testOrthogonalizeVectors() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(null);
  flagConfig.setDimension(3);
  Vector vec1 = new RealVector(new float[] {1, 2, 1});
  Vector vec2 = new RealVector(new float[] {2, 3, 1});
  Vector vec3 = new RealVector(new float[] {2, 1, 1});
  ArrayList<Vector> list = new ArrayList<Vector>();
  list.add(vec1);
  list.add(vec2);
  list.add(vec3);

  VectorUtils.orthogonalizeVectors(list);
  
  assertEquals(1.0, list.get(0).measureOverlap(list.get(0)), TOL);
  assertEquals(1.0, list.get(1).measureOverlap(list.get(1)), TOL);
  assertEquals(1.0, list.get(2).measureOverlap(list.get(2)), TOL);
  assertEquals(0, list.get(0).measureOverlap(list.get(1)), TOL);
  assertEquals(0, list.get(0).measureOverlap(list.get(2)), TOL);
  assertEquals(0, list.get(1).measureOverlap(list.get(2)), TOL);
}
 
开发者ID:tuxdna,项目名称:semanticvectors-googlecode,代码行数:22,代码来源:VectorUtilsTest.java

示例5: VectorSearcherSubspaceSim

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherSubspaceSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctSpace = new ArrayList<Vector>();
  this.vectorType = flagConfig.vectortype();
  
  for (int i = 0; i < queryTerms.length; ++i) {
    System.out.println("\t" + queryTerms[i]);
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    String[] tmpTerms = queryTerms[i].split("\\s");
    Vector tmpVector = CompoundVectorBuilder.getQueryVector(
        queryVecStore, luceneUtils, flagConfig, tmpTerms);
    if (tmpVector != null) {
      this.disjunctSpace.add(tmpVector);
    }
  }
  if (this.disjunctSpace.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
  if (!vectorType.equals(VectorType.BINARY))
    VectorUtils.orthogonalizeVectors(this.disjunctSpace);
  else BinaryVectorUtils.orthogonalizeVectors(this.disjunctSpace);
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:34,代码来源:VectorSearcher.java

示例6: getVector

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Method gets a query vector from a query string of the form:
 * S(concept1)*E(relation2)+S(concept3)*E(relation4) 
 * 
 * the resulting vector will be the bundle of the semantic vector for each concept
 * bound to the elemental vector of the relevant relation
 * 
 * @return the resulting query vector
 */
private static Vector getVector(
    FlagConfig flagConfig, VectorStore elementalVectors, VectorStore semanticVectors, VectorStore predicateVectors, String term) {
 
 try {
  //permit negation across different vector stores
  if (term.contains(NEGATION_TOKEN))
  {
	  ArrayList<Vector> disjunctSpace = new ArrayList<Vector>();
	  String[] terms = term.split(NEGATION_TOKEN);
	  disjunctSpace.add(getVector( flagConfig, elementalVectors, semanticVectors, predicateVectors, terms[1]));
	  disjunctSpace.add(getVector( flagConfig,   elementalVectors, semanticVectors, predicateVectors, terms[0]));
	   VectorUtils.orthogonalizeVectors(disjunctSpace);
	  
	  return disjunctSpace.get(disjunctSpace.size()-1);
  }
  else if (term.startsWith("E(") && term.endsWith(")"))
    return elementalVectors.getVector(term.substring(2,term.length()-1)).copy();
 else if (term.startsWith("S(") && term.endsWith(")"))
    return semanticVectors.getVector(term.substring(2,term.length()-1)).copy();
 else if (term.startsWith("P(") && term.endsWith(")"))
    return predicateVectors.getVector(term.substring(2,term.length()-1)).copy();
 else return VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension());
 		
 		}
 catch (NullPointerException npe)
 {
  return VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension());
  }
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:39,代码来源:CompoundVectorBuilder.java

示例7: getBoundProductQuerySubSpaceFromString

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Method gets a query subspace from a query string of the form:
 * relation1*relation2+relation3*relation4 
 * 
 * The resulting subspace (or binary approximation) will be derived from the bound product of concept1 and r1*r2, and the
 * bound product of the concept vector  and relation r3*r4.
 * 
 * This method facilitates the combination of single or dual predicate paths using the quantum OR operator, or a binary approximation thereof
 * 
 * @param vecReader Vector store reader for input
 * @param queryString Query expression to be turned into vector subspace
 * @return List of vectors that are basis elements for subspace
 */
public static ArrayList<Vector> getBoundProductQuerySubSpaceFromString(
    FlagConfig flagConfig, VectorStore vecReader, Vector conceptVector, String queryString) {
  ArrayList<Vector> disjunctSpace = new ArrayList<Vector>();
  // Split initially at "+" to construct derive components.
  StringTokenizer subspaceTokenizer = new StringTokenizer(queryString,"+");

  while (subspaceTokenizer.hasMoreTokens()) { 
    // Allow for binding of multiple concepts/relations.
    StringTokenizer bindingTokenizer = new StringTokenizer(subspaceTokenizer.nextToken(),"*");
    Vector boundQueryvector = vecReader.getVector(bindingTokenizer.nextToken()).copy();

    while (bindingTokenizer.hasMoreTokens()) {
  	  if (flagConfig.bindnotreleasehack()) boundQueryvector.bind(vecReader.getVector(bindingTokenizer.nextToken()));
        else boundQueryvector.release(vecReader.getVector(bindingTokenizer.nextToken()));
    }

    Vector copyConceptVector = conceptVector.copy();
    
    if (flagConfig.bindnotreleasehack()) copyConceptVector.bind(boundQueryvector);
    else copyConceptVector.release(boundQueryvector);
    disjunctSpace.add(copyConceptVector);  
  }

  if (flagConfig.searchtype() != SearchType.BOUNDMINIMUM) VectorUtils.orthogonalizeVectors(disjunctSpace);
  return disjunctSpace;
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:40,代码来源:CompoundVectorBuilder.java

示例8: NumberRepresentation

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Initializes an instance of {@link NumberRepresentation} with its start and end vectors,
 * checking that these demarcator vectors are not too close together. 
 * 
 * Allows for the specification of a start and end seed, so mutually near-orthogonal sets
 * of demarcator vectors can be created
 * 
 * @param flagConfig Flag configuration, used in particular to control vectortype and dimension. 
 */
public NumberRepresentation(FlagConfig flagConfig, String startSeed, String endSeed) {
  if (flagConfig == null) throw new NullPointerException("flagConfig cannot be null");

  //enforce probabilistic normalization for binary vectors
  if (flagConfig.vectortype().equals(VectorType.BINARY))
  		BinaryVector.setNormalizationMethod(BinaryVector.NORMALIZE_METHOD.PROBABILISTIC);
  
  this.startRandomSeed = startSeed;
  this.endRandomSeed = endSeed;

  this.flagConfig = flagConfig;

  // Generate a vector for the lowest number and one for the highest and make sure they
  // have no significant overlap.
  Random random = new Random(Bobcat.asLong(startRandomSeed));
  vL = VectorFactory.generateRandomVector(
      flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
  vL.normalize();

  random.setSeed(Bobcat.asLong(endRandomSeed));
  vR = VectorFactory.generateRandomVector(
      flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
  vR.normalize();

  // Small routine to guarantee that end vector has low similarity with start vector.
  ArrayList<Vector> toOrthogonalize = new ArrayList<Vector>();
  toOrthogonalize.add(vL);
  toOrthogonalize.add(vR);
  VectorUtils.orthogonalizeVectors(toOrthogonalize);
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:40,代码来源:NumberRepresentation.java

示例9: VectorSearcherSubspaceSim

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * @param queryVecStore Vector store to use for query generation.
 * @param searchVecStore The vector store to search.
 * @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
 * @param queryTerms Terms that will be parsed and used to generate a query subspace.
 */
public VectorSearcherSubspaceSim(VectorStore queryVecStore,
    VectorStore searchVecStore,
    LuceneUtils luceneUtils,
    FlagConfig flagConfig,
    String[] queryTerms)
        throws ZeroVectorException {
  super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
  this.disjunctSpace = new ArrayList<Vector>();

  for (int i = 0; i < queryTerms.length; ++i) {
    System.out.println("\t" + queryTerms[i]);
    // There may be compound disjuncts, e.g., "A NOT B" as a single argument.
    String[] tmpTerms = queryTerms[i].split("\\s");
    Vector tmpVector = CompoundVectorBuilder.getQueryVector(
        queryVecStore, luceneUtils, flagConfig, tmpTerms);
    if (tmpVector != null) {
      this.disjunctSpace.add(tmpVector);
    }
  }
  if (this.disjunctSpace.size() == 0) {
    throw new ZeroVectorException("No nonzero input vectors ... no results.");
  }
  if (!vectorType.equals(VectorType.BINARY))
    VectorUtils.orthogonalizeVectors(this.disjunctSpace);
  else BinaryVectorUtils.orthogonalizeVectors(this.disjunctSpace);
}
 
开发者ID:tuxdna,项目名称:semanticvectors-googlecode,代码行数:33,代码来源:VectorSearcher.java

示例10: NumberRepresentation

import pitt.search.semanticvectors.vectors.VectorUtils; //导入方法依赖的package包/类
/**
 * Initializes an instance of {@link NumberRepresentation} with its start and end vectors,
 * checking that these demarcator vectors are not too close together. 
 * 
 * Allows for the specification of a start and end seed, so mutually near-orthogonal sets
 * of demarcator vectors can be created
 * 
 * @param flagConfig Flag configuration, used in particular to control vectortype and dimension. 
 */
public NumberRepresentation(FlagConfig flagConfig, String startSeed, String endSeed) {
  if (flagConfig == null) throw new NullPointerException("flagConfig cannot be null");

  this.startRandomSeed = startSeed;
  this.endRandomSeed = endSeed;

  this.flagConfig = flagConfig;

  // Generate a vector for the lowest number and one for the highest and make sure they
  // have no significant overlap.
  Random random = new Random(Bobcat.asLong(startRandomSeed));
  vL = VectorFactory.generateRandomVector(
      flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
  vL.normalize();

  random.setSeed(Bobcat.asLong(endRandomSeed));
  vR = VectorFactory.generateRandomVector(
      flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
  vR.normalize();

  // Small routine to guarantee that end vector has low similarity with start vector.
  ArrayList<Vector> toOrthogonalize = new ArrayList<Vector>();
  toOrthogonalize.add(vL);
  toOrthogonalize.add(vR);
  VectorUtils.orthogonalizeVectors(toOrthogonalize);
}
 
开发者ID:tuxdna,项目名称:semanticvectors-googlecode,代码行数:36,代码来源:NumberRepresentation.java


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