keras: multiple w_constraints
<p>I want a set of weights to be constrained to have a fixed norm (as in <code>unitnorm</code>) and non-negative values (as in <code>nonneg</code>).  This pair of constraints is useful in some kinds of optical modeling.</p>

<p>I'm not a Python expert, so I tried <code>W_constraint = nonneg(), W_constraint = maxnorm(1))</code> and got <code>SyntaxError: keyword argument repeated</code>.  Is there a better way?  Thanks in advance!</p>

<p>If you look at the topology.py file in the keras source code it has a property:</p>

<pre><code>    @property
def constraints(self):
    cons = {}
    for layer in self.layers:
        for key, value in layer.constraints.items():
            if key in cons:
                raise Exception('Received multiple constraints '
                                'for one weight tensor: ' + str(key))
            cons[key] = value
    return cons
</code></pre>

<p>which raises an exception when multiple constraints are received for one weight tensor. I think the best way to do this would be to implement a custom constraint (say nonneg_and_maxnorm?), you can see examples of implemented constraints in constraints.py in the keras source code.</p>

python constraints keras