Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weighted Centroid seems to be not working correctly #79

Closed
saleiva opened this issue Jun 22, 2016 · 10 comments
Closed

Weighted Centroid seems to be not working correctly #79

saleiva opened this issue Jun 22, 2016 · 10 comments
Labels

Comments

@saleiva
Copy link

saleiva commented Jun 22, 2016

Download this dataset.
https://team.cartodb.com/u/saleiva/tables/chicago_crimes_2014

I've created two fake columns for testing (crimes_value and crimes_value_2)
The centroids you get when using crimes_value column (all rows equal to 1) as weight is the same result you get when using cromes_value_2 (lots of rows equal to 2, the rest to 1).

cc/ @javisantana @rochoa @ohasselblad @stuartlynn

@saleiva saleiva added the bug label Jun 22, 2016
@stuartlynn
Copy link
Contributor

Looking in to it now thanks for the heads up @saleiva

@javisantana
Copy link
Contributor

with that amount of points and randomly distributed '2' and '1' I think is correct. Test it with two points table

@saleiva
Copy link
Author

saleiva commented Jun 23, 2016

but the centers are exactly the same, that's very weird, don't you think?

@rochoa
Copy link
Contributor

rochoa commented Jun 23, 2016

Try it with something like:

with points as (
  select (s * s) as weight, st_makepoint(s,s) as the_geom from generate_series(1,2) s
)
--select st_astext(the_geom), weight
select st_astext(cdb_crankshaft.CDB_WeightedMean(the_geom, weight)) as the_geom
from points

And play with the weight value from the CTE.

IMO it's working OK.

@javisantana
Copy link
Contributor

@saleiva visually can be misleading (since there is snapping), did you test it matematically?

@saleiva
Copy link
Author

saleiva commented Jun 23, 2016

lat/long values where the same at a quick sight

2016-06-23 12:16 GMT+02:00 javi santana notifications@github.com:

@saleiva https://github.com/saleiva visually can be misleading (since
there is snapping), did you test it matematically?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#79 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAIENWBrXbKYujXSQxciBE9WGRCF0UKaks5qOlzggaJpZM4I8Kgf
.

Sergio Alvarez Leiva

@stuartlynn
Copy link
Contributor

@saleiva When I try it they look different . Not by much but different

screen shot 2016-06-23 at 9 47 59 am
screen shot 2016-06-23 at 9 47 46 am

@stuartlynn
Copy link
Contributor

With some more tests it seams to be working . 4 points 3 on the right 1 on the left with various weightings does what you would expect it to do.

screen shot 2016-06-23 at 10 49 32 am
screen shot 2016-06-23 at 10 50 11 am
screen shot 2016-06-23 at 10 50 21 am

I think one of the reasons your not seeing a big effect in the crimes data is the weights are essentially randomly assigned so they will tend to cancel out. If you give crimes where there was an arrest weight 200 and crimes where there wasn't a weight of 1 then the map looks like this:

screen shot 2016-06-23 at 11 01 05 am

Where the blue points are the unweighted centroids and the orange points are the weighted centroids.

So I think its working ok

@saleiva
Copy link
Author

saleiva commented Jun 23, 2016

retested. Seems like yesterday we fucked up the data or something. You guys win

@saleiva saleiva closed this as completed Jun 23, 2016
@javisantana
Copy link
Contributor

FAV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants