Datasets:
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Tags:
mathematics
information-theory
renyi-entropy
shannon-entropy
hidden-markov-models
bernoulli-convolutions
Download tests/reference.py from PureOne/VELORYN-Boundary-Kernel-Entropy: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/datasets/PureOne/VELORYN-Boundary-Kernel-Entropy/resolve/main/tests/reference.py
- Command line
-
hf download hf://datasets/PureOne/VELORYN-Boundary-Kernel-Entropy/tests/reference.py
-
curl -L -o reference.py https://huggingface.co/datasets/PureOne/VELORYN-Boundary-Kernel-Entropy/resolve/main/tests/reference.py
1.75 kB
| """Small exhaustive reference. Does not use the production carry/compiler code.""" | |
| from collections import defaultdict | |
| from fractions import Fraction as Q | |
| def multiply_add(coeff,clock,digit,polynomial): | |
| d=len(polynomial) | |
| work=[0]*clock+list(coeff) | |
| for j in range(len(work)-1,d-1,-1): | |
| c=work[j] | |
| for k,p in enumerate(polynomial): | |
| work[j-d+k]-=c*p | |
| work[j]=0 | |
| work+=([0]*max(0,d-len(work))) | |
| return tuple(work[i]+digit[i] for i in range(d)) | |
| def distributions(source,n): | |
| all_starts=[] | |
| for start in range(source.states): | |
| table={(start,0,(0,)*source.field.degree):Q(1)} | |
| for _ in range(n): | |
| nxt=defaultdict(Q) | |
| for (state,clock,u),weight in table.items(): | |
| for e in source.edges: | |
| if e.start==state: | |
| v=multiply_add(u,e.clock,e.digit,source.field.polynomial) | |
| nxt[(e.end,clock+e.clock,v)]+=weight*e.probability | |
| table=dict(nxt) | |
| all_starts.append(table) | |
| return all_starts | |
| def moment_matrix(source,n,q): | |
| rows=distributions(source,n) | |
| return [[sum((p**q for (end,clock,u),p in row.items() if end==b),Q(0)) | |
| for b in range(source.states)] for row in rows] | |
| def aggregate(source,n): | |
| out=defaultdict(Q) | |
| for a,row in enumerate(distributions(source,n)): | |
| for (b,clock,u),p in row.items(): | |
| out[(clock,u)]+=source.initial[a]*p | |
| return dict(out) | |
| def paths(source,n,start): | |
| if n==0: | |
| yield (),start,Q(1) | |
| return | |
| for i,e in enumerate(source.edges): | |
| if e.start==start: | |
| for rest,end,p in paths(source,n-1,e.end): | |
| yield (i,)+rest,end,e.probability*p | |