本文整理汇总了Java中pitt.search.semanticvectors.vectors.RealVector类的典型用法代码示例。如果您正苦于以下问题:Java RealVector类的具体用法?Java RealVector怎么用?Java RealVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealVector类属于pitt.search.semanticvectors.vectors包,在下文中一共展示了RealVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PrincipalComponents
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
public PrincipalComponents (ObjectVector[] vectorInput) {
this.vectorInput = vectorInput;
this.dimension = vectorInput[0].getVector().getDimension();
double[][] vectorArray = new double[vectorInput.length][dimension];
for (int i = 0; i < vectorInput.length; ++i) {
if (vectorInput[i].getVector().getClass() != RealVector.class) {
throw new IncompatibleVectorsException(
"Principal components class only works with Real Vectors so far!");
}
if (vectorInput[i].getVector().getDimension() != dimension) {
throw new IncompatibleVectorsException("Dimensions must all be equal!");
}
RealVector realVector = (RealVector) vectorInput[i].getVector();
float[] tempVec = realVector.getCoordinates().clone();
for (int j = 0; j < dimension; ++j) {
vectorArray[i][j] = (double) tempVec[j];
}
}
this.matrix = new DMat(vectorArray.length, vectorArray[0].length);
matrix.value = vectorArray;
System.err.println("Created matrix ... performing svd ...");
Svdlib svd = new Svdlib();
System.err.println("Starting SVD using algorithm LAS2");
svdR = svd.svdLAS2A(Svdlib.svdConvertDtoS(matrix), matrix.cols);
}
示例2: BeagleVectorSearcher
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的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 into a query expression.
*/
public BeagleVectorSearcher(VectorStore queryVecStore, VectorStore searchVecStore,
LuceneUtils luceneUtils,
FlagConfig flagConfig,
String[] queryTerms)
throws ZeroVectorException
{
super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
BeagleCompoundVecBuilder bcvb = new BeagleCompoundVecBuilder(flagConfig);
queryVector = new RealVector(bcvb.getNGramQueryVector(queryVecStore, queryTerms));
if (this.queryVector.isZeroVector()) {
throw new ZeroVectorException("Query vector is zero ... no results.");
}
}
示例3: normalise
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
public void normalise( Enumeration<ObjectVector> e )
{
int zeroVecs = 0, totVecs = 0;
while (e.hasMoreElements())
{
ObjectVector temp = (ObjectVector) e.nextElement();
if (temp.getVector() == null) continue;
float[] next = ((RealVector) temp.getVector()).getCoordinates();
// Normalise and count any zero vectors
// (There shouldn't be any zero vectors)
if (!utils.normalize(next)) zeroVecs++;
totVecs++;
}
System.out.println("Total number of vectors: " + totVecs);
System.out.println("Number of zero vectors: " + zeroVecs);
}
示例4: makeFlagsCompatible
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
/**
* Checks some interaction between flags, and fixes them up to make them compatible.
*
* <br/>
* In practice, this means:
* <ul><li>If {@link #vectortype()} is {@code binary}, {@link #dimension()} is a multiple of 64,
* or is increased to be become a multiple of 64. {@link #seedlength()} is set to be half this
* number.</li>
* <li>Setting {@link #searchvectorfile()} to {@link #queryvectorfile()} unless explicitly set otherwise.</li>
* <li>Setting {@link RealVector#setBindType} if directed (this is something of a hack).</li>
* </ul>
*/
private void makeFlagsCompatible() {
if (vectortype == VectorType.BINARY) {
// Impose "multiple-of-64" constraint, to facilitate permutation of 64-bit chunks.
if (dimension % 64 != 0) {
dimension = (1 + (dimension / 64)) * 64;
logger.fine("For performance reasons, dimensions for binary vectors must be a mutliple "
+ "of 64. Flags.dimension set to: " + dimension + ".");
}
// Impose "balanced binary vectors" constraint, to facilitate reasonable voting.
if (seedlength != dimension / 2) {
seedlength = dimension / 2;
logger.fine("Binary vectors must be generated with a balanced number of zeros and ones."
+ " FlagConfig.seedlength set to: " + seedlength + ".");
}
}
if (searchvectorfile.isEmpty()) searchvectorfile = queryvectorfile;
// This is a potentially dangerous pattern! An alternative would be to make this setting
// part of each real vector, as with complex Modes. But they aren't so nice either.
// Let's avoid getting too committed to either approach and refactor at will.
// dwiddows, 2013-09-27.
if (vectortype == VectorType.REAL && realbindmethod == RealVector.RealBindMethod.PERMUTATION) {
RealVector.setBindType(RealVector.RealBindMethod.PERMUTATION);
}
}
示例5: plotVectors
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
public void plotVectors() {
DMat reducedVectors = this.svdR.Ut;
ObjectVector[] vectorsToPlot = new ObjectVector[vectorInput.length];
int truncate = 4;
for (int i = 0; i < vectorInput.length; i++) {
float[] tempVec = new float[truncate];
for (int j = 0; j < truncate; ++j) {
tempVec[j] = (float) (reducedVectors.value[j][i]);
}
vectorsToPlot[i] = new ObjectVector(vectorInput[i].getObject().toString(),
new RealVector(tempVec));
}
Plot2dVectors myPlot = new Plot2dVectors(vectorsToPlot);
myPlot.createAndShowGUI();
}
示例6: testCreateWriteAndRead
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
@Test
public void testCreateWriteAndRead() {
VectorStoreRAM vectorStore = new VectorStoreRAM(FLAG_CONFIG);
assertEquals(0, vectorStore.getNumVectors());
Vector vector = new RealVector(new float[] {1.0f, 0.0f});
vectorStore.putVector("my vector", vector);
assertEquals(1, vectorStore.getNumVectors());
Vector vectorOut = vectorStore.getVector("my vector");
assertEquals(2, vectorOut.getDimension());
assertEquals(1, vectorOut.measureOverlap(vector), TOL);
}
示例7: testRepeatReads
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
@Test
public void testRepeatReads() {
VectorStoreRAM vectorStore = new VectorStoreRAM(FLAG_CONFIG);
assertEquals(0, vectorStore.getNumVectors());
Vector vector = new RealVector(new float[] {1.0f, 0.0f});
vectorStore.putVector("my vector", vector);
assertEquals(1, vectorStore.getNumVectors());
Vector vectorOut = vectorStore.getVector("my vector");
assertEquals(2, vectorOut.getDimension());
vectorOut = null;
vectorOut = vectorStore.getVector("my vector");
assertEquals(2, vectorOut.getDimension());
}
示例8: createVectorStore
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
private VectorStoreRAM createVectorStore() {
VectorStoreRAM vectorStore = new VectorStoreRAM(FLAG_CONFIG);
Vector vector1 = new RealVector(new float[] {1.0f, 0.0f});
vectorStore.putVector("vector1", vector1);
Vector vector2 = new RealVector(new float[] {1.0f, -1.0f});
vectorStore.putVector("vector2", vector2);
return vectorStore;
}
示例9: createNormalizedVectorStore
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
private VectorStoreRAM createNormalizedVectorStore() {
VectorStoreRAM vectorStore = new VectorStoreRAM(FLAG_CONFIG);
Vector vector1 = new RealVector(new float[] {1.0f, 0.0f});
vector1.normalize();
vectorStore.putVector("vector1", vector1);
Vector vector2 = new RealVector(new float[] {1.0f, -1.0f});
vector2.normalize();
vectorStore.putVector("vector2", vector2);
return vectorStore;
}
示例10: setUp
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
@Before
public void setUp() {
System.out.println("Setting up " + this.getClass().getCanonicalName());
FLAG_CONFIG = FlagConfig.getFlagConfig(COMMAND_LINE_ARGS);
VectorStoreRAM store = new VectorStoreRAM(FLAG_CONFIG);
store.putVector("isaac", new RealVector(new float[] {1, 0}));
store.putVector("abraham", new RealVector(new float[] {0.7f, 0.7f}));
try {
indexOutput = directory.createOutput(TEST_VECTOR_FILE, IOContext.DEFAULT);
VectorStoreWriter.writeToIndexOutput(store, FLAG_CONFIG, indexOutput);
indexOutput.close();
threadLocalIndexInput = new ThreadLocal<IndexInput>() {
@Override
protected IndexInput initialValue() {
try {
return directory.openInput(TEST_VECTOR_FILE, IOContext.READ);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: testReadFromTestData
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
@Test
public void testReadFromTestData() throws IOException {
VectorStoreReaderLucene reader = new VectorStoreReaderLucene(threadLocalIndexInput, FLAG_CONFIG);
assertEquals(2, reader.getNumVectors());
Vector abraham = reader.getVector("abraham");
assertEquals(0.707106f, abraham.measureOverlap(new RealVector(new float[] {1, 0})), TOL);
}
示例12: setUp
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
@Before
public void setUp() {
System.out.println("Setting up " + this.getClass().getCanonicalName());
FLAG_CONFIG = FlagConfig.getFlagConfig(COMMAND_LINE_ARGS);
VectorStoreRAM store = new VectorStoreRAM(FLAG_CONFIG);
store.putVector("isaac", new RealVector(new float[] {1, 0}));
store.putVector("abraham", new RealVector(new float[] {0.7f, 0.7f}));
try {
indexOutput = directory.createOutput(TEST_VECTOR_FILE, IOContext.DEFAULT);
VectorStoreWriter.writeToIndexOutput(store, FLAG_CONFIG, indexOutput);
indexOutput.flush();
threadLocalIndexInput = new ThreadLocal<IndexInput>() {
@Override
protected IndexInput initialValue() {
try {
return directory.openInput(TEST_VECTOR_FILE, IOContext.READ);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: main
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
/**
* 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);
}
示例14: createTestVectorStore
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
public VectorStoreRAM createTestVectorStore() {
VectorStoreRAM store = new VectorStoreRAM(FLAG_CONFIG);
store.putVector("isaac", new RealVector(new float[] {1, 0}));
store.putVector("abraham", new RealVector(new float[] {0.7f, 0.7f}));
return store;
}
示例15: getNGramQueryVector
import pitt.search.semanticvectors.vectors.RealVector; //导入依赖的package包/类
public float[] getNGramQueryVector(VectorStore vecReader, String[] queryTerms) throws IllegalArgumentException
{
// Check basic invariant that there must be one and only one "?" in input.
int queryTermPosition = -1;
for (int j = 0; j < queryTerms.length; ++j)
{
if (queryTerms[j].equals("?"))
{
if (queryTermPosition == -1)
{
queryTermPosition = j;
}
else
{
// If we get to here, there was more than one "?" argument.
System.err.println("Illegal query argument: arguments to getNGramQueryVector must " +
"have only one '?' string to denote target term position.");
throw new IllegalArgumentException();
}
}
}
// If we get to here, there were no "?" arguments.
if (queryTermPosition == -1)
{
System.err.println("Illegal query argument: arguments to getNGramQueryVector must " +
"have exactly one '?' string to denote target term position.");
throw new IllegalArgumentException();
}
DenseFloatMatrix1D vec;
int numpositions = queryTerms.length;
ngBuilder.initialiseNGrams(numpositions);
short[] positions = new short[numpositions];
DenseFloatMatrix1D[] indexvectors = new DenseFloatMatrix1D[numpositions];
String[] docterms = queryTerms;
float[] tmpVec;
boolean problem = false;
for (int i=0; i<numpositions; i++)
{
positions[i] = (short)i;
if (i!=queryTermPosition)
{
tmpVec = ((RealVector) vecReader.getVector(queryTerms[i])).getCoordinates();
if (tmpVec==null)
{
problem = true;
System.out.println("No vector for " + queryTerms[i]);
break;
}
indexvectors[i] = new DenseFloatMatrix1D( tmpVec );
}
}
if (problem) return null;
vec = ngBuilder.generateNGramVector( docterms, positions, indexvectors, 0, numpositions, queryTermPosition );
return vec.toArray();
}