Skip to content

Inf values for variance explained during L2 regularization #614

@jkim0731

Description

@jkim0731

There is an edge case where -Inf values are returned during L2 regularization process.

This happens when fit_trace_test values are all 0 for certain cells, for certain split.

e.g. oeid = 879331157

result_dir = Path(r'\\allen\programs\braintv\workgroups\nc-ophys\visual_behavior\ophys_glm\v_24_events_all_L2_optimize_by_session')
run_param = json.load(open(alex_result_dir / 'run_params.json', 'r'))

session, fit, design = gft.load_fit_experiment(oeid, run_param)
num_splits = len(fit['ridge_splits'])
for split_ind in range(num_splits):
    test_split = fit['ridge_splits'][split_ind]
    fit_trace_test  = fit['fit_trace_arr'][test_split,:]
    print((fit_trace_test[:,78].values != 0).any())
for split_ind in range(num_splits):
    test_split = fit['ridge_splits'][split_ind]
    fit_trace_test  = fit['fit_trace_arr'][test_split,:]
    print((fit_trace_test[:,18].values != 0).any())

Eventually test_cv values for these 2 cells are all -Inf.

L329 of GLM_fit_tools.py gets around this by
fit['avg_L2_regularization'] = np.mean([fit['L2_grid'][x] for x in np.argmax(test_cv,1)])
where np.argmax returns 0 and lambda is set to L2_grid[0].

Is this intended?
I think it should be either nan'ed for splits with 0 trace or the cell should be removed from the analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions