Created
June 21, 2017 10:40
-
-
Save micmn/f1044ef5d828b6bd84ef35c6cb3dab75 to your computer and use it in GitHub Desktop.
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
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <shogun/base/init.h> | |
#include <shogun/lib/config.h> | |
#include <shogun/labels/MulticlassLabels.h> | |
#include <shogun/multiclass/MCLDA.h> | |
#include <shogun/features/DenseFeatures.h> | |
#include <shogun/io/SGIO.h> | |
#include <shogun/lib/common.h> | |
#include <shogun/features/DataGenerator.h> | |
using namespace shogun; | |
#define NUM 1605 | |
#define DIMS 294 | |
#define CLASSES 2 | |
void test() | |
{ | |
printf("%d: Training...\n", getpid()); | |
SGVector< float64_t > lab(CLASSES*NUM); | |
SGMatrix< float64_t > feat(DIMS, CLASSES*NUM); | |
feat = CDataGenerator::generate_gaussians(NUM,CLASSES,DIMS); | |
for( int i = 0 ; i < CLASSES ; ++i ) | |
for( int j = 0 ; j < NUM ; ++j ) | |
lab[i*NUM+j] = double(i); | |
CMulticlassLabels* labels = new CMulticlassLabels(lab); | |
CDenseFeatures< float64_t >* features = new CDenseFeatures< float64_t >(feat); | |
CMCLDA* lda = new CMCLDA(features, labels); | |
SG_REF(lda); | |
lda->train(); | |
// Free memory | |
SG_UNREF(lda); | |
printf("%d: done.\n", getpid()); | |
} | |
int main(int argc, char ** argv) | |
{ | |
init_shogun_with_defaults(); | |
test(); | |
int s; | |
printf("%d: Spawning process...\n", getpid()); | |
pid_t pID = fork(); | |
if (pID == 0) { | |
test(); | |
} | |
else { | |
printf("%d: Joining ...\n", getpid()); | |
waitpid(pID, &s, 0); | |
printf("%d: done.\n", getpid()); | |
} | |
exit_shogun(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment