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

Replacing undocumented python example for Sparse Euclidian Distance with a meta-example #4945

Merged
merged 5 commits into from
Apr 3, 2020

Conversation

Hephaestus12
Copy link
Contributor

Removed .py file.
Added .sg.in file.
Compiled successfully on local machine.
#3555 #3000 #4942
Sorry for creating a new PR, had deleted the old branch by mistake.

@vigsterkr
Copy link
Member

that doesn't matter... plz read up on git and github. there's absolutely no reason the close and open another PR.... except the case of a forced pushed branch while PR is being close.. in that case you cannot open a PR on github for some reason. other than that you should be able to have one PR open for a specific task...

@vigsterkr
Copy link
Member

the linux tests are failing while trying to execute the meta example this PR adds. plz try to debug locally what's happening

#![create_features]

#![create_instance]
Distance d = distance("SparseEuclideanDistance", lhs=features_a, rhs=features_a)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the documentation stats SparseEuclideanDistance is expecting SparseFeatures.... imo the features you are reading above are not SparseFeatures but DenseFeatures.

plz make sure that you compile and test your changes before sending in a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all the other examples(.sg.in files), features_a and features_b are defined as variables of the Features class, and they directly become DenseFeatures by calling the constructor of the CDenseFeatures class.
How should we ensure that the features are sparse and the constructor of the CSparseFeatures class is called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the examples are actually using methods that requires SparseFeatures... for that actually you'll need to patch factory.h to be able to read sparse format (say libsvmfile) and create a SparseFeature from it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a bit beyond an entrance task so might be worth starting an issue and then rebase this when it’s done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm! Does it work? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started new issue #4947

@vigsterkr
Copy link
Member

i think you haven't tested this code locally...

@Hephaestus12
Copy link
Contributor Author

I added 2 functions to the factory.h file.
I am now getting some errors in the translate.py file which I was unable to solve.

translate.TranslationFailure: 'Failed to obtain include path for Csparse_features or sparse_features or Csparse_features or sparse_features'

import shogun as sg

feats_train=SparseRealFeatures(sg.libsvm_file(train_fname))
feats_test=SparseRealFeatures(sg.libsvm_file(test_fname))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don’t you use this parser and files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't I have to add functions to the factory.h file nevertheless? so that it can be translated?

Copy link
Member

@vigsterkr vigsterkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would like to kindly ask again that before you send a PR compile and test it locally. this obviously has not been tested locally.

@@ -130,6 +131,41 @@ namespace shogun
return result;
}

template <class T>
std::shared_ptr<Features> sparse_features(SGMatrix<T> mat)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exposing the SparseMatrix ctor would be good as well, but as for factory we would like to have this under one common function, namely features.

std::shared_ptr<Features> sparse_features(std::shared_ptr<File> file, EPrimitiveType primitive_type = PT_FLOAT64)
{
require(file, "No file provided.");
std::shared_ptr<Features> result = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again as said above this should be within features factory function.
for that to be able to work you'll have to do a bit of dispatching, i.e. to detect the type of File object being passed (csv or libsvmfile) and based on that create the right feature type object (dense or sparse). i'd use type_index(typeid()) to detect the type of file that has been passed over, but you can even use get_name() and do a string comparison.

@Hephaestus12
Copy link
Contributor Author

@vigsterkr Is this okay?

@@ -106,25 +107,51 @@ namespace shogun
require(file, "No file provided.");
std::shared_ptr<Features> result = nullptr;

switch (primitive_type)
if(strcmp( file->get_name(), "LibSVMFile") == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vigsterkr I guess this works, just not very maintainable... What are the other sparse data file format available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you do something like std::type_index(typeid(*file)) == std::type_index(typeid(LibSVMFile))?

@Hephaestus12
Copy link
Contributor Author

Is this fine? @gf712 @vigsterkr

@gf712
Copy link
Member

gf712 commented Mar 24, 2020

Is this fine? @gf712 @vigsterkr

does it work locally?

@Hephaestus12
Copy link
Contributor Author

does it work locally?

A few unit tests failed. However they are failing in the original code(before making the changes) as well.

@karlnapf
Copy link
Member

unit tests only cover c++ code, you need to build, run, and test the meta examples. Check the examples readme for that

@gf712
Copy link
Member

gf712 commented Apr 2, 2020

Could you trigger the CI please? It seems like the previous failures were due to the alignment bug, which is unrelated to this and has been fixed. If it passes CI now we can merge!

@Hephaestus12 Hephaestus12 force-pushed the feature/metaExample branch from 99a0f1e to 3e0f2d0 Compare April 2, 2020 22:53
@Hephaestus12
Copy link
Contributor Author

Is this fine?

@gf712
Copy link
Member

gf712 commented Apr 3, 2020

@vigsterkr is this fine?

@vigsterkr
Copy link
Member

yeah lets squash this one! i suppose the Accelerate fail is totally unrelated...right?

@gf712
Copy link
Member

gf712 commented Apr 3, 2020

yeah lets squash this one! i suppose the Accelerate fail is totally unrelated...right?

yup, that's just the cblas header issue

@vigsterkr vigsterkr merged commit 57b5209 into shogun-toolbox:develop Apr 3, 2020
@Hephaestus12 Hephaestus12 deleted the feature/metaExample branch June 20, 2020 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants