Skip to content

Commit

Permalink
Add fix_values option
Browse files Browse the repository at this point in the history
  • Loading branch information
pbloem committed Apr 26, 2018
1 parent 8ae1dda commit 044530d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions g1vae.experiment.py
Expand Up @@ -136,7 +136,7 @@ def generate_er(n=128, m=512, num=64):
SIZE = 60000
PLOT = True

def go(nodes=128, links=512, batch=64, epochs=350, k=750, kpe=7, additional=512, modelname='baseline', cuda=False, seed=1, bias=True, lr=0.001, lambd=0.01, subsample=None):
def go(nodes=128, links=512, batch=64, epochs=350, k=750, kpe=7, additional=512, modelname='baseline', cuda=False, seed=1, bias=True, lr=0.001, lambd=0.01, subsample=None, fix_values=False):

FT = torch.cuda.FloatTensor if cuda else torch.FloatTensor

Expand All @@ -154,9 +154,10 @@ def go(nodes=128, links=512, batch=64, epochs=350, k=750, kpe=7, additional=512,

zsize = 256

encoder = GraphASHLayer(nodes, (zsize * 2, ), k=kpe, additional=additional, subsample=subsample)
encoder = GraphASHLayer(nodes, (zsize * 2, ), k=kpe, additional=additional, subsample=subsample, fix_values=fix_values)

decoder = gaussian.CASHLayer((1, zsize), SHAPE, poolsize=1, k=k, additional=additional, has_bias=bias, has_channels=True, adaptive_bias=False, subsample=subsample)
decoder = gaussian.CASHLayer((1, zsize), SHAPE, poolsize=1, k=k, additional=additional, has_bias=bias,
has_channels=True, adaptive_bias=False, subsample=subsample, fix_values=fix_values)

if cuda:
encoder.cuda()
Expand Down Expand Up @@ -292,11 +293,15 @@ def go(nodes=128, links=512, batch=64, epochs=350, k=750, kpe=7, additional=512,
help="Sample a subset of the indices to estimate gradients for",
default=None, type=float)

parser.add_argument("-F", "--fix-values", dest="fix_values",
help="Whather to force the values to be 1",
action="store_true")

options = parser.parse_args()

print('OPTIONS ', options)
LOG.info('OPTIONS ' + str(options))

go(batch=options.batch_size, nodes=options.nodes, links=options.links, k=options.k, kpe=options.kpe, bias=options.bias,
additional=options.additional, modelname=options.model, cuda=options.cuda,
lr=options.lr, lambd=options.lambd, subsample=options.subsample)
lr=options.lr, lambd=options.lambd, subsample=options.subsample, fix_values=options.fix_values)
6 changes: 5 additions & 1 deletion gaussian.py
Expand Up @@ -904,7 +904,7 @@ class CASHLayer(HyperLayer):
"""
def __init__(self, in_shape, out_shape, k,
additional=0, poolsize=4, deconvs=2, ksize=2, sigma_scale=0.1, has_bias=True,
has_channels=False, adaptive_bias=False, subsample=None, min_sigma=0.0):
has_channels=False, adaptive_bias=False, subsample=None, min_sigma=0.0, fix_values=False):
"""
:param in_shape:
:param out_shape:
Expand All @@ -930,6 +930,7 @@ def forward(self, input):
self.sigma_scale = sigma_scale
self.has_channels = has_channels
self.adaptive_bias = adaptive_bias
self.fix_values = fix_values

self.w_rank = len(in_shape) + len(out_shape)

Expand Down Expand Up @@ -1009,6 +1010,9 @@ def hyper(self, input):
means, sigmas, values = self.split_out(res, input.size()[1:], self.out_shape)
sigmas = sigmas * self.sigma_scale

if self.fix_values:
values = values * 0.0 + 1.0

if not self.has_bias:
return means, sigmas, values
if self.adaptive_bias:
Expand Down

0 comments on commit 044530d

Please sign in to comment.