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

Set lhs of underlying distance to cluster centers (#4388) #4510

Closed
wants to merge 1 commit into from
Closed

Set lhs of underlying distance to cluster centers (#4388) #4510

wants to merge 1 commit into from

Conversation

braceletboy
Copy link

No description provided.

scripts/check_format.sh Outdated Show resolved Hide resolved
src/shogun/clustering/Hierarchical.cpp Outdated Show resolved Hide resolved
src/shogun/clustering/Hierarchical.cpp Outdated Show resolved Hide resolved
src/shogun/clustering/Hierarchical.cpp Outdated Show resolved Hide resolved
    modified:   src/shogun/clustering/Hierarchical.cpp
    modified:   src/shogun/clustering/Hierarchical.h

    (Squashed)Made minor changes based on the suggestions of reviewers
void CHierarchical::store_model_features()
{
/* TODO. Currently does nothing since apply methods are not implemented. */
CDenseFeatures<float64_t>* rhs =
(distance->get_rhs())->as<CDenseFeatures<float64_t>>();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need the parenthesis here.
Also, are we really sure that the features are float64 bit?

Copy link
Author

Choose a reason for hiding this comment

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

Will remove the parenthesis.
I checked the KmeansBase file and used float64 bit. I felt that it made sense to make it float64 bit. What other type do you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

KMeans is another algorithm. I just checked Hierarchical.cpp and it does not fix the features to be 64 bit float, but rather just calles the distance method of CDistance. So we will need to think a bit more here in order to not make the algorithm only work for those 64bit dense feautres. What about 32 bit? What about sparse features?` What about string features? But let's address the other points first, this one will take some time and effort

Copy link
Author

Choose a reason for hiding this comment

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

Okay. I get your point. Thanks!

CDenseFeatures<float64_t>* temp_cluster_centers =
new CDenseFeatures<float64_t>(null_matrix);

for (int32_t i = 0; i < num_vectors; i++)
Copy link
Member

Choose a reason for hiding this comment

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

auto

Copy link
Author

Choose a reason for hiding this comment

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

Okay, makes sense.

int32_t centerIdx = assignment[i];
SG_DEBUG("\n");
SG_DEBUG("On %04i point, with assignment=%04i \n", i, centerIdx);
float64_t* center = temp_cluster_centers->get_feature_vector(
Copy link
Member

Choose a reason for hiding this comment

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

I think there should be a SGVector based API for feature vectors that you could use here. This pointer based one is deprecated

Copy link
Author

Choose a reason for hiding this comment

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

Will do. Thanks :)

center, num_features, dofree_c);
}

CDenseFeatures<float64_t>* cluster_centers =
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the code to compute something should be in here. This is just a method to store a "smaller" version of the features, namely only those needed to apply the model to new data. If you need to compute things in order to do that, it should happen in a helper method

curr_index, num_features, dofree);
SG_DEBUG("\n");
SG_DEBUG("The %04i cluster center:\n", curr_index);
for (int32_t j = 0; j < num_features; j++)
Copy link
Member

Choose a reason for hiding this comment

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

pls use std::copy or similar for those operations, it is faster

Copy link
Author

Choose a reason for hiding this comment

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

Okay. Thank you!

cluster_centers->free_feature_vector(center, num_features, dofree);
}
}
distance->init(cluster_centers, rhs);
Copy link
Member

Choose a reason for hiding this comment

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

you should add a unit test that

  1. Trains the clustering
  2. Applies to test data
  3. Calls store_model_features, asserts that now the features are different
  4. Now applies to test data again and assert that results didnt change

{
if (n_cluster_samples[centerIdx] > 0)
{
center[j] = (center[j] * n_cluster_samples[centerIdx] +
Copy link
Member

Choose a reason for hiding this comment

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

you should leave a comment on what type of algorithm/approach is used here to store/compute model features

Copy link
Member

@karlnapf karlnapf left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! :)
There are some things that need to be addresses in terms of style/API, structuring and tests.
Let's iterate!

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 26, 2020
@stale
Copy link

stale bot commented Mar 4, 2020

This issue is now being closed due to a lack of activity. Feel free to reopen it.

@stale stale bot closed this Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants