├── gradle.properties ├── src ├── main │ ├── resources │ │ └── datasets │ │ │ └── python │ │ │ ├── 73.py │ │ │ ├── 81.py │ │ │ ├── 82.py │ │ │ ├── 83.py │ │ │ ├── 71.py │ │ │ ├── 74.py │ │ │ ├── 75.py │ │ │ ├── 84.py │ │ │ ├── 106.py │ │ │ ├── 126.py │ │ │ ├── 127.py │ │ │ ├── 128.py │ │ │ ├── 129.py │ │ │ ├── 17.py │ │ │ ├── 35.py │ │ │ ├── 46.py │ │ │ ├── 63.py │ │ │ ├── 64.py │ │ │ ├── 68.py │ │ │ ├── 69.py │ │ │ ├── 72.py │ │ │ ├── 78.py │ │ │ ├── 107.py │ │ │ ├── 109.py │ │ │ ├── 110.py │ │ │ ├── 111.py │ │ │ ├── 112.py │ │ │ ├── 118.py │ │ │ ├── 119.py │ │ │ ├── 123.py │ │ │ ├── 124.py │ │ │ ├── 130.py │ │ │ ├── 131.py │ │ │ ├── 135.py │ │ │ ├── 136.py │ │ │ ├── 18.py │ │ │ ├── 2.py │ │ │ ├── 20.py │ │ │ ├── 21.py │ │ │ ├── 22.py │ │ │ ├── 23.py │ │ │ ├── 24.py │ │ │ ├── 25.py │ │ │ ├── 28.py │ │ │ ├── 29.py │ │ │ ├── 3.py │ │ │ ├── 56.py │ │ │ ├── 79.py │ │ │ ├── 85.py │ │ │ ├── 87.py │ │ │ ├── 108.py │ │ │ ├── 11.py │ │ │ ├── 132.py │ │ │ ├── 134.py │ │ │ ├── 137.py │ │ │ ├── 138.py │ │ │ ├── 139.py │ │ │ ├── 15.py │ │ │ ├── 158.py │ │ │ ├── 159.py │ │ │ ├── 16.py │ │ │ ├── 164.py │ │ │ ├── 165.py │ │ │ ├── 19.py │ │ │ ├── 26.py │ │ │ ├── 40.py │ │ │ ├── 41.py │ │ │ ├── 42.py │ │ │ ├── 43.py │ │ │ ├── 44.py │ │ │ ├── 50.py │ │ │ ├── 51.py │ │ │ ├── 52.py │ │ │ ├── 8.py │ │ │ ├── 80.py │ │ │ ├── 9.py │ │ │ ├── 133.py │ │ │ ├── 154.py │ │ │ ├── 155.py │ │ │ ├── 160.py │ │ │ ├── 161.py │ │ │ ├── 162.py │ │ │ ├── 27.py │ │ │ ├── 30.py │ │ │ ├── 31.py │ │ │ ├── 32.py │ │ │ ├── 33.py │ │ │ ├── 34.py │ │ │ ├── 4.py │ │ │ ├── 47.py │ │ │ ├── 49.py │ │ │ ├── 5.py │ │ │ ├── 6.py │ │ │ ├── 65.py │ │ │ ├── 7.py │ │ │ ├── 1.py │ │ │ ├── 10.py │ │ │ ├── 12.py │ │ │ ├── 122.py │ │ │ ├── 141.py │ │ │ ├── 157.py │ │ │ ├── 163.py │ │ │ ├── 166.py │ │ │ ├── 168.py │ │ │ ├── 45.py │ │ │ ├── 48.py │ │ │ ├── 66.py │ │ │ ├── 91.py │ │ │ ├── 95.py │ │ │ ├── 125.py │ │ │ ├── 144.py │ │ │ ├── 145.py │ │ │ ├── 156.py │ │ │ ├── 169.py │ │ │ ├── 39.py │ │ │ ├── 57.py │ │ │ ├── 58.py │ │ │ ├── 59.py │ │ │ ├── 60.py │ │ │ ├── 61.py │ │ │ ├── 62.py │ │ │ ├── 67.py │ │ │ ├── 77.py │ │ │ ├── 96.py │ │ │ ├── 101.py │ │ │ ├── 13.py │ │ │ ├── 14.py │ │ │ ├── 36.py │ │ │ ├── 37.py │ │ │ ├── 53.py │ │ │ ├── 54.py │ │ │ ├── 55.py │ │ │ ├── 86.py │ │ │ ├── 97.py │ │ │ ├── 98.py │ │ │ ├── 100.py │ │ │ ├── 38.py │ │ │ ├── 93.py │ │ │ ├── 99.py │ │ │ ├── 140.py │ │ │ ├── 89.py │ │ │ ├── 102.py │ │ │ ├── 104.py │ │ │ ├── 105.py │ │ │ ├── 120.py │ │ │ ├── 121.py │ │ │ ├── 117.py │ │ │ ├── 94.py │ │ │ ├── 70.py │ │ │ ├── 88.py │ │ │ ├── 170.py │ │ │ ├── 171.py │ │ │ ├── 76.py │ │ │ ├── 153.py │ │ │ ├── 167.py │ │ │ ├── 116.py │ │ │ ├── 147.py │ │ │ ├── 150.py │ │ │ ├── 148.py │ │ │ ├── 149.py │ │ │ ├── 152.py │ │ │ ├── 103.py │ │ │ ├── 151.py │ │ │ ├── 90.py │ │ │ ├── 142.py │ │ │ ├── 115.py │ │ │ ├── 113.py │ │ │ ├── 143.py │ │ │ ├── 114.py │ │ │ ├── 146.py │ │ │ └── 92.py │ ├── java │ │ └── edu │ │ │ ├── caltech │ │ │ ├── spn │ │ │ │ ├── Instance.java │ │ │ │ ├── Node.java │ │ │ │ ├── ProdNode.java │ │ │ │ ├── Decomposition.java │ │ │ │ ├── SumNode.java │ │ │ │ └── GenerativeLearning.java │ │ │ ├── common │ │ │ │ ├── Timer.java │ │ │ │ ├── Parameter.java │ │ │ │ ├── Utils.java │ │ │ │ └── MyMPI.java │ │ │ └── eval │ │ │ │ ├── Eval.java │ │ │ │ ├── ImageCompletion.java │ │ │ │ ├── Dataset.java │ │ │ │ └── Run.java │ │ │ └── washington │ │ │ ├── data │ │ │ ├── Partition.java │ │ │ ├── Dataset.java │ │ │ ├── QueryDataset.java │ │ │ ├── SparseDataset.java │ │ │ └── Discretized.java │ │ │ ├── spn │ │ │ ├── DatasetDep.java │ │ │ ├── ListNode.java │ │ │ ├── LinkedSetIterator.java │ │ │ ├── Node.java │ │ │ ├── SmoothedMultinomialNode.java │ │ │ ├── ProdNode.java │ │ │ ├── SumNode.java │ │ │ ├── GraphSPN.java │ │ │ └── LinkedSet.java │ │ │ ├── slalg │ │ │ └── SLAlg.java │ │ │ ├── util │ │ │ ├── SPNMath.java │ │ │ ├── Parameter.java │ │ │ └── SPNUtil.java │ │ │ └── exp │ │ │ ├── inference │ │ │ ├── SPNInfTest.java │ │ │ ├── SPNInf.java │ │ │ ├── SPNInfPLL.java │ │ │ ├── SPNInfCMLL.java │ │ │ └── GenQEV.java │ │ │ └── RunSLSPN.java │ └── kotlin │ │ ├── edu │ │ └── mcgill │ │ │ └── markovian │ │ │ ├── concurrency │ │ │ └── ResettableLazy.kt │ │ │ └── Utils.kt │ │ ├── Kalman.kt │ │ ├── Render.kt │ │ ├── Distributions.kt │ │ ├── BayesLR.kt │ │ ├── SPN.kt │ │ ├── HMM.kt │ │ ├── Integration.kt │ │ └── Mixtures.kt └── test │ └── kotlin │ └── edu │ └── mcgill │ └── markovian │ ├── RatioDistribution.kt │ └── mcmc │ └── MarkovChainTest.kt ├── libs └── mpj-0.44.jar ├── .gitattributes ├── latex └── ift6269 │ ├── mila.png │ ├── plot.png │ ├── bayesR.png │ ├── mcgill.png │ ├── poster.pdf │ ├── bayesLR.png │ ├── kotlin_file.png │ ├── bayesLR_plot.png │ ├── example_paper.pdf │ ├── bayesR.dot │ ├── bayesLR.dot │ ├── algorithm.sty │ ├── a0poster.cls │ ├── algorithmic.sty │ └── a0size.sty ├── README.md ├── .gitmodules ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle.kts ├── .gitignore ├── .github └── workflows │ └── main.yml ├── gradlew.bat └── gradlew /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /src/main/resources/datasets/python/73.py: -------------------------------------------------------------------------------- 1 | 1 * 2 2 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/81.py: -------------------------------------------------------------------------------- 1 | def test18(): 2 | None.a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/82.py: -------------------------------------------------------------------------------- 1 | def test19(a): 2 | a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/83.py: -------------------------------------------------------------------------------- 1 | def test20(a): 2 | a.b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/71.py: -------------------------------------------------------------------------------- 1 | def test8(x, y): 2 | x * y 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/74.py: -------------------------------------------------------------------------------- 1 | def test11(x): 2 | (yield x) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/75.py: -------------------------------------------------------------------------------- 1 | def test12(y): 2 | yield y 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/84.py: -------------------------------------------------------------------------------- 1 | def test21(a, b): 2 | a + b.x 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/106.py: -------------------------------------------------------------------------------- 1 | def power0(): 2 | return 2 ** 3 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/126.py: -------------------------------------------------------------------------------- 1 | def unaryOp0(a): 2 | return +a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/127.py: -------------------------------------------------------------------------------- 1 | def unaryOp1(a): 2 | return -a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/128.py: -------------------------------------------------------------------------------- 1 | def unaryOp2(a): 2 | return ~a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/129.py: -------------------------------------------------------------------------------- 1 | def unaryOp3(a): 2 | return +~-a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/17.py: -------------------------------------------------------------------------------- 1 | def power0(): 2 | return 2 ** 3 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/35.py: -------------------------------------------------------------------------------- 1 | def boolop7(a): 2 | return not a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/46.py: -------------------------------------------------------------------------------- 1 | def bool2(a, b): 2 | return a < b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/63.py: -------------------------------------------------------------------------------- 1 | def test0(a): 2 | return [1, 2, 3] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/64.py: -------------------------------------------------------------------------------- 1 | def test1(b): 2 | return test0(b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/68.py: -------------------------------------------------------------------------------- 1 | def test5(a): 2 | return a[1].x 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/69.py: -------------------------------------------------------------------------------- 1 | def test6(a, b): 2 | return a(b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/72.py: -------------------------------------------------------------------------------- 1 | def test9(x, y, z): 2 | x = y = z 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/78.py: -------------------------------------------------------------------------------- 1 | def test15(x, y): 2 | {x.a, y.b} 3 | -------------------------------------------------------------------------------- /libs/mpj-0.44.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/libs/mpj-0.44.jar -------------------------------------------------------------------------------- /src/main/resources/datasets/python/107.py: -------------------------------------------------------------------------------- 1 | def power1(): 2 | return 2 ** 3 ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/109.py: -------------------------------------------------------------------------------- 1 | def power3(): 2 | return (2 ** 3) ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/110.py: -------------------------------------------------------------------------------- 1 | def power4(): 2 | return 2 ** (3 ** 4) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/111.py: -------------------------------------------------------------------------------- 1 | def power5(): 2 | return 2 ** (3 + 4) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/112.py: -------------------------------------------------------------------------------- 1 | def power6(): 2 | return (2 + 3) ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/118.py: -------------------------------------------------------------------------------- 1 | def stringTest0(): 2 | return "test" 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/119.py: -------------------------------------------------------------------------------- 1 | def stringTest1(): 2 | return 'test' 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/123.py: -------------------------------------------------------------------------------- 1 | def byteString5(): 2 | return b"Test" 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/124.py: -------------------------------------------------------------------------------- 1 | def byteString6(): 2 | return b'Test' 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/130.py: -------------------------------------------------------------------------------- 1 | def unaryOp4(a, b): 2 | return +a + -b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/131.py: -------------------------------------------------------------------------------- 1 | def unaryOp5(a, b): 2 | return not +a 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/135.py: -------------------------------------------------------------------------------- 1 | def unaryOp9(a): 2 | return not (+a) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/136.py: -------------------------------------------------------------------------------- 1 | def unaryOp10(a): 2 | return not (+-a) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/18.py: -------------------------------------------------------------------------------- 1 | def power1(): 2 | return 2 ** 3 ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/2.py: -------------------------------------------------------------------------------- 1 | def sum2(a, b, c): 2 | return a * b + c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/20.py: -------------------------------------------------------------------------------- 1 | def power3(): 2 | return (2 ** 3) ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/21.py: -------------------------------------------------------------------------------- 1 | def power4(): 2 | return 2 ** (3 ** 4) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/22.py: -------------------------------------------------------------------------------- 1 | def power5(): 2 | return 2 ** (3 + 4) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/23.py: -------------------------------------------------------------------------------- 1 | def power6(): 2 | return (2 + 3) ** 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/24.py: -------------------------------------------------------------------------------- 1 | def bitwise1(x, y, z): 2 | (x & y) | z 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/25.py: -------------------------------------------------------------------------------- 1 | def bitwise2(x, y, z): 2 | x & (y | z) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/28.py: -------------------------------------------------------------------------------- 1 | def boolop0(a, b): 2 | return a and b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/29.py: -------------------------------------------------------------------------------- 1 | def boolop1(a, b): 2 | return a or b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/3.py: -------------------------------------------------------------------------------- 1 | def sum3(a, b, c): 2 | return a - b / c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/56.py: -------------------------------------------------------------------------------- 1 | def bool12(a, b): 2 | return a < b + 4 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/79.py: -------------------------------------------------------------------------------- 1 | def test16(x, y): 2 | {(x.a), (y.b)} 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/85.py: -------------------------------------------------------------------------------- 1 | def test22(a): 2 | x = a + "one" "two" 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/87.py: -------------------------------------------------------------------------------- 1 | def test24(): 2 | {1, 2, 3} 3 | {} 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | latex/** linguist-detectable=false 2 | notebooks/** linguist-detectable=false -------------------------------------------------------------------------------- /src/main/resources/datasets/python/108.py: -------------------------------------------------------------------------------- 1 | def power2(): 2 | return 2 ** 3 ** 4 ** 5 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/11.py: -------------------------------------------------------------------------------- 1 | def sum11(a, b, c): 2 | return a + (b - c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/132.py: -------------------------------------------------------------------------------- 1 | def unaryOp6(a, b): 2 | return ~a and -b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/134.py: -------------------------------------------------------------------------------- 1 | def unaryOp8(a, b): 2 | return ~(a and b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/137.py: -------------------------------------------------------------------------------- 1 | def unaryOp11(a, b): 2 | return +(not a) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/138.py: -------------------------------------------------------------------------------- 1 | def unaryOp12(a, b): 2 | return ~(a + b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/139.py: -------------------------------------------------------------------------------- 1 | def unaryOp13(a, b): 2 | return +(a + b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/15.py: -------------------------------------------------------------------------------- 1 | def sum15(a, b, c): 2 | return a * b + c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/158.py: -------------------------------------------------------------------------------- 1 | def sum2(a, b, c): 2 | return a * b + c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/159.py: -------------------------------------------------------------------------------- 1 | def sum3(a, b, c): 2 | return a + b * c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/16.py: -------------------------------------------------------------------------------- 1 | def sum16(a, b, c): 2 | return a + b - c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/164.py: -------------------------------------------------------------------------------- 1 | def sum8(a, b, c): 2 | return a * (b + c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/165.py: -------------------------------------------------------------------------------- 1 | def sum9(a, b, c): 2 | return (a + b) * c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/19.py: -------------------------------------------------------------------------------- 1 | def power2(): 2 | return 2 ** 3 ** 4 ** 5 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/26.py: -------------------------------------------------------------------------------- 1 | def bitwise3(x, y, z): 2 | x << (y >> z) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/40.py: -------------------------------------------------------------------------------- 1 | def boolop12(a, b): 2 | return not (a < b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/41.py: -------------------------------------------------------------------------------- 1 | def boolop13(a, b): 2 | return (not a) < b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/42.py: -------------------------------------------------------------------------------- 1 | def boolop14(a, b): 2 | return not a + b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/43.py: -------------------------------------------------------------------------------- 1 | def boolop15(a, b): 2 | return (not a) + b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/44.py: -------------------------------------------------------------------------------- 1 | def boolop16(a, b): 2 | return not (a + b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/50.py: -------------------------------------------------------------------------------- 1 | def bool6(a, b, c): 2 | return a + (b * c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/51.py: -------------------------------------------------------------------------------- 1 | def bool7(a, b, c): 2 | return a + (b - c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/52.py: -------------------------------------------------------------------------------- 1 | def bool8(a, b, c): 2 | return a + (b < c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/8.py: -------------------------------------------------------------------------------- 1 | def sum8(a, b, c): 2 | return a * (b + c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/80.py: -------------------------------------------------------------------------------- 1 | def test17(): 2 | [[1, 2], [3, 4], [5, 6].a] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/9.py: -------------------------------------------------------------------------------- 1 | def sum9(a, b, c): 2 | return (a + b) / c 3 | -------------------------------------------------------------------------------- /latex/ift6269/mila.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/mila.png -------------------------------------------------------------------------------- /latex/ift6269/plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/plot.png -------------------------------------------------------------------------------- /src/main/resources/datasets/python/133.py: -------------------------------------------------------------------------------- 1 | def unaryOp7(a, b): 2 | return (~a) and (-b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/154.py: -------------------------------------------------------------------------------- 1 | if test == 1: body 2 | else: 3 | orElseBody 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/155.py: -------------------------------------------------------------------------------- 1 | if test2 == 2: 2 | body2 3 | else: orElseBody2 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/160.py: -------------------------------------------------------------------------------- 1 | def sum4(a, b, c, d): 2 | return a + b * c + d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/161.py: -------------------------------------------------------------------------------- 1 | def sum5(a, b, c, d): 2 | return a * b + c * d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/162.py: -------------------------------------------------------------------------------- 1 | def sum6(a, b, c, d): 2 | return a + b + c + d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/27.py: -------------------------------------------------------------------------------- 1 | def bitwise4(w, x, y, z): 2 | (w | x) ^ (y & z) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/30.py: -------------------------------------------------------------------------------- 1 | def boolop2(a, b, c): 2 | return a or b and c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/31.py: -------------------------------------------------------------------------------- 1 | def boolop3(a, b, c): 2 | return (a or b) and c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/32.py: -------------------------------------------------------------------------------- 1 | def boolop4(a, b, c): 2 | return a or (b and c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/33.py: -------------------------------------------------------------------------------- 1 | def boolop5(a, b, c): 2 | return ((a or b) or c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/34.py: -------------------------------------------------------------------------------- 1 | def boolop6(a, b, c): 2 | return (a or (b or c)) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/4.py: -------------------------------------------------------------------------------- 1 | def sum4(a, b, c, d): 2 | return a + b * c + d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/47.py: -------------------------------------------------------------------------------- 1 | def bool3(a, b, c, d): 2 | return a < b < c < d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/49.py: -------------------------------------------------------------------------------- 1 | def bool5(a, b, c, d): 2 | return a < b > c == d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/5.py: -------------------------------------------------------------------------------- 1 | def sum5(a, b, c, d): 2 | return a * b - c * d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/6.py: -------------------------------------------------------------------------------- 1 | def sum6(a, b, c, d): 2 | return a + b - c + d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/65.py: -------------------------------------------------------------------------------- 1 | def test2(a, b, c): 2 | return [a.x, b.y, c.z] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/7.py: -------------------------------------------------------------------------------- 1 | def sum7(a, b, c, d): 2 | return (a + (b + c) + d) 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project has moved [here](https://github.com/breandan/kaliningraph) and will be archived. -------------------------------------------------------------------------------- /latex/ift6269/bayesR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/bayesR.png -------------------------------------------------------------------------------- /latex/ift6269/mcgill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/mcgill.png -------------------------------------------------------------------------------- /latex/ift6269/poster.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/poster.pdf -------------------------------------------------------------------------------- /src/main/resources/datasets/python/1.py: -------------------------------------------------------------------------------- 1 | def sum(a, b, c, d, e): 2 | return ((a + b) * d) - e 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/10.py: -------------------------------------------------------------------------------- 1 | def sum10(a, b, c, d): 2 | return (a + b) * (c - d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/12.py: -------------------------------------------------------------------------------- 1 | def sum12(a, b, c, d, e): 2 | return a + b + c + d + e 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/122.py: -------------------------------------------------------------------------------- 1 | def joinedStringTest4(): 2 | return "first" "second" 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/141.py: -------------------------------------------------------------------------------- 1 | def add_parser(self, name, **kwargs): 2 | return 1 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/157.py: -------------------------------------------------------------------------------- 1 | def sum(a, b, c, d, e): 2 | return ((a + b) * d) + e 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/163.py: -------------------------------------------------------------------------------- 1 | def sum7(a, b, c, d): 2 | return (a + (b + c) + d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/166.py: -------------------------------------------------------------------------------- 1 | def sum10(a, b, c, d): 2 | return (a + b) * (c - d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/168.py: -------------------------------------------------------------------------------- 1 | def sum(a, b, *c, d, e): 2 | return ((a + b) * d) + e 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/45.py: -------------------------------------------------------------------------------- 1 | def bool1(a, b, c, d): 2 | return a < (b < (c < d)) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/48.py: -------------------------------------------------------------------------------- 1 | def bool4(a, b, c, d): 2 | return ((a < b) < c) < d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/66.py: -------------------------------------------------------------------------------- 1 | def test3(a, b, c): 2 | return [(a.x), (b.y), (c.z)] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/91.py: -------------------------------------------------------------------------------- 1 | def test3(): 2 | 1, 2 + 3, 4 3 | (1, 2) + (3, 4) 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/95.py: -------------------------------------------------------------------------------- 1 | def ifExpr1(a, b): 2 | return a if (a and b) else b 3 | -------------------------------------------------------------------------------- /latex/ift6269/bayesLR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/bayesLR.png -------------------------------------------------------------------------------- /src/main/resources/datasets/python/125.py: -------------------------------------------------------------------------------- 1 | def byteStringJoined7(): 2 | return b"first" b'second' 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/144.py: -------------------------------------------------------------------------------- 1 | def one(): 2 | one_number = 1 3 | print(one_number) 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/145.py: -------------------------------------------------------------------------------- 1 | def two(): 2 | two_number = 2 3 | print(two_number) 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/156.py: -------------------------------------------------------------------------------- 1 | def lambdaTest(): 2 | s = lambda x: -1 3 | return s 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/169.py: -------------------------------------------------------------------------------- 1 | def sum2(a, b, *c, d, e): 2 | return sum(a, b, d=4, e=6) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/39.py: -------------------------------------------------------------------------------- 1 | def boolop11(a, b, c, d): 2 | return a and ((not b) or c) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/57.py: -------------------------------------------------------------------------------- 1 | def bool13(a, b, c, d): 2 | return a < b + 4 == c + 5 < d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/58.py: -------------------------------------------------------------------------------- 1 | def bool14(a, b, c, d): 2 | return a < b + 4 == (c + 5 < d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/59.py: -------------------------------------------------------------------------------- 1 | def bool15(a, b, c, d): 2 | return (a < b + 4) == c + 5 < d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/60.py: -------------------------------------------------------------------------------- 1 | def bool16(a, b, c, d): 2 | return (a <= b >= (c != d)) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/61.py: -------------------------------------------------------------------------------- 1 | def bool17(a, b, c, d): 2 | return a in b not in (c is d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/62.py: -------------------------------------------------------------------------------- 1 | def bool18(a, b, c, d): 2 | return (a is not b) >= (c + d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/67.py: -------------------------------------------------------------------------------- 1 | def test4(a, b, c): 2 | return [(a.x.u), (b.y.v), (c.z.w)] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/77.py: -------------------------------------------------------------------------------- 1 | def test14(x, y): 2 | ({1, 2, 3} + {4, 5, 6}) * {7, 8, 9} 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/96.py: -------------------------------------------------------------------------------- 1 | def ifExpr2(a, b, c, d): 2 | return a or (b if c else d) 3 | -------------------------------------------------------------------------------- /latex/ift6269/kotlin_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/kotlin_file.png -------------------------------------------------------------------------------- /src/main/resources/datasets/python/101.py: -------------------------------------------------------------------------------- 1 | def ifExpr7(a, b, c): 2 | return a if (c if c else c) else b 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/13.py: -------------------------------------------------------------------------------- 1 | def sum13(a, b, c, d, e): 2 | return (((a + b) + c) + d) + e 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/14.py: -------------------------------------------------------------------------------- 1 | def sum14(a, b, c, d, e): 2 | return a + (b + (c + (d + e))) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/36.py: -------------------------------------------------------------------------------- 1 | def boolop8(a, b, c, d): 2 | return a and (b or c) and not d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/37.py: -------------------------------------------------------------------------------- 1 | def boolop9(a, b, c, d): 2 | return ((a and b) or c) and not d 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/53.py: -------------------------------------------------------------------------------- 1 | def bool9(a, b, c, d): 2 | return ((a < b) + 4) == ((c + 5) < d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/54.py: -------------------------------------------------------------------------------- 1 | def bool10(a, b, c, d): 2 | return (a < b + 4) == ((c + 5) < d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/55.py: -------------------------------------------------------------------------------- 1 | def bool11(a, b, c, d): 2 | return a < b + 4 == ((c + 5) < d) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/86.py: -------------------------------------------------------------------------------- 1 | def test23(): 2 | [1 + 2, 3 + 4, 4 + 5] + [1 + 2, 3 + 4, 4 + 5] 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/97.py: -------------------------------------------------------------------------------- 1 | def ifExpr3(a, b): 2 | return (a if a else a) & (b if b else b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/98.py: -------------------------------------------------------------------------------- 1 | def ifExpr4(a, b): 2 | return (a if a else a) or (b if b else b) 3 | -------------------------------------------------------------------------------- /latex/ift6269/bayesLR_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/bayesLR_plot.png -------------------------------------------------------------------------------- /latex/ift6269/example_paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/latex/ift6269/example_paper.pdf -------------------------------------------------------------------------------- /src/main/resources/datasets/python/100.py: -------------------------------------------------------------------------------- 1 | def ifExpr6(a, b, c): 2 | return (a if a else a) if (b and b) else c 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/38.py: -------------------------------------------------------------------------------- 1 | def boolop10(a, b, c, d): 2 | return a and (b or (c and (not d))) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/93.py: -------------------------------------------------------------------------------- 1 | def test5(list): 2 | for a, (x, y) in list: 3 | z = y + 1 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/99.py: -------------------------------------------------------------------------------- 1 | def ifExpr5(a, b, c): 2 | return a if (a and b) else (c if c else c) 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "kaliningraph"] 2 | path = kaliningraph 3 | url = https://github.com/breandan/kaliningraph 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/breandan/markovian/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/datasets/python/140.py: -------------------------------------------------------------------------------- 1 | def atomTest(a, b): 2 | tuple = (1,2,3) 3 | return (yield from 3) 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/89.py: -------------------------------------------------------------------------------- 1 | def test1(a, b, c): 2 | del a 3 | del a, b, c 4 | del a.x, b.y 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/102.py: -------------------------------------------------------------------------------- 1 | def ifExpr8(a, b, c): 2 | return a if (c if c else c) else (b if b else b) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/104.py: -------------------------------------------------------------------------------- 1 | def lambda1(a, b): 2 | return lambda c, d, *e, f, **g: c * d + e - 2 + f - g 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/105.py: -------------------------------------------------------------------------------- 1 | def lambda2(a, b): 2 | return lambda c, d: c + (d - a) * (lambda e, f: e / f) 3 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/120.py: -------------------------------------------------------------------------------- 1 | def stringTest2(): 2 | return """test 3 | 2 line, 4 | 3 line, 5 | """ 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/121.py: -------------------------------------------------------------------------------- 1 | def stringTest3(): 2 | return '''test 3 | 2 line, 4 | 3 line, 5 | ''' 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/117.py: -------------------------------------------------------------------------------- 1 | def sum(a, b): 2 | return a + b 3 | print("The sum of %i and %i is %i" % (5, 3, sum(5, 3))) 4 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/94.py: -------------------------------------------------------------------------------- 1 | for a, b in list: 2 | a = b + 1 3 | def ifExpr0(a, b): 4 | return a if True else b 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/70.py: -------------------------------------------------------------------------------- 1 | def test7(x, y): 2 | z = test0(x) 3 | test1(y) 4 | y.a 5 | x[1] 6 | return test5(z) 7 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/88.py: -------------------------------------------------------------------------------- 1 | def test25(a, b): 2 | (a) + (b.x) 3 | (None) + (a[1]) 4 | def test0(): 5 | return 1, 2, 3 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/170.py: -------------------------------------------------------------------------------- 1 | def sum3(): 2 | x = 0 3 | if (x >= 0): 4 | x = x + 1 5 | x = x + 1 6 | return x 7 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/171.py: -------------------------------------------------------------------------------- 1 | def sum(a, b): 2 | return a + bdef tuplefunction(): 3 | a = 1, 2, 3 4 | b = 1, 2, 3, 5 | return a 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/76.py: -------------------------------------------------------------------------------- 1 | def test13(a, b): 2 | """Test for Docstring""" 3 | a.b[1] 4 | ziffern = "0123456789" 5 | ziffern[a:b] 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/153.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | if (1!=1) : print("IF") 3 | else : print("InnerElse") 4 | else: print("OuterElse") 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/167.py: -------------------------------------------------------------------------------- 1 | def slice(): 2 | ziffer = "0123456789" 3 | zahl = ziffer[2:7:2]def sum(a, b): 4 | return a if ( a < b ) else b 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/116.py: -------------------------------------------------------------------------------- 1 | @app.context_processor 2 | def render_helpers(): 3 | return dict(render_headers=render_headers, render_patch=render_patch) 4 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "markovian" 2 | 3 | pluginManagement.repositories { 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | 8 | includeBuild("kaliningraph") -------------------------------------------------------------------------------- /src/main/resources/datasets/python/147.py: -------------------------------------------------------------------------------- 1 | def listgen0(): 2 | testlist = [1,2,3,4,5,6] 3 | genlist = [x**2 for x in testlist if x % 2 == 0 if x > 2] 4 | return genlist 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/150.py: -------------------------------------------------------------------------------- 1 | def listgen3(): 2 | testlist = [1,2,3,4,5,6] 3 | genlist = [x**y for x, y in testlist if x % 2 == 0 if x > 2] 4 | return genlist 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/148.py: -------------------------------------------------------------------------------- 1 | def listgen1(): 2 | testlist = [1,2,3,4,5,6] 3 | genlist = [(x**2 + 4) for x in testlist if x % 2 == 0 if x > 2] 4 | return genlist 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/149.py: -------------------------------------------------------------------------------- 1 | def listgen2(): 2 | testlist = [1,2,3,4,5,6] 3 | genlist = [(x**(2 + 4)) for x in testlist if x % 2 == 0 if x > 2] 4 | return genlist 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/152.py: -------------------------------------------------------------------------------- 1 | def dictgen5(): 2 | testset = {1, 2, 3, 4, 5} 3 | genset = {(x**(2 + 4)) for x in testset if x % 2 == 0 if x > 2} 4 | return genset 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/103.py: -------------------------------------------------------------------------------- 1 | def ifExpr9(a, b, c): 2 | return (a if a else a) if (c if c else c) else (b if b else b) 3 | def lambda0(a, b): 4 | return lambda c, d: a * b 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/151.py: -------------------------------------------------------------------------------- 1 | def dictgen4(): 2 | testdict = {1: 10, 2: 20, 3: 30} 3 | gendict = {(x**(2 + 4)): x for x in testdict if x % 2 == 0 if x > 2} 4 | return gendict 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/90.py: -------------------------------------------------------------------------------- 1 | def test2(list): 2 | for element1, element2 in list: 3 | element1 + 1 4 | element2 - 1 5 | for element in list: 6 | element + 1 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | out 3 | **/.ipynb_checkpoints 4 | build 5 | .gradle 6 | *.aux 7 | *.log 8 | *.out 9 | *.pdf 10 | *.gz 11 | *.blg 12 | *.bbl 13 | *.listing 14 | *.bst 15 | *.ps 16 | *.DS_Store 17 | -------------------------------------------------------------------------------- /src/main/java/edu/caltech/spn/Instance.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.spn; 2 | 3 | // represent an image instance 4 | public class Instance { 5 | public double[][] vals_; 6 | public double mean_=0, std_=1; 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/data/Partition.java: -------------------------------------------------------------------------------- 1 | package edu.washington.data; 2 | 3 | import java.io.Serializable; 4 | 5 | public enum Partition implements Serializable { 6 | Training, Testing, Validation 7 | } -------------------------------------------------------------------------------- /src/main/java/edu/washington/spn/DatasetDep.java: -------------------------------------------------------------------------------- 1 | package edu.washington.spn; 2 | 3 | import edu.washington.data.Dataset; 4 | 5 | public interface DatasetDep { 6 | public void setDataset(Dataset d); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/142.py: -------------------------------------------------------------------------------- 1 | @decTest.dot(a, b, c) 2 | def decoratorTest(): 3 | return 0def dict(): 4 | a = { "key1" : "value1", "key2" : "value2"} 5 | b = {"key1" : "value2", **a} 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/115.py: -------------------------------------------------------------------------------- 1 | def render_headers(data): 2 | lexer = EmailLexer() 3 | formatter = HtmlFormatter(encoding='utf-8') 4 | return Markup(highlight(data, lexer, formatter).decode('utf-8')) 5 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/113.py: -------------------------------------------------------------------------------- 1 | def render_patch(data): 2 | lexer = lexers.get_lexer_by_name('diff') 3 | formatter = CodeHtmlFormatter(encoding='utf-8') 4 | return Markup(highlight(data, lexer, formatter).decode('utf-8')) 5 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/slalg/SLAlg.java: -------------------------------------------------------------------------------- 1 | package edu.washington.slalg; 2 | 3 | import edu.washington.spn.GraphSPN; 4 | import edu.washington.data.Dataset; 5 | 6 | public interface SLAlg { 7 | public GraphSPN learnStructure(Dataset d); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/143.py: -------------------------------------------------------------------------------- 1 | def docstringTest(a, b): 2 | """D.popitem() -> (k, v), remove and return some (key, value) pair 3 | as a 2-tuple; but raise KeyError if D is empty. 4 | """ 5 | return (yield from 3) 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/114.py: -------------------------------------------------------------------------------- 1 | class EmailLexer(RegexLexer): 2 | tokens = { 3 | 'root': [ 4 | (r'\s*<[^>]*>', Keyword), 5 | (r'^([^:]*)(: )', bygroups(Name.Attribute, Operator)), 6 | (r'.*\n', Text) 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/146.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | building = Building(5) 3 | elevator = Elevator(10, building) 4 | elevator.up() 5 | elevator.up() 6 | elevator.down() 7 | print(elevator.floor)def func(a, b, c=3, d=4, *list, e=6, f, **keywords) : 8 | return 1 9 | -------------------------------------------------------------------------------- /src/main/java/edu/caltech/common/Timer.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.common; 2 | 3 | public class Timer { 4 | long startTime_; 5 | public Timer() { 6 | timerStart(); 7 | } 8 | public void timerStart() { 9 | startTime_=System.currentTimeMillis(); 10 | } 11 | public long getTimeElapsed() { 12 | return System.currentTimeMillis()-startTime_; 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/spn/ListNode.java: -------------------------------------------------------------------------------- 1 | package edu.washington.spn; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | public class ListNode implements Serializable { 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | public ListNode next, prev; 12 | public E item; 13 | public double pos; 14 | public ListNode(E e) { 15 | this.item = e; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/datasets/python/92.py: -------------------------------------------------------------------------------- 1 | def test4(a, x, list): 2 | b = (yield from a) 3 | c = (yield a) 4 | d = (yield a, x) 5 | e = (z**2 for z in list if x % 2 == 0) 6 | f = (yield (z**2 for z in list if x % 2 == 0)) 7 | # grammar does not accept it, but Intellij (SDK Python 3.6) does accept it: 8 | # g = (yield z**2 for z in list if x % 2 == 0) 9 | h = ((yield z**2) for z in list if x % 2 == 0) 10 | i = () 11 | return b, c, d, e 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.kt' 7 | - '**.kts' 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up JDK 15 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: 15 20 | - name: Build with Gradle 21 | run: | 22 | git submodule update --init --recursive 23 | ./gradlew test --stacktrace -------------------------------------------------------------------------------- /src/main/java/edu/caltech/spn/Node.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.spn; 2 | 3 | // SPN node 4 | public abstract class Node { 5 | public static double ZERO_LOGVAL_=Double.NEGATIVE_INFINITY; 6 | double logval_; 7 | double logDerivative_=Node.ZERO_LOGVAL_; 8 | 9 | public double getLogVal() {return logval_;} 10 | public void setVal(double v) {if (v==0) logval_=ZERO_LOGVAL_; else logval_=Math.log(v);} 11 | 12 | // evaluate root 13 | public void eval() {} 14 | 15 | // propagate derivative to children 16 | public void passDerivative(){} 17 | } -------------------------------------------------------------------------------- /src/test/kotlin/edu/mcgill/markovian/RatioDistribution.kt: -------------------------------------------------------------------------------- 1 | package edu.mcgill.markovian 2 | 3 | import kotlin.math.* 4 | 5 | // https://en.wikipedia.org/wiki/Ratio_distribution#Means_and_variances_of_random_ratios 6 | fun main() { 7 | val t1 = (0..10).map { Math.random() } 8 | val t2 = (0..10).map { Math.random() } 9 | 10 | val t2_t1_var = t2.zip(t1).map { (a, b) -> a / b }.variance() 11 | println(t2_t1_var) 12 | 13 | // σ²[t2/t1] == 𝔼([t2/t1]²) - 𝔼²(t2/t1) 14 | val var_t2_t1 = t2.zip(t1).let { 15 | it.map { (a, b) -> (a / b).pow(2) }.average() - 16 | it.map { (a, b) -> (a / b) }.average().pow(2) 17 | } 18 | 19 | println(var_t2_t1) 20 | } -------------------------------------------------------------------------------- /src/main/java/edu/caltech/common/Parameter.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.common; 2 | 3 | public class Parameter { 4 | // EM 5 | public static int maxIter_=30; 6 | public static double thresholdLLHChg_=0.1; 7 | public static int batch_size_=50; 8 | public static double sparsePrior_=1; 9 | 10 | // SPN 11 | public static int numSumPerRegion_=20; 12 | public static int inputDim1_=64; 13 | public static int inputDim2_=64; 14 | public static int baseResolution_=4; 15 | public static double smoothSumCnt_=0.01; 16 | public static int numComponentsPerVar_=4; 17 | 18 | // Eval 19 | public static int maxTestSize_=50; 20 | public static String domain_=null; 21 | public static int numSlavePerClass_=50; 22 | public static int numSlaveGrp_=1; 23 | } 24 | -------------------------------------------------------------------------------- /latex/ift6269/bayesR.dot: -------------------------------------------------------------------------------- 1 | digraph bayesLR { 2 | margin=0 3 | compound=true 4 | rankdir=LR 5 | node [shape=Mrecord,fontname="JetBrains Mono"] 6 | edge [fontsize=8,fontcolor=indigo] 7 | bgcolor=transparent 8 | nslimit=20 9 | 10 | g0 [label="{{μ|σ}|Normal|{g0}}"] 11 | g1 [label="{{μ|σ}|Normal|{g1}}"] 12 | g2 [label="{{μ|σ}|Normal|{g2}}"] 13 | g3 [label="{{μ|σ}|Normal|{g3}}"] 14 | 15 | f4 [label="{{g0|g1|g2}|Σ|{f4}}"] 16 | f5 [label="{{f4|g3}|Π|{f5}}"] 17 | 18 | g0:Out0 -> f4:In0 19 | g1:Out0 -> f4:In1 20 | g2:Out0 -> f4:In2 21 | g3:Out0 -> f5:In1 22 | f4:Out0 -> f5:In0 23 | 24 | 25 | out1 [style=invis,shape=point] 26 | out2 [style=invis,shape=point] 27 | 28 | f5 -> out1 29 | } -------------------------------------------------------------------------------- /latex/ift6269/bayesLR.dot: -------------------------------------------------------------------------------- 1 | digraph bayesLR { 2 | margin=0 3 | compound=true 4 | rankdir=LR 5 | node [shape=Mrecord,fontname="JetBrains Mono"] 6 | edge [fontsize=8,fontcolor=indigo] 7 | bgcolor=transparent 8 | nslimit=20 9 | 10 | 11 | 12 | a [label="{{μ|σ}|𝒩|{a}}"] 13 | b [label="{{μ|σ}|𝒩|{b}}"] 14 | 15 | 16 | f3 [label="{{a|b}|\×3+|{f3}}"] 17 | f4 [label="{{a|b}|\×2+|{f4}}"] 18 | 19 | v [label="{{α|β}|InvG|{v}}"] 20 | 21 | 22 | y3 [label="{{μ|σ}|𝒩|{}}"] 23 | y4 [label="{{μ|σ}|𝒩|{}}"] 24 | 25 | a:Out0 -> f3:In0 [] 26 | a:Out0 -> f4:In0 [] 27 | b:Out0 -> f3:In1 [] 28 | b:Out0 -> f4:In1 [] 29 | f3:Out0 -> y3:In0 [] 30 | f4:Out0 -> y4:In0 [] 31 | v:Out0 -> y3:In1 [] 32 | v:Out0 -> y4:In1 [] 33 | } -------------------------------------------------------------------------------- /src/main/java/edu/washington/util/SPNMath.java: -------------------------------------------------------------------------------- 1 | package edu.washington.util; 2 | 3 | public class SPNMath { 4 | private static final double LOGZERO = Double.NEGATIVE_INFINITY; 5 | 6 | public static double log_sum_exp(double l1, double l2){ 7 | if(l1 == LOGZERO && l2 == LOGZERO) 8 | return LOGZERO; 9 | if(l1 > l2) 10 | return l1 + Math.log(1 + Math.exp(l2 - l1)); 11 | else 12 | return l2 + Math.log(1 + Math.exp(l1 - l2)); 13 | } 14 | 15 | public static double exp(double val) { 16 | if(val == LOGZERO) return 0; 17 | if(val > 70) return Math.exp(val); 18 | if(val < -70) return Math.exp(val); 19 | final long tmp = (long) (1512775 * val + 1072632447); 20 | return Double.longBitsToDouble(tmp << 32); 21 | } 22 | 23 | public static double log_minus_exp(double l1, double l2){ 24 | if(l1 == LOGZERO || l1 <= l2) 25 | return LOGZERO; 26 | if(l2 == LOGZERO) 27 | return l1; 28 | // if(l1 < l2) 29 | // throw new ArithmeticException("Trying to subtract a large number ("+l2+") from a smaller number ("+l1+") abs diff = "+Math.abs(l1 - l2)); 30 | return l1 + Math.log(1 - Math.exp(l2 - l1)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/spn/LinkedSetIterator.java: -------------------------------------------------------------------------------- 1 | package edu.washington.spn; 2 | 3 | import java.util.Iterator; 4 | 5 | class LinkedSetIterator implements Iterator { 6 | LinkedSet set; 7 | ListNode pointerToNext; 8 | 9 | public LinkedSetIterator(LinkedSet set) { 10 | this.set = set; 11 | this.pointerToNext = set.head; 12 | } 13 | 14 | public LinkedSetIterator(LinkedSet set, ListNode start) { 15 | this.set = set; 16 | this.pointerToNext = start; 17 | } 18 | 19 | @Override 20 | public boolean hasNext() { 21 | return pointerToNext != null; 22 | } 23 | 24 | @Override 25 | public E next() { 26 | E toret = pointerToNext.item; 27 | pointerToNext = pointerToNext.next; 28 | return toret; 29 | } 30 | 31 | @Override 32 | public void remove() { 33 | ListNode previouslyReturned = pointerToNext.prev; 34 | 35 | set.index.remove(previouslyReturned.item); 36 | 37 | if(pointerToNext != null) 38 | pointerToNext.prev = previouslyReturned.prev; 39 | if(previouslyReturned.prev != null) 40 | previouslyReturned.prev.next = pointerToNext; 41 | if(set.head.equals(previouslyReturned)) 42 | set.head = pointerToNext; 43 | if(set.tail.equals(previouslyReturned)) 44 | set.tail = previouslyReturned.prev; 45 | previouslyReturned = null; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/main/java/edu/washington/data/Dataset.java: -------------------------------------------------------------------------------- 1 | package edu.washington.data; 2 | 3 | import java.io.Serializable; 4 | 5 | public abstract class Dataset implements Serializable{ 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | private int currentFold = 0; 11 | public int numFeats; 12 | 13 | public abstract double getNumFolds(); 14 | 15 | public void setFold(int f) { 16 | currentFold = f; 17 | } 18 | 19 | public abstract int getNumClasses(); 20 | 21 | public abstract int getNumTesting(); 22 | public abstract int getNumTraining(); 23 | public abstract int getNumValidation(); 24 | 25 | public abstract int trueLabel(); 26 | 27 | public void show(int i, Partition testing){ 28 | show(i, testing, true); 29 | } 30 | 31 | public abstract void show(int i, Partition testing, boolean b); 32 | 33 | 34 | 35 | public int getNumItems(Partition p) { 36 | switch (p) { 37 | case Training: return getNumTraining(); 38 | case Validation: return getNumValidation(); 39 | case Testing: return getNumTesting(); 40 | default: 41 | break; 42 | } 43 | return 0; 44 | } 45 | 46 | public abstract int getUniqueInstanceID(); 47 | 48 | public abstract int getNumFeatures(); 49 | public abstract int[] getAttrSizes(); 50 | public abstract int[] getValues(); 51 | 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/kotlin/edu/mcgill/markovian/concurrency/ResettableLazy.kt: -------------------------------------------------------------------------------- 1 | package edu.mcgill.markovian.concurrency 2 | 3 | import java.util.* 4 | import kotlin.reflect.KProperty 5 | 6 | //https://stackoverflow.com/a/35757638 7 | class ResettableLazyManager { 8 | // we synchronize to make sure the timing of a reset() call and new inits do not collide 9 | val managedDelegates = LinkedList() 10 | 11 | fun register(managed: Resettable) = 12 | synchronized(managedDelegates) { 13 | managedDelegates.add(managed) 14 | } 15 | 16 | fun reset() = synchronized(managedDelegates) { 17 | managedDelegates.forEach { it.reset() } 18 | managedDelegates.clear() 19 | } 20 | } 21 | 22 | interface Resettable { 23 | fun reset() 24 | } 25 | 26 | class ResettableLazy

( 27 | val manager: ResettableLazyManager, 28 | val init: () -> P 29 | ): Resettable { 30 | @Volatile 31 | var lazyHolder = makeInitBlock() 32 | 33 | operator fun getValue(thisRef: Any?, property: KProperty<*>): P = 34 | lazyHolder.value 35 | 36 | override fun reset() { 37 | lazyHolder = makeInitBlock() 38 | } 39 | 40 | fun makeInitBlock(): Lazy

= lazy { 41 | manager.register(this) 42 | init() 43 | } 44 | } 45 | 46 | fun

resettableLazy( 47 | manager: ResettableLazyManager, 48 | init: () -> P 49 | ): ResettableLazy

= ResettableLazy(manager, init) -------------------------------------------------------------------------------- /src/main/kotlin/Kalman.kt: -------------------------------------------------------------------------------- 1 | //import com.analog.lyric.dimple.model.core.FactorGraph 2 | //import com.analog.lyric.dimple.model.variables.RealJoint 3 | // 4 | //fun main() { 5 | // val dt = 1.0 6 | // val gamma = 1.0 7 | // val m = 1.0 8 | // val F = arrayOf( 9 | // doubleArrayOf(1.0, 0.0, dt, 0.0, dt * dt / 2, 0.0, 0.0, 0.0), 10 | // doubleArrayOf(0.0, 1.0, 0.0, dt, 0.0, dt * dt / 2, 0.0, 0.0), 11 | // doubleArrayOf(0.0, 0.0, 1.0, 0.0, dt / 2, 0.0, 0.0, 0.0), 12 | // doubleArrayOf(0.0, 0.0, 0.0, 1.0, 0.0, dt / 2, 0.0, 0.0), 13 | // doubleArrayOf(0.0, 0.0, -gamma / m, 0.0, 0.0, 0.0, 0.0, 0.0), 14 | // doubleArrayOf(0.0, 0.0, 0.0, -gamma / m, 0.0, 0.0, 0.0, 0.0), 15 | // doubleArrayOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0), 16 | // doubleArrayOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0) 17 | // ) 18 | // 19 | // //H is the matrix that projects down to the observation. 20 | // val H = arrayOf( 21 | // doubleArrayOf(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), 22 | // doubleArrayOf(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) 23 | // ) 24 | // val fz = RealJoint(2) 25 | // val fv = RealJoint(2) 26 | // val fznonoise = RealJoint(2) 27 | // val fx = RealJoint(8) 28 | // val fxnext = RealJoint(8) 29 | // val fg = FactorGraph().apply { 30 | // addFactor("constmult", fznonoise, H, fx) 31 | // addFactor("add", fz, fv, fznonoise) 32 | // addFactor("constmult", fxnext, F, fx) 33 | // } 34 | //} -------------------------------------------------------------------------------- /src/main/java/edu/washington/exp/inference/SPNInfTest.java: -------------------------------------------------------------------------------- 1 | package edu.washington.exp.inference; 2 | 3 | import edu.washington.spn.GraphSPN; 4 | import edu.washington.util.Parameter; 5 | import edu.washington.data.Dataset; 6 | import edu.washington.data.Partition; 7 | import edu.washington.exp.RunSLSPN; 8 | 9 | public class SPNInfTest { 10 | 11 | /** 12 | * @param args 13 | */ 14 | public static void main(String[] args) { 15 | RunSLSPN.parseParameters(args); 16 | String prefix = "edu/caltech/data/"; 17 | 18 | Dataset d = null; 19 | try { 20 | d = (Dataset) RunSLSPN.ds[RunSLSPN.data_id].newInstance(); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | GraphSPN spn = GraphSPN.load(Parameter.filename, d); 26 | 27 | double LL = 0, LLsq = 0; 28 | long tic = System.currentTimeMillis(); 29 | for(int inst=0; inst Double): Plot = 23 | compare( 24 | *samplers.map { f -> 25 | (1..POPCOUNT).pmap { f(Random.Default.nextDouble()) } 26 | }.toTypedArray() 27 | ) 28 | 29 | fun compare(vararg samples: List): Plot = 30 | letsPlot( 31 | mapOf( 32 | "x" to samples.fold(listOf()) { acc, function -> acc + function }, 33 | "" to samples.mapIndexed { i, s -> List(s.size) { "PDF$i" } }.flatten() 34 | ) 35 | ).let { 36 | it + geomDensity(alpha = .3) { x = "x"; fill = "" } + ggsize(500, 250) 37 | } 38 | -------------------------------------------------------------------------------- /src/main/kotlin/edu/mcgill/markovian/Utils.kt: -------------------------------------------------------------------------------- 1 | package edu.mcgill.markovian 2 | 3 | import ai.hypergraph.kaliningraph.types.cc 4 | import kotlinx.coroutines.* 5 | import kotlin.math.pow 6 | import kotlin.random.Random 7 | 8 | // Generates a rational number in (0, 1). Approximates nextDouble() as n -> \infty 9 | tailrec fun Random.nextRational(n: Int = 100): String { 10 | val (j, i) = nextInt(3, n).let { it cc nextInt(1, it - 1) } 11 | return if (1 < i.gcd(j)) nextRational(n) else "$i/$j" 12 | } 13 | 14 | tailrec fun Int.gcd(b: Int): Int = 15 | if (this == b) this 16 | else if (this > b) (this - b).gcd(b) 17 | else gcd(b - this) 18 | 19 | // https://medium.com/@elizarov/the-reason-to-avoid-globalscope-835337445abc 20 | fun Iterable.pmap(f: suspend (A) -> B): List = 21 | runBlocking { map { async { f(it) } }.awaitAll() } 22 | 23 | fun List.variance() = 24 | average().let { mean -> map { (it - mean).pow(2) } }.average() 25 | 26 | fun log2(b: Int) = 32 - Integer.numberOfLeadingZeros(b - 1) 27 | fun Int.pow(p: Int) = toDouble().pow(p.toDouble()).toInt() 28 | 29 | // All vertices of a Hamming space 30 | // https://en.wikipedia.org/wiki/Hamming_space 31 | fun List.allMasks(): List> = 32 | indices.map { it.toString(2) }.map { bitMask -> 33 | mapIndexed { i, t -> 34 | // null represents unknown/unconditioned values 35 | if(bitMask.length <= i || bitMask[i] == '1') null else t 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/edu/caltech/spn/ProdNode.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.spn; 2 | 3 | import java.util.*; 4 | 5 | import edu.caltech.common.*; 6 | 7 | // Product Node 8 | public class ProdNode extends Node { 9 | ArrayList chds_; 10 | 11 | public ProdNode() { 12 | chds_=new ArrayList(); 13 | } 14 | 15 | public void passDerivative() { 16 | if (logDerivative_==Node.ZERO_LOGVAL_) return; 17 | 18 | if (logval_==Node.ZERO_LOGVAL_) { 19 | int cnt=0; 20 | for (Node n: chds_) if (n.logval_==Node.ZERO_LOGVAL_) {cnt++; if (cnt>1) return;} 21 | } 22 | 23 | for (Node n: chds_) { 24 | if (n.logval_==Node.ZERO_LOGVAL_) { 25 | double l=0; 26 | for (Node m:chds_) { 27 | if (m.logval_!=Node.ZERO_LOGVAL_) l+=m.logval_; 28 | } 29 | l+=logDerivative_; 30 | if (n.logDerivative_==Node.ZERO_LOGVAL_) n.logDerivative_=l; 31 | else n.logDerivative_=Utils.addLog(n.logDerivative_, l); 32 | } 33 | else if (logval_!=Node.ZERO_LOGVAL_) { 34 | double l=logDerivative_+logval_-n.logval_; 35 | if (n.logDerivative_==Node.ZERO_LOGVAL_) n.logDerivative_=l; 36 | else n.logDerivative_=Utils.addLog(n.logDerivative_, l); 37 | } 38 | } 39 | } 40 | 41 | public void eval() { 42 | logval_=0; 43 | for (Node n: chds_) { 44 | double v=n.getLogVal(); 45 | if (v==Node.ZERO_LOGVAL_) {logval_=Node.ZERO_LOGVAL_; return;} 46 | logval_+=v; 47 | } 48 | } 49 | 50 | public void addChd(Node n) { 51 | chds_.add(n); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/spn/Node.java: -------------------------------------------------------------------------------- 1 | package edu.washington.spn; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | public abstract class Node implements Serializable { 7 | public static double ZERO_LOGVAL_=Double.NEGATIVE_INFINITY; 8 | 9 | public boolean dirty = true; 10 | // public final static int TYPE_VAR_=0; 11 | // public final static int TYPE_PROD_=1; 12 | // public final static int TYPE_SUM_=2; 13 | // 14 | // public Node(int type, int regId, int nodeIdx) { 15 | // public Node(int type) { 16 | // type_=type; 17 | //// regId_=regId; 18 | //// nodeIdx_=nodeIdx; 19 | // } 20 | 21 | // ref: type, region, nodeIdx (among nodes in same layer) 22 | public Integer shapeID = -1; 23 | // public int tie = -1; 24 | public int firstX=-1, firstY=-1; 25 | 26 | int type_; 27 | // int regId_; 28 | // int nodeIdx_; 29 | // public int getType() {return type_;} 30 | // public int getRegionId() {return regId_;} 31 | // public int getNodeIdx() {return nodeIdx_;} 32 | 33 | // val 34 | public double logval_ = 0; 35 | public double getLogVal() {return logval_;} 36 | // public void setVal(double v) {if (v==0) logval_=ZERO_LOGVAL_; else logval_=Math.log(v);} 37 | public void eval() {} 38 | 39 | public double der = 0; 40 | public double logder_=Node.ZERO_LOGVAL_; 41 | public void passDer(){} // sent to chd 42 | public void passSampledDer() {} 43 | 44 | // cond der 45 | // double jntder_=Node.ZERO_LOGVAL_; // P(X,Y) 46 | // double marder_=Node.ZERO_LOGVAL_; // P(X) 47 | // public void passCondDer(){} 48 | } -------------------------------------------------------------------------------- /src/main/java/edu/washington/exp/inference/SPNInf.java: -------------------------------------------------------------------------------- 1 | package edu.washington.exp.inference; 2 | 3 | import edu.washington.spn.GraphSPN; 4 | import edu.washington.util.Parameter; 5 | import edu.washington.data.Dataset; 6 | import edu.washington.data.Partition; 7 | import edu.washington.data.QueryDataset; 8 | import edu.washington.exp.RunSLSPN; 9 | 10 | public class SPNInf { 11 | 12 | /** 13 | * @param args 14 | */ 15 | public static void main(String[] args) { 16 | RunSLSPN.parseParameters(args); 17 | String prefix = "edu/caltech/data/"; 18 | Dataset d = new QueryDataset(prefix+RunSLSPN.queryfile, prefix+RunSLSPN.evidencefile); 19 | 20 | GraphSPN spn = GraphSPN.load(Parameter.filename, d); 21 | 22 | double LL = 0, LLsq = 0; 23 | long tic = System.currentTimeMillis(); 24 | for(int inst=0; inst { 13 | override val density: ContinuousDistribution = UniformDist(lo, hi) 14 | override fun new(name: String): Uniform = Uniform(name, lo, hi) 15 | } 16 | 17 | class Beta( 18 | override val name: String = "", 19 | val α: Double = 2.0, 20 | val β: Double = 2.0, 21 | override val μ: Double = α / (α + β), 22 | override val σ: Double = α * β / ((α + β).pow(2) * (α + β + 1)) 23 | ): Dist { 24 | override val density: ContinuousDistribution = BetaDist(α, β) 25 | override fun new(name: String): Beta = Beta(name, α, β) 26 | } 27 | 28 | tailrec fun > Dist.cdf( 29 | z: Double, 30 | sum: Double = 0.0, 31 | term: Double = z, 32 | i: Int = 3 33 | ): Double = 34 | when { 35 | z < -8.0 -> 0.0 36 | z > 8.0 -> 1.0 37 | sum + term == sum -> 0.5 + sum * pdf(z) 38 | else -> cdf(z, sum + term, term * z * z / i, i + 2) 39 | } 40 | 41 | // Binary search root-finder 42 | tailrec fun > Dist.invcdf( 43 | y: Double, lo: Double = -4.0, hi: Double = 8.0, 44 | mid: Double = lo + (hi - lo) / 2 45 | ): Double = when { 46 | hi - lo < precision -> mid 47 | cdf(mid) < y -> invcdf(y, mid, hi) 48 | else -> invcdf(y, lo, mid) 49 | } -------------------------------------------------------------------------------- /src/main/java/edu/washington/util/Parameter.java: -------------------------------------------------------------------------------- 1 | package edu.washington.util; 2 | 3 | public class Parameter { 4 | 5 | public static final double convergenceThreshold = 0.1;// 0.1; 6 | public static double invVar = 1; //00; 7 | public static int spn_width = 64; 8 | public static int spn_height = 64; 9 | public static boolean mpe = false; 10 | 11 | public static final double smoothSumCnt_ = 0.01; 12 | public static final double measurementPenalty = 1; 13 | public static final int batchsize = 50; 14 | public static double penalty = 1.0; 15 | public static double zero_tolerance = 0.01; 16 | public static double edgePenalty = 0.03; 17 | // public static int maxCandidatesMemory = 16000; 18 | public static int maxEdgesMemory = 9000000; 19 | public static int maxFanIn = 128 ; 20 | public static boolean resetBWrounds = false; 21 | public static int numRoundsTrainInSL = 1; 22 | 23 | public static double initLSNC = 1; 24 | public static double initSNC = 1; 25 | public static int slRoundLimit = 10000; 26 | public static double regularization_coefficient = 0.0; 27 | public static boolean normImPatch = true; 28 | public static int patchWidth = 4; 29 | public static int patchStride = patchWidth; 30 | public static String filename = "untitled"; 31 | public static String loadFilename = "load"; 32 | public static int maxEpochs = 1000; 33 | public static int dictionarySize = 1000; 34 | public static double featThreshold = 0.0; 35 | 36 | public static int featGrid = 8; 37 | public static int numFeats = 200; 38 | 39 | // public static int numMOLOGcomp = 2; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/util/SPNUtil.java: -------------------------------------------------------------------------------- 1 | package edu.washington.util; 2 | 3 | import java.util.List; 4 | import java.util.Random; 5 | import java.util.Set; 6 | 7 | import edu.washington.spn.Node; 8 | import edu.washington.spn.SumNode; 9 | 10 | public class SPNUtil { 11 | public static Random rand = new Random(); 12 | 13 | 14 | 15 | public static double AddIdIfGEQ(double reference, double new_value, List ids, T new_id){ 16 | if(ids.isEmpty() || new_value > reference){ 17 | ids.clear(); 18 | reference = new_value; 19 | } 20 | if(new_value == reference) 21 | ids.add(new_id); 22 | return reference; 23 | } 24 | 25 | // public static int RandomElement(List list){ 26 | // return list.get((int) (Math.random() * list.size())); 27 | // } 28 | 29 | public static Node RandomSumChild(SumNode sn, Random rnd){ 30 | double d = rnd.nextDouble(); 31 | double runsum = 0; 32 | for(int c=0; c T RandomElement(List list){ 43 | return list.get((int) (rand.nextDouble() * list.size())); 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | public static T RandomElement(Set set){ 48 | return (T) set.toArray()[(int) (rand.nextDouble() * set.size())]; 49 | } 50 | 51 | public static byte flipCoin(double d) { 52 | if(rand.nextDouble() < d) 53 | return 1; 54 | else 55 | return 0; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/spn/SmoothedMultinomialNode.java: -------------------------------------------------------------------------------- 1 | package edu.washington.spn; 2 | 3 | import edu.washington.data.Dataset; 4 | import edu.washington.data.Partition; 5 | 6 | public class SmoothedMultinomialNode extends Node implements DatasetDep { 7 | private static final long serialVersionUID = 1L; 8 | public static double smooth = 0.0000001; 9 | private double logvals[]; 10 | private final int attr; 11 | private Dataset d; 12 | private final int[] instances; 13 | 14 | public SmoothedMultinomialNode(Dataset d, int variable, int instances[]) { 15 | this.d = d; 16 | attr = variable; 17 | this.instances = instances; 18 | 19 | reset(); 20 | } 21 | 22 | public void setDataset(Dataset d) { 23 | this.d = d; 24 | } 25 | 26 | public void reset(){ 27 | int numvals = d.getAttrSizes()[attr]; 28 | double counts[] = new double[numvals]; 29 | double countsum=numvals*smooth; 30 | 31 | for(int val=0; val 34 | val x = Random.nextDouble() 35 | (a * x + b + NormalGen(rand, NormalDist(0.0, v.nextDouble().coerceAtLeast(0.01))).nextDouble()).coerceIn(-3.0, 3.0) 36 | } 37 | 38 | compare(at, bt, yt).display() 39 | } 40 | 41 | fun plot(samples: List>, points: List>) = 42 | ggplot( 43 | mapOf( 44 | "a" to samples.unzip().first, 45 | "b" to samples.unzip().second, 46 | "x" to points.unzip().first, 47 | "y" to points.unzip().second 48 | ) 49 | ) { x = "x"; y = "y" }.let { 50 | samples.fold(it) { plot, (a, b) -> 51 | plot + geomABLine(alpha = .1, slope = a, intercept = b) 52 | } + ggsize(500, 250) + geomPoint(color = "red", shape = 21, fill = "red", size = 5) 53 | // it + geomPoint(shape=1) 54 | }.display() -------------------------------------------------------------------------------- /src/main/java/edu/caltech/spn/Decomposition.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.spn; 2 | 3 | import java.util.*; 4 | 5 | // represent a decomposition of a region into two sub-regions 6 | public class Decomposition { 7 | static Map id_decomp_=new HashMap(); 8 | static Decomposition blankDecomp_=new Decomposition("",-1,-1,-1,-1); 9 | 10 | String id_; 11 | int regionId1_, regionId2_, typeId1_, typeId2_; 12 | 13 | private Decomposition(String id, int regionId1, int regionId2, int typeId1, int typeId2) { 14 | id_=id; 15 | regionId1_=regionId1; regionId2_=regionId2; 16 | typeId1_=typeId1; typeId2_=typeId2; 17 | } 18 | public static Decomposition getDecomposition(int regionId1, int regionId2, int typeId1, int typeId2) { 19 | String id=getIdStr(regionId1,regionId2,typeId1,typeId2); 20 | Decomposition d=id_decomp_.get(id); 21 | if (d==null) id_decomp_.put(id, d); 22 | return d; 23 | } 24 | public static Decomposition getDecomposition(String id) { 25 | Decomposition d=id_decomp_.get(id); 26 | if (d==null) { 27 | if (id==null) { 28 | // blank; doesn't matter 29 | return blankDecomp_; 30 | } 31 | String[] ts=id.split(" "); 32 | int regionId1=Integer.parseInt(ts[0]); 33 | int regionId2=Integer.parseInt(ts[1]); 34 | int typeId1=Integer.parseInt(ts[2]); 35 | int typeId2=Integer.parseInt(ts[3]); 36 | d=new Decomposition(id, regionId1, regionId2, typeId1, typeId2); 37 | } 38 | return d; 39 | } 40 | public String getId() {return id_;} 41 | public static void remove(String id) { 42 | id_decomp_.remove(id); 43 | } 44 | public static String getIdStr(int regionId1, int regionId2, int typeId1, int typeId2) { 45 | String id=regionId1+" "+regionId2+" "+typeId1+" "+typeId2; 46 | return id; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/edu/washington/exp/inference/SPNInfPLL.java: -------------------------------------------------------------------------------- 1 | package edu.washington.exp.inference; 2 | 3 | import edu.washington.spn.GraphSPN; 4 | import edu.washington.util.Parameter; 5 | import edu.washington.data.Dataset; 6 | import edu.washington.data.Partition; 7 | import edu.washington.exp.RunSLSPN; 8 | 9 | public class SPNInfPLL { 10 | 11 | /** 12 | * @param args 13 | */ 14 | public static void main(String[] args) { 15 | RunSLSPN.parseParameters(args); 16 | String prefix = "edu/caltech/data/"; 17 | 18 | Dataset d = null; 19 | try { 20 | d = (Dataset) RunSLSPN.ds[RunSLSPN.data_id].newInstance(); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | GraphSPN spn = GraphSPN.load(Parameter.filename, d); 26 | 27 | double LL = 0, LLsq = 0; 28 | long tic = System.currentTimeMillis(); 29 | for(int inst=0; inst0){ 40 | refvals[marg-1] =rightvals[marg-1]; 41 | } 42 | refvals[marg] = -1; 43 | ill -= spn.upwardPass(); 44 | } 45 | refvals[d.getNumFeatures()-1] = rightvals[d.getNumFeatures()-1]; 46 | 47 | System.out.println(ill); 48 | LL += ill; 49 | LLsq += ill*ill; 50 | } 51 | long toc = System.currentTimeMillis(); 52 | LL /= d.getNumTesting(); 53 | LLsq /= d.getNumTesting(); 54 | 55 | System.out.println("avg = "+LL+" +/- "+Math.sqrt(LLsq - LL*LL)); 56 | System.out.println("Total time: "+(1.0*(toc-tic)/1000)+"s"); 57 | // avg = -21.734815 +/- 0.363440 58 | // Total time: 424.504467s 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/edu/caltech/common/Utils.java: -------------------------------------------------------------------------------- 1 | package edu.caltech.common; 2 | 3 | import java.io.*; 4 | import java.util.Random; 5 | import edu.caltech.spn.Instance; 6 | 7 | public class Utils { 8 | // return intensity value in gray scale 9 | public static int getIntVal(Instance inst, double p) { 10 | return (int)(p*inst.std_+inst.mean_); 11 | } 12 | 13 | // time 14 | static Timer timer_=new Timer(); 15 | static {timer_.timerStart();} 16 | public static void logTime(String msg) { 17 | long sec=timer_.getTimeElapsed()/1000; 18 | println("