Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Social-weights creation: In the weights manager dialogue, the "distance var" is not displayed.
  • Loading branch information
lixun910 committed Jan 14, 2019
1 parent ba4a73f commit cec4cfd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
27 changes: 19 additions & 8 deletions DialogTools/CreatingWeightDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void CreatingWeightDlg::UpdateThresholdValuesMultiVars()
}

// update Threshold values for distance weight
std::vector<wxString> col_names;
col_names.clear();
std::vector<std::vector<double> > data;
std::vector<std::vector<bool> > undefs;
for (int i=0; i<num_var; i++) {
Expand Down Expand Up @@ -1171,11 +1171,14 @@ bool CreatingWeightDlg::CheckTableVariableInput()
return true;
}

void CreatingWeightDlg::CreateWeightsFromTable(wxString id, wxString outputfile, WeightsMetaInfo& wmi)
void CreatingWeightDlg::CreateWeightsFromTable(wxString id, wxString outputfile,
WeightsMetaInfo& wmi)
{
GeoDa::Weights w;
int metric = m_dist_choice_vars->GetSelection();
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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion DialogTools/CreatingWeightDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ public TableStateObserver, public WeightsManStateObserver
std::vector<double> m_YCOO;

GeoDa::DistUtils* dist_util;
std::vector<wxString> col_names;

WeightsMetaInfo::DistanceMetricEnum dist_metric;
WeightsMetaInfo::DistanceUnitsEnum dist_units;
WeightsMetaInfo::DistanceUnitsEnum dist_units;
WeightsMetaInfo::DistanceValuesEnum dist_values;

wxString dist_units_str;
Expand Down
24 changes: 23 additions & 1 deletion ShapeOperations/WeightsManPtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <set>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <wx/tokenzr.h>

#include "../ShapeOperations/GeodaWeight.h"
#include "../ShapeOperations/WeightsManager.h"
#include "../GdaException.h"
Expand Down Expand Up @@ -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<wxString> 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);
Expand Down Expand Up @@ -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<e.wmi.dist_multivars.size(); ++i) {
s << e.wmi.dist_multivars[i];
if (i < e.wmi.dist_multivars.size()-1) s << ",";
}
sssub.put("dist_multivars", s);
}
}

if (e.wmi.weights_type == WeightsMetaInfo::WT_knn) {
sssub.put("num_neighbors", e.wmi.num_neighbors);
Expand Down
19 changes: 17 additions & 2 deletions VarCalc/WeightsMetaInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ void WeightsMetaInfo::SetToKnn(const wxString& idv,
}
}

void WeightsMetaInfo::SetToKernel(const wxString &id_var_, WeightsMetaInfo::DistanceMetricEnum dist_metric_, WeightsMetaInfo::DistanceUnitsEnum dist_units_, wxString dist_units_str_, WeightsMetaInfo::DistanceValuesEnum dist_values_, wxString kernel_, long k_, double bandwidth_, bool is_adaptive_kernel_, bool use_kernel_diagnals_,wxString dist_var1_, long dist_tm1_, wxString dist_var2_, long dist_tm2_)
void WeightsMetaInfo::SetToKernel(const wxString &id_var_,
WeightsMetaInfo::DistanceMetricEnum dist_metric_,
WeightsMetaInfo::DistanceUnitsEnum dist_units_,
wxString dist_units_str_,
WeightsMetaInfo::DistanceValuesEnum dist_values_,
wxString kernel_, long k_, double bandwidth_,
bool is_adaptive_kernel_, bool use_kernel_diagnals_,
wxString dist_var1_, long dist_tm1_,
wxString dist_var2_, long dist_tm2_)
{
SetToDefaults();
id_var = id_var_;
Expand Down Expand Up @@ -299,7 +307,14 @@ wxString WeightsMetaInfo::DistValsToStr() const
if (dist_tm2 >= 0) s << " (t=" << dist_tm2 << ")";
}
return s;
}
} else if (dist_values == DV_multivars) {
wxString s;
for (size_t i=0; i<dist_multivars.size(); ++i) {
s << dist_multivars[i];
if (i < dist_multivars.size()-1) s << ",";
}
return s;
}
return "unspecified";
}

Expand Down
8 changes: 6 additions & 2 deletions VarCalc/WeightsMetaInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
struct WeightsMetaInfo
{
enum WeightTypeEnum {
WT_custom, WT_rook, WT_queen, WT_threshold, WT_inverse, WT_kernel, WT_knn, WT_tree
WT_custom, WT_rook, WT_queen, WT_threshold, WT_inverse, WT_kernel,
WT_knn, WT_tree
};
enum SymmetryEnum {
SYM_unknown, SYM_symmetric, SYM_asymmetric
};
enum DistanceValuesEnum {
DV_unspecified, DV_centroids, DV_mean_centers, DV_vars, DV_coordinates
DV_unspecified, DV_centroids, DV_mean_centers, DV_vars, DV_coordinates,
DV_multivars
};
enum DistanceMetricEnum {
DM_unspecified, DM_euclidean, DM_arc, DM_manhattan
Expand Down Expand Up @@ -114,6 +116,8 @@ struct WeightsMetaInfo
// written to gda file.
long dist_tm1;
long dist_tm2;

std::vector<wxString> dist_multivars;

// Used by knn
long num_neighbors; // 1 or more. If knn_make_sym then this will be boosted
Expand Down

0 comments on commit cec4cfd

Please sign in to comment.