Skip to content

Fix Covariate constructor and GLM intervalNr calculation#15

Merged
alexeid merged 3 commits intomasterfrom
fix-covariate-constructor
May 4, 2026
Merged

Fix Covariate constructor and GLM intervalNr calculation#15
alexeid merged 3 commits intomasterfrom
fix-covariate-constructor

Conversation

@alexeid
Copy link
Copy Markdown
Member

@alexeid alexeid commented Feb 4, 2026

Summary

  • Fix Covariate(Double[], String) constructor to also populate valuesInput
  • Fix GLM intervalNr calculation for single-epoch models

Fix 1: Covariate constructor (fixes #14)

The constructor was setting the values field directly but not populating valuesInput. This caused:

  1. initAndValidate() to overwrite values with an empty array
  2. XML serialization to omit covariate values

Fix 2: GLM intervalNr calculation (fixes #16)

The hardcoded -2 in intervalNr calculation only worked when firstlargerzero=1 (i.e., when rateShifts starts with 0.0).

Changed to -firstlargerzero-1 which correctly computes the last valid interval index for any rateShifts configuration, including single-epoch models with rateShifts=[Infinity].

Fixes getCoalescentRate(), getNe(), and getMig() methods.

@alexeid alexeid changed the title Fix Covariate constructor to populate valuesInput Fix Covariate constructor and GLM intervalNr calculation Feb 4, 2026
@alexeid alexeid requested review from nicfel and removed request for nicfel May 4, 2026 22:38
alexeid added 3 commits May 5, 2026 10:51
The Covariate(Double[], String) constructor was setting the values field
directly but not populating valuesInput. This caused two problems:

1. Calling initAndValidate() after the constructor would overwrite the
   values array with an empty array (since valuesInput was empty)
2. XML serialization would not include the covariate values

The fix ensures valuesInput is populated in the constructor, making the
object properly initialized and serializable.

Fixes #14
The hardcoded -2 in intervalNr calculation only worked when
firstlargerzero=1 (i.e., when rateShifts starts with 0.0).

Changed to -firstlargerzero-1 which correctly computes the last
valid interval index for any rateShifts configuration, including
single-epoch models with rateShifts=[Infinity].

Fixes getCoalescentRate(), getNe(), and getMig() methods.
CovariateTest covers the Covariate(Double[], String) constructor populating
valuesInput so that initAndValidate does not clobber values.

GLMTest covers single-epoch GLM rate lookups (firstlargerzero == 0), the
case where the old hardcoded intervalNr = dim - 2 produced -1 and the
downstream Ne/migration covariate lookup threw ArrayIndexOutOfBounds.
@alexeid alexeid force-pushed the fix-covariate-constructor branch from 25a5161 to e1049f4 Compare May 4, 2026 23:01
@alexeid alexeid merged commit f9b962c into master May 4, 2026
1 check passed
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.

GLM requires rateShifts even though marked as optional Covariate constructor values overwritten by initAndValidate()

1 participant