Simulai activations

Activations#

Siren#

Bases: Module

Sinusoidal Representation Networks (SIREN)

Source code in simulai/activations.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Siren(torch.nn.Module):
    """Sinusoidal Representation Networks (SIREN)"""

    name = "Siren"

    def __init__(self, omega_0: float = None, c: float = None) -> None:
        """Initialize SIREN model with given parameters.

        Args:
            omega_0 (float, optional):  (Default value = None)
            c (float, optional):  (Default value = None)
        """

        super(Siren, self).__init__()

        self.omega_0 = omega_0
        self.c = c

    @property
    def share_to_host(self) -> dict:
        """Return the parameters of the SIREN model.


        Returns:
            dict: A dictionary containing the parameters 'omega_0' and 'c'.

        """
        return {"omega_0": self.omega_0, "c": self.c}

    def forward(self, input: torch.Tensor) -> torch.Tensor:
        """Perform the forward pass of the SIREN model on the input.

        Args:
            input (torch.Tensor): The input to the SIREN model.

        Returns:
            torch.Tensor: The output of the SIREN model.

        """
        return torch.sin(self.omega_0 * input)

share_to_host: dict property #

Return the parameters of the SIREN model.

Returns:

Name Type Description
dict dict

A dictionary containing the parameters 'omega_0' and 'c'.

__init__(omega_0=None, c=None) #

Initialize SIREN model with given parameters.

Parameters:

Name Type Description Default
omega_0 float

(Default value = None)

None
c float

(Default value = None)

None
Source code in simulai/activations.py
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(self, omega_0: float = None, c: float = None) -> None:
    """Initialize SIREN model with given parameters.

    Args:
        omega_0 (float, optional):  (Default value = None)
        c (float, optional):  (Default value = None)
    """

    super(Siren, self).__init__()

    self.omega_0 = omega_0
    self.c = c

forward(input) #

Perform the forward pass of the SIREN model on the input.

Parameters:

Name Type Description Default
input Tensor

The input to the SIREN model.

required

Returns:

Type Description
Tensor

torch.Tensor: The output of the SIREN model.

Source code in simulai/activations.py
53
54
55
56
57
58
59
60
61
62
63
def forward(self, input: torch.Tensor) -> torch.Tensor:
    """Perform the forward pass of the SIREN model on the input.

    Args:
        input (torch.Tensor): The input to the SIREN model.

    Returns:
        torch.Tensor: The output of the SIREN model.

    """
    return torch.sin(self.omega_0 * input)

sin#

Bases: Module

Sine activation function.

This module applies the sine function element-wise to the input.

Source code in simulai/activations.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class sin(torch.nn.Module):
    """Sine activation function.

    This module applies the sine function element-wise to the input.

    """

    name = "sin"

    def __init__(self) -> None:
        """Initialize the sine activation function.

        """

        super(sin, self).__init__()

    def forward(self, input: torch.Tensor) -> torch.Tensor:
        """Perform the forward pass of the sine activation function on the input.

        Args:
            input (torch.Tensor): The input to the sine activation function.

        Returns:
            torch.Tensor: The output of the sine activation function.

        """
        return torch.sin(input)

__init__() #

Initialize the sine activation function.

Source code in simulai/activations.py
75
76
77
78
79
80
def __init__(self) -> None:
    """Initialize the sine activation function.

    """

    super(sin, self).__init__()

forward(input) #

Perform the forward pass of the sine activation function on the input.

Parameters:

Name Type Description Default
input Tensor

The input to the sine activation function.

required

Returns:

Type Description
Tensor

torch.Tensor: The output of the sine activation function.

Source code in simulai/activations.py
82
83
84
85
86
87
88
89
90
91
92
def forward(self, input: torch.Tensor) -> torch.Tensor:
    """Perform the forward pass of the sine activation function on the input.

    Args:
        input (torch.Tensor): The input to the sine activation function.

    Returns:
        torch.Tensor: The output of the sine activation function.

    """
    return torch.sin(input)

Wavelet#

Bases: TrainableActivation

Wavelet activation

Source code in simulai/activations.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class Wavelet(TrainableActivation):
    """Wavelet activation"""

    name = "wavelet"

    def __init__(self, device:str="cpu") -> None:

        super(Wavelet, self).__init__()

        self.device = device
        self.w1 = torch.nn.Parameter(torch.ones(1).to(self.device), requires_grad=True)
        self.w2 = torch.nn.Parameter(torch.ones(1).to(self.device), requires_grad=True)

    def setup(self, device:str=None) -> None:

        self.w1 = torch.nn.Parameter(torch.ones(1).to(self.device), requires_grad=True)
        self.w2 = torch.nn.Parameter(torch.ones(1).to(self.device), requires_grad=True)

    def forward(self, input: torch.Tensor) -> torch.Tensor:
        """Perform the forward pass of the Wavelet activation on the input.

        Args:
            input (torch.Tensor): The input to the sine activation function.

        Returns:
            torch.Tensor: The output of the sine activation function.

        """

        return self.w1 * torch.sin(input) + self.w2 * torch.cos(input)

forward(input) #

Perform the forward pass of the Wavelet activation on the input.

Parameters:

Name Type Description Default
input Tensor

The input to the sine activation function.

required

Returns:

Type Description
Tensor

torch.Tensor: The output of the sine activation function.

Source code in simulai/activations.py
113
114
115
116
117
118
119
120
121
122
123
124
def forward(self, input: torch.Tensor) -> torch.Tensor:
    """Perform the forward pass of the Wavelet activation on the input.

    Args:
        input (torch.Tensor): The input to the sine activation function.

    Returns:
        torch.Tensor: The output of the sine activation function.

    """

    return self.w1 * torch.sin(input) + self.w2 * torch.cos(input)