-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_codes.py
More file actions
62 lines (51 loc) · 1.96 KB
/
sample_codes.py
File metadata and controls
62 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
exp_sample = '''def dijkstra(graph, start, end):
table = {}
for vertex in graph.vertexes:
table[vertex] = {'distance': float('inf'), 'path': None}
table[start]['distance'] = 0
processed_vertexes = set()
min_heap = MinHeap()
min_heap.insert(start, 0)
while min_heap:
distance, vertex = min_heap.extract_min()
if vertex in processed_vertexes:
continue
if vertex == end:
return table
for edge in graph.vertexes[vertex]:
if edge.end not in processed_vertexes:
if edge.weight + table[vertex]['distance'] < table[edge.end]['distance']:
table[edge.end]['distance'] = edge.weight + table[vertex]['distance']
table[edge.end]['path'] = vertex
min_heap.insert(edge.end, table[edge.end]['distance'])
processed_vertexes.add(vertex)
return table'''
test_sample = '''class SimpleCNN(nn.Module):
def __init__(self, num_classes=10):
super(SimpleCNN, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=5, stride=1, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(32, 32, kernel_size=5, stride=1, padding=2),
nn.ReLU(inplace=True),
nn.AvgPool2d(kernel_size=3, stride=2),
nn.Conv2d(32, 64, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.AvgPool2d(kernel_size=3, stride=2),
)
self.classifier = nn.Sequential(
nn.Dropout(),
nn.Linear(64 * 4 * 4, 256),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(256, 256),
nn.ReLU(inplace=True),
nn.Linear(256, num_classes),
)
def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 64 * 4 * 4)
x = self.classifier(x)
return x
'''