Machine Learning Library
CVector.h
Go to the documentation of this file.
1 /*
2  COPYRIGHT (C) 2003 APPLIED NEUROINFORMATIC GROUP - UNIVERSITY OF BIELEFELD.
3 
4  ALL RIGHTS RESERVED.
5 
6  REDISTRIBUTION AND USE IN SOURCE AND BINARY FORM, WITH OR WITHOUT
7  MODIFICATION, REQUIRE THE PERMISSION OF THE COPYRIGHT HOLDERS.
8 
9  COMMERCIAL USE WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT HOLDERS
10  IS FORBIDDEN
11 
12  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
13  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 
25 #ifndef CVECTOR_H
26 #define CVECTOR_H
27 
28 #include <cassert>
29 #include <cstring>
30 #include <cstdio>
31 #include <cmath>
32 #include <iostream>
33 #include <vector>
34 #include "Macros.h"
35 #include "CException.h"
36 #include "CVectorOperations.h"
37 #include "CObject.h"
38 using std::vector;
39 
40 
41 
42 template<class Type> struct keyed_iterator;
43 template<typename Type> class CDenseVector;
44 template<typename Type> class CSparseVector;
45 
52 template <class Type>
53 class CVector : public CObject<Type>
54 {
55 protected:
57 
58 public:
59  virtual ~CVector() {};
60  virtual CVector<Type>* clone() const = 0;
61 
63  virtual CVector<double>* toDouble() const = 0;
65  virtual CVector<float>* toFloat() const = 0;
66 
67  virtual vector<Type> toSTL() const;
68  virtual CDenseVector<int> sort() = 0;
69 
71  virtual bool operator==(const CVector<Type>& rhs) const;
72 
74  Type operator*(const CVector<Type>&) const;
79 
81  virtual CVector<Type>& operator*=(const Type&) = 0;
83  virtual CVector<Type>& operator/=(const Type&) = 0;
84 
86  virtual int dimension(void) const = 0;
88  virtual int getNumNonZero() const = 0;
89 
91  virtual bool isNaN() const = 0;
92 
94  virtual Type euclideanLength(bool bQuad=false) const = 0;
95 
97  virtual const Type& operator[](int n) const = 0;
99  virtual Type getElement(int n) const = 0;
102  virtual string className() const { return string("CVector"); };
103 
107  Type euclideanDistance(const CVector<Type>& , bool b=false) const;
108 
110  Type coCosineDistance(const CVector<Type>&) const;
111 
112 
113 
125  void adaptToVec(const CVector<Type>&, float fEps1, float fEps2);
126 
127  virtual bool serialize(fstream& stream, IO_MODE mode);
128 
129 }; // end of class
130 
131 
132 /*
133  * Local variables:
134  * mode: c++
135  * End:
136  */
137 
138 #endif
IO_MODE
Definition: CObject.h:38
virtual string className() const
Returns the class name.
Definition: CVector.h:102
Type euclideanDistance(const CVector< Type > &, bool b=false) const
virtual int getNumNonZero() const =0
returns the number of non-zero entries
Definition: CDenseVector.h:35
static const CVectorOperations< Type > & op_table
Definition: CVector.h:56
CVector< Type > & operator*=(const CVector< Type > &)
multiply vectors elementwise
virtual vector< Type > toSTL() const
Sparse, immutable vector representation.
Definition: CSparseVector.h:42
CVector< Type > & operator/=(const CVector< Type > &)
divide vectors elementwise
virtual CVector< double > * toDouble() const =0
create a copy with every element stored as 'double'
virtual const Type & operator[](int n) const =0
return constant reference to n'th vector element
virtual CDenseVector< int > sort()=0
virtual bool operator==(const CVector< Type > &rhs) const
returns true if rhs has the same elements
Template object for vectors of single and double precision and integer.
Definition: CDenseVector.h:37
Type coCosineDistance(const CVector< Type > &) const
returns common cosine distance of the two vectors
templatized vector for numerical applications
Definition: CMatrix.h:39
Base class for all object.
Definition: CObject.h:51
void adaptToVec(const CVector< Type > &, float fEps1, float fEps2)
virtual bool serialize(fstream &stream, IO_MODE mode)
Read/write from binary stream.
virtual bool isNaN() const =0
returns true if vector contains nan elements
virtual ~CVector()
Definition: CVector.h:59
virtual Type euclideanLength(bool bQuad=false) const =0
returns euclidean length of vector
Type operator*(const CVector< Type > &) const
scalar product with vector
virtual Type getElement(int n) const =0
return copy of n'th vector element
virtual CVector< Type > * clone() const =0
destructor
virtual CVector< float > * toFloat() const =0
create a copy with every element stored as 'float'
virtual int dimension(void) const =0
return vector dimension