Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kepler Mapper returns an empty graph #26

Open
calebgeniesse opened this issue Dec 12, 2023 · 4 comments
Open

Kepler Mapper returns an empty graph #26

calebgeniesse opened this issue Dec 12, 2023 · 4 comments

Comments

@calebgeniesse
Copy link
Collaborator

See PR 24 for reports relating to an issue with kmapper. Several different reported errors were found to be due to an empty graph being returned by kmapper. These errors were only observed in 02_haxby_fmri.ipynb, a notebook in DyNeuSR Notebooks repository. See below for more notes taken from PR 24, which has since been merged for other reasons.

@calebgeniesse
Copy link
Collaborator Author

There is a special undocumented option I added awhile back to help shift the cover bins a bit, so that points near the boundaries were accounted for properly. See scale_limits=True in the following line (executed cell 11 in the notebook):

cover = optimize_cover(
    X, r=15, g=0.67, 
    scale_r=not True, 
    scale_limits=True
)

The corresponding code is defined in dyneusr/mapper/utils.py, see e.g.,

# Define optimized limits
limits = None
if scale_limits is True:
    offset = p_overlap / float(n_cubes)
    limits = [[-offset, 1+offset] for _ in range(ndim)]
    n_cubes += 2 #* ndim

Not 100% sure why this doesn't work with kmapper anymore, but I will take a closer look and see if there's an obvious way to fix this. Otherwise, the easiest thing to do may be to just turn it off in the tutorial, and possibly deprecate the option altogether.

Edit: To clarify, when I use scale_limits=False, I get a graph with 2007 edges and 211 nodes, for the first subject.

@calebgeniesse
Copy link
Collaborator Author

For more context, when I use scale_limits=True, I get the following:

>>> cover.limits
array([[-0.04466667,  1.04466667],
       [-0.04466667,  1.04466667]])
>>> cube_centers = cover.fit(lens)
>>> cube_centers
[array([-0.01262745]),
 array([0.05145098]),
 array([0.11552941]),
 array([0.17960784]),
 array([0.24368627]),
 array([0.30776471]),
 array([0.37184314]),
 array([0.43592157]),
 array([0.5]),
 array([0.56407843]),
 array([0.62815686]),
 array([0.69223529]),
 array([0.75631373]),
 array([0.82039216]),
 array([0.88447059]),
 array([0.94854902]),
 array([1.01262745])]
>>> hyper_cubes = cover.transform(lens, cube_centers)
>>> [_.shape for _ in hyper_cubes]
[(3, 2),
 (2, 2),
 (1, 2),
 (1, 2),
 (1, 2),
 (2, 2),
 (2, 2),
 (3, 2),
 (3, 2),
 (4, 2),
 (4, 2),
 (4, 2),
 (3, 2),
 (2, 2),
 (1, 2)]

and when I use scale_limits=False:

>>> cover.limits
None
>>> cube_centers = cover.fit(lens)
>>> cube_centers
[array([-17.97072105]),
 array([-15.59127478]),
 array([-13.2118285]),
 array([-10.83238223]),
 array([-8.45293595]),
 array([-6.07348968]),
 array([-3.6940434]),
 array([-1.31459713]),
 array([1.06484915]),
 array([3.44429542]),
 array([5.82374169]),
 array([8.20318797]),
 array([10.58263424]),
 array([12.96208052]),
 array([15.34152679])]
>>> hyper_cubes = cover.transform(lens, cube_centers)
>>> [_.shape for _ in hyper_cubes]
[(26, 2),
 (40, 2),
 (48, 2),
 (47, 2),
 (47, 2),
 (46, 2),
 (50, 2),
 (58, 2),
 (60, 2),
 (56, 2),
 (49, 2),
 (47, 2),
 (51, 2),
 (50, 2),
 (32, 2)]

So it seems to me like it has to do with the scaling of these limits or the lens itself.

@calebgeniesse
Copy link
Collaborator Author

@kristiandroste looping you in here

@kristiandroste
Copy link
Contributor

Thanks @calebgeniesse!

The notebook runs start to finish without catching any errors when I use scale_limits=False, but it seems something is still not right with my graphs. I document some discrepancies below and will try debugging further

The shapes of my hyper_cubes and my cube_centers differ from those you posted above:
Running

cube_centers = cover.fit(lens)
print(cube_centers)
hyper_cubes = cover.transform(lens, cube_centers)
shapes = [arr.shape for arr in hyper_cubes]
print(shapes)

at the end of cell 12 yields

# cube_centers
[array([-15.88660342]), 
array([-13.70202765]), 
array([-11.51745188]), 
array([-9.33287611]), 
array([-7.14830033]), 
array([-4.96372456]), 
array([-2.77914879]), 
array([-0.59457302]), 
array([1.59000275]), 
array([3.77457852]), 
array([5.95915429]),
array([8.14373006]), 
array([10.32830583]), 
array([12.51288161]), 
array([14.69745738])]

# shapes of hyper_cubes
[(26, 2), 
(41, 2), 
(47, 2), 
(50, 2), 
(54, 2), 
(57, 2), 
(60, 2), 
(61, 2), 
(60, 2), 
(55, 2), 
(45, 2), 
(43, 2), 
(43, 2), 
(43, 2), 
(27, 2)]

Also, the output from cell 11 shows that I'm getting the same shape of X for all subjects:

 X has shape: (242, 577)

Comparing this to the shapes listed in the screenshot of the output in the DyNeuSR Notebooks repo, it appears that this shape is correct for subject 1, but the other five subjects should have different shapes for X.

Visualization of mapper (cell 14), heatmaps (cell 16), and TCM visualizations in step 6 all differ from the output in the DyNeuSR Notebooks repo

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

No branches or pull requests

2 participants