From 6d7cb692dc7e1962656f3827a33937a4dbf4a421 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 19 Oct 2016 12:13:16 -0500 Subject: [PATCH] #501 scatter plot table deal with undefs --- Explore/BoxNewPlotView.cpp | 43 ++++++++++++++++++++++-- Explore/ScatterNewPlotView.cpp | 39 +++++++++++++++++---- GenUtils.cpp | 18 +++------- GenUtils.h | 3 +- ShapeOperations/PolysToContigWeights.cpp | 31 ++++++++++------- 5 files changed, 97 insertions(+), 37 deletions(-) diff --git a/Explore/BoxNewPlotView.cpp b/Explore/BoxNewPlotView.cpp index 794910a66..eb566ba81 100644 --- a/Explore/BoxNewPlotView.cpp +++ b/Explore/BoxNewPlotView.cpp @@ -281,9 +281,10 @@ void BoxPlotCanvas::DetermineMouseHoverObjects() for (int t=0; tcenter; + wxPoint& pt1 = sel1; sel_scratch[i] = sel_scratch[i] || - GenUtils::distance_sqrd(selectable_shps[t*num_obs + i]->center, - sel1) <= 16.5; + GenUtils::distance_sqrd(pt0, pt1) <= 16.5; } } for (int i=0; iGetStatusBar(); if (!sb) return; + + TableInterface* table_int = project->GetTableInt(); + + const std::vector& hl = highlight_state->GetHighlight(); + wxString s; if (highlight_state->GetTotalHighlighted()> 0) { - s << "#selected=" << highlight_state->GetTotalHighlighted() << " "; + int n_total_hl = highlight_state->GetTotalHighlighted(); + s << "#selected=" << n_total_hl << " "; + + if (num_time_vals == 1) { + int t = 0; + int n_undefs = 0; + for (int i=0; i 0) { + s << "(undefined:" << n_undefs << ") "; + } + } else { + wxString str; + for (int t=0; t 0) { + wxString t_str = table_int->GetTimeString(t); + str << n_undefs << "@" << t_str <<" "; + } + } + if (!str.IsEmpty()) { + s << "(undefined:" << str << ")"; + } + } } + if (mousemode == select && selectstate == start) { if (total_hover_obs >= 1) { s << "hover obs " << hover_obs[0]+1; diff --git a/Explore/ScatterNewPlotView.cpp b/Explore/ScatterNewPlotView.cpp index cacc94599..c09187448 100644 --- a/Explore/ScatterNewPlotView.cpp +++ b/Explore/ScatterNewPlotView.cpp @@ -1049,11 +1049,11 @@ void ScatterNewPlotCanvas::PopulateCanvas() // create axes x_baseline = new GdaAxis(GetNameWithTime(0), axis_scale_x, - wxRealPoint(0,0), wxRealPoint(100, 0)); + wxRealPoint(0,0), wxRealPoint(100, 0)); x_baseline->setPen(*GdaConst::scatterplot_scale_pen); background_shps.push_back(x_baseline); y_baseline = new GdaAxis(GetNameWithTime(1), axis_scale_y, - wxRealPoint(0,0), wxRealPoint(0, 100)); + wxRealPoint(0,0), wxRealPoint(0, 100)); y_baseline->setPen(*GdaConst::scatterplot_scale_pen); background_shps.push_back(y_baseline); @@ -1080,7 +1080,6 @@ void ScatterNewPlotCanvas::PopulateCanvas() foreground_shps.push_back(reg_line_excluded); foreground_shps.push_back(reg_line); - if (IsShowLinearSmoother() && !is_bubble_plot) { double cc_degs_of_rot; double reg_line_slope; @@ -1088,7 +1087,8 @@ void ScatterNewPlotCanvas::PopulateCanvas() bool reg_line_defined; wxRealPoint a, b; SmoothingUtils::CalcRegressionLine(*reg_line, - reg_line_slope, reg_line_infinite_slope, + reg_line_slope, + reg_line_infinite_slope, reg_line_defined, a, b, cc_degs_of_rot, axis_scale_x, axis_scale_y, regressionXY, *pens.GetRegPen()); @@ -1170,6 +1170,8 @@ void ScatterNewPlotCanvas::TimeChange() cat_data.SetCurrentCanvasTmStep(ref_time - ref_time_min); invalidateBms(); PopulateCanvas(); + UpdateStatusBar(); + Refresh(); LOG_MSG("Exiting ScatterNewPlotCanvas::TimeChange"); } @@ -1735,14 +1737,22 @@ void ScatterNewPlotCanvas::UpdateDisplayStats() for (int k=i*cols, kend=i*cols+cols; k& hl = highlight_state->GetHighlight(); int tot_obs = 0; + int tot_sel_obs = 0; + int tot_unsel_obs = 0; + for (size_t i=0; iGetTotalHighlighted(); - int tot_unsel_obs = tot_obs - tot_sel_obs; + vals[i*cols+j++] = "#obs"; vals[i*cols+j++] = "R^2"; vals[i*cols+j++] = "const a"; @@ -1910,8 +1920,23 @@ void ScatterNewPlotCanvas::UpdateStatusBar() wxStatusBar* sb = template_frame->GetStatusBar(); if (!sb) return; wxString s; + TableInterface* table_int = project->GetTableInt(); + + const std::vector& hl = highlight_state->GetHighlight(); + if (highlight_state->GetTotalHighlighted()> 0) { - s << "#selected=" << highlight_state->GetTotalHighlighted(); + int n_total_hl = highlight_state->GetTotalHighlighted(); + s << "#selected=" << n_total_hl << " "; + + int n_undefs = 0; + for (int i=0; i 0) { + s << "(undefined:" << n_undefs << ") "; + } if (brushtype == rectangle) { wxRealPoint pt1 = MousePntToObsPnt(sel1); diff --git a/GenUtils.cpp b/GenUtils.cpp index ce743e7fc..da82acca7 100644 --- a/GenUtils.cpp +++ b/GenUtils.cpp @@ -471,7 +471,7 @@ SimpleLinearRegression::SimpleLinearRegression(const std::vector& X, const std::vector& Y, double meanX, double meanY, double varX, double varY) - : covariance(0), correlation(0), alpha(0), beta(0), r_squared(0), + : n(0), covariance(0), correlation(0), alpha(0), beta(0), r_squared(0), std_err_of_estimate(0), std_err_of_beta(0), std_err_of_alpha(0), t_score_alpha(0), t_score_beta(0), p_value_alpha(0), p_value_beta(0), valid(false), valid_correlation(false), valid_std_err(false), @@ -486,7 +486,7 @@ SimpleLinearRegression::SimpleLinearRegression(const std::vector& X, const std::vector& Y_undef, double meanX, double meanY, double varX, double varY) - : covariance(0), correlation(0), alpha(0), beta(0), r_squared(0), + : n(0), covariance(0), correlation(0), alpha(0), beta(0), r_squared(0), std_err_of_estimate(0), std_err_of_beta(0), std_err_of_alpha(0), t_score_alpha(0), t_score_beta(0), p_value_alpha(0), p_value_beta(0), valid(false), valid_correlation(false), valid_std_err(false), @@ -512,25 +512,19 @@ void SimpleLinearRegression::CalculateRegression(const std::vector& X, double varX, double varY) { LOG_MSG("Entering SimpleLinearRegression::CalculateRegression"); - LOG(meanX); - LOG(meanY); - LOG(varX); - LOG(varY); - if (X.size() != Y.size() || X.size() < 2 ) return; + n = X.size(); + if (X.size() != Y.size() || X.size() < 2 ) + return; double expectXY = 0; for (int i=0, iend=X.size(); i 4*DBL_MIN) { beta = covariance / varX; alpha = meanY - beta * meanX; valid = true; - LOG(alpha); - LOG(beta); } double SS_tot = varY*Y.size(); error_sum_squares = 0; // error_sum_squares = SS_err @@ -539,13 +533,11 @@ void SimpleLinearRegression::CalculateRegression(const std::vector& X, err = Y[i] - (alpha + beta * X[i]); error_sum_squares += err * err; } - LOG(error_sum_squares); if (error_sum_squares < 16*DBL_MIN) { r_squared = 1; } else { r_squared = 1 - error_sum_squares / SS_tot; } - LOG(r_squared); if (Y.size()>2 && varX > 4*DBL_MIN) { // error_sum_squares/(n-k-1), k=1 diff --git a/GenUtils.h b/GenUtils.h index cda92117c..af46ba0a7 100644 --- a/GenUtils.h +++ b/GenUtils.h @@ -238,7 +238,8 @@ struct SimpleLinearRegression { static double TScoreTo2SidedPValue(double tscore, int df); std::string ToString(); - + + int n; double covariance; double correlation; double alpha; diff --git a/ShapeOperations/PolysToContigWeights.cpp b/ShapeOperations/PolysToContigWeights.cpp index 8d4b2d023..c1df25cf9 100644 --- a/ShapeOperations/PolysToContigWeights.cpp +++ b/ShapeOperations/PolysToContigWeights.cpp @@ -1157,13 +1157,17 @@ GalElement* MakeContiguity(Shapefile::Main& main, bool is_queen, for (int step= 0; step < gMinX.Cells(); ++step) { // include all elements from xmin[step] for (curr= gMinX.first(step); curr != GdaConst::EMPTY; - curr= gMinX.tail(curr)) gY->include(curr); + curr= gMinX.tail(curr)) + { + gY->include(curr); + } // test each element in xmax[step] for (curr= gMaxX.first(step); curr != GdaConst::EMPTY; - curr= gMaxX.tail(curr)) { - PolygonContents* ply = dynamic_cast ( - main.records[curr].contents_p); + curr= gMaxX.tail(curr)) + { + RecordContents* rec = main.records[curr].contents_p; + PolygonContents* ply = dynamic_cast (rec); PolygonPartition testPoly(ply); testPoly.MakePartition(); @@ -1179,7 +1183,8 @@ GalElement* MakeContiguity(Shapefile::Main& main, bool is_queen, // test each potential neighbor for (int nbr = Neighbors.Pop(); nbr != GdaConst::EMPTY; nbr = Neighbors.Pop()) { - PolygonContents* nbr_ply = dynamic_cast (main.records[nbr].contents_p); + RecordContents* nbr_rec = main.records[nbr].contents_p; + PolygonContents* nbr_ply = dynamic_cast(nbr_rec); if (ply->intersect(nbr_ply)) { @@ -1190,10 +1195,8 @@ GalElement* MakeContiguity(Shapefile::Main& main, bool is_queen, if (curr == 0 && nbr == 0) { } - // run sweep with testPoly as a host and nbrPoly as a guest - int related = testPoly.sweep(nbrPoly, is_queen, - precision_threshold); + int related = testPoly.sweep(nbrPoly, is_queen, precision_threshold); if (related) Related.Push(nbr); } } @@ -1201,7 +1204,9 @@ GalElement* MakeContiguity(Shapefile::Main& main, bool is_queen, if (size_t sz = Related.Size()) { gl[curr].SetSizeNbrs(sz); - for (size_t i=0; iremove(curr); // remove from the partition @@ -1236,7 +1241,7 @@ void MakeFull(GalElement* W, size_t obs) GalElement* PolysToContigWeights(Shapefile::Main& main, bool is_queen, - double precision_threshold) + double precision_threshold) { using namespace Shapefile; @@ -1255,9 +1260,9 @@ GalElement* PolysToContigWeights(Shapefile::Main& main, bool is_queen, gMaxX.alloc(gRecords, gx, shp_x_len ); for (cnt= 0; cnt < gRecords; ++cnt) { - PolygonContents* ply = dynamic_cast ( - main.records[cnt].contents_p); - + RecordContents* rec = main.records[cnt].contents_p; + PolygonContents* ply = dynamic_cast(rec); + gMinX.include( cnt, ply->box[0] - shp_min_x ); gMaxX.include( cnt, ply->box[2] - shp_min_x ); }