Skip to content

Fix dtype casting error in scaled_centered_kpi method#1056

Open
ishanrajsingh wants to merge 1 commit intogoogle:mainfrom
ishanrajsingh:fix-aks-dtype-casting-error
Open

Fix dtype casting error in scaled_centered_kpi method#1056
ishanrajsingh wants to merge 1 commit intogoogle:mainfrom
ishanrajsingh:fix-aks-dtype-casting-error

Conversation

@ishanrajsingh
Copy link
Copy Markdown

Fix dtype casting error in AKS algorithm when enable_aks=True

  • Convert kpi and population arrays to float64 in scaled_centered_kpi method
  • Prevents UFuncTypeError: Cannot cast ufunc 'divide' output from
    dtype('float64') to dtype('int64') with casting rule 'same_kind'
  • Use explicit dtype=np.float64 for output arrays in np.divide operations
  • Maintains numerical accuracy while handling integer input data
  • Enables successful prior and posterior sampling with enable_aks=True
  • Also documents TensorFlow dtype compatibility fix in comments

Fixes #1042

Tested with:

  • Integer KPI data (int32) that previously caused casting errors
  • Both national and geo-level models
  • Prior sampling with enable_aks=True
  • Posterior sampling with enable_aks=True
  • Maintains backward compatibility when enable_aks=False

- Convert kpi and population arrays to float64 before operations
- Use explicit dtype=np.float64 for output arrays in np.divide
- Prevents UFuncTypeError when enable_aks=True in ModelSpec
- Maintains numerical accuracy and handles edge cases properly

Fixes google#1042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when setting enable_aks=True in version 1.2.0

1 participant