Ensembles of NN's

IN=7
HU=35
model=nn.Sequential(nn.Linear(IN,HU),nn.Dropout(p=0.1),
                    nn.ReLU(),
                    nn.Linear(HU,HU),
                    nn.ReLU(),
                    nn.Linear(HU,HU),
                    nn.ReLU(),
                    nn.Linear(HU,IN),nn.Dropout(p=0.1),
                    nn.ReLU(),
                    nn.Linear(IN,1))

def create_ensembles(num):
    ensembles=[model for i in range(num)]
    
    return ensembles

ensembles=create ensembles(10)

Does this create 10 isolated neural networks that can be trained by looping? Or these are connected? I want to train these and use majority voting for classification.

Hi Akt!

Your code creates only a single neural network.

This is really a python question rather than about pytorch in particular.

Your create_ensembles() creates a list (using a list comprehension)
that contains num references that all refer to the same model.

You first instantiate a single instance of a Sequential (and then
assign it to the reference model). create_ensembles() then makes
10 copies of that same reference and puts them in a list.

Here is some pure python (no pytorch) that illustrates what is going on:

>>> dict = {}     # make an instance of something
>>> l = [dict for i in range (5)]
>>> for i in l:   # all elements of the list refer to the same instance
...     print (id (l))
...
139963655730048
139963655730048
139963655730048
139963655730048
139963655730048

What you would want to do instead is package your desired network
architecture as python class, and then instantiate num instances of
your network class.

This tutorial, PyTorch: Custom nn Modules, gives an example of defining
such a class.

Good luck.

K. Frank