Skip to content

Commit

Permalink
report weights for geometric centroids #1760
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Dec 3, 2018
1 parent 9aacabe commit 626de7d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions DialogTools/AbstractClusterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,30 @@ double AbstractClusterDlg::CreateSummary(const vector<vector<int> >& solution, c
if (isolated.size()>0)
summary << _("Number of not clustered observations: ") << isolated.size() << "\n";
summary << _printConfiguration();

// auto weighting
if (m_use_centroids->IsChecked()) {
wxString w_val = m_wc_txt->GetValue();
double w_valf = 0;
if (w_val.ToDouble(&w_valf)) {
double w_valf_vars = 1 - w_valf;
w_valf = w_valf * 0.5;
w_valf_vars = w_valf_vars / (columns - 2);

summary << _("Use geometric centroids (weighting): \n");
for (int i=0; i<columns; i++) {
if (col_names[i] == "CENTX") {
summary <<" " << _("Centroid (X)") << " " << w_valf << "\n";
} else if (col_names[i] == "CENTY") {
summary <<" " << _("Centroid (Y)") << " " << w_valf << "\n";
} else {
summary <<" " << col_names[i] << " " << w_valf_vars << "\n";
}
}
}

}
summary << "\n";
summary << _printMeanCenters(mean_centers);
summary << _("The total sum of squares:\t") << totss << "\n";
summary << _printWithinSS(withinss);
Expand Down
13 changes: 13 additions & 0 deletions DialogTools/KMeansDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ void KClusterDlg::BinarySearch(double left, double right, std::vector<std::pair<
if ( delta < 0.01 )
return;

int ncluster = 0;
wxString str_ncluster = combo_n->GetValue();
long value_ncluster;
if (str_ncluster.ToLong(&value_ncluster)) {
ncluster = value_ncluster;
}
if (ncluster < 2 || ncluster > num_obs) {
wxString err_msg = _("Please enter a valid number of clusters.");
wxMessageDialog dlg(NULL, err_msg, _("Error"), wxOK | wxICON_ERROR);
dlg.ShowModal();
return;
}

double mid = left + delta /2.0;

// assume left is always not contiguity and right is always contiguity
Expand Down
1 change: 1 addition & 0 deletions Weights/DistUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ DistUtils::~DistUtils()
delete kdTree;
}
}

double DistUtils::GetMinThreshold()
{
double max_1nn_dist = 0;
Expand Down

0 comments on commit 626de7d

Please sign in to comment.