(self, in_features, out_features,
num_hidden_layers, hidden_features,
outermost_linear=False, nonlinearity='relu',
weight_init=None, w0=30, set_bias=None,
dropout=0.0)
| 669 | Can be used just as a normal neural network though, as well. |
| 670 | ''' |
| 671 | def __init__(self, in_features, out_features, |
| 672 | num_hidden_layers, hidden_features, |
| 673 | outermost_linear=False, nonlinearity='relu', |
| 674 | weight_init=None, w0=30, set_bias=None, |
| 675 | dropout=0.0): |
| 676 | super().__init__() |
| 677 | |
| 678 | self.first_layer_init = None |
| 679 | self.dropout = dropout |
| 680 | |
| 681 | # Create hidden features list |
| 682 | if not isinstance(hidden_features, list): |
| 683 | num_hidden_features = hidden_features |
| 684 | hidden_features = [] |
| 685 | for i in range(num_hidden_layers+1): |
| 686 | hidden_features.append(num_hidden_features) |
| 687 | else: |
| 688 | num_hidden_layers = len(hidden_features)-1 |
| 689 | print(f"net_size={hidden_features}") |
| 690 | |
| 691 | # Create the net |
| 692 | print(f"num_layers={len(hidden_features)}") |
| 693 | if isinstance(nonlinearity, list): |
| 694 | print(f"num_non_lin={len(nonlinearity)}") |
| 695 | assert len(hidden_features) == len(nonlinearity), "Num hidden layers needs to " \ |
| 696 | "match the length of the list of non-linearities" |
| 697 | |
| 698 | self.net = [] |
| 699 | self.net.append(nn.Sequential( |
| 700 | nn.Linear(in_features, hidden_features[0]), |
| 701 | layer_factory(nonlinearity[0])[0] |
| 702 | )) |
| 703 | for i in range(num_hidden_layers): |
| 704 | self.net.append(nn.Sequential( |
| 705 | nn.Linear(hidden_features[i], hidden_features[i+1]), |
| 706 | layer_factory(nonlinearity[i+1])[0] |
| 707 | )) |
| 708 | |
| 709 | if outermost_linear: |
| 710 | self.net.append(nn.Sequential( |
| 711 | nn.Linear(hidden_features[-1], out_features), |
| 712 | )) |
| 713 | else: |
| 714 | self.net.append(nn.Sequential( |
| 715 | nn.Linear(hidden_features[-1], out_features), |
| 716 | layer_factory(nonlinearity[-1])[0] |
| 717 | )) |
| 718 | elif isinstance(nonlinearity, str): |
| 719 | nl, weight_init = layer_factory(nonlinearity, w0=w0) |
| 720 | if(nonlinearity == 'sine'): |
| 721 | first_nl = FirstSine(w0=w0) |
| 722 | self.first_layer_init = first_layer_sine_init |
| 723 | else: |
| 724 | first_nl = nl |
| 725 | |
| 726 | if weight_init is not None: |
| 727 | self.weight_init = weight_init |
| 728 |
nothing calls this directly
no test coverage detected