This file contains hidden or 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
| import sys | |
| from sklearn.datasets import fetch_mldata | |
| from sklearn import neighbors | |
| options = [['2', 'uniform'], ['2', 'distance'], ['3', 'uniform'], ['3', 'distance'] ] | |
| index = int(sys.argv[1]) | |
| # Fetch MNIST database | |
| mnist = fetch_mldata('MNIST original') |
This file contains hidden or 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
| import sys | |
| from sklearn.datasets import fetch_mldata | |
| from sklearn import neighbors | |
| # Fetch MNIST database | |
| mnist = fetch_mldata('MNIST original') | |
| # crop to keep only 0's, 1's and 2's and normalize greyscale to 1.0 | |
| L = 18622 | |
| X, y = mnist.data[:L] / 255., mnist.target[:L] |
This file contains hidden or 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
| from sklearn.datasets import fetch_mldata | |
| # Fetch MNIST database | |
| mnist = fetch_mldata('MNIST original') | |
| X, y = mnist.data / 255., mnist.target |
This file contains hidden or 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
| smith@wesson:~$ python qPiMc.py | |
| 3> 3.168 | |
| 1> 3.112 | |
| 2> 3.128 | |
| 9> 3.14 | |
| 6> 3.12 | |
| 10> 3.104 | |
| 7> 3.152 | |
| 5> 3.128 | |
| 8> 3.192 |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import qarnot | |
| conn = qarnot.connection.Connection(client_token='<YOUR_API_TOKEN>') | |
| task = conn.create_task('pi Monte Carlo', 'docker-batch', '1-10') | |
| d = conn.create_disk('disk') | |
| d.add_file('piMc.py') | |
| task.resources.append(d) |
This file contains hidden or 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
| smith@wesson:~$ python piMc.py 1 1000 | |
| 3.112 | |
| smith@wesson:~$ python piMc.py 2 1000 | |
| 3.128 |
This file contains hidden or 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
| import random, sys | |
| seed = int(sys.argv[1]) | |
| samples = int(sys.argv[2]) | |
| def in_circle(point): | |
| x = point[0] | |
| y = point[1] | |
| return x**2 + y**2 < 1 | |
This file contains hidden or 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
| >>> import math | |
| >>> abs(piMc2(1000,100) – math.pi) # 1000*100 samples | |
| 0.0033126535897927134 | |
| >>> abs(piMc2(10000,100) – math.pi) # 10000*100 samples | |
| 0.002076653589794475 | |
| >>> abs(piMc2(1000,1000) – math.pi) # 1000*1000 samples | |
| 0.00252734641020691 | |
| >>> abs(piMc2(10000,1000) – math.pi) # 10000*1000 samples | |
| 0.00011454641020680612 | |
| >>> abs(piMc2(1000,10000) – math.pi) # 1000*10000 samples |
This file contains hidden or 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
| def piMc(seed, samples): | |
| random.seed(seed) | |
| count = inside_count = 0 | |
| i = samples | |
| while i>0: | |
| point = random.random(),random.random() | |
| if in_circle(point): | |
| inside_count += 1 | |
| count += 1 | |
| i = i-1 |
This file contains hidden or 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
| import random | |
| def in_circle(point): | |
| x = point[0] | |
| y = point[1] | |
| return x**2 + y**2 < 1 | |
| def piMc(samples): | |
| count = inside_count = 0 | |
| i = samples |
NewerOlder