Closed lukeamendola closed 4 years ago
roundMatrix = method() -- only accepts real matrices roundMatrix (ZZ, Matrix) := Matrix => (n, A) -> matrix apply(entries A, r -> r/(e -> (round(n,0.0+e))^QQ))
Implement for list
add if not class U ===QQ then U=roundList U;
roundList = method() -- only accepts real lists roundList (ZZ, List) := List => (n, L) -> apply(L, r -> r/(e -> (round(n,0.0+e))^QQ)
@harshitmotwani2015 you were right to say that it's best to convert to QQ anyway without a prior check. I completely forgot that the input is a List and I've just checked that it stores the class of each element separately picking the smallest ring. L={0,1/3,3.0999} has classes ZZ,QQ and RR for example.
Note that the default input is now a matrix (and the list case is converted into a matrix from the very begining), so we can always just check ring matrix===RR and only apply the change in this case
My suggestion would be to add the check ring V===R below these two lines: https://github.com/Macaulay2/Workshop-2020-Warwick/blob/576babef07c2a1bd1a6c474195280d84ac3031e2/AlgebraicStatistics/MLE/GraphicalModelsMLE.m2#L176 https://github.com/Macaulay2/Workshop-2020-Warwick/blob/576babef07c2a1bd1a6c474195280d84ac3031e2/AlgebraicStatistics/MLE/GraphicalModelsMLE.m2#L200
Please @harshitmotwani2015 let me know about if there's any conflict if writing the function roundMatrix as an internal method.
Done
For example:
needsPackage "GraphicalModelsMLE" G = mixedGraph(digraph {{1,3},{2,4}},bigraph {{3,4}}) S = matrix{{2.93, -1.7, 0.76, -0.06}, {-1.7, 1.64, -0.78, 0.1}, {0.76, -0.78, 1.66, -0.78}, {-0.06, 0.1, -0.78, 0.81}} solverMLE(G,S)