#18834: Use Sage to compute clustering coefficient
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  ncohen                 |       Status:  needs_review
           Type:         |    Milestone:  sage-6.8
  enhancement            |   Resolution:
       Priority:  major  |    Merged in:
      Component:  graph  |    Reviewers:
  theory                 |  Work issues:
       Keywords:         |       Commit:
        Authors:         |  6274bff716b13f4ef7b3e1745d8dcbf761336826
  Nathann Cohen          |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  u/ncohen/18834         |
   Dependencies:         |
  #18811                 |
-------------------------+-------------------------------------------------

Comment (by dcoudert):

 Also, I have an issue:
 {{{
 sage: g = graphs.RandomGNP(1000,.1)
 sage: N = 1000
 sage: g = graphs.RandomGNP(N, log(N)/N)
 sage: g.order(), g.size()
 (1000, 3567)
 sage: %timeit _=g.clustering_coeff(implementation="boost")
 100 loops, best of 3: 2.78 ms per loop
 sage: %timeit _=g.clustering_coeff(implementation="dense_copy")
 ---------------------------------------------------------------------------
 ZeroDivisionError                         Traceback (most recent call
 last)
 <ipython-input-31-cd519bf674aa> in <module>()
 ----> 1 get_ipython().magic(u'timeit
 _=g.clustering_coeff(implementation="dense_copy")')

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
    2305         magic_name, _, magic_arg_s = arg_s.partition(' ')
    2306         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
 -> 2307         return self.run_line_magic(magic_name, magic_arg_s)
    2308
    2309
 #-------------------------------------------------------------------------

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/interactiveshell.pyc in run_line_magic(self,
 magic_name, line)
    2226                 kwargs['local_ns'] =
 sys._getframe(stack_depth).f_locals
    2227             with self.builtin_trap:
 -> 2228                 result = fn(*args,**kwargs)
    2229             return result
    2230

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/magics/execution.pyc in timeit(self, line, cell)

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
     191     # but it's overkill for just that one bit of state.
     192     def magic_deco(arg):
 --> 193         call = lambda f, *a, **k: f(*a, **k)
     194
     195         if callable(arg):

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/magics/execution.pyc in timeit(self, line, cell)
    1034             number = 1
    1035             for _ in range(1, 10):
 -> 1036                 time_number = timer.timeit(number)
    1037                 worst_tuning = max(worst_tuning, time_number /
 number)
    1038                 if time_number >= 0.2:

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/IPython/core/magics/execution.pyc in timeit(self, number)
     130         gc.disable()
     131         try:
 --> 132             timing = self.inner(it, self.timer)
     133         finally:
     134             if gcold:

 <magic-timeit> in inner(_it, _timer)

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/sage/graphs/generic_graph.pyc in clustering_coeff(self, nodes,
 weight, implementation, return_vertex_weights)
   12437             from sage.rings.integer import Integer
   12438             return
 {v:Integer(count)/((self.degree(v)*(self.degree(v)-1))/2)
 > 12439                     for v,count in
 triangles_count(self).iteritems()}
   12440
   12441     def cluster_transitivity(self):

 /Users/dcoudert/sage/local/lib/python2.7/site-
 packages/sage/graphs/generic_graph.pyc in <dictcomp>((v, count))
   12437             from sage.rings.integer import Integer
   12438             return
 {v:Integer(count)/((self.degree(v)*(self.degree(v)-1))/2)
 > 12439                     for v,count in
 triangles_count(self).iteritems()}
   12440
   12441     def cluster_transitivity(self):

 /Users/dcoudert/sage/src/sage/structure/element.pyx in
 sage.structure.element.RingElement.__div__
 (/Users/dcoudert/sage/src/build/cythonized/sage/structure/element.c:17310)()
    1991         if have_same_parent_c(self, right):
    1992             return (<RingElement>self)._div_(<RingElement>right)
 -> 1993         return coercion_model.bin_op(self, right, div)
    1994
    1995     cpdef RingElement _div_(self, RingElement right):

 /Users/dcoudert/sage/src/sage/structure/coerce.pyx in
 sage.structure.coerce.CoercionModel_cache_maps.bin_op
 (/Users/dcoudert/sage/src/build/cythonized/sage/structure/coerce.c:8195)()
     994         try:
     995             xy = self.canonical_coercion(x,y)
 --> 996             return PyObject_CallObject(op, xy)
     997         except TypeError as err:
     998             if xy is not None:

 /Users/dcoudert/sage/src/sage/structure/element.pyx in
 sage.structure.element.RingElement.__div__
 (/Users/dcoudert/sage/src/build/cythonized/sage/structure/element.c:17293)()
    1990         """
    1991         if have_same_parent_c(self, right):
 -> 1992             return (<RingElement>self)._div_(<RingElement>right)
    1993         return coercion_model.bin_op(self, right, div)
    1994

 /Users/dcoudert/sage/src/sage/rings/integer.pyx in
 sage.rings.integer.Integer._div_
 (/Users/dcoudert/sage/src/build/cythonized/sage/rings/integer.c:11621)()
    1728         # This is vastly faster than doing it here, since here
    1729         # we can't cimport rationals.
 -> 1730         return the_integer_ring._div(self, right)
    1731
    1732     def __floordiv__(x, y):

 /Users/dcoudert/sage/src/sage/rings/integer_ring.pyx in
 sage.rings.integer_ring.IntegerRing_class._div
 (/Users/dcoudert/sage/src/build/cythonized/sage/rings/integer_ring.c:4894)()
     420         cdef rational.Rational x =
 rational.Rational.__new__(rational.Rational)
     421         if mpz_sgn(right.value) == 0:
 --> 422             raise ZeroDivisionError('Rational division by zero')
     423         mpz_set(mpq_numref(x.value), left.value)
     424         mpz_set(mpq_denref(x.value), right.value)

 ZeroDivisionError: Rational division by zero
 }}}
 I'll send you the graph by mail if you want to investigate.

--
Ticket URL: <http://trac.sagemath.org/ticket/18834#comment:12>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to