Skip to content

Instantly share code, notes, and snippets.

@karlnapf
Created June 6, 2013 17:21
Show Gist options
  • Save karlnapf/5723230 to your computer and use it in GitHub Desktop.
Save karlnapf/5723230 to your computer and use it in GitHub Desktop.
TParameter serialization
/*
* 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) 2013 Heiko Strathmann
*/
#include <shogun/lib/config.h>
#ifdef HAVE_EIGEN3
#include <shogun/labels/RegressionLabels.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/regression/GaussianProcessRegression.h>
#include <shogun/regression/gp/ExactInferenceMethod.h>
#include <shogun/regression/gp/ZeroMean.h>
#include <shogun/regression/gp/GaussianLikelihood.h>
#include <shogun/io/SerializableAsciiFile.h>
#include <shogun/statistics/QuadraticTimeMMD.h>
#include <shogun/lib/DynamicObjectArray.h>
using namespace shogun;
void test()
{
float64_t a=1.7126587125;
float64_t b=0;
TSGDataType type(CT_SCALAR, ST_NONE, PT_FLOAT64);
TParameter* param1=new TParameter(&type, &a, "param1", "");
TParameter* param2=new TParameter(&type, &b, "param1", "");
const char* filename="float64_param.txt";
// save parameter to an ascii file
CSerializableAsciiFile *file=new CSerializableAsciiFile(filename, 'w');
param1->save(file);
file->close();
SG_UNREF(file);
// load parameter from an ascii file
file=new CSerializableAsciiFile(filename, 'r');
param2->load(file);
file->close();
SG_UNREF(file);
// check for equality
float64_t accuracy=0.1;
SG_SPRINT("%d\n", param1->equals(param2, accuracy));
delete param1;
delete param2;
}
int main(int argc, char **argv)
{
init_shogun_with_defaults();
sg_io->set_loglevel(MSG_DEBUG);
test();
exit_shogun();
return 0;
}
#endif //HAVE_EIGEN3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment