Skip to content

Commit

Permalink
fix issue #292 #288
Browse files Browse the repository at this point in the history
#288 causes crash due to large number of observations (>70000) generates
too many pairs (which is set as default) and cause memory issue and
crash in non-parametric correlogram. So, a detection is added to set
"Random Sample" as default when observation number is larger than 10000.

Note: this crash only appears on Windows platform.
  • Loading branch information
lixun910 committed Jan 15, 2016
1 parent ab8539a commit e2d0784
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 47 deletions.
15 changes: 7 additions & 8 deletions Explore/CorrelParamsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#include "../DialogTools/WebViewHelpWin.h"
#include "CorrelParamsDlg.h"

CorrelParamsFrame::CorrelParamsFrame(const CorrelParams& correl_params,
GdaVarTools::Manager& var_man,
Project* project_)
CorrelParamsFrame::CorrelParamsFrame(const CorrelParams& correl_params, GdaVarTools::Manager& var_man, Project* project_)
: wxFrame((wxWindow*) 0, wxID_ANY, "Correlogram Parameters",
wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE),
CorrelParamsObservable(correl_params, var_man), project(project_),
Expand All @@ -44,7 +42,9 @@ help_btn(0), apply_btn(0)
LOG_MSG("Entering CorrelParamsFrame::CorrelParamsFrame");

wxPanel* panel = new wxPanel(this);

panel->SetBackgroundColour(*wxWHITE);
SetBackgroundColour(*wxWHITE);

{
var_txt = new wxStaticText(panel, XRCID("ID_VAR_TXT"), "Variable:");
var_choice = new wxChoice(panel, XRCID("ID_VAR_CHOICE"), wxDefaultPosition,wxSize(160,-1));
Expand Down Expand Up @@ -244,9 +244,7 @@ CorrelParamsFrame::~CorrelParamsFrame()
void CorrelParamsFrame::OnHelpBtn(wxCommandEvent& ev)
{
LOG_MSG("In CorrelParamsFrame::OnHelpBtn");
WebViewHelpWin* win = new WebViewHelpWin(project, GetHelpPageHtml(), NULL,
wxID_ANY,
"Correlogram Parameters Help");
WebViewHelpWin* win = new WebViewHelpWin(project, GetHelpPageHtml(), NULL, wxID_ANY, "Correlogram Parameters Help");
}

void CorrelParamsFrame::OnApplyBtn(wxCommandEvent& ev)
Expand Down Expand Up @@ -290,6 +288,8 @@ void CorrelParamsFrame::OnApplyBtn(wxCommandEvent& ev)
}
}



if (all_pairs_rad->GetValue() == true) {
correl_params.method = CorrelParams::ALL_PAIRS;
if (use_thresh) {
Expand All @@ -306,7 +306,6 @@ void CorrelParamsFrame::OnApplyBtn(wxCommandEvent& ev)
long v;
long revert_val = correl_params.max_iterations;
bool apply_revert = true;
LOG(v);
if (s.ToLong(&v)) {
if (v > CorrelParams::max_iter_cnst) {
revert_val = CorrelParams::max_iter_cnst;
Expand Down
2 changes: 1 addition & 1 deletion Explore/CorrelParamsObservable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct CorrelParams
bins = def_bins_cnst;
dist_metric = WeightsMetaInfo::DM_euclidean;
dist_units = WeightsMetaInfo::DU_mile;
method = ALL_PAIRS;
method = RAND_SAMP;
max_iterations = def_iter_cnst;
threshold = -1;
}
Expand Down
40 changes: 20 additions & 20 deletions Explore/CorrelogramView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ BEGIN_EVENT_TABLE(CorrelogramFrame, TemplateFrame)
EVT_ACTIVATE(CorrelogramFrame::OnActivate)
END_EVENT_TABLE()

CorrelogramFrame::CorrelogramFrame(wxFrame *parent, Project* project,
const wxString& title,
const wxPoint& pos,
const wxSize& size)
CorrelogramFrame::CorrelogramFrame(wxFrame *parent, Project* project, const wxString& title, const wxPoint& pos, const wxSize& size)
: TemplateFrame(parent, project, title, pos, size, wxDEFAULT_FRAME_STYLE),
correl_params_frame(0), panel(0),
panel_v_szr(0), bag_szr(0), top_h_sizer(0),
Expand Down Expand Up @@ -178,6 +175,15 @@ void CorrelogramFrame::OnShowCorrelParams(wxCommandEvent& event)
CorrelParams cp;
cp.dist_metric = project->GetDefaultDistMetric();
cp.dist_units = project->GetDefaultDistUnits();
/*
std::vector<wxRealPoint> pts;
project->GetCentroids(pts);
size_t pts_size = pts.size();
if (pts_size > 10000) {
// try to avoid out-of-memory
cp.method = CorrelParams::RAND_SAMP;
}
*/
correl_params_frame = new CorrelParamsFrame(cp, var_man, project);
correl_params_frame->registerObserver(this);
}
Expand Down Expand Up @@ -707,29 +713,23 @@ bool CorrelogramFrame::UpdateCorrelogramData()
if (is_arc) {
th_rad = is_mi ? EarthMiToRad(par.threshold) : EarthKmToRad(par.threshold);
}
if (par.method == CorrelParams::ALL_PAIRS) {
std::vector<wxRealPoint> pts;
project->GetCentroids(pts);

std::vector<wxRealPoint> pts;
project->GetCentroids(pts);

if (par.method == CorrelParams::ALL_PAIRS) {
success = MakeCorrAllPairs(pts, Z, is_arc, par.bins, cbins);

} else if (par.method == CorrelParams::ALL_PAIRS_THRESH) {
if (is_arc) {
success = MakeCorrThresh(project->GetUnitSphereRtree(), Z,
th_rad, par.bins, cbins);
success = MakeCorrThresh(project->GetUnitSphereRtree(), Z, th_rad, par.bins, cbins);
} else {
success = MakeCorrThresh(project->GetEucPlaneRtree(), Z,
par.threshold, par.bins, cbins);
success = MakeCorrThresh(project->GetEucPlaneRtree(), Z, par.threshold, par.bins, cbins);
}
} else if (par.method == CorrelParams::RAND_SAMP) {
std::vector<wxRealPoint> pts;
project->GetCentroids(pts);
success = MakeCorrRandSamp(pts, Z, is_arc, -1, par.bins,
par.max_iterations, cbins);
success = MakeCorrRandSamp(pts, Z, is_arc, -1, par.bins, par.max_iterations, cbins);
} else if (par.method == CorrelParams::RAND_SAMP_THRESH) {
std::vector<wxRealPoint> pts;
project->GetCentroids(pts);
success = MakeCorrRandSamp(pts, Z, is_arc,
(is_arc ? th_rad : par.threshold), par.bins,
par.max_iterations, cbins);
success = MakeCorrRandSamp(pts, Z, is_arc, (is_arc ? th_rad : par.threshold), par.bins, par.max_iterations, cbins);
}
if (success && par.bins != local_hl_state->GetHighlightSize()) {
local_hl_state->SetSize(par.bins);
Expand Down
16 changes: 9 additions & 7 deletions Explore/LowessParamDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ project(project_)
LOG_MSG("Entering LowessParamFrame::LowessParamFrame");

wxPanel* panel = new wxPanel(this);

panel->SetBackgroundColour(*wxWHITE);
SetBackgroundColour(*wxWHITE);

wxButton* help_btn = new wxButton(panel,
XRCID("ID_HELP_BTN"),
"Help",
Expand Down Expand Up @@ -201,8 +203,8 @@ void LowessParamFrame::UpdateParamsFromFields()
{
wxString s = f_text->GetValue();
double v;
LOG(v);
if (s.ToDouble(&v)) temp_l.SetF(v);
if (s.ToDouble(&v))
temp_l.SetF(v);
f = temp_l.GetF();
wxString sf = wxString::Format("%.2f", GetF());
LOG_MSG("Formated f: " + sf);
Expand All @@ -211,8 +213,8 @@ void LowessParamFrame::UpdateParamsFromFields()
{
wxString s = iter_text->GetValue();
long v;
LOG(v);
if (s.ToLong(&v)) temp_l.SetIter((long) v);
if (s.ToLong(&v))
temp_l.SetIter((long) v);
iter = temp_l.GetIter();
wxString sf = wxString::Format("%d", GetIter());
LOG_MSG("Formated iter: " + sf);
Expand All @@ -221,8 +223,8 @@ void LowessParamFrame::UpdateParamsFromFields()
{
wxString s = delta_factor_text->GetValue();
double v;
LOG(v);
if (s.ToDouble(&v)) temp_l.SetDeltaFactor(v);
if (s.ToDouble(&v))
temp_l.SetDeltaFactor(v);
delta_factor = temp_l.GetDeltaFactor();
wxString sf = wxString::Format("%.4f", GetDeltaFactor());
LOG_MSG("Formated delta_factor: " + sf);
Expand Down
3 changes: 1 addition & 2 deletions Explore/SimpleScatterPlotCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ void SimpleScatterPlotCanvas::PopulateCanvas()
size_t n = X.size();
wxString key = SmoothingUtils::LowessCacheKey(0, 0);

SmoothingUtils::LowessCacheEntry* lce =
SmoothingUtils::UpdateLowessCacheForTime(lowess_cache, key, lowess, X, Y);
SmoothingUtils::LowessCacheEntry* lce = SmoothingUtils::UpdateLowessCacheForTime(lowess_cache, key, lowess, X, Y);

if (!lce) {
LOG_MSG("Error: could not create or find LOWESS cache entry");
Expand Down
27 changes: 18 additions & 9 deletions ShapeOperations/Lowess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,31 @@ void Lowess::lowest(const double *x, const double *y, int n,
*ok = true;
/* weighted least squares */
/* make sum of w[j] == 1 */
for (j=nleft ; j<=nrt ; j++) w[j] /= a;
for (j=nleft ; j<=nrt ; j++)
w[j] /= a;
if (h > 0.) {
a = 0.;

/* use linear fit */
/* weighted center of x values */

for (j=nleft ; j<=nrt ; j++) a += w[j] * x[j];
for (j=nleft ; j<=nrt ; j++)
a += w[j] * x[j];
b = *xs - a;
c = 0.;
for (j=nleft ; j<=nrt ; j++) c += w[j]*fsquare(x[j]-a);
for (j=nleft ; j<=nrt ; j++)
c += w[j]*fsquare(x[j]-a);
if (sqrt(c) > 0.001*range) {
b /= c;
/* points are spread out */
/* enough to compute slope */
for (j=nleft; j <= nrt; j++) w[j] *= (b*(x[j]-a) + 1.);
for (j=nleft; j <= nrt; j++)
w[j] *= (b*(x[j]-a) + 1.);
}
}
*ys = 0.;
for (j=nleft; j <= nrt; j++) *ys += w[j] * y[j];
for (j=nleft; j <= nrt; j++)
*ys += w[j] * y[j];
}
}

Expand Down Expand Up @@ -292,17 +297,21 @@ void Lowess::clowess(const double *x, const double *y, int n,
/* compute robustness weights */
/* except last time */

if (cur_iter > iter) break;
if (cur_iter > iter)
break;

for(i = 0 ; i < n ; i++) rw[i] = fabs(res[i]);
for(i = 0 ; i < n ; i++)
rw[i] = fabs(res[i]);

/* Compute cmad := 6 * median(rw[], n) ---- */
m1 = n/2;
/* partial sort, for m1 & m2 */
rPsort(rw, n, m1);
//rPsort(rw, n, m1);
rPsort(rw, m1, n);
if (n % 2 == 0) {
m2 = n-m1-1;
rPsort(rw, n, m2);
//rPsort(rw, n, m2);
rPsort(rw, m2, n);
cmad = 3.*(rw[m1]+rw[m2]);
}
else { /* n odd */
Expand Down

0 comments on commit e2d0784

Please sign in to comment.