Macaulay2 / Workshop-2020-Warwick

6 stars 9 forks source link

Sample does not accept real values #137

Closed lukeamendola closed 4 years ago

lukeamendola commented 4 years ago

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)

roserhp commented 4 years ago

. http://www2.macaulay2.com/Macaulay2/doc/Macaulay2-1.16/share/doc/Macaulay2/DeterminantalRepresentations/html/_round__Matrix.html

olgakuznetsova commented 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

olgakuznetsova commented 4 years ago

after https://github.com/Macaulay2/Workshop-2020-Warwick/blob/6264214edf4781bd6d7371d7ce94695b9633cb1d/AlgebraicStatistics/MLE/GraphicalModelsMLE.m2#L363-L364

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)

olgakuznetsova commented 4 years ago

@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.

roserhp commented 4 years ago

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

roserhp commented 4 years ago

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.

roserhp commented 4 years ago

Done