I’m working on creating a notebook on machine learning with synaptic.
see
I have two questions. First, Synaptic uses can be trained by asynchronously and can log to the javascript console and/or run a function at an interval.
Since the function is called async, I can’t yield from the method, but I wanted to get a progress report I can rely on. So I created a raise_event method similar to the Generator notify pattern.
the raise_event function looks like this:
function raise_event(event_name, data){
var event; // The custom event that will be created
if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent(event_name, true, true);
} else {
event = document.createEventObject();
event.eventType = event_name;
}
event.custom_data = data;
event.eventName = event_name;
if (document.createEvent) {
window.dispatchEvent(event);
} else {
window.fireEvent("on" + event.eventType, event);
}
}
And is used by a generator like this:
progress_report = Generators.queue(notify => {
const received_data = event => {notify(event.custom_data)};
window.addEventListener("progress_report", received_data);
return () => window.removeEventListener("progress_report", received_data);
})
So the first question: Does this stink? See cells "synaptic_network, “raise_event”, and “progress_report”.
The second question is related to the ability to cancel the async training. Returning true from the scheduled function in synaptic’s trainer will cause the training to stop. I want to be able to abort training without re-evaluating the network cell and restarting the trainer.
For example, if I was to add a toggle training button producing a true false by relying on “this” and reference its value within the function, I would successfully stop the training, but immediately restart because the cell is being re-evaluated. Maybe I have to utilize the value of “this”? If so, I don’t know how for this particular case.
Maybe this doesn’t fit in Observablehq?
Any advice you have would be great.