from __future__ import print_function
from archery import *
from json import dumps
a = mdict(p=mdict(x=1, y=1, z=1), c = mdict(r=34, g=45, b=1, a=.4))
pp = lambda d : print(dumps(d, indent=4))
pp(a)
pp(a+{})
pp(a+0)
assert(a+0==a+{})
print(0=={} and "Youpi" or "Humm")
assert(a+{}==a+0==1+a-1)
print("it is true")
pp(1+a-1)
I HATE FLOATS since ana num 101
They introduce non commutative behaviours when symbol leads me to think otherwhise.
pp(a*1)
print("hum")
pp(a*mdict(p=1, c=1))
print("hum "*2)
pp(a*a/a)
pp(a+a)
assert(a+a == 2*a)
print("it is true")
pp(1/(a-1))
Not a bug : a feature. let's see. 1/0 make a division by 0 error. But a float is an implicit 1 dimnesional value like this:
b=mdict(IAmAReal=0.0)
1/b
Did we invented stuff that have no meanings here?!
How can we make sense of this?
Given an endomorphism in matrice calculus 0 matrice is 0 on all diagonal 1 is 1 on the all the diagonal and if you work with eigenvalues vector if we work with x, y, z then 1 is:
{ x=1, y=1, z=1}
a+0 == a
a*1 == a
pp(a*mdict(p=1,c=1))
u = mdict(p=mdict(x=1,y=1,z=1), c = mdict(r=1,g=1,b=1, a=1))
assert(a*u==a*1)
a-a == a + (-1 *a)
Basically we just linked translation to homothetia.
We have : adding a vector of opposite direction to itself result in a null vector
So + is a translation of n in every declared direction
ex let's translate p of 1
a+mdict(p=1)
What does * means?
pp(a*mdict(p=1))
multiplying by a subpath = 1 is equivalent to get a vector in the sub dimension
We have a pretty intuitional behaviour that match what is known of linear algebra
Of course, I could have implemented other algebra for the fun...
what about cos?
Let's implement "Tanimoto" coefficient cf https://en.wikipedia.org/wiki/Cosine_similarity
$$T(A,B) = \frac{A \cdot B}{\|A\|^2 +\|B\|^2 - A \cdot B}$$cos_sim = lambda a,b : dot(a,b) / (vabs(a*a) + vabs(b*b) - dot(a,b))
this_theme=mdict(foss=.2, math=1, python=1, perl=1)
python_fosdem=mdict(foss=1, python=2, )
fosdem=mdict(python=1, ruby=1, php=1, perl=1, foss=1, crypto=1)
print(vcos(python_fosdem, fosdem))
print(cos_sim(python_fosdem,fosdem))
print("-"*10)
print(vcos(python_fosdem, this_theme))
print(cos_sim(python_fosdem,this_theme))
print("-"*10)
print(vcos(fosdem, this_theme))
print(cos_sim(fosdem,this_theme))
In this case cos will not work we use:
$$\forall (u,v) \in E\times E,\ d(u,v) = \|u-v\|.$$(math don't follow PEP8)
For the distance
You can thus define - \o/
type | overload sub with |
---|---|
string | levensthein/hamming |
sets | len(a&b)/len(u or b) |
tuple/lists | Hamming/levenstehin |
int as bits | .... |
fallback | 1 - (self==other) |
PS : distance must stay symmetric |a-b| == |b-a|
We may not now what is a+b but we may know |a-b|
We may define for every algebraic dict (object?!) a distance as long as equal operator is defined