Skip to content

Commit

Permalink
better way of generating mean samples
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 22, 2012
1 parent f1232bc commit 3d23819
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
21 changes: 17 additions & 4 deletions src/shogun/features/DataGenerator.cpp
Expand Up @@ -27,16 +27,29 @@ void CDataGenerator::init()
}

SGMatrix<float64_t> CDataGenerator::generate_mean_data(index_t m,
index_t dim, float64_t mean_shift)
index_t dim, float64_t mean_shift, float64_t* target_data)
{
SGMatrix<float64_t> result(dim, m);
/* evtl use pre-allocated space */
SGMatrix<float64_t> result;

for (index_t i=0; i<m; ++i)
if (target_data)
{
result.matrix=target_data;
result.num_rows=dim;
result.num_cols=2*m;
}
else
result=SGMatrix<float64_t>(dim, 2*m);

/* fill matrix with normal data */
for (index_t i=0; i<2*m; ++i)
{
for (index_t j=0; j<dim; ++j)
result(j,i)=CMath::randn_double();

result(0,i)+=mean_shift;
/* mean shift for second half */
if (i>=m)
result(0,i)+=mean_shift;
}

return result;
Expand Down
14 changes: 8 additions & 6 deletions src/shogun/features/DataGenerator.h
Expand Up @@ -26,17 +26,19 @@ class CDataGenerator: public CSGObject

virtual ~CDataGenerator();

/** produces a set of vectors, where each dimension is standard normally
* distributed and the mean of the first dimension is shifted by a
* provided value
/** Takes each m samples from two distributions p and q, where each element
* is standard normally distributed, except for the first dimension of q,
* where the mean is shifted by a specified value.
*
* @param m number of samples to generate
* @param dim dimension of generated samples
* @param mean_shift is added mean of first dimension
* @return matrix with samples
* @target_data if non-NULL then this is used as matrix data storage. Make
* sure that its dimensions fit
* @return matrix with concatenated samples,first p then q
*/
SGMatrix<float64_t> generate_mean_data(index_t m, index_t dim,
float64_t mean_shift);
static SGMatrix<float64_t> generate_mean_data(index_t m, index_t dim,
float64_t mean_shift, float64_t* target_data=NULL);

inline virtual const char* get_name() const { return "DataGenerator"; }

Expand Down

0 comments on commit 3d23819

Please sign in to comment.