diff --git a/DialogTools/CreatingWeightDlg.cpp b/DialogTools/CreatingWeightDlg.cpp index e28862965..6c3b17423 100644 --- a/DialogTools/CreatingWeightDlg.cpp +++ b/DialogTools/CreatingWeightDlg.cpp @@ -269,7 +269,7 @@ void CreatingWeightDlg::UpdateThresholdValuesMultiVars() } // update Threshold values for distance weight - std::vector col_names; + col_names.clear(); std::vector > data; std::vector > undefs; for (int i=0; iGetSelection(); - WeightsMetaInfo::DistanceMetricEnum dist_metric = metric == 1 ? WeightsMetaInfo::DM_manhattan : WeightsMetaInfo::DM_euclidean; + WeightsMetaInfo::DistanceMetricEnum dist_metric = + metric == 1 ? WeightsMetaInfo::DM_manhattan : + WeightsMetaInfo::DM_euclidean; int method = m_nb_distance_methods->GetSelection(); if (method == 0) { @@ -1191,7 +1194,8 @@ void CreatingWeightDlg::CreateWeightsFromTable(wxString id, wxString outputfile, } } w = dist_util->CreateDistBandWeights(band, is_inverse, power); - wmi.SetToThres(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", WeightsMetaInfo::DV_vars, band, power); + wmi.SetToThres(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", + WeightsMetaInfo::DV_multivars, band, power); } else if ( method == 1) { // kNN @@ -1206,7 +1210,8 @@ void CreatingWeightDlg::CreateWeightsFromTable(wxString id, wxString outputfile, } } w = dist_util->CreateKNNWeights(k, is_inverse, power); - wmi.SetToKnn(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", WeightsMetaInfo::DV_vars, k, power); + wmi.SetToKnn(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", + WeightsMetaInfo::DV_multivars, k, power); } else if ( method == 2) { // adaptive kernel @@ -1218,12 +1223,18 @@ void CreatingWeightDlg::CreateWeightsFromTable(wxString id, wxString outputfile, int k = m_spinn_kernel->GetValue(); if (m_radio_manu_bandwdith->GetValue() == true) { - w = dist_util->CreateAdaptiveKernelWeights(kernel_type, bandwidth, apply_kernel_to_diag); + w = dist_util->CreateAdaptiveKernelWeights(kernel_type, bandwidth, + apply_kernel_to_diag); } else { - w = dist_util->CreateAdaptiveKernelWeights(kernel_type, k, is_adaptive_bandwidth, apply_kernel_to_diag); + w = dist_util->CreateAdaptiveKernelWeights(kernel_type, k, + is_adaptive_bandwidth, apply_kernel_to_diag); } - wmi.SetToKernel(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", WeightsMetaInfo::DV_vars, kernel, k, bandwidth, is_adaptive_bandwidth, apply_kernel_to_diag); + wmi.SetToKernel(id, dist_metric, WeightsMetaInfo::DU_unspecified, "", + WeightsMetaInfo::DV_multivars, kernel, k, bandwidth, + is_adaptive_bandwidth, apply_kernel_to_diag); } + + wmi.dist_multivars = col_names; // save to file GwtWeight* Wp = new GwtWeight; diff --git a/DialogTools/CreatingWeightDlg.h b/DialogTools/CreatingWeightDlg.h index d5c13e1d1..39e41fbd7 100644 --- a/DialogTools/CreatingWeightDlg.h +++ b/DialogTools/CreatingWeightDlg.h @@ -194,9 +194,10 @@ public TableStateObserver, public WeightsManStateObserver std::vector m_YCOO; GeoDa::DistUtils* dist_util; + std::vector col_names; WeightsMetaInfo::DistanceMetricEnum dist_metric; - WeightsMetaInfo::DistanceUnitsEnum dist_units; + WeightsMetaInfo::DistanceUnitsEnum dist_units; WeightsMetaInfo::DistanceValuesEnum dist_values; wxString dist_units_str; diff --git a/ShapeOperations/WeightsManPtree.cpp b/ShapeOperations/WeightsManPtree.cpp index ed62a30c2..38ef4c095 100644 --- a/ShapeOperations/WeightsManPtree.cpp +++ b/ShapeOperations/WeightsManPtree.cpp @@ -20,6 +20,8 @@ #include #include #include +#include + #include "../ShapeOperations/GeodaWeight.h" #include "../ShapeOperations/WeightsManager.h" #include "../GdaException.h" @@ -205,6 +207,16 @@ void WeightsManPtree::ReadPtree(const boost::property_tree::ptree& pt, wxString s = v.second.data(); e.wmi.dist_var2 = s; e.wmi.dist_values = WeightsMetaInfo::DV_vars; + } else if (key == "dist_multivars") { + wxString s = v.second.data(); + std::vector multi_vars; + wxStringTokenizer tokenizer(s, ","); + while (tokenizer.HasMoreTokens() ) { + wxString token = tokenizer.GetNextToken(); + multi_vars.push_back(token); + } + e.wmi.dist_multivars = multi_vars; + e.wmi.dist_values = WeightsMetaInfo::DV_multivars; } else if (key == "dist_tm1") { long l; wxString(v.second.data()).ToLong(&l); @@ -375,7 +387,17 @@ void WeightsManPtree::WritePtree(boost::property_tree::ptree& pt, sssub.put("dist_tm2", e.wmi.dist_tm2); } } - } + } else if (e.wmi.dist_values == WeightsMetaInfo::DV_multivars) { + sssub.put("dist_values", "vars"); + if (!e.wmi.dist_multivars.empty()) { + wxString s; + for (size_t i=0; i= 0) s << " (t=" << dist_tm2 << ")"; } return s; - } + } else if (dist_values == DV_multivars) { + wxString s; + for (size_t i=0; i dist_multivars; // Used by knn long num_neighbors; // 1 or more. If knn_make_sym then this will be boosted