Ask Your Question

SYLA's profile - activity

2023-03-29 05:44:09 +0200 received badge  Notable Question (source)
2023-03-29 05:44:09 +0200 received badge  Popular Question (source)
2022-12-25 17:01:26 +0200 received badge  Famous Question (source)
2022-11-26 23:37:35 +0200 received badge  Popular Question (source)
2021-03-07 17:37:47 +0200 received badge  Notable Question (source)
2021-01-29 16:18:57 +0200 asked a question Functions with operation (multiplication) as argument

Suppose I have functions $f$, $g_1$, $g_2$, $h$ and an operation $*$, which is not necessarily multiplication, satisfying the following relations:

$$ f(X * Y) = g_1(X) g_2(Y) + g_1(Y) g_2(X) + f(X) * f(Y) + h(X * Y) $$

$$ h(X * Y) = h^2(X) * g_1(Y) $$

How to find a symbolic expression for $f(X^7)$?

2021-01-21 16:26:34 +0200 asked a question Cluster transitivity

The cluster transitivity (the fraction of closed triangles ) of g is equal to:

C =(number of triangles) × 3/(number of connected triples)

Formula (7.28) Networks Mark Newman (2018)

I would like to ask you about the method cluster_transitivity() It gives 0.0853107962707866 for this network: http://snap.stanford.edu/data/email-E... , but a table from this page shows that Fraction of closed triangles is 0.03015. So, these two number are not equal.

If I omit 3 in the formula (7.28) and I get 0.0284369320902622.

Why?

On this page: http://snap.stanford.edu/data/index.html (at the end), we have a definition of the fraction of closed triangles: Number of connected triples of nodes / number of (undirected) length 2 paths

2020-11-08 11:53:26 +0200 received badge  Popular Question (source)
2020-05-21 16:29:39 +0200 answered a question Kronecker Power of sparse matrices problem

Yes, I made many errors. Sorry! I took some unchecked codes and translated it. I had in my mind the following solution:

def SparseMatrixPower(A,p): 
    if p == 1: 
        return(A) 
    elif Mod(p,2): 
        return(SparseMatrixProduct(A,SparseMatrixPower(SparseMatrixProduct(A,A), (p - 1) / 2)))
    else: 
        return(SparseMatrixPower(SparseMatrixProduct(A,A), p / 2))
2020-05-12 13:10:38 +0200 commented answer Kronecker Power of sparse matrices problem

Yes, this is typo, I repaired my code. It does not work as well.

2020-05-02 22:36:12 +0200 asked a question Kronecker Power of sparse matrices problem

Why the following code does not work? I try it also in loops.

import numpy

from scipy import sparse

from scipy.sparse import coo_matrix

def SparseMatrixPower(A,p):
    if p == 1: 
        return(A)
    elif Mod(p,2):
        return(SparseMatrixPower(A,SparseMatrixProduct(A,A)), (p - 1) / 2)  
    else:
        return(SparseMatrixPower(SparseMatrixProduct(A,A), p / 2))

def SparseMatrixProduct(A,B):
        return(sparse.kron(A,B)+sparse.kronsum(A,B))

A=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
B=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
SparseMatrixProduct(A,B)
SparseMatrixPower(A,3)
2020-05-02 22:20:19 +0200 received badge  Scholar (source)
2020-05-02 22:20:15 +0200 received badge  Supporter (source)
2020-05-02 17:28:01 +0200 answered a question Graph indexed from zero

Maybe faster than that:

def ChangeVertices(g,di):  
    G=Graph()
    for v in di.values():
        G.add_vertex(v)
    for e in g.edge_iterator():
        G.add_edge(di[e[0]] if e[0] in di else e[0],di[e[1]] if e[1] in di else e[1])
    return(G)

def GraphFromZero(g):
    return(ChangeVertices(g,{v:i for i,v in enumerate(g.vertices())}))
2020-05-02 17:01:38 +0200 asked a question Graph indexed from zero

How to change vertices of a graph to that are indexed from 0?

In Mathematica: ChangeVertices.

We can change it to the adjacency matrix A and from A to the graph. A faster solution?

Ho to get a permutation of vertices?

2020-04-29 15:58:57 +0200 asked a question How to create url/file link in jupyter/sage?

I have file/url:

load("/home/***/MJRun.sage")

I would like to open (fast) this file/url in Jupyter in another card of Firefox. For example by one click. I use this file very often. How to do that?

2020-04-29 11:39:31 +0200 commented answer Problem: Jupyter (Sage) with Numba and pypy

What's about PyPy?

2020-04-29 11:38:26 +0200 commented answer Problem: Jupyter (Sage) with Numba and pypy

I now have (after the substitution):

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Cannot unify array(int64, 2d, C) and array(float64, 2d, C) for '$56binary_add.2', defined at <ipython-input-2-d69b3052de9b> (12)

File "<ipython-input-2-d69b3052de9b>", line 12:
def go_fast(a): # Function is compiled and runs in machine code
    <source elided>
        trace += np.tanh(a[i, i])
    return a + trace
    ^

[1] During: typing of intrinsic-call at <ipython-input-2-d69b3052de9b> (12)

File "<ipython-input-2-d69b3052de9b>", line 12:
def go_fast(a): # Function is compiled and runs in machine code
    <source elided>
        trace += np.tanh(a[i, i])
    return a + trace
    ^
2020-04-28 22:21:46 +0200 commented answer Problem: Jupyter (Sage) with Numba and pypy

Does not work.

2020-04-28 18:43:44 +0200 received badge  Student (source)
2020-04-28 16:40:16 +0200 commented answer Problem: Jupyter (Sage) with Numba and pypy

Now I get:

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'Integer': cannot determine Numba type of <class 'sage.misc.inherit_comparison.InheritComparisonMetaclass'>

File "<ipython-input-2-450bc39e89d0>", line 9:
def go_fast(a): # Function is compiled and runs in machine code
    trace = Integer(0)
    ^
2020-04-28 12:48:10 +0200 received badge  Editor (source)
2020-04-28 12:42:46 +0200 commented answer Problems with AMS symbols in Sage, Jupyter

Great! Thank you.

2020-04-28 12:39:37 +0200 asked a question Problem: Jupyter (Sage) with Numba and pypy

I install it by:

pip3 install numba

How to use and import numba, pypy in sage.

I get:

ModuleNotFoundError: No module named 'numba'

when I run the following code (from https://numba.pydata.org/numba-doc/la... )

from numba import jit 
import numpy as np 
import time

x = np.arange(100).reshape(10, 10)

@jit(nopython=True) 
def go_fast(a): # Function is compiled and runs in machine code
    trace = 0
    for i in range(a.shape[0]):
        trace += np.tanh(a[i, i])
    return a + trace

start = time.time() 
go_fast(x) 
end = time.time() 
print("Elapsed (with compilation) = %s" % (end - start))

start = time.time()
go_fast(x)
end = time.time()
print("Elapsed (after compilation) = %s" % (end - start))
2020-04-28 12:38:12 +0200 asked a question Problem Jupyter (Sage) with numba and pypy

How to use and import numba, pypy in sage.

I get:

ModuleNotFoundError: No module named 'numba'

when I run the following code:

from numba import jit import numpy as np import time

x = np.arange(100).reshape(10, 10)

@jit(nopython=True) def go_fast(a): # Function is compiled and runs in machine code
    trace = 0
    for i in range(a.shape[0]):
        trace += np.tanh(a[i, i])
    return a + trace

start = time.time() go_fast(x) end = time.time() print("Elapsed (with compilation) = %s" % (end - start))


start = time.time() go_fast(x) end = time.time() print("Elapsed (after compilation) = %s" % (end - start))
2019-10-12 16:45:27 +0200 asked a question Problems with AMS symbols in Sage, Jupyter

How to display the square (\square) symbol in a graph (Jupyter, maybe not only). Why \boxtimes is too large?

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

I tried \box \square \emptybox etc. and

from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amssymb}')

I get:

ValueError: F(G\,\square\,H) ^ Unknown symbol: \square (at char 5), (line:1, col:6)

2019-10-12 16:45:27 +0200 asked a question Problems with AMS symbols in Sage, Jupyter

How to display the square (\square) symbol in a graph (Jupyter, maybe not only). Why \boxtimes is too large?

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

I tried \box \square \emptybox etc. and

from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amssymb}')

I get:

ValueError: F(G\,\square\,H) ^ Unknown symbol: \square (at char 5), (line:1, col:6)