Skip to content

Bug when combining grouped model with >1 starting_points #309

Description

@rickdott

I used an EventModel with grouped parameters (first 2 events shared across groups)

Coded as follows:
0: ['pos']
1: ['neg']
2: ['negfb']

Channel map:
0: [0 0 0 0 0 0]
1: [0 0 1 1 1 1]
2: [0 0 2 2 2 2]

Time map:
0: [0 0 0 0 0 0 0]
1: [0 0 1 1 1 1 1]
2: [0 0 2 2 2 2 2]

And encountered an issue when using multiple starting points. In my head, this would fit the remaining events better, since I did not see differences in their timing when using 1 starting point. Regardless of whether this is a good use of HMP, it is behavior that leads to a crash, specifically in this code:
hmp/models/event.py, rows 336-340

        lkhs = np.array([x[0] for x in estimates])
        if self.starting_points > 1 :
            max_lkhs = np.argmax(lkhs)
        else:
            max_lkhs = 0

When x[0] is not a single likelihood, but a list of likelihoods (per group, as happens when grouping parameters), lkhs becomes a list of lists, rather than a flat list.

Using np.argmax() on a list of lists flattens the list internally. Example:
np.argmax([[0, 0, 0], [0, 0, 1]])
Would return index 5, rather than 1.

Proposed solution:
When lkhs.ndim() > 1, take the average over the group dim:
lkhs.mean(dim=-1)

No idea if its statistically allowed to average over different model fits like this though :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions