Skip to content

Instantly share code, notes, and snippets.

@karlnapf

karlnapf/CLabels Secret

Last active June 1, 2017 09:27
Show Gist options
  • Save karlnapf/939e8b1df0046f9fc22c4fc170012f42 to your computer and use it in GitHub Desktop.
Save karlnapf/939e8b1df0046f9fc22c4fc170012f42 to your computer and use it in GitHub Desktop.
// summary of API ideas
//option1:(tags) no explicit instantiation of sub-class, runtime error when labels are used
// note the subclasses (CBinaryLabels, ... ) do exist still (implementing e.g. "get_binary_vector",
// or "get_confidence_matrix", they are just never instantiated by the user
labels = CLabels()
labels.set_data(file, vector, or matrix) // tags
{
how to do this?
}
// user calls algorithm
machine.set_labels(labels) // tags, no runtime error
predicted = machine.apply()
{
// algorithm knows which representation it wants, so can now "cast"
// preferably, this vector would be template free
SGVector label_vector = get("labels").as_binary().get_values() // potential runtime error
// how is as_binary implemented?
}
//user extracts
SGVector predicted.as_binary().get_values() // works, returns vector {-1,1}
SGVector predicted.as_binary().get_scores() // works, returns real vector
SGMatrix predicted.as_multiclass().get_values() // works, vector {0,1}
SGMatrix predicted.as_multiclass().get_scores() // works, real matrix (with only two rows)
predicted.as_regression().get_values() // runtime error, no point to convert discrete to real
@iglesias
Copy link

iglesias commented May 31, 2017

It looks like we need to define what type apply() and as_binary() should return. If we want both as_binary().get_values() and as_binary().get_scores(), in addition to label values we need to have prediction scores in there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment