Last active
March 6, 2019 14:44
-
-
Save geektoni/77285a6a01ca166cab0289020d256ab1 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
/******/ | |
/* How observable parameters can be registered*/ | |
/******/ | |
MyFabulousMachine::init() | |
{ | |
// Register standard parameters | |
SG_ADD(&m_w, "weights", "Model weigths", ParameterProperties::MODEL); | |
// Version A: Register observable parameters. The user could then get a list | |
// (vector) of the parameters he can observe inside this model. Only the parameters | |
// registered with this method can be observed through observe(). | |
register_observable_param("run_weigths", "Model weights during training"); | |
// Version B: Register observable parameters using SG_ADD. This would require | |
// to add a member variable for each observable value we will emit. | |
SG_ADD(&m_obs_weights, "run_weights", "Model weights during training", ParameterProperties::OBSERVABLE); | |
} | |
void MyFabulousMachine::train() | |
{ | |
/* Train method Code */ | |
// Version A: This will lead to an error if the specified name was not registered before | |
// using the register_observale_param method. | |
observe("run_weights", step, make_any(variable_containing_the_weights)); | |
// Version B: If the parameter has as property OBSERVABLE, then it will be emitted through the | |
// observe() method inside put. This will also unify the observable framework with the put one | |
// (which may make things a bit unclear). | |
put("run_weights", &m_obs_weigths) | |
/* Other train method code */ | |
} | |
// Version A: The "new" observe method. | |
void observe(string name, int step, Any value) | |
{ | |
if (!m_observable_parameters.contains(name)) | |
{ | |
error; | |
} | |
this->_observe(ObservedValue::make_observation(name, step, value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment