Skip to content

Commit

Permalink
EB Moran and Local Moran - enable saving standardized rates GeoDaCent…
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Mar 5, 2019
1 parent 95ab5a4 commit 9776eb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
26 changes: 16 additions & 10 deletions Explore/LisaCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ LisaCoordinator(wxString weights_path,
last_seed_used = 0;
reuse_last_seed = false;
isBivariate = false;

// std::vector<GdaVarTools::VarInfo> var_info;
int num_vars = 1;
isBivariate = false;
Expand Down Expand Up @@ -206,7 +206,12 @@ void LisaCoordinator::DeallocateVectors()
if (data2_vecs[i]) delete [] data2_vecs[i];
}
data2_vecs.clear();


for (int i=0; i<smoothed_results.size(); i++) {
if (smoothed_results[i]) delete [] smoothed_results[i];
}
smoothed_results.clear();

wxLogMessage("Exiting LisaCoordinator::DeallocateVectors()");
}

Expand All @@ -219,11 +224,13 @@ void LisaCoordinator::AllocateVectors()
lags_vecs.resize(tms);
local_moran_vecs.resize(tms);
data1_vecs.resize(tms);
smoothed_results.resize(tms);

for (int i=0; i<tms; i++) {
lags_vecs[i] = new double[num_obs];
local_moran_vecs[i] = new double[num_obs];
data1_vecs[i] = new double[num_obs];
smoothed_results[i] = new double[num_obs];
}

if (lisa_type == bivariate) {
Expand Down Expand Up @@ -294,12 +301,13 @@ void LisaCoordinator::Init()
}
} else { // lisa_type == eb_rate_standardized
std::vector<bool> undef_res(num_obs, false);
double* smoothed_results = new double[num_obs];

double* E = new double[num_obs]; // E corresponds to var_info[0]
double* P = new double[num_obs]; // P corresponds to var_info[1]
// we will only fill data1 for eb_rate_standardized and
// further lisa calcs will treat as univariate
for (int t=0; t<num_time_vals; t++) {
double* local_smoothed_results = smoothed_results[t];
int v0_t = var_info[0].time_min;
if (var_info[0].is_time_variant &&
var_info[0].sync_with_global_time) {
Expand All @@ -314,17 +322,16 @@ void LisaCoordinator::Init()
for (int i=0; i<num_obs; i++) {
P[i] = data[1][v1_t][i];
}
bool success = GdaAlgs::RateStandardizeEB(num_obs, P, E, smoothed_results, undef_res);
bool success = GdaAlgs::RateStandardizeEB(num_obs, P, E, local_smoothed_results, undef_res);
if (!success) {
for (int i=0; i<num_obs; i++) {
undef_data[0][t][i] = undef_data[0][t][i] || undef_res[i];
}
}
for (int i=0; i<num_obs; i++) {
data1_vecs[t][i] = smoothed_results[i];
data1_vecs[t][i] = local_smoothed_results[i];
}
}
if (smoothed_results) delete [] smoothed_results;
if (E) delete [] E;
if (P) delete [] P;
}
Expand Down Expand Up @@ -357,7 +364,7 @@ void LisaCoordinator::GetRawData(int time, double* data1, double* data2)
}
} else { // lisa_type == eb_rate_standardized
std::vector<bool> undef_res(num_obs, false);
double* smoothed_results = new double[num_obs];
double* local_smoothed_results = smoothed_results[time];
double* E = new double[num_obs]; // E corresponds to var_info[0]
double* P = new double[num_obs]; // P corresponds to var_info[1]
// we will only fill data1 for eb_rate_standardized and
Expand All @@ -369,17 +376,16 @@ void LisaCoordinator::GetRawData(int time, double* data1, double* data2)
P[i] = data[1][time][i];
}
bool success = GdaAlgs::RateStandardizeEB(num_obs, P, E,
smoothed_results,
local_smoothed_results,
undef_res);
if (!success) {
for (int i=0; i<num_obs; i++) {
undef_data[0][time][i] = undef_data[0][time][i] || undef_res[i];
}
}
for (int i=0; i<num_obs; i++) {
data1[i] = smoothed_results[i];
data1[i] = local_smoothed_results[i];
}
if (smoothed_results) delete [] smoothed_results;
if (E) delete [] E;
if (P) delete [] P;
}
Expand Down
1 change: 1 addition & 0 deletions Explore/LisaCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class LisaCoordinator : public AbstractCoordinator
double* sigLocalMoran; // The significances / pseudo p-vals

public:
std::vector<double*> smoothed_results; // LISA EB
std::vector<double*> lags_vecs;
std::vector<double*> local_moran_vecs;
std::vector<double*> data1_vecs;
Expand Down
16 changes: 12 additions & 4 deletions Explore/LisaMapNewView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void LisaMapFrame::OnSaveResult(wxCommandEvent& event)

std::vector<SaveToTableEntry> data;

if (lc->is_diff) {
if (lc->is_diff || lc->is_rate) {
data.resize(4);
} else {
data.resize(3);
Expand Down Expand Up @@ -297,8 +297,6 @@ void LisaMapFrame::OnSaveResult(wxCommandEvent& event)

for (int i=0, iend=lisa_coord->num_obs; i<iend; i++) {
sig[i] = p[i];


if (lc->is_diff ) {
int t0 = lisa_coord->var_info[0].time;
int t1 = lisa_coord->var_info[1].time;
Expand All @@ -319,7 +317,17 @@ void LisaMapFrame::OnSaveResult(wxCommandEvent& event)
data[3].type = GdaConst::double_type;
data[3].undefined = &undefs;
}

if (lc->is_rate) {
std::vector<double> ebr(lisa_coord->num_obs);
for (int i=0, iend=lisa_coord->num_obs; i<iend; i++) {
ebr[i] = lisa_coord->smoothed_results[t][i];
}
data[3].d_val = &ebr;
data[3].label = "EB Rates";
data[3].field_default = "LISA_EB";
data[3].type = GdaConst::double_type;
data[3].undefined = &undefs;
}
SaveToTableDlg dlg(project, this, data,
"Save Results: LISA",
wxDefaultPosition, wxSize(400,400));
Expand Down
6 changes: 3 additions & 3 deletions Explore/LisaMapNewView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class LisaMapCanvas : public AbstractMapCanvas
virtual wxString GetCanvasTitle();
virtual wxString GetVariableNames();
bool is_diff;

bool is_rate; // true = Moran Empirical Bayes Rate Smoothing

protected:
LisaCoordinator* lisa_coord;
bool is_bi; // true = Bivariate, false = Univariate
bool is_rate; // true = Moran Empirical Bayes Rate Smoothing


wxString str_highhigh;
wxString str_highlow;
wxString str_lowlow;
Expand Down

0 comments on commit 9776eb2

Please sign in to comment.