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

Adjust blur_width hyperparameter #195

Open
adisidev opened this issue Sep 19, 2024 · 1 comment
Open

Adjust blur_width hyperparameter #195

adisidev opened this issue Sep 19, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed priority: low

Comments

@adisidev
Copy link
Collaborator

double InsetState::blur_width() const
{
// Blur density to speed up the numerics in flatten_density() below.
// We slowly reduce the blur width so that the areas can reach their
// target values. In case of failure during flatten_density, we increase
// the blur width to avoid the flipped Delaunay triangles.
// TODO: whenever blur_width hits 0, the maximum area error will start
// increasing again and eventually lead to an invalid grid
// cell error when projecting with triangulation. Investigate
// why. As a temporary fix, we set blur_width to be always
// positive, regardless of the number of integrations.
const unsigned int blur_default_pow =
static_cast<unsigned int>(
1 + log2(std::max(lx(), ly()) / default_long_grid_length)) +
n_fails_during_flatten_density_;
double blur_width =
std::pow(2.0, blur_default_pow - (0.5 * n_finished_integrations_));
// NOTE: Read TODO above
// if (inset_state.n_finished_integrations() < max_integrations) {
// blur_width =
// std::pow(2.0, 5 - int(inset_state.n_finished_integrations()));
// } else {
// blur_width = 0.0;
// }
std::cerr << "blur_width = " << blur_width << std::endl;
return blur_width;
}

@adisidev
Copy link
Collaborator Author

adisidev commented Sep 19, 2024

I believe the initial blur_width can be adjusted heuristically.

Below is some output of all the countries that had repeat integrations (indicating blur width was too low).

I believe there is a pattern here, and we can come up with a heuristic to increase initial blur_width on said pattern. Although I initially thought it had to just do with max area error and average area error, I believe those don't matter as much as absolute area error (as evidenced by Brazil's low max area error and low average area error, but it still having repeat integrations. Thus, I believe "absolute area error" (calculated as the sum of region_area_error * region_proportion_of_total_area or sum of (region_area_error * region_proportion_of_target_area_to_total_cartogram_area) would be a good heuristic for initial blur_width.

Keep in mind, with blur_width in general, we are trying to balance having a low enough blur width to make actual progress, but also a high enough blur width so the integrator does not fail and so that we get better shape similarity.

ALGERIA
max. area err: 0.999998, GeoDiv: Alger            ⬜⬜                                      0%
average area err: 0.998243
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 80.5311, GeoDiv: Illizi
average area err: 4.23577
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                17%
Integration number 1
max. area err: 26.3797, GeoDiv: Illizi
average area err: 1.8762
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜                               20%
Integration number 2
max. area err: 5.10426, GeoDiv: Illizi
average area err: 0.446879
Integration number 3
max. area err: 2.46791, GeoDiv: Illizi
average area err: 0.168939

BAHAMAS
max. area err: 0.999957, GeoDiv: City of Freeport ⬜⬜                                      0%
average area err: 0.983335
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 50.5531, GeoDiv: Inagua
average area err: 9.42815
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                18%
Integration number 1
max. area err: 48.9825, GeoDiv: Inagua
average area err: 6.97365
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%
max. area err: 16.3668, GeoDiv: Rum Cay
average area err: 3.33572



BRAZIL
max. area err: 0.999998, GeoDiv: Federal District ⬜⬜                                      0%
average area err: 0.999891
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 8.17692, GeoDiv: Amazonas
average area err: 1.81109
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜⬜                              23%
Integration number 1
Integration number 1
max. area err: 3.20394, GeoDiv: Roraima
average area err: 0.667096
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                            27%
max. area err: 1.11485, GeoDiv: Roraima
average area err: 0.27623


CHINA
max. area err: 1, GeoDiv: Macao Special Administrative Region                             0%
average area err: 0.999976
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 46.5929, GeoDiv: Tibet Autonomous Region
average area err: 2.87247
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜                               19%
Integration number 1
max. area err: 5.89154, GeoDiv: Tibet Autonomous Region
average area err: 0.506768
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜                             25%
max. area err: 1.11903, GeoDiv: Tibet Autonomous Region
average area err: 0.161027

USA_COUNTY
max. area err: 1, GeoDiv: 0500000US36061          ⬜⬜                                      0%
average area err: 0.999924
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 41.2673, GeoDiv: 0500000US32023
average area err: 1.87969
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜                               19%
Integration number 1
Integration number 1
max. area err: 45.1578, GeoDiv: 0500000US06027
average area err: 1.31477
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜                               19%
max. area err: 21.3945, GeoDiv: 0500000US06027
average area err: 1.02187


USA_COUNTY_2
max. area err: 6.46692, GeoDiv: 0500000US06071    ⬜⬜                                      0%
average area err: 0.882339
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜                             24%
max. area err: 66.706, GeoDiv: 0500000US06071
average area err: 1.00541
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                18%
Integration number 1
max. area err: 13.1023, GeoDiv: 0500000US06073
average area err: 0.406562
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜                              22%
max. area err: 6.14655, GeoDiv: 0500000US04003
average area err: 0.333577


EGYPT_BY_GOVERNATE
max. area err: 0.999996, GeoDiv: Qalyubia Governorate                                     0%
average area err: 0.997887
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 171.478, GeoDiv: New Valley Governorate
average area err: 10.5817
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                16%
Integration number 1
Integration number 1
Integration number 1
Integration number 1
max. area err: 75.6021, GeoDiv: New Valley Governorate
average area err: 7.46942
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%


GERMANY
max. area err: 0.999989, GeoDiv: Berlin           ⬜⬜                                      0%
average area err: 0.999799
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 2.1912, GeoDiv: Mecklenburg-Vorpommern
average area err: 0.667218
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                           29%
Integration number 1
Integration number 1
max. area err: 1.2033, GeoDiv: Brandenburg
average area err: 0.383586
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          33%


MALAYSIA
max. area err: 0.999975, GeoDiv: Labuan           ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜        81%
average area err: 0.999388
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜     87%
max. area err: 0.969844, GeoDiv: Labuan
average area err: 0.612628
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜     87%
Integration number 1
max. area err: 0.77951, GeoDiv: Labuan
average area err: 0.333949
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜     88%
max. area err: 0.349194, GeoDiv: Labuan
average area err: 0.12391
Integration number 3                              ⬜⬜⬜


PARIS
max. area err: 0.999999, GeoDiv: Paris            ⬜⬜                                      0%
average area err: 0.999671
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 7.00928, GeoDiv: Lozère
average area err: 1.10541
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜                             24%
Integration number 1
max. area err: 1.69333, GeoDiv: Haute-Corse
average area err: 0.374886
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                           31%
max. area err: 0.821163, GeoDiv: Rhône
average area err: 0.146353

RUSSIA
max. area err: 1, GeoDiv: Moscow City             ⬜⬜                                      0%
average area err: 0.999803
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 118.94, GeoDiv: Chukot
average area err: 3.64016
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                17%
Integration number 1
Integration number 1
max. area err: 75.9413, GeoDiv: Chukot
average area err: 1.91155
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%
Integration number 2
max. area err: 37.7918, GeoDiv: Chukot
average area err: 1.19987

SINGAPORE
max. area err: 0.999647, GeoDiv: Choa Chu Kang    ⬜⬜                                      0%
average area err: 0.884153
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 856.364, GeoDiv: North-Eastern Islands
average area err: 76.2376
Integration number 1                              ⬜⬜⬜⬜⬜                                 14%
Integration number 1
Integration number 1
max. area err: 374.614, GeoDiv: North-Eastern Islands
average area err: 43.0859
Integration number 2                              ⬜⬜⬜⬜⬜                                 15%

SWITZERLAND
max. area err: 0.999771, GeoDiv: Basel-City       ⬜⬜                                      0%
average area err: 0.972726
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 8.46291, GeoDiv: Uri
average area err: 1.43089
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜⬜                              23%
Integration number 1
max. area err: 1.99285, GeoDiv: Grisons
average area err: 0.444028
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                           30%
max. area err: 0.653004, GeoDiv: Appenzell Innerrhoden
average area err: 0.158785

TUNISIA
max. area err: 0.999988, GeoDiv: Tunis            ⬜⬜                                      0%
average area err: 0.998756
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 17.2264, GeoDiv: Tataouine
average area err: 1.68936
Integration number 1                              ⬜⬜⬜⬜⬜⬜⬜                               21%
Integration number 1
max. area err: 4.86759, GeoDiv: Tataouine
average area err: 0.497082
Integration number 2                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜                             26%
max. area err: 0.735202, GeoDiv: Tataouine
average area err: 0.118009


WORLD
max. area err: 1, GeoDiv: Macao                   ⬜⬜                                      0%
average area err: 0.999993
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 834.35, GeoDiv: Antarctica
average area err: 5.42833
Integration number 1                              ⬜⬜⬜⬜⬜                                 14%
Integration number 1
Integration number 1
max. area err: 577.985, GeoDiv: Antarctica
average area err: 3.6954
Integration number 2                              ⬜⬜⬜⬜⬜                                 14%


WORLD_w_wo_antarctica_csv
max. area err: 1, GeoDiv: Macao
average area err: 0.999997
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 155.568, GeoDiv: Greenland
average area err: 2.11211
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                16%
Integration number 1
Integration number 1
max. area err: 61.5262, GeoDiv: Greenland
average area err: 1.38395
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%
max. area err: 28.645, GeoDiv: Greenland
average area err: 0.992094


WORLD_by_country
max. area err: 1, GeoDiv: MDV                     ⬜⬜                                      0%
average area err: 0.999997
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 155.874, GeoDiv: GRL
average area err: 2.46174
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                16%
Integration number 1
Integration number 1
max. area err: 61.8732, GeoDiv: GRL
average area err: 1.55955
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%
max. area err: 24.9938, GeoDiv: GRL
average area err: 1.0906


WORLD_wo_antarctica
max. area err: 1, GeoDiv: Macao                   ⬜⬜                                      0%
average area err: 0.999997
Integration number 0                              ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜                          34%
max. area err: 155.853, GeoDiv: Greenland
average area err: 2.12186
Integration number 1                              ⬜⬜⬜⬜⬜⬜                                16%
Integration number 1
Integration number 1
max. area err: 61.0831, GeoDiv: Greenland
average area err: 1.38242
Integration number 2                              ⬜⬜⬜⬜⬜⬜                                18%
max. area err: 28.2876, GeoDiv: Greenland
average area err: 0.9905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed priority: low
Projects
None yet
Development

No branches or pull requests

1 participant