Skip to content

Instantly share code, notes, and snippets.

@geektoni
Last active June 30, 2017 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geektoni/a32be8e4460215ea8bcd1ccf54ac4cb7 to your computer and use it in GitHub Desktop.
Save geektoni/a32be8e4460215ea8bcd1ccf54ac4cb7 to your computer and use it in GitHub Desktop.
#include <shogun/base/init.h>
#include <shogun/base/some.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/lib/SGVector.h>
#include <shogun/lib/Signal.h>
#include <shogun/machine/Machine.h>
#include <shogun/lib/ParameterObserverScalar.h>
#include <shogun/lib/any.h>
#include <vector>
using namespace shogun;
using namespace std;
// Mock algorithm which implements a fake train_machine method
class MockAlg : public CMachine {
public:
MockAlg() {}
~MockAlg() {}
protected:
// emits 10000 std::pair<std::string, Any> objects
virtual bool train_machine(CFeatures * feat) {
for(int32_t i=0; i<10000; i++)
{
observe_scalar("random", erase_type(i));
}
}
};
int main() {
init_shogun_with_defaults();
// Set up binary labels
int * labs = new int[2];
labs[0] = -1;
labs[1] = 1;
SGVector<int32_t> labs_v {labs, 2};
auto train_labs = some<CBinaryLabels>(labs_v);
// Create a list of parameter we want to observe
auto p = std::vector<std::string>();
p.push_back(std::string("random"));
MockAlg a;
a.set_labels(train_labs);
//Subscribe to the parameters
a.subscribe_to_parameters(new ParameterObserverScalar(p));
a.train();
exit_shogun();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment