mikegashler / waffles

A toolkit of machine learning algorithms.
http://gashler.com/mike/waffles/
86 stars 33 forks source link

KNN : Cannot use SparseMetrics #7

Closed skn123 closed 8 years ago

skn123 commented 8 years ago

I would like to use a set of feature stored in GMatrix and a sparse distance metrix (e.g., Cosine). However, there is no API to do this. Can this be fixed in the code?

mikegashler commented 8 years ago

The GSparseSimilarity class (which is the parent class of all my sparse metrics) currently contains 2 abstract methods named "similarity". One of them compares a sparse vector with a sparse vector, and the other one compares a sparse vector with a GVec (fully-specified vector). If I understand your request correctly, you would like a third overload that compares two GVec instances. This would allow you to use any of the sparse similarity metrics to compare two rows from a GMatrix. Do I understand correctly?

skn123 commented 8 years ago

Yes.. Distances can and should be defined for any type of vectors; sparse or dense.

mikegashler commented 8 years ago

Good idea! Done.

skn123 commented 8 years ago

I am still getting this error RuntimeError: This method is not compatible with sparse similarity metrics. You should either use trainSparse instead, or use a dense dissimilarity metric. I am trying to use the cosine dissimilarity metric

skn123 commented 8 years ago

I think this is coming from GKNN ''' void GKNN::trainInner(const GMatrix& feats, const GMatrix& labs) { //if(m_pSparseMetric) // throw Ex("This method is not compatible with sparse similarity metrics. You should either use trainSparse instead, or use a dense dissimilarity metric."); If I comment those lines out to let the program run, then the program crashes.