Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
python
MLglideSolver.py
Go to the documentation of this file.
1
import
os
2
os.environ[
"DGLBACKEND"
] =
"pytorch"
3
import
math
4
import
numpy
as
np
5
import
sys
6
import
torch
7
import
torch.nn
as
nn
8
import
torchvision
9
import
dgl
10
import
dgl.data
11
import
torch.nn.functional
as
F
12
from
dgl.nn
import
GraphConv
13
import
vtk
14
15
# dglContainer Class
16
# Linking a Machine Learning Model to the c++
17
class
GCN
(nn.Module):
18
def
__init__
(self, in_feats, h_feats, num_classes):
19
super(GCN, self).
__init__
()
20
self.
conv1
= GraphConv(in_feats, h_feats)
21
self.
conv2
= GraphConv(h_feats, num_classes)
22
23
def
forward
(self, g, in_feat):
24
h = self.
conv1
(g, in_feat)
25
h = F.relu(h)
26
h = self.
conv2
(g, h)
27
return
h
28
29
def
passing
(self):
30
src_ids = torch.tensor([1, 2, 3, 4])
# Source nodes for edges
31
dst_ids = torch.tensor([0, 1, 2, 3])
# Destination nodes for edges
32
g2 = dgl.graph((src_ids, dst_ids))
33
l = torch.randn(5,5)
34
g2 = dgl.add_self_loop(g2)
35
return
self.
forward
(g2,l)
36
37
def
dglgraph
():
38
graph =
GCN
(5, 16, 2)
#Create the model with given dimensions
39
return
graph
40
41
42
# MultContainer Class
43
def
mult
(A,B):
44
result = np.matmul(A,B)
45
return
result
46
MLglideSolver.GCN
Definition
MLglideSolver.py:17
MLglideSolver.GCN.forward
forward(self, g, in_feat)
Definition
MLglideSolver.py:23
MLglideSolver.GCN.conv2
conv2
Definition
MLglideSolver.py:21
MLglideSolver.GCN.conv1
conv1
Definition
MLglideSolver.py:20
MLglideSolver.GCN.passing
passing(self)
Definition
MLglideSolver.py:29
MLglideSolver.GCN.__init__
__init__(self, in_feats, h_feats, num_classes)
Definition
MLglideSolver.py:18
MLglideSolver.dglgraph
dglgraph()
Definition
MLglideSolver.py:37
MLglideSolver.mult
mult(A, B)
Definition
MLglideSolver.py:43
Generated by
1.15.0