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

bct.randomize_graph_partial_und does not converge? #101

Open
JohannesWiesner opened this issue Jul 29, 2021 · 1 comment
Open

bct.randomize_graph_partial_und does not converge? #101

JohannesWiesner opened this issue Jul 29, 2021 · 1 comment

Comments

@JohannesWiesner
Copy link

I wanted to use bct.randomize_graph_partial_und to shuffle my connectivity matrix while keeping the diagonal untouched. However, the algorithm does not seems to converge (?). Instead, I wrote my own function that does this job. Did I do something wrong?

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 29 14:30:02 2021

@author: Johannes.Wiesner
"""
import numpy as np
import bct

# initialize inputs
np.random.seed(42)
A = np.random.rand(5,5)
np.fill_diagonal(A,0, wrap=False)
B = np.eye(5,dtype=bool)

def shuffle_array(A):
    
    A_copy = A.copy()
    
    m = ~np.eye(len(A), dtype=bool) # mask of non-diagonal elements
    
    # Extract non-diagonal elements as a new array and shuffle in-place
    Am = A[m]
    np.random.shuffle(Am)
    
    # Assign back the shuffled values into non-diag positions of input
    A_copy[m] = Am
    
    return A_copy


A_shuffled = shuffle_array(A)


# this does not work
# A_shuffled_bct = bct.randomize_graph_partial_und(A,B,maxswap=2)
@aestrivex
Copy link
Owner

Sorry for the long delay, can you provide the example inputs that do not converge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants