[sage-support] Re: [sage-algebra] Improving the next code
Thanks, David, I think that the problem is with the operation "+" I have using Profiler and when the matrix has dimensios, 12 x 19 these are the times 9.932s -- line 15: v = (particular_soln + homogeneous_soln) 0.004s -- line 17: print len(v.nonzero_positions()) Maybe there is some way to sum particular_soln + homogeneous_soln in a fast way? 2018-02-25 19:23 GMT-03:00 David Joyner : > On Sun, Feb 25, 2018 at 4:11 PM, Juan Grados wrote: > > How can I improve the time for the next code?. Basically, I want to > solve a > > large undetermined binary linear system and then I need to calculate its > > hamming weight. > > > > A = random_matrix(GF(2), 10, 12, density=0.55) > > b = random_vector(GF(2), 10) > > particular_soln = A.solve_right(b, check=False) > > A_right_kernel = A.right_kernel() > > for homogeneous_soln in A_right_kernel: > > v = (particular_soln + homogeneous_soln) > > print len(v.nonzero_positions()) > > > > You are computing the min wt of a coset of a binary linear code. > I don't know of a fast stand alone function that does this. > > Printing slows you down a lot. Just make the list of wts using list > comprehension and find its minimum later. > > For real speed, you make want to modify the C code in > GAP's AClosestVectorCombinationsMatFFEVecFFE. > > > > > > > -- > > - > > MSc. Juan del Carmen Grados Vásquez > > Laboratório Nacional de Computação Científica > > Tel: +55 21 97633 3228 > > (http://www.lncc.br/) > > http://juaninf.blogspot.com > > - > > > > -- > > You received this message because you are subscribed to the Google Groups > > "sage-algebra" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to sage-algebra+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "sage-algebra" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-algebra+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- - MSc. Juan del Carmen Grados Vásquez Laboratório Nacional de Computação Científica Tel: +55 21 97633 3228 (http://www.lncc.br/) http://juaninf.blogspot.com - -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: [sage-algebra] Improving the next code
On Sun, Feb 25, 2018 at 4:11 PM, Juan Grados wrote: > How can I improve the time for the next code?. Basically, I want to solve a > large undetermined binary linear system and then I need to calculate its > hamming weight. > > A = random_matrix(GF(2), 10, 12, density=0.55) > b = random_vector(GF(2), 10) > particular_soln = A.solve_right(b, check=False) > A_right_kernel = A.right_kernel() > for homogeneous_soln in A_right_kernel: > v = (particular_soln + homogeneous_soln) > print len(v.nonzero_positions()) > You are computing the min wt of a coset of a binary linear code. I don't know of a fast stand alone function that does this. Printing slows you down a lot. Just make the list of wts using list comprehension and find its minimum later. For real speed, you make want to modify the C code in GAP's AClosestVectorCombinationsMatFFEVecFFE. > > -- > - > MSc. Juan del Carmen Grados Vásquez > Laboratório Nacional de Computação Científica > Tel: +55 21 97633 3228 > (http://www.lncc.br/) > http://juaninf.blogspot.com > - > > -- > You received this message because you are subscribed to the Google Groups > "sage-algebra" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-algebra+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Improving the next code
How can I improve the time for the next code?. Basically, I want to solve a large undetermined binary linear system and then I need to calculate its hamming weight. A = random_matrix(GF(2), 10, 12, density=0.55) b = random_vector(GF(2), 10) particular_soln = A.solve_right(b, check=False) A_right_kernel = A.right_kernel() for homogeneous_soln in A_right_kernel: v = (particular_soln + homogeneous_soln) print len(v.nonzero_positions()) -- - MSc. Juan del Carmen Grados Vásquez Laboratório Nacional de Computação Científica Tel: +55 21 97633 3228 (http://www.lncc.br/) http://juaninf.blogspot.com - -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Relabel vertices of vertex graph of a polytope?
Thanks, Moritz. I found a solution which used strings instead of tuples: for v in G.vertex_iterator(): v.rename(str(v)[12:]) Probably not as elegant as your solution, but it did the job! -Alasdair On Monday, 26 February 2018 06:22:32 UTC+11, moritz wrote: > > > > On Saturday, February 24, 2018 at 9:56:04 AM UTC+1, Alasdair wrote: >> >> Hello, >> >> I have defined a polyhedron by a collection of linear inequalities over >> three variables, and it's all lovely: I can access the vertices, draw all >> sorts of nice pictures, get all sorts of information. The one problem is >> the vertex graph. If my polyhedron is P, say, then P.vertex_graph() gives >> me a graph where each vertex is labelled something like "A vertex at >> (0,1,0)". This seems somewhat redundant labelling, and ideally I'd like to >> relabel the vertices to simply "(0,1,0)". >> >> I attempted to relabel the vertex graph with: >> >> dict ={i:j, for (i,j) in zip(P.vertices(),P.vertex_list()) >> G = P.vertex_graph() >> G.relabel(dict) >> >> >> However, that attempt produced the error: >> >> TypeError: unhashable type: 'list' >> >> >> I'm not sure how to go about this relabelling... any idea? Thanks! >> > a 'list' cant be a vertex of a graph. It needs to be something hashable, > like a 'tupe'. Try the code below. > > Cheers > Moritz > > sage: P = polytopes.cube() > sage: G = P.graph() > sage: G.vertices() > [A vertex at (-1, -1, -1), > A vertex at (-1, -1, 1), > A vertex at (-1, 1, -1), > A vertex at (-1, 1, 1), > A vertex at (1, -1, -1), > A vertex at (1, -1, 1), > A vertex at (1, 1, -1), > A vertex at (1, 1, 1)] > sage: dict ={i:tuple(j) for (i,j) in zip(P.vertices(),P.vertices_list())} > sage: G.relabel(dict) > sage: G.vertices() > [(-1, -1, -1), > (-1, -1, 1), > (-1, 1, -1), > (-1, 1, 1), > (1, -1, -1), > (1, -1, 1), > (1, 1, -1), > (1, 1, 1)] > sage: dict > {A vertex at (-1, -1, -1): (-1, -1, -1), > A vertex at (-1, -1, 1): (-1, -1, 1), > A vertex at (-1, 1, -1): (-1, 1, -1), > A vertex at (-1, 1, 1): (-1, 1, 1), > A vertex at (1, -1, -1): (1, -1, -1), > A vertex at (1, -1, 1): (1, -1, 1), > A vertex at (1, 1, -1): (1, 1, -1), > A vertex at (1, 1, 1): (1, 1, 1)} > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Relabel vertices of vertex graph of a polytope?
On Saturday, February 24, 2018 at 9:56:04 AM UTC+1, Alasdair wrote: > > Hello, > > I have defined a polyhedron by a collection of linear inequalities over > three variables, and it's all lovely: I can access the vertices, draw all > sorts of nice pictures, get all sorts of information. The one problem is > the vertex graph. If my polyhedron is P, say, then P.vertex_graph() gives > me a graph where each vertex is labelled something like "A vertex at > (0,1,0)". This seems somewhat redundant labelling, and ideally I'd like to > relabel the vertices to simply "(0,1,0)". > > I attempted to relabel the vertex graph with: > > dict ={i:j, for (i,j) in zip(P.vertices(),P.vertex_list()) > G = P.vertex_graph() > G.relabel(dict) > > > However, that attempt produced the error: > > TypeError: unhashable type: 'list' > > > I'm not sure how to go about this relabelling... any idea? Thanks! > a 'list' cant be a vertex of a graph. It needs to be something hashable, like a 'tupe'. Try the code below. Cheers Moritz sage: P = polytopes.cube() sage: G = P.graph() sage: G.vertices() [A vertex at (-1, -1, -1), A vertex at (-1, -1, 1), A vertex at (-1, 1, -1), A vertex at (-1, 1, 1), A vertex at (1, -1, -1), A vertex at (1, -1, 1), A vertex at (1, 1, -1), A vertex at (1, 1, 1)] sage: dict ={i:tuple(j) for (i,j) in zip(P.vertices(),P.vertices_list())} sage: G.relabel(dict) sage: G.vertices() [(-1, -1, -1), (-1, -1, 1), (-1, 1, -1), (-1, 1, 1), (1, -1, -1), (1, -1, 1), (1, 1, -1), (1, 1, 1)] sage: dict {A vertex at (-1, -1, -1): (-1, -1, -1), A vertex at (-1, -1, 1): (-1, -1, 1), A vertex at (-1, 1, -1): (-1, 1, -1), A vertex at (-1, 1, 1): (-1, 1, 1), A vertex at (1, -1, -1): (1, -1, -1), A vertex at (1, -1, 1): (1, -1, 1), A vertex at (1, 1, -1): (1, 1, -1), A vertex at (1, 1, 1): (1, 1, 1)} -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.