Notebook for debugging stuff - to see some relevant stuff, see relmath-demo.ipynb
In [1]:
get_ipython().display_formatter.formatters
Out[1]:
In [2]:
import math
def normalize(m):
for row in m.g:
norm = math.sqrt(sum((x**2 for x in row)))
for i in range(len(row)):
row[i] = row[i] / norm
In [3]:
getattr("ciao", "upper")()
Out[3]:
Nodes and Links should be supplied to the Graph mark.
Node attributes
Attribute | Type | Description | Default |
---|---|---|---|
label | str | node label | mandatory attribute |
label_display | {center, outside, none} | label display options | center |
shape | {circle, ellipse, rect} | node shape | circle |
shape_attrs | dict | node SVG attributes | {'r': 15} |
Link Attributes
Attribute | Type | Description | Default |
---|---|---|---|
source | int | source node index | mandatory attribute |
target | int | target node index | mandatory attribute |
value | float | value of the link. Use np.nan if you do not want a link | - |
Link data can also be supplied using a link_matrix which is a numpy array of shape (n, n) where n is the number of nodes in the graph
Link Data can be passed in through 3 data attributes -
In [15]:
import numpy as np
from bqplot import *
from bqplot.marks import Graph
from ipywidgets import Layout, VBox, HBox
from relmath import *
from relmath_bq import *
State.s.push_env()
with quote():
M = Rel([
[0.2, 0.7, 0, 0],
[0.9,0,0.5,0],
[0.9,0,0,0]
],
['a','b','c'],
['x','y','z','w'])
E = M * M.T
#print(E)
#print(E.simp())
E.to_bq()
In [7]:
import math
def normalize(m):
for row in m.g:
norm = math.sqrt(sum((x.val**2 for x in row)))
for i in range(len(row)):
row[i] = RD(row[i].val / norm)
with quote():
A = Rel([
[0.7, 0.7, 0, 0.6],
[0.9,0.2,0.5,0.3],
[0.9,0,0,0.6]
],
['Mario','Luigi','Bowser'],
['cinema','musica','sport','scommesse'])
normalize(A)
M = A * A.T
MAT = A * A.T.simp()
print(MAT)
print(M.simp())
M.to_bq()
In [ ]:
math.sqrt(0.87)
In [ ]:
math.sqrt((0.5**2 )*4)
x1^2 + x2^2 + x3^2 = 1
In [12]:
from relmath import *
from relmath_bq import *
State.s.push_env()
with quote():
A = Rel([
[0.1, 0.6, 0.3, 0.0, 0.2, 0.6],
[0.0, 0.8, 0.2, 0.0, 0.2, 0.6],
[0.0, 0.0, 0.1, 0.9, 0.2, 0.6]
],
['Mario','Luigi','Bowser'],
['Movies','Music','Sport','Kidnapping','a','b'])
M = A * A.T
MAT = A * A.T.simp()
print(MAT)
Ms = M.simp()
print(Ms)
M.to_bq()
In [ ]: