Skip to content

Commit

Permalink
Sort constituency weights (#46)
Browse files Browse the repository at this point in the history
* Constituency weights are not in sorted-name order
Fixes #45

* Versioning

* Fix minor bug
  • Loading branch information
nikhilwoodruff authored Nov 30, 2024
1 parent 1ac4e77 commit 08853c4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.9.2] - 2024-11-30 13:23:17

### Fixed

- Constituency weights are in A-Z order.

## [1.9.1] - 2024-11-27 19:28:29

### Added
Expand Down Expand Up @@ -97,6 +103,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



[1.9.2]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.9.1...1.9.2
[1.9.1]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.9.0...1.9.1
[1.9.0]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.8.0...1.9.0
[1.8.0]: https://github.com/PolicyEngine/policyengine-us-data/compare/1.7.0...1.8.0
Expand Down
5 changes: 5 additions & 0 deletions changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@
added:
- Automatic calibration.
date: 2024-11-27 19:28:29
- bump: patch
changes:
fixed:
- Constituency weights are in A-Z order.
date: 2024-11-30 13:23:17
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def loss(w):
def update_weights(weights, mapping_matrix):
mapping_matrix = mapping_matrix.set_index(mapping_matrix.columns[0])
mapping_matrix = mapping_matrix.div(mapping_matrix.sum(), axis=1)
return mapping_matrix.T.dot(weights)
mapped_weights = mapping_matrix.T.dot(weights).values
return mapped_weights[mapping_matrix.columns.argsort(), :]


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "policyengine_uk_data"
version = "1.9.1"
version = "1.9.2"
description = "A package to create representative microdata for the UK."
readme = "README.md"
authors = [
Expand Down

0 comments on commit 08853c4

Please sign in to comment.