Batch Product AND Layer Theano Neupy / Theano

131 Views Asked by At

How do I implement product AND in Theano? Mathematically that is the equivalent of multiply all of the previous layer (no weights). I think my code works for a batch size of 1 but I want it to work for batches.

Here is what I have tried. Note, I have no clue what I am doing.

Product AND function

def prod_and(result, k):
    elif k[0][0] == 7:
        return theano.tensor.stack([
            [result[i][0] * result[i][1]*\
            result[i][2] * result[i][3]*\
            result[i][4] * result[i][5]*\
            result[i][6]] for i in np.arange(1)
    ])

Product AND Layer

class ProdAnd(layers.BaseLayer):

    # Begin by initializing.
    def initialize(self,):
        super(ProdAnd, self).initialize()

    # Create output from input.
    def output(self, *input_values):
        return prod_and(input_values[0], self.input_shape)

I think that my problem arises from my inability to understand the relationship between neupy types (example what is connecting neupy layers {layers.0}). Also I don't think that I understand how Theano implements batch differently than stochastic.

Ideally the best answer would include the fix to the product and function as well as an explanation on how inputs and outputs work in this particular example.

Demonstration

An example where you would use this is a fuzzy-neuro network that utilizes Takagi-Sugeno style fuzzy inference (look at layer 5).

enter image description here

Im trying to make the problem easy so I broke it down into simply multiplying all of the input of the previous layer.

The equation is given by:

enter image description here

where x is the input layer and y is the output layer. Differentiating with respect to each variables leaves the other variable from the previous layer (so it is not a difficult computation).

0

There are 0 best solutions below