1 // Vector of floating-point values with mostly zero entries
2 // Copyright © 2009 The University of Chicago
6 // See also CSparseIntVector.
8 #include <q3textstream.h>
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.
24 friend int Overlap (CSparseVector
& List1
, CSparseVector
& List2
);
25 friend class CLexicon
;
26 // friend class CSparseVector; // Implicitly friends with itself
30 int m_Length
; // the number of slots currently in use.
31 // int m_MaximalIndex; // highest index available to outside world
37 int ContainsDim (int n
);
39 // void SetLength(int n);
40 float operator[] (int n
); //n is the local value
45 CSparseVector ( int n
);
46 CSparseVector (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
);
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
*);
72 float InnerProduct (CSparseVector
*);
76 #endif // SPARSEVECTOR_H