-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).
- Loading branch information
1 parent
6bcf55d
commit a2f6207
Showing
12 changed files
with
184 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#1/bin/bash | ||
|
||
java -classpath build/java/DafnyVMC.jar docs/java/TestSamplers.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#1/bin/bash | ||
|
||
java -classpath build/java/DafnyVMC.jar docs/java/TestShuffling.java |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#1/bin/bash | ||
|
||
PYTHONPATH=.:build/py/DafnyVMC-py python3 docs/py/TestSamplers.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#1/bin/bash | ||
|
||
PYTHONPATH=.:build/py/DafnyVMC-py python3 docs/py/TestShuffling.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import java.security.SecureRandom; | ||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
|
||
import DafnyVMC.Random; | ||
|
||
class TestSamplers { | ||
|
||
public static void main(String[] args) { | ||
|
||
/* STANDARD RNG */ | ||
System.out.println("\nSTANDARD RNG TESTS\n"); | ||
|
||
DafnyVMC.Random r = new DafnyVMC.Random(); | ||
|
||
for (int a = 1; a < 1000; a++) { | ||
BigInteger i = BigInteger.valueOf(a); | ||
|
||
System.out.println("Testing Uniform(" + a + ")"); | ||
System.out.println(r.UniformSample(i)); | ||
|
||
for (int b = 1; b <= 1000; b++) { | ||
BigInteger j = BigInteger.valueOf(b); | ||
|
||
System.out.println("Testing Bernoulli(" + a + "/" + b + ")"); | ||
System.out.println(r.BernoulliSample(i, j)); | ||
|
||
System.out.println("Testing BernoulliExpNeg(" + a + "/" + b + ")"); | ||
System.out.println(r.BernoulliExpNegSample(i, j)); | ||
|
||
System.out.println("Testing DiscreteGaussian(" + a + "/" + b + ")"); | ||
System.out.println(r.DiscreteGaussianSample(i, j)); | ||
|
||
System.out.println("Testing DiscreteLaPlace(" + a + "/" + b + ")"); | ||
System.out.println(r.DiscreteLaplaceSample(i, j)); | ||
} | ||
} | ||
|
||
// Edge cases | ||
|
||
BigInteger k = BigInteger.valueOf(1000000); | ||
BigInteger l = BigInteger.valueOf(1); | ||
|
||
System.out.println("Testing Bernoulli(1000000, 1)"); | ||
System.out.println(r.BernoulliSample(k, l)); | ||
System.out.println("Testing Bernoulli(1, 1000000)"); | ||
System.out.println(r.BernoulliSample(l, k)); | ||
|
||
System.out.println("Testing BernoulliExpNeg(1000000, 1)"); | ||
System.out.println(r.BernoulliExpNegSample(k, l)); | ||
System.out.println("Testing BernoulliExpNeg(1, 1000000)"); | ||
System.out.println(r.BernoulliExpNegSample(l, k)); | ||
|
||
System.out.println("Testing DiscreteGaussianSample(1000000, 1)"); | ||
System.out.println(r.DiscreteGaussianSample(k, l)); | ||
System.out.println("Testing DiscreteGaussianSample(1, 1000000)"); | ||
System.out.println(r.DiscreteGaussianSample(l, k)); | ||
|
||
System.out.println("Testing DiscreteLaplace(1000000, 1)"); | ||
System.out.println(r.DiscreteLaplaceSample(k, l)); | ||
System.out.println("Testing DiscreteLaplace(1, 1000000)"); | ||
System.out.println(r.DiscreteLaplaceSample(l, k)); | ||
|
||
/* CUSTOM RNG */ | ||
System.out.println("\nCUSTOM RNG TESTS\n"); | ||
|
||
SecureRandom rng = new SecureRandom(); | ||
DafnyVMC.Random t = new DafnyVMC.Random(() -> rng); | ||
|
||
for (int a = 1; a < 1000; a++) { | ||
BigInteger i = BigInteger.valueOf(a); | ||
System.out.println("Testing Uniform(" + a + ")"); | ||
System.out.println(t.UniformSample(i)); | ||
|
||
for (int b = 1; b <= 1000; b++) { | ||
BigInteger j = BigInteger.valueOf(b); | ||
System.out.println("Testing Bernoulli(" + a + "/" + b + ")"); | ||
System.out.println(t.BernoulliSample(i, j)); | ||
|
||
System.out.println("Testing BernoulliExpNeg(" + a + "/" + b + ")"); | ||
System.out.println(t.BernoulliExpNegSample(i, j)); | ||
|
||
System.out.println("Testing DiscreteGaussian(" + a + "/" + b + ")"); | ||
System.out.println(t.DiscreteGaussianSample(i, j)); | ||
|
||
System.out.println("Testing DiscreteLaPlace(" + a + "/" + b + ")"); | ||
System.out.println(t.DiscreteLaplaceSample(i, j)); | ||
} | ||
} | ||
|
||
|
||
// Edge cases | ||
|
||
System.out.println("Testing Bernoulli(1000000, 1)"); | ||
System.out.println(t.BernoulliSample(k, l)); | ||
System.out.println("Testing Bernoulli(1, 1000000)"); | ||
System.out.println(t.BernoulliSample(l, k)); | ||
|
||
System.out.println("Testing BernoulliExpNeg(1000000, 1)"); | ||
System.out.println(t.BernoulliExpNegSample(k, l)); | ||
System.out.println("Testing BernoulliExpNeg(1, 1000000)"); | ||
System.out.println(t.BernoulliExpNegSample(l, k)); | ||
|
||
System.out.println("Testing DiscreteGaussianSample(1000000, 1)"); | ||
System.out.println(t.DiscreteGaussianSample(k, l)); | ||
System.out.println("Testing DiscreteGaussianSample(1, 1000000)"); | ||
System.out.println(t.DiscreteGaussianSample(l, k)); | ||
|
||
System.out.println("Testing DiscreteLaplace(1000000, 1)"); | ||
System.out.println(t.DiscreteLaplaceSample(k, l)); | ||
System.out.println("Testing DiscreteLaplace(1, 1000000)"); | ||
System.out.println(t.DiscreteLaplaceSample(l, k)); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import DafnyVMC | ||
|
||
def main(): | ||
|
||
# STANDARD RNG | ||
print("\nSTANDARD RNG TESTS\n") | ||
|
||
r = DafnyVMC.Random() | ||
|
||
for i in range(1, 1000): | ||
print("Testing Uniform("+str(i)+")") | ||
print(r.UniformSample(i)) | ||
|
||
for j in range(1, 1000): | ||
print("Testing Bernoulli("+str(i)+"/"+str(j)+")\n") | ||
print(r.BernoulliSample(i, j), end="\n") | ||
|
||
print("Testing BernoulliExpNeg("+str(i)+"/"+str(j)+")\n") | ||
print(r.BernoulliExpNegSample(i, j), end="\n") | ||
|
||
print("Testing DiscreteGaussian("+str(i)+"/"+str(j)+")\n") | ||
print(r.DiscreteGaussianSample(i, j), end="\n") | ||
|
||
print("Testing DiscreteLaPlace("+str(i)+"/"+str(j)+")\n") | ||
print(r.DiscreteLaplaceSample(i, j), end="\n") | ||
|
||
# Edge cases | ||
print("Testing Bernoulli(1000000, 1)\n") | ||
print(r.BernoulliSample(1000000, 1), end="\n") | ||
print("Testing Bernoulli(1, 1000000)\n") | ||
print(r.BernoulliSample(1, 1000000), end="\n") | ||
|
||
print("Testing BernoulliExpNeg(1000000, 1)\n") | ||
print(r.BernoulliExpNegSample(1000000, 1), end="\n") | ||
print("Testing BernoulliExpNeg(1, 1000000)\n") | ||
print(r.BernoulliExpNegSample(1, 1000000), end="\n") | ||
|
||
print("Testing DiscreteGaussianSample(1000000, 1)\n") | ||
print(r.DiscreteGaussianSample(1000000, 1), end="\n") | ||
print("Testing DiscreteGaussianSample(1, 1000000)\n") | ||
print(r.DiscreteGaussianSample(1, 1000000), end="\n") | ||
|
||
print("Testing DiscreteLaplace(1000000, 1)\n") | ||
print(r.DiscreteLaplaceSample(1000000, 1), end="\n") | ||
print("Testing DiscreteLaplace(1, 1000000)\n") | ||
print(r.DiscreteLaplaceSample(1, 1000000), end="\n") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters