Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #668 from karlnapf/master
new data generator class to generate example data
- Loading branch information
Showing
5 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2012 Heiko Strathmann | ||
*/ | ||
|
||
#include <shogun/features/DataGenerator.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
using namespace shogun; | ||
|
||
CDataGenerator::CDataGenerator() : CSGObject() | ||
{ | ||
init(); | ||
} | ||
|
||
CDataGenerator::~CDataGenerator() | ||
{ | ||
|
||
} | ||
|
||
void CDataGenerator::init() | ||
{ | ||
} | ||
|
||
SGMatrix<float64_t> CDataGenerator::generate_mean_data(index_t m, | ||
index_t dim, float64_t mean_shift, float64_t* target_data) | ||
{ | ||
/* evtl use pre-allocated space */ | ||
SGMatrix<float64_t> result; | ||
|
||
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(); | ||
|
||
/* mean shift for second half */ | ||
if (i>=m) | ||
result(0,i)+=mean_shift; | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2012 Heiko Strathmann | ||
*/ | ||
|
||
#ifndef __DATAGENERATOR_H_ | ||
#define __DATAGENERATOR_H_ | ||
|
||
#include <shogun/base/SGObject.h> | ||
#include <shogun/lib/SGMatrix.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** @brief Class that is able to generate various data samples, which may be | ||
* used for examples in SHOGUN. | ||
*/ | ||
class CDataGenerator: public CSGObject | ||
{ | ||
public: | ||
CDataGenerator(); | ||
|
||
virtual ~CDataGenerator(); | ||
|
||
/** 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 | ||
* @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 | ||
*/ | ||
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"; } | ||
|
||
private: | ||
/** registers all parameters and initializes variables with defaults */ | ||
void init(); | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif /* __DATAGENERATOR_H_ */ |