CMiniLexicon::FindMajorSignatures(): use log file routines
[linguistica.git] / SparseVector.h
blobec932d2978d943875a69590c726dbf95a553033e
1 // Vector of floating-point values with mostly zero entries
2 // Copyright © 2009 The University of Chicago
3 #ifndef SPARSEVECTOR_H
4 #define SPARSEVECTOR_H
6 // See also CSparseIntVector.
8 #include <q3textstream.h>
10 class CLexicon;
11 class CWordCollection;
12 class CMorphemeCollection;
14 // this is a class which keeps track of values
15 // associated with an integer (the "dimension"),
16 // useful when such a vector is "sparse," that is,
17 // the values for most of the "dimensions" is zero
18 // (and hence you don't want to have to remember each zero).
19 // It keeps track of the dimensions that we care about,
20 // with their corresponding "values"; any dimension not
21 // explicitly listed is taken to have a zero value.
22 class CSparseVector
24 friend int Overlap (CSparseVector& List1, CSparseVector& List2);
25 friend class CLexicon;
26 // friend class CSparseVector; // Implicitly friends with itself
28 protected:
30 int m_Length; // the number of slots currently in use.
31 // int m_MaximalIndex; // highest index available to outside world
32 int* m_Dimension;
33 float* m_Values;
34 int m_NormalizedFlag;
35 int m_NumberOfSlots;
37 int ContainsDim (int n);
38 int GetLength();
39 // void SetLength(int n);
40 float operator[] (int n); //n is the local value
42 public:
44 CSparseVector();
45 CSparseVector ( int n);
46 CSparseVector (CSparseVector&);
47 ~CSparseVector();
49 void operator() (int n, float val); // n is the value of Dimension
50 float operator() (int n); // n is the value of Dimension
51 void operator= (CSparseVector&);
52 int operator== (CSparseVector&);
55 // for iteration: (uses MFC-style syntax):
56 int GetNextDimension (int& DimOut, float& Value, int& Position);
58 void Clear();
59 void ClearOut();
60 int GetNormalizedFlag();
61 int GetTopDimension();
62 float GetAt( int dim ); //uses outside world value of dimension
63 void SetAt ( int, float);
64 int Delete (int dim); //uses outside world value of dim
65 void IncrementAt(int, float = 1);
66 int GetNumberOfSlots ();
67 void SetNumberOfSlots(int);
68 // int GetNumberOfNonZeroMembers();
69 Q3TextStream& OutputToStream (CWordCollection&, Q3TextStream& stream, int threshold=2);
70 void MakeLogFreq (CWordCollection*);
71 void Normalize();
72 float InnerProduct (CSparseVector*);
76 #endif // SPARSEVECTOR_H