-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Jade_unittest.cc
68 lines (53 loc) · 1.54 KB
/
Jade_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
64
65
66
67
68
#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/Jade.h>
#include <shogun/evaluation/ica/PermutationMatrix.h>
using namespace Eigen;
typedef Matrix< float64_t, Dynamic, Dynamic, ColMajor > EMatrix;
typedef Matrix< float64_t, Dynamic, 1, ColMajor > EVector;
using namespace shogun;
TEST(CJade, 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
CJade* jade = new CJade();
SG_REF(jade);
CFeatures* signals = jade->apply(mixed_signals);
SG_REF(signals);
// Close to a permutation matrix (with random scales)
Eigen::Map<EMatrix> EA(jade->get_mixing_matrix().matrix,2,2);
SGMatrix<float64_t> P(2,2);
Eigen::Map<EMatrix> EP(P.matrix,2,2);
EP = EA.inverse() * A;
// Test if output is correct
bool isperm = is_permutation_matrix(P);
EXPECT_EQ(isperm,true);
SG_UNREF(jade);
SG_UNREF(mixed_signals);
SG_UNREF(signals);
}
#endif //HAVE_EIGEN3