Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest class name in factory instantiation #4475

Closed
gf712 opened this issue Jan 18, 2019 · 1 comment · Fixed by #5110
Closed

Suggest class name in factory instantiation #4475

gf712 opened this issue Jan 18, 2019 · 1 comment · Fixed by #5110

Comments

@gf712
Copy link
Member

gf712 commented Jan 18, 2019

Intro

Instead of using directly the classes from C++, we use factories (see here). So for example in Python, instead of

import shogun as sg
kernel = sg.GaussianKernel()

we have

import shogun as sg
kernel = sg.kernel("GaussianKernel")

To find out what all possible names you can have a look at src/shogun/base/class_list.cpp, after compiling shogun.
The issue with this approach is that it is easy to mistype a name, e.g. "Gaussiankernel", and after several hours of writing code these errors might happen more frequently and not so obvious to debug.
Right now you would get a message like this:

SystemError: [ERROR] In file /home/gil/shogun/src/shogun/base/class_list.h line 51: Class Gaussiankernel with primitive type SGOBJECT does not exist.

The task

Catch these errors with SWIG, for example in src/interfaces/shogun.i and try to find out what the user actually meant. This should be written in C++, which would make it accessible to all languages.

Some pointers

  • A good approach would be to calculate the distance between the string the user passed and all the classes in shogun
  • All classes in shogun that are exposed via factories can be accessed with shogun::available_objects()
  • A good distance metric for this is levenshtein, which is not implemented anywhere in shogun, but it is pretty straighforward (see here).
  • Check Suggest class names if class name not found #4473, it has a Python implementation of this
@karlnapf karlnapf changed the title Check class name in factory instantiation Suggest class name in factory instantiation Jan 18, 2019
@karlnapf
Copy link
Member

karlnapf commented Jan 18, 2019

Note: this should not be implemented in a standard c++ shogun source, but in the swig extension. E.g. see https://github.com/shogun-toolbox/shogun/blob/develop/src/interfaces/swig/shogun.i

EDIT: Or, since string distances are actually kinda useful, this can be added to shogun itself in the same way as CHammingWordDistance. Then shogun would use itself for generating error messages 😎

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

Successfully merging a pull request may close this issue.

2 participants