SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GaussianBlobsDataGenerator.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Heiko Strathmann
8  */
9 
11 
12 using namespace shogun;
13 
16 {
17  init();
18 }
19 
21  float64_t distance, float64_t stretch, float64_t angle) :
23 {
24  init();
25  set_blobs_model(sqrt_num_blobs, distance, stretch, angle);
26 }
27 
29 {
30 }
31 
33  float64_t distance, float64_t stretch, float64_t angle)
34 {
35  m_sqrt_num_blobs=sqrt_num_blobs;
37  m_stretch=stretch;
38  m_angle=angle;
39 
40  /* precompute cholesky decomposition, start with rotation matrix */
41  SGMatrix<float64_t> R(2, 2);
42  R(0, 0)=CMath::cos(angle);
43  R(0, 1)=-CMath::sin(angle);
44  R(1, 0)=CMath::sin(angle);
45  R(1, 1)=CMath::cos(angle);
46 
47  /* diagonal eigenvalue matrix */
48  SGMatrix<float64_t> L(2, 2);
49  L(0, 0)=CMath::sqrt(stretch);
50  L(1, 0)=0;
51  L(0, 1)=0;
52  L(1, 1)=1;
53 
54  /* compute and save cholesky for sampling later on */
56 }
57 
58 void CGaussianBlobsDataGenerator::init()
59 {
60  SG_ADD(&m_sqrt_num_blobs, "sqrt_num_blobs", "Number of Blobs per row",
62  SG_ADD(&m_distance, "distance", "Distance between blobs",
64  SG_ADD(&m_stretch, "stretch", "Stretch of blobs",
66  SG_ADD(&m_angle, "angle", "Angle of Blobs",
68  SG_ADD(&m_cholesky, "cholesky", "Cholesky factor of covariance matrix",
70 
72  m_distance=0;
73  m_stretch=1;
74  m_angle=0;
76  m_cholesky(0, 0)=1;
77  m_cholesky(0, 1)=0;
78  m_cholesky(1, 0)=0;
79  m_cholesky(1, 1)=1;
80 
81  unset_generic();
82 }
83 
85 {
86  SG_SDEBUG("entering CGaussianBlobsDataGenerator::get_next_example()\n");
87 
88  /* allocate space */
90 
91  /* sample latent distribution to compute offsets */
94 
95  /* sample from std Gaussian */
98 
99  /* transform through cholesky and add offset */
100  result[0]=m_cholesky(0, 0)*x+m_cholesky(0, 1)*y+x_offset;
101  result[1]=m_cholesky(1, 0)*x+m_cholesky(1, 1)*y+y_offset;
102 
103  /* save example back to superclass */
105 
106  SG_SDEBUG("leaving CGaussianBlobsDataGenerator::get_next_example()\n");
107  return true;
108 }
109 
111 {
114 }
115 

SHOGUN Machine Learning Toolbox - Documentation