Java Code Examples for pitt.search.semanticvectors.FlagConfig#getFlagConfig()

The following examples show how to use pitt.search.semanticvectors.FlagConfig#getFlagConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VectorUtilsTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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]);
}
 
Example 2
Source File: SemanticVectorSearcher.java    From uncc2014watsonsim with GNU General Public License v2.0 6 votes vote down vote up
public SemanticVectorSearcher(Environment env) {
	super(env);

	try {
		// How to use SemanticVectors comes from their Wiki.
		// The search function takes many arguments, which are what we are
		// storing as fields here.
		fconfig = FlagConfig.getFlagConfig(
				new String[]{"-luceneindexpath", env.getConfOrDie("lucene_index"),
						"-docvectorsfile", "data/semanticvectors/docvectors.bin",
						"-termvectorsfile", "data/semanticvectors/termvectors.bin"});
		queryVecReader =
				VectorStoreReader.openVectorStore(
						fconfig.termvectorsfile(), fconfig);
		resultsVecReader =
				VectorStoreReader.openVectorStore(
						fconfig.docvectorsfile(), fconfig);
		luceneUtils = new LuceneUtils(fconfig); 
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	Score.register("SEMVEC_RANK", -1, Merge.Mean);
	Score.register("SEMVEC_SCORE", -1, Merge.Mean);
	Score.register("SEMVEC_PRESENT", 0.0, Merge.Sum);
}
 
Example 3
Source File: NumberRepresentationTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testVectorsNearerToBeginningOrEnd() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(
      new String[] {"-vectortype", "binary", "-dimension", "2048"});
  NumberRepresentation numberRepresentation = new NumberRepresentation(flagConfig);
  
  VectorStoreRAM vsr = numberRepresentation.getNumberVectors(0, 4);
  assertTrue(vsr.getVector(0).measureOverlap(vsr.getVector(1))
      > vsr.getVector(4).measureOverlap(vsr.getVector(1)));
  assertTrue(vsr.getVector(4).measureOverlap(vsr.getVector(3))
      > vsr.getVector(3).measureOverlap(vsr.getVector(0)));
  /** This "half-way" equality isn't exact, demonstrating that I don't exactly understand
   * the process. -DW. */
  assertEquals(vsr.getVector(4).measureOverlap(vsr.getVector(2)),
      vsr.getVector(2).measureOverlap(vsr.getVector(0)), 0.05);
}
 
Example 4
Source File: NumberRepresentationTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testCreateAndGetNumberVectors() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(
      new String[] {"-vectortype", "real", "-dimension", "200"});
  NumberRepresentation numberRepresentation = new NumberRepresentation(flagConfig);
  
  VectorStoreRAM vsr2 = numberRepresentation.getNumberVectors(0, 2);
  assertEquals(5, vsr2.getNumVectors());
  
  VectorStoreRAM vsr4 = numberRepresentation.getNumberVectors(0, 4);
  assertEquals(7, vsr4.getNumVectors());
  
  // The beginning and end vectors should be the same in all cases.
  assertEquals(1.0, vsr2.getVector(0).measureOverlap(vsr4.getVector(0)), TOL);
  assertEquals(1.0, vsr2.getVector(2).measureOverlap(vsr4.getVector(4)), TOL);
}
 
Example 5
Source File: TableIndexer.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  FlagConfig flagConfig = null;
  try {
    flagConfig = FlagConfig.getFlagConfig(args);
    args = flagConfig.remainingArgs;
  } catch (IllegalArgumentException e) {
    System.err.println(usageMessage);
    throw e;
  }

  if (flagConfig.remainingArgs.length != 1) {
    throw new IllegalArgumentException("Wrong number of arguments after parsing command line flags.\n" + usageMessage);
  }

  VerbatimLogger.info("Building vector index of table in file: " + args[0] + "\n");
  BufferedReader fileReader = new BufferedReader(new FileReader(args[0]));
  String[] columnHeaders = fileReader.readLine().split(",");
  ArrayList<String[]> dataRows = new ArrayList<>();
  String dataLine;
  while((dataLine = fileReader.readLine()) != null) {
    String[] dataEntries = dataLine.split(",");
    if (dataEntries.length != columnHeaders.length) {
      throw new IllegalArgumentException(String.format(
          "Column headers have length %d and this row has length %d. This indicates a data error or a csv parsing error."
          + "\nColumn headers:%s\nData row: %s\n",
          columnHeaders.length, dataEntries.length,
          StringUtils.join(columnHeaders), StringUtils.join(dataEntries)));
    }
    dataRows.add(dataEntries);
  }
  fileReader.close();
  
  Table table = new Table(flagConfig, columnHeaders, dataRows);
  VectorStoreWriter.writeVectors(flagConfig.termvectorsfile(), flagConfig, table.getRowVectorStore());

  queryForSpecialValues(table);
  //queryForName(table, "J. Adams");
 // queryForName(table, "T. Roosevelt");
  
}
 
Example 6
Source File: VectorStoreOrthographicalTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void initAndRetrieveTest() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(null);
  VectorStoreOrthographical store = new VectorStoreOrthographical(flagConfig);
  Vector fooVector = store.getVector("foo");
  Vector fooVector2 = store.getVector("foo");
  Assert.assertEquals(1, fooVector.measureOverlap(fooVector2), TOL);

  Vector footVector = store.getVector("foot");
  Assert.assertTrue(1 > fooVector.measureOverlap(footVector));

  Vector barVector = store.getVector("bar");
  Assert.assertTrue(fooVector.measureOverlap(barVector) < fooVector.measureOverlap(footVector));

}
 
Example 7
Source File: SemanticVectorsManager.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
private VectorStoreRAM createSVPeer(BufferedReader reader) throws IOException
{
	FlagConfig flagConfig = FlagConfig.getFlagConfig(null);
	String firstLine = reader.readLine();
	FlagConfig.mergeWriteableFlagsFromString(firstLine, flagConfig);
	VectorStoreRAM svstore = new VectorStoreRAM(flagConfig);
	VectorEnumerationText vectorEnumeration = new VectorEnumerationText(reader,flagConfig);
	while (vectorEnumeration.hasMoreElements()) {
		ObjectVector objectVector = vectorEnumeration.nextElement();
		svstore.putVector(objectVector.getObject(), objectVector.getVector());
	}
	return svstore;
}
 
Example 8
Source File: NumberRepresentationTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testBinaryVectorsChangeGradually() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(
      new String[] {"-vectortype", "binary", "-dimension", "2048"});
  NumberRepresentation numberRepresentation = new NumberRepresentation(flagConfig);
  
  VectorStoreRAM vsr = numberRepresentation.getNumberVectors(0, 4);
  assertEquals(0.75, vsr.getVector(0).measureOverlap(vsr.getVector(1)), TOL);
}
 
Example 9
Source File: NumberRepresentationTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAbsoluteValuesOfEndpointsDontMatter() {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(
      new String[] {"-vectortype", "binary", "-dimension", "2048"});
  NumberRepresentation numberRepresentation = new NumberRepresentation(flagConfig);
  
  VectorStoreRAM vsr1 = numberRepresentation.getNumberVectors(0, 4);    
  VectorStoreRAM vsr2 = numberRepresentation.getNumberVectors(8, 12);
  assertEquals(1.0, vsr1.getVector(0).measureOverlap(vsr2.getVector(8)), TOL);
  assertEquals(1.0, vsr1.getVector(2).measureOverlap(vsr2.getVector(10)), TOL); 
}
 
Example 10
Source File: TableTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setUp() {
  columnNames = new String[] {"Name", "Start", "End"};
  dataRows = Arrays.asList(new String[][]{
      new String[]{"a", "1600", "1700"},
      new String[]{"b", "1600", "1800"},
      new String[]{"c", "1700", "1800"}
  });
  table = new Table(FlagConfig.getFlagConfig("-vectortype complex -dimension 1000 -seedlength 500".split(" ")), columnNames, dataRows);
}
 
Example 11
Source File: MarkedUpDocumentAnalyzer.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
  FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
  MarkedUpDocumentAnalyzer analyzer = new MarkedUpDocumentAnalyzer(flagConfig);

  Vector othelloVector = analyzer.getVectorForString(othello);
  Vector midsummerVector = analyzer.getVectorForString(midsummerNightsDream);
  Vector twelfthNightVector = analyzer.getVectorForString(twelfthNight);

  System.out.println("Structural similarity of Othello with A Midsummer Night's Dream:");
  System.out.println(othelloVector.measureOverlap(midsummerVector));
  System.out.println("Structural similarity of Othello with Twelfth Night:");
  System.out.println(twelfthNightVector.measureOverlap(othelloVector));
  System.out.println("Structural similarity of A Midsummer Night's Dream with Twelfth Night:");
  System.out.println(twelfthNightVector.measureOverlap(midsummerVector));
}
 
Example 12
Source File: BeagleTest.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args)
{
	BeagleTest bt = new BeagleTest();
  FlagConfig flagConfig = FlagConfig.getFlagConfig(
      new String[] {"-vectortype", "real", "-dimension", "512"});

	// Some example method calls
	bt.createNGrams("KJB", flagConfig, 3 );

	bt.testQuery(flagConfig, "KJB_512_3.bin", "KJB_512_3_index.bin", "king ?" );
}
 
Example 13
Source File: LuceneIndexFromTriples.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Index all text files under a directory. */
public static void main(String[] args) {
  String usage = "java pitt.search.lucene.LuceneIndexFromTriples [triples text file] ";
  if (args.length == 0) {
    System.err.println("Usage: " + usage);
    System.exit(1);
  }
  FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
  // Allow for the specification of a directory to write the index to.
  if (flagConfig.luceneindexpath().length() > 0) {
    INDEX_DIR = FileSystems.getDefault().getPath(flagConfig.luceneindexpath());
  }
  if (Files.exists(INDEX_DIR)) {
     throw new IllegalArgumentException(
         "Cannot save index to '" + INDEX_DIR + "' directory, please delete it first");
  }

  try {
    // Create IndexWriter using WhiteSpaceAnalyzer without any stopword list.
    IndexWriterConfig writerConfig = new IndexWriterConfig(new WhitespaceAnalyzer());
    IndexWriter writer = new IndexWriter(FSDirectory.open(INDEX_DIR), writerConfig);

    final File triplesTextFile = new File(args[0]);
    if (!triplesTextFile.exists() || !triplesTextFile.canRead()) {
      writer.close();
      throw new IOException("Document file '" + triplesTextFile.getAbsolutePath() +
          "' does not exist or is not readable, please check the path");
    }

    System.out.println("Indexing to directory '" +INDEX_DIR+ "'...");
    indexDoc(writer, triplesTextFile);
    writer.close();       
  } catch (IOException e) {
    System.out.println(" caught a " + e.getClass() +
        "\n with message: " + e.getMessage());
  }
}
 
Example 14
Source File: Retrofit.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Java implementation of vector retrofitting technique described in:
 * 
 * @InProceedings{faruqui:2014:NIPS-DLRLW,
 *	 author    = {Faruqui, Manaal and Dodge, Jesse and Jauhar, Sujay K.  and  Dyer, Chris and Hovy, Eduard and Smith, Noah A.},
 * title     = {Retrofitting Word Vectors to Semantic Lexicons},
 * booktitle = {Proceedings of NAACL},
 * year      = {2015},
 *}
 * @param args
 * @throws IOException 
 */

public static void main(String[] args) throws IOException {
	
	double alpha=1; double beta=1; //standard parameters
	
	FlagConfig flagConfig 			 = FlagConfig.getFlagConfig(args);
	VectorStoreRAM initialVectors  	 = new VectorStoreRAM(flagConfig);
	VectorStoreRAM retroVectors		 = new VectorStoreRAM(flagConfig);
	
	//read in initial term vectors, initialize retrofitted vectors to initial vectors
	initialVectors.initFromFile(flagConfig.initialtermvectors());
	retroVectors.initFromFile(flagConfig.initialtermvectors());
	
	
	//read in lexicon, a space-separated file consisting of all concepts related to the first concept to appear
	BufferedReader lexiconReader = new BufferedReader(new FileReader(new File(flagConfig.startlistfile())));
	
	Hashtable<String,String[]> relations = new Hashtable<String,String[]>();
	
	String lexiconLine = lexiconReader.readLine();
	
	while (lexiconLine != null)
	{
		String[] tokenizedLine = lexiconLine.split(" "); 
		relations.put(tokenizedLine[0].toLowerCase(),tokenizedLine);
		lexiconLine = lexiconReader.readLine();
		}
	
	lexiconReader.close();
	
	//facilitate shuffling of concept list on each iteration of training
	ArrayList<String> keyList = new ArrayList<String>();
	Enumeration<String> keySet = relations.keys();
	while (keySet.hasMoreElements())
		keyList.add(keySet.nextElement());
	
	//iterate
	for (int epoch=0; epoch < flagConfig.trainingcycles(); epoch++)
	{
		System.out.println("Training cycle "+epoch);
		
		Collections.shuffle(keyList);
		
			for (String key:keyList)
			{
				
				String[] relationships = relations.get(key);
				
				//skip if no relationships for this CUI
				if (!retroVectors.containsVector(key)) continue;
				if (relationships.length <= 1) continue;
				
					
				retroVectors.removeVector(key);
				retroVectors.putVector(key, VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension()));
				
				int relcnt = 0;
				
				for (int x=1; x < relationships.length; x++)
					if (retroVectors.containsVector(relationships[x].toLowerCase()))
					{
						retroVectors.getVector(key).superpose(retroVectors.getVector(relationships[x].toLowerCase()), beta, null);
						retroVectors.getVector(key).superpose(initialVectors.getVector(key),alpha,null);
						relcnt++;
					}
				
				if (relcnt > 0)
				{
					//rescale
					for (int y=0; y < flagConfig.dimension(); y++)
					((RealVector) retroVectors.getVector(key)).getCoordinates()[y] /= (double) 2*alpha*beta*relcnt;
			
				}
			}
			

			
	}
	
	VectorStoreWriter.writeVectorsInLuceneFormat(flagConfig.initialtermvectors().substring(0,flagConfig.initialtermvectors().indexOf("."))+flagConfig.startlistfile().substring(flagConfig.startlistfile().lastIndexOf("/")+1,flagConfig.startlistfile().indexOf("."))+".bin", flagConfig, retroVectors);
	
}
 
Example 15
Source File: VectorStoreTruncater.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	try {
	FlagConfig flagConfig 			= FlagConfig.getFlagConfig(args);
	VectorStoreRAM objectVectors 	= new VectorStoreRAM(flagConfig);
	String[] argsRemaining			= flagConfig.remainingArgs;
	String incomingVecs				= argsRemaining[0];
	int newDimension				= Integer.parseInt(argsRemaining[1]);
	objectVectors.initFromFile(incomingVecs);
	
	if (newDimension > flagConfig.dimension())
		{
		
				System.out.println("Incoming file has dimensionality of " +flagConfig.dimension());
				System.out.println("New dimensionality must be less than incoming vector length, quitting");
				System.exit(0);	
		}
	
		String vectorFileName = incomingVecs.replaceAll("\\.bin", "")+"_"+newDimension+".bin";
	  	File vectorFile = new File(vectorFileName);
	    String parentPath = vectorFile.getParent();
	    if (parentPath == null) parentPath = "";
	    FSDirectory fsDirectory = FSDirectory.open(FileSystems.getDefault().getPath(parentPath));
	    IndexOutput outputStream = fsDirectory.createOutput(vectorFile.getName(), IOContext.DEFAULT);
	 	flagConfig.setDimension(newDimension);
		outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
	    Enumeration<ObjectVector> vecEnum = objectVectors.getAllVectors();

	    // Write each vector.
	    while (vecEnum.hasMoreElements()) {
	      ObjectVector objectVector = vecEnum.nextElement();
	      outputStream.writeString(objectVector.getObject().toString());
	      objectVector.getVector().writeToLuceneStream(outputStream,flagConfig.dimension());
	    }
	    
	    
	    outputStream.close();
	    fsDirectory.close();
		
	    VerbatimLogger.info("wrote "+objectVectors.getNumVectors()+" vectors to file "+ vectorFileName);
	    VerbatimLogger.info("finished writing vectors.\n");
	 		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("Usage: VectorStoreTruncater incomingFile.bin newDimensinoality");
	}
	
	
	
}
 
Example 16
Source File: VectorStoreSubset.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Main class of a utility method that takes as input:
 * (1) -queryvectorfile: the original vector store OR
 * (1.1) -elementalvectofile, -semanticvectorfile, -predicatevectorfile (for PSI queries)
 * (2) -startlistfile: the list of queries (e.g. terms), one per line, from which to construct a new vector store 
 * @param args
 * @throws IOException 
 */


public static void main(String[] args) throws IOException {
	
	FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
	boolean PSIquery = true;
	
	VectorStoreRAM queryVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM elementalVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM predicateVectors = new VectorStoreRAM(flagConfig);
	VectorStoreRAM semanticVectors = new VectorStoreRAM(flagConfig);

	
	//if all PSI/ESP query files are at the default value, assume this is not a PSI/ESP query
	if (flagConfig.elementalvectorfile().equals("elementalvectors")
			&& flagConfig.semanticvectorfile().equals("semanticvectors")
			  && flagConfig.elementalpredicatevectorfile().equals("predicatevectors")
			) 
		{
			PSIquery = false;
			queryVectors.initFromFile(flagConfig.queryvectorfile());
		}
	else
	{
		elementalVectors.initFromFile(flagConfig.elementalvectorfile());
		semanticVectors.initFromFile(flagConfig.semanticvectorfile());
		predicateVectors.initFromFile(flagConfig.elementalpredicatevectorfile());
	}
	
	VectorStoreRAM outGoingVectors = new VectorStoreRAM(flagConfig);
	
	
	BufferedReader theReader = new BufferedReader(new FileReader(new File(flagConfig.startlistfile())));
	
	String inputString = theReader.readLine();
	while (inputString != null)
	{
		Vector vectorToAdd = null;
		
		if (!PSIquery) vectorToAdd = CompoundVectorBuilder.getQueryVectorFromString(queryVectors, null, flagConfig, inputString);
		else 		   vectorToAdd = CompoundVectorBuilder.getBoundProductQueryVectorFromString(flagConfig, elementalVectors, semanticVectors, predicateVectors, null, inputString);
		
		if (vectorToAdd == null || 
				vectorToAdd.isZeroVector() || 
					(flagConfig.vectortype().equals(VectorType.REAL) && (Float.isNaN(  ((RealVector) vectorToAdd).getCoordinates()[0]))) ||
					(flagConfig.vectortype().equals(VectorType.COMPLEX) && (Float.isNaN(  ((ComplexVector) vectorToAdd).getCoordinates()[0])))
						
				)
		{	VerbatimLogger.info("Could not represent "+inputString);}
		else
		{
			VerbatimLogger.info("Adding "+inputString.replaceAll(" ", "_"));
			outGoingVectors.putVector(inputString.replaceAll(" ", "_"),vectorToAdd);
		}  
		
		inputString = theReader.readLine();
	}
	
	theReader.close();
	
	VerbatimLogger.info("\nFinished adding vectors, proceeding to write out\n");
	
	VectorStoreWriter.writeVectorsInLuceneFormat(flagConfig.startlistfile().replaceAll("\\..*", "_subset.bin"), flagConfig, outGoingVectors);
	

}
 
Example 17
Source File: GenerateProximityData.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
public static void main(String[] args) {
	// TODO Auto-generated method stub

	FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
	GenerateProximityData g = new GenerateProximityData();
	g.outputProximityData(flagConfig); //redo for 2019 with seelength mod *** training cycles do not improve coherence***
	
	
}
 
Example 18
Source File: SemanticVectorCollider.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
public static void main(String[] args)
{
	FlagConfig flagConfig = FlagConfig.getFlagConfig(args);
  args = flagConfig.remainingArgs;
			
	Random random = new Random();
	
	
	int iterations = 1000; //number of times to perform experiment
	int superpositions = 15000; //number of superpositions per experiment (at most)
	int min = Integer.MAX_VALUE;
	int max = Integer.MIN_VALUE;
	
	System.out.println("Number of iterations "+iterations);
	System.out.println("Number of superpositions per iteration (if no collision occurs) "+superpositions);
	System.out.println("Vector type "+flagConfig.vectortype());
	System.out.println("Dimension "+flagConfig.dimension());
	System.out.println("Seed length "+flagConfig.seedlength());
	
	int overlapcnt = 0;
	int overlaprank = 0;
	ArrayList<Double> overlapRank = new ArrayList<Double>();
	
	int overlapcount = 0;
	double overlapscore=0;
	ArrayList<Double> overlapScore = new ArrayList<Double>();
	
	
	for (int cnt = 0; cnt < iterations; cnt++)
	{	
		System.err.println("\nIteration "+cnt);
		
	
	Vector originalVector = VectorFactory.generateRandomVector(
	    flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
	
	Vector superPosition = VectorFactory.createZeroVector(flagConfig.vectortype(), flagConfig.dimension());
	
	superPosition.superpose(originalVector, 1, null);
	if (flagConfig.vectortype() == VectorType.BINARY) {
	  ((BinaryVector) superPosition).tallyVotes();
	}
	
	Vector additionalVector = VectorFactory.generateRandomVector(
       flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
	
	for (int x =0; x < superpositions; x++)
	{
		if (x % 100 == 0) System.err.print("...");
		
		
		double overlapWithOrigin = superPosition.measureOverlap(originalVector); 
	
		//generate another random vector
		Vector randomVector = VectorFactory.generateRandomVector(
        flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
		double overlapWithRandom = superPosition.measureOverlap(randomVector); 
		
		
			overlapscore += overlapWithRandom;
			overlapScore.add(new Double(overlapWithRandom));
			
		
		if (overlapWithRandom >= overlapWithOrigin) //version 2.0 based on Roger Schvaneveldt's Matlab edition: compare superposition:origin vs. superposition:random (this is different than the implementation in Wahle et al 2012, which compared origin:superposition vs. origin:random) 
		{
			System.out.println("Iteration " +cnt+": Incidental overlap occurred at superposition number "+x);
			
			min = Math.min(min,x);
			max = Math.max(max,x);
			
			overlapcnt++;
			overlaprank += x;
			overlapRank.add(new Double(x));
			
				
			x = 999999999;
		}
		
		additionalVector = VectorFactory.generateRandomVector(
		    flagConfig.vectortype(), flagConfig.dimension(), flagConfig.seedlength(), random);
		
		superPosition.superpose(additionalVector, 1, null);
		
		if (flagConfig.vectortype() == VectorType.BINARY) {
		  ((BinaryVector) superPosition).tallyVotes();
		}
	}
	
	}
	
	double stdRank = calculateSTD(overlapRank, (double) overlaprank/ (double) overlapcnt);
	
	System.out.println("Collisions occurred in "+(100)*((double) overlapcnt/(double) iterations) +"% of iterations");
	System.out.println("\nAverage collision rank "+ (double) overlaprank/ (double) overlapcnt);
	System.out.println("STD collision rank "+ stdRank);
	System.out.println("Minimum collision rank "+min);
	System.out.println("Maximum collision rank "+max);
	
	
}