-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodel.py
More file actions
23 lines (20 loc) · 652 Bytes
/
model.py
File metadata and controls
23 lines (20 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
import torch.nn as nn
# ------------------------------
# ENERGY-BASED MODEL
# ------------------------------
class EBM(nn.Module):
def __init__(self, dim=2):
super(EBM, self).__init__()
# The normalizing constant logZ(θ)
self.c = nn.Parameter(torch.tensor([1.], requires_grad=True))
self.f = nn.Sequential(
nn.Linear(dim, 128),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(128, 128),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(128, 1),
)
def forward(self, x):
log_p = - self.f(x) - self.c
return log_p