Skip to content

Commit

Permalink
Add Monotonic function toy example
Browse files Browse the repository at this point in the history
  • Loading branch information
AWehenkel committed Jan 25, 2020
1 parent 7404356 commit df673c7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions models/UMNN/UMNNMAF.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import math
from .made import MADE, ConditionnalMADE

dict_act_func = {"Sigmoid": nn.Sigmoid(), "ELU": nn.ELU()}
dict_act_func = {"Sigmoid": nn.Sigmoid(), "ELU": lambda x: nn.ELU(x) + 1.}

def _flatten(sequence):
flat = [p.contiguous().view(-1) for p in sequence]
Expand Down Expand Up @@ -219,7 +219,7 @@ def force_lipschitz(self, L=1.5):

class EmbeddingNetwork(nn.Module):
def __init__(self, in_d, hiddens_embedding=[50, 50, 50, 50], hiddens_integrand=[50, 50, 50, 50], out_made=1,
cond_in=0, device="cpu"):
cond_in=0, act_func='ELU', device="cpu"):
super().__init__()
self.m_embeding = None
self.device = device
Expand All @@ -229,7 +229,7 @@ def __init__(self, in_d, hiddens_embedding=[50, 50, 50, 50], hiddens_integrand=[
natural_ordering=True).to(device)
else:
self.made = MADE(in_d, hiddens_embedding, in_d * (out_made), num_masks=1, natural_ordering=True).to(device)
self.parallel_nets = IntegrandNetwork(in_d, 1 + out_made, hiddens_integrand, 1, device=device)
self.parallel_nets = IntegrandNetwork(in_d, 1 + out_made, hiddens_integrand, 1, act_func=act_func, device=device)

def make_embeding(self, x_made, context=None):
self.m_embeding = self.made.forward(x_made, context)
Expand Down
4 changes: 2 additions & 2 deletions models/UMNN/UMNNMAFFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __getitem__(self, i):
class UMNNMAFFlow(nn.Module):

def __init__(self, nb_flow=1, nb_in=1, hidden_derivative=[50, 50, 50, 50], hidden_embedding=[50, 50, 50, 50],
embedding_s=20, nb_steps=50, solver="CC", cond_in=0, device="cpu"):
embedding_s=20, nb_steps=50, act_func='ELU', solver="CC", cond_in=0, device="cpu"):
"""
UMNNMAFFlow class is a normalizing flow made of UMNNMAF blocks.
:int nb_flow: The number of components in the flow
Expand All @@ -57,7 +57,7 @@ def __init__(self, nb_flow=1, nb_in=1, hidden_derivative=[50, 50, 50, 50], hidde

self.nets = ListModule(self, "Flow")
for i in range(nb_flow):
auto_net = EmbeddingNetwork(nb_in, hidden_embedding, hidden_derivative, embedding_s,
auto_net = EmbeddingNetwork(nb_in, hidden_embedding, hidden_derivative, embedding_s, act_func='ELU',
device=device, cond_in=cond_in).to(device)

model = UMNNMAF(auto_net, nb_in, nb_steps, device, solver=solver).to(device)
Expand Down
3 changes: 2 additions & 1 deletion models/UMNN/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .UMNNMAFFlow import UMNNMAFFlow
from .MonotonicNN import MonotonicNN, IntegrandNN
from .MonotonicNN import MonotonicNN, IntegrandNN
from .made import MADE
2 changes: 1 addition & 1 deletion models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from models.UMNN import UMNNMAFFlow
from models.UMNN import UMNNMAFFlow, MADE

0 comments on commit df673c7

Please sign in to comment.