Last active
June 30, 2017 15:27
-
-
Save geektoni/a32be8e4460215ea8bcd1ccf54ac4cb7 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 <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