-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfisher.h
99 lines (67 loc) · 1.56 KB
/
fisher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/// \Class fisher fisher.h "fisher.h"
///
/// \brief
///
/// \version 1.0
/// \author Jorge A. Sanchez
/// \date 02/08/2010
#ifndef __FISHER_H
#define __FISHER_H
#include <limits>
#include "simd_math.h"
#include "gmm.h"
// -------------------------------------------------------------------------
// Fisher Vector
struct fisher_param {
fisher_param() :
grad_weights(false),
grad_means(true),
grad_variances(true),
alpha(0.5),
pnorm(2.0) { }
bool grad_weights;
bool grad_means;
bool grad_variances;
float alpha;
float pnorm;
float gamma_eps;
void print();
};
// -------------------------------------------------------------------------
template<class T>
class fisher
{
public:
fisher( fisher_param &_param );
~fisher( );
void set_model( gaussian_mixture<T> &_gmm );
// unweighted
int compute( std::vector<T*> &x, T *fk );
void Compute();
void Accumulate_statics( std::vector<T*> &x);
void AddSub(fisher<T> *sub_fisher);
void AddOne(T *sample);
T* get_fv();
int get_num();
void alpha_and_lp_normalization();
// weighted
int compute( std::vector<T*> &x, std::vector<T> &wgh, T *fk);
int dim(){ return fkdim; }
private:
bool equal( T a, T b )
{
if( fabs((T)a-(T)b)<std::numeric_limits<T>::epsilon() )
return true;
return false;
}
//void alpha_and_lp_normalization( T *fk );
protected:
fisher_param param;
int ndim, ngauss, ngrad, fkdim;
gaussian_mixture<T> *gmm;
T *iwgh, *istd;
T *s0, **s1, **s2;
T *fv;
int snum; // number of samples;
};
#endif