-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
SOBI_unittest.cc
63 lines (48 loc) · 1.38 KB
/
SOBI_unittest.cc
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
#include <shogun/base/init.h>
#include <shogun/lib/common.h>
#include <shogun/features/DenseFeatures.h>
#include <gtest/gtest.h>
#ifdef HAVE_EIGEN3
#include <shogun/mathematics/Math.h>
#include <shogun/mathematics/eigen3.h>
#include <shogun/converter/ica/SOBI.h>
using namespace Eigen;
typedef Matrix< float64_t, Dynamic, Dynamic, ColMajor > EMatrix;
typedef Matrix< float64_t, Dynamic, 1, ColMajor > EVector;
using namespace shogun;
TEST(CSOBI, blind_source_separation)
{
// Generate sample data
int FS = 4000;
EVector t(FS+1, true);
t.setLinSpaced(FS+1,0,1);
// Source Signals
EMatrix S(2,FS+1);
for(int i = 0; i < FS+1; i++)
{
S(0,i) = sin(2*M_PI*55*t[i]);
S(1,i) = cos(2*M_PI*100*t[i]);
}
// Mixing Matrix
EMatrix A(2,2);
A(0,0) = 1; A(0,1) = 0.85;
A(1,0) = 0.55; A(1,1) = 1;
// Mix signals
SGMatrix<float64_t> X(2,FS+1);
Eigen::Map<EMatrix> EX(X.matrix,2,FS+1);
EX = A * S;
CDenseFeatures< float64_t >* mixed_signals = new CDenseFeatures< float64_t >(X);
// Separate
CSOBI* sobi = new CSOBI();
SG_REF(sobi);
CFeatures* signals = sobi->apply(mixed_signals);
SG_REF(signals);
// Separation error
Eigen::Map<EMatrix> ES (((CDenseFeatures<float64_t>*)signals)->get_feature_matrix().matrix,2,FS+1);
double sep_error = (S-ES).array().abs().sum();
EXPECT_LE(sep_error, 1e-6);
SG_UNREF(sobi);
SG_UNREF(mixed_signals);
SG_UNREF(signals);
}
#endif //HAVE_EIGEN3