SHOGUN  6.0.0
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
static float64_t sin(float64_t x)
tanh(x), x being a complex128_t
Definition: Math.h:815
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
This class implements streaming features with dense feature vectors.
int32_t index_t
Definition: common.h:72
void unset_generic()
Definition: SGObject.cpp:336
static float64_t randn_double()
Definition: Math.h:1127
SGVector< float64_t > current_vector
The current example's feature vector as an SGVector
void set_blobs_model(index_t sqrt_num_blobs, float64_t distance, float64_t stretch, float64_t angle)
static uint64_t random()
Definition: Math.h:1014
static SGMatrix< float64_t > matrix_multiply(SGMatrix< float64_t > A, SGMatrix< float64_t > B, bool transpose_A=false, bool transpose_B=false, float64_t scale=1.0)
Definition: SGMatrix.cpp:1037
double float64_t
Definition: common.h:60
static float64_t cos(float64_t x)
sinh(x), x being a complex128_t
Definition: Math.h:851
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_SDEBUG(...)
Definition: SGIO.h:167