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

Make spatial completion ponderation f(level, population) with priority on level #811

Merged
merged 1 commit into from Mar 1, 2017
Merged

Make spatial completion ponderation f(level, population) with priority on level #811

merged 1 commit into from Mar 1, 2017

Conversation

noirbizarre
Copy link
Contributor

This PR try to enhance spatial completion for zones with short name and few population (or no population data available) by taking in account administrative level and area.
The algorithm gives priority to the administrative level and then optionally to the population.
It could be enhanced with the area too which is also available.

Copy link
Member

@jdesboeufs jdesboeufs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

return 2147483647
def compute_weight(cls, zone):
'''
Give a weight to the zone according its administrative level first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to

and then its population.
'''
# Each level give give a step
level = min(admin_levels.get(zone.level, ADMIN_LEVEL_MAX), 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADMIN_LEVEL_MIN instead of 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: here to avoir devision by zero so I prefer explicit 1 over an ADMIN_LEVEL_MIN which can be 0.

Give a weight to the zone according its administrative level first
and then its population.
'''
# Each level give give a step
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-give

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put boundaries like with population to have an idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but I don't think it brings any value because this is relative scoring. What matter is that admin level weight more that population.

'''
# Each level give give a step
level = min(admin_levels.get(zone.level, ADMIN_LEVEL_MAX), 1)
level_weight = (ADMIN_LEVEL_MAX / level) * 10 * PONDERATION_STEP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not set PONDERATION_STEP to 10000 in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because, of the use later: for the mathemtical explnation, th * 10 is here to dilate the (ADMIN_LEVEL_MAX / level) which is 1 < f(level) < inf. The factor is only here to ensure steps are not overlapping too much. If I touch the PONDERATION_STEP, the overlapping doesn't change, it is dilated too.

level_weight = (ADMIN_LEVEL_MAX / level) * 10 * PONDERATION_STEP
# Population gives 0 < weight < 1000 to rank between level steps only
population = min(max(0, zone.population), POPULATION_MAX)
population_weight = (population / POPULATION_MAX) * PONDERATION_STEP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh ok got it for the ponderation, in that case why not below directly to the sum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because (population / POPULATION_MAX) < 1 so population_weight < PONDERATION_STEP

@@ -24,6 +24,9 @@

ADMIN_LEVEL_MIN = 1
ADMIN_LEVEL_MAX = 110
# Max known population for a zone
# World population is 6772425850.
POPULATION_MAX = 2147483647
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes from an ES limitation given that it's the maximum positive value for a 32-bit signed binary integer. So it's not related to the population.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a consequence, it should be the max for the level weight too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so not a problem here because the max computed value is far from it.
I changed for the world population (approximative) so the number means something and the algo works on any zone

@noirbizarre noirbizarre merged commit 353eb1e into opendatateam:master Mar 1, 2017
@noirbizarre noirbizarre deleted the spatial-completion-ponderation branch March 1, 2017 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants