Skip to content

Commit

Permalink
added bias to convolution, improved init of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-krill committed Jul 26, 2024
1 parent 1e85f02 commit 6888bbf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/UQpy/scientific_machine_learning/layers/Fourier1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
:math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
where :math:`k = \frac{1}{\text{width}}`"""
self.bias_conv: nn.Parameter = nn.Parameter(
torch.empty(self.width, self.width, kernel_size, device=device)
torch.empty(self.width, device=device)
)
r"""The learnable bias of the convolution of shape :math:`(\text{width})`.
Expand All @@ -71,7 +71,7 @@ def __init__(
where :math:`k = \frac{1}{\text{width}}`
"""

k = torch.sqrt(1 / width)
k = torch.sqrt(1 / torch.tensor(self.width, device=device))
self.reset_parameters(-k, k)

def forward(self, x: torch.Tensor) -> torch.Tensor:
Expand Down
2 changes: 1 addition & 1 deletion src/UQpy/scientific_machine_learning/layers/Fourier2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
)
r"""The learnable bias of the convolution of shape :math:`(\text{width})`."""

k = torch.sqrt(1 / self.width)
k = torch.sqrt(1 / torch.tensor(self.width, device=device))
self.reset_parameters(-k, k)

def forward(self, x: torch.Tensor) -> torch.Tensor:
Expand Down
4 changes: 2 additions & 2 deletions src/UQpy/scientific_machine_learning/layers/Fourier3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
:math:`(\text{width}, \text{width}, \text{modes[0]}, \text{modes[1]}, \text{modes[2]})`
with complex entries"""
self.weight_spectral_2: nn.Parameter = nn.Parameter(
self.scale * torch.rand(shape, dtype=torch.cfloat, device=device)
torch.empty(shape, dtype=torch.cfloat, device=device)
)
r"""The second of four learnable weights for the spectral convolution of shape
:math:`(\text{width}, \text{width}, \text{modes[0]}, \text{modes[1]}, \text{modes[2]})`
Expand All @@ -76,7 +76,7 @@ def __init__(
torch.empty(self.width, device=device)
)
r"""The learnable bias of the convolution of shape :math:`(\text{out_channels})`"""
k = torch.sqrt(1 / self.width)
k = torch.sqrt(1 / torch.tensor(self.width, device=device))
self.reset_parameters(-k, k)

def forward(self, x: torch.Tensor) -> torch.Tensor:
Expand Down

0 comments on commit 6888bbf

Please sign in to comment.