I'm still a beginner with mathematica so maybe the solution is obvious, but for some reason my code that worked fine earlier doesn't work now. I haven't changed anything about it. I've restarted Mathematica and cleared all global variables to no avail. Here's what I'm working with:
flip[A_ , n_] :=
Block[{lis1, lis2, S, size},
size = Dimensions[A];
lis1 = Most[ArrayRules[A]];
lis2 = RandomChoice[lis1, n] ;
lis2 = Map[ReplacePart[#, 2 -> -2] &, lis2[[1 ;; n]]];
S = SparseArray[lis2, {size[[1]], size[[1]]}, 0] + A ;];
It takes an adjacency matrix and flips a couple of entries. Or did anyway. Now nothing happens.
*One thing I still need to tweak is making sure I the entries are flipped symmetrically, i.e. if the (1,2) entry is picked by RandomChoice
then I need to also add the (2,1) entry of lis1
so that S
is a symmetric matrix. If someone could point me in the right direction I would appreciate it. (I think SymmetrizedArray
might do it, but I'm not familiar enough with it).
EDIT: It all works now. I didn't change anything, and ran it today and it works fine. I really hope this is the last time I encounter these sort of Gremlins.