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
Make spatial completion ponderation f(level, population) with priority on level #811
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
udata/core/spatial/search.py
Outdated
return 2147483647 | ||
def compute_weight(cls, zone): | ||
''' | ||
Give a weight to the zone according its administrative level first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to
udata/core/spatial/search.py
Outdated
and then its population. | ||
''' | ||
# Each level give give a step | ||
level = min(admin_levels.get(zone.level, ADMIN_LEVEL_MAX), 1) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
udata/core/spatial/search.py
Outdated
Give a weight to the zone according its administrative level first | ||
and then its population. | ||
''' | ||
# Each level give give a step |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-give
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
udata/core/spatial/search.py
Outdated
''' | ||
# 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
udata/core/spatial/search.py
Outdated
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
udata/core/spatial/models.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.