File size: 1,414 Bytes
ffd9d26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
import torch.nn as nn
import torchvision
from monotonenorm import GroupSort, direct_norm


# GroupSort Neural Networks created using monotonenorm package.
#See https://github.com/niklasnolte/MonotoneNorm for more information

class NN_phi(nn.Module):
    
    def __init__(self,dim_input):
        
        
        super(NN_phi, self).__init__()
        self.linear1=direct_norm(torch.nn.Linear(dim_input,16),kind="two-inf")
        self.group1=GroupSort(16//2)#GroupSort with a grouping size of 2
        self.linear2=direct_norm(torch.nn.Linear(16,32),kind="inf")
        self.group2=GroupSort(32//2)
        self.linear3=direct_norm(torch.nn.Linear(32,1),kind="inf")
    

    def forward(self, x):
        x=self.linear1(x)
        x=self.group1(x)
        x=self.linear2(x)
        x=self.group2(x)
        x=self.linear3(x)
        
        return x
    


class NN_h_RELU(nn.Module):
    def __init__(self,dim_input):
        
        
        super(NN_h_RELU, self).__init__()
        
        
        self.linear1=torch.nn.Linear(dim_input,16)
        self.RELU=torch.nn.ReLU()
        self.linear2=torch.nn.Linear(16,32)
        self.linear3=torch.nn.Linear(32,1)
            
            
            

    def forward(self, x):
        x=self.linear1(x)
        x=self.RELU(x)
        x=self.linear2(x)
        x=self.RELU(x)
        x=self.linear3(x)
            
        return x