Clifford models¤
We provide exemplary 2D and 3D Clifford models as used in the paper.
All these modules are available for different algebras.
2D models¤
The following code snippet initializes a 2D Clifford ResNet.
import torch.nn.functional as F
from cliffordlayers.models.basic.twod import (
CliffordFluidNet2d,
CliffordBasicBlock2d,
)
model = CliffordFluidNet2d(
g = [-1, -1],
block = CliffordBasicBlock2d,
num_blocks = [2, 2, 2, 2],
in_channels = in_channels,
out_channels = out_channels,
hidden_channels = 32,
activation = F.gelu,
norm = True,
rotation = False,
)
The following code snippet initializes a 2D rotational Clifford ResNet.
import torch.nn.functional as F
from cliffordlayers.models.basic.twod import (
CliffordFluidNet2d,
CliffordBasicBlock2d,
)
model = CliffordNet2d(
g = [-1, -1],
block = CliffordBasicBlock2d,
num_blocks = [2, 2, 2, 2],
in_channels = in_channels,
out_channels = out_channels,
hidden_channels = 32,
activation = F.gelu,
norm = True,
rotation = True,
)
The following code snippet initializes a 2D Clifford FNO.
import torch.nn.functional as F
from cliffordlayers.models.utils import partialclass
from cliffordlayers.models.basic.twod import (
CliffordFluidNet2d,
CliffordFourierBasicBlock2d,
)
model = CliffordFluidNet2d(
g = [-1, -1],
block = partialclass(
"CliffordFourierBasicBlock2d", CliffordFourierBasicBlock2d, modes1=32, modes2=32
),
num_blocks = [1, 1, 1, 1],
in_channels = in_channels,
out_channels = out_channels,
hidden_channels = 32,
activation = F.gelu,
norm = False,
rotation = False,
)
CliffordBasicBlock2d
¤
Bases: Module
2D building block for Clifford ResNet architectures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
gelu
|
kernel_size |
int
|
Kernel size of Clifford convolution. Defaults to 3. |
3
|
stride |
int
|
Stride of Clifford convolution. Defaults to 1. |
1
|
padding |
int
|
Padding of Clifford convolution. Defaults to 1. |
1
|
rotation |
bool
|
Wether to use rotational Clifford convolution. Defaults to False. |
False
|
norm |
bool
|
Wether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/basic/twod.py
CliffordFluidNet2d
¤
Bases: Module
2D building block for Clifford architectures for fluid mechanics (vector field+scalar field) with ResNet backbone network. The backbone networks follows these three steps: 1. Clifford scalar+vector field encoding. 2. Basic blocks as provided. 3. Clifford scalar+vector field decoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
block |
Module
|
Choice of basic blocks. |
required |
num_blocks |
list
|
List of basic blocks in each residual block. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
required |
rotation |
bool
|
Wether to use rotational Clifford convolution. Defaults to False. |
required |
norm |
bool
|
Wether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/basic/twod.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
CliffordFourierBasicBlock2d
¤
Bases: Module
2D building block for Clifford FNO architectures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
gelu
|
kernel_size |
int
|
Kernel size of Clifford convolution. Defaults to 3. |
1
|
stride |
int
|
Stride of Clifford convolution. Defaults to 1. |
1
|
padding |
int
|
Padding of Clifford convolution. Defaults to 1. |
0
|
rotation |
bool
|
Wether to use rotational Clifford convolution. Defaults to False. |
False
|
norm |
bool
|
Wether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
modes1 |
int
|
Number of Fourier modes in the first dimension. Defaults to 16. |
16
|
modes2 |
int
|
Number of Fourier modes in the second dimension. Defaults to 16. |
16
|
Source code in cliffordlayers/models/basic/twod.py
CliffordG3BasicBlock2d
¤
Bases: Module
Basic block for G3 convolutions on 2D grids, comprising two G3 Clifford convolutional layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
kernel_size |
int
|
Size of the convolutional kernel. Defaults to 3. |
3
|
stride |
int
|
Stride of the convolution operation. Defaults to 1. |
1
|
padding |
int
|
Padding added to both sides of the input. Defaults to 1. |
1
|
activation |
str
|
Type of activation function. Defaults to "vlin". |
'vlin'
|
norm |
bool
|
If True, normalization is applied. Defaults to True. |
True
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
Source code in cliffordlayers/models/gca/twod.py
CliffordG3DownBlock
¤
Bases: Module
UNet encoder block for G3 Clifford convolutions on 2D grids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
str
|
Type of activation function. |
required |
norm |
bool
|
If True, normalization is applied. Defaults to False. |
False
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/gca/twod.py
CliffordG3Downsample
¤
Bases: Module
Scale down the two-dimensional G3 Clifford feature map by a half.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels. |
required |
Source code in cliffordlayers/models/gca/twod.py
CliffordG3MiddleBlock
¤
Bases: Module
UNet middle block for G3 Clifford convolutions on 2D grids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels. |
required |
activation |
str
|
Type of activation function. |
required |
norm |
bool
|
If True, normalization is applied. Defaults to False. |
False
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/gca/twod.py
CliffordG3ResNet2d
¤
Bases: Module
ResNet for G3 Clifford convolutions on 2D grids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_blocks |
list
|
Number of blocks at each resolution. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
hidden_channels |
int
|
Number of hidden channels. |
required |
activation |
str
|
Type of activation function. Defaults to "vlin". |
'vlin'
|
block |
Module
|
Type of block. Defaults to CliffordG3BasicBlock2d. |
CliffordG3BasicBlock2d
|
norm |
bool
|
If True, normalization is applied. Defaults to True. |
False
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
Source code in cliffordlayers/models/gca/twod.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
CliffordG3UNet2d
¤
Bases: Module
U-Net architecture with Clifford G3 convolutions for 2D grids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
hidden_channels |
int
|
Number of channels in the first hidden convolutional layer. |
required |
activation |
str
|
Type of activation function. Defaults to "vlin". |
'vlin'
|
norm |
bool
|
If True, normalization is applied. Defaults to False. |
False
|
ch_mults |
Union[Tuple[int, ...], List[int]]
|
Multipliers for the number of channels at each depth. Defaults to (1, 2, 2, 2). |
(1, 2, 2, 2)
|
n_blocks |
int
|
Number of convolutional blocks at each resolution. Defaults to 2. |
2
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/gca/twod.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|
CliffordG3UpBlock
¤
Bases: Module
UNet decoder block for G3 Clifford convolutions on 2D grids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
str
|
Type of activation function. |
required |
norm |
bool
|
If True, normalization is applied. Defaults to False. |
False
|
prenorm |
bool
|
If True, normalization is applied before activation, otherwise after. Defaults to True. |
True
|
num_groups |
int
|
Number of groups for the group normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/gca/twod.py
CliffordUpsample
¤
Bases: Module
Scale up the two-dimensional G3 Clifford feature map by a factor of two.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_channels |
int
|
Number of channels. |
required |
Source code in cliffordlayers/models/gca/twod.py
3D models¤
The following code snippet initializes a 3D Clifford FNO.
import torch.nn.functional as F
from cliffordlayers.models.models_3d import (
CliffordMaxwellNet3d,
CliffordFourierBasicBlock3d,
)
model = CliffordMaxwellNet3d(
g = [1, 1, 1],
block = CliffordFourierBasicBlock3d,
num_blocks = [1, 1, 1, 1],
in_channels = 4,
out_channels = 1,
hidden_channels = 16,
activation = F.gelu,
norm = False,
)
CliffordFourierBasicBlock3d
¤
Bases: Module
3D building block for Clifford FNO architectures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
gelu
|
kernel_size |
int
|
Kernel size of Clifford convolution. Defaults to 3. |
1
|
stride |
int
|
Stride of Clifford convolution. Defaults to 1. |
1
|
padding |
int
|
Padding of Clifford convolution. Defaults to 1. |
0
|
norm |
bool
|
Wether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
modes1 |
int
|
Number of Fourier modes in the first dimension. Defaults to 8. |
8
|
modes2 |
int
|
Number of Fourier modes in the second dimension. Defaults to 8. |
8
|
modes3 |
int
|
Number of Fourier modes in the third dimension. Defaults to 8. |
8
|
Source code in cliffordlayers/models/basic/threed.py
CliffordMaxwellNet3d
¤
Bases: Module
3D building block for Clifford architectures with ResNet backbone network. The backbone networks follows these three steps: 1. Clifford vector+bivector encoding. 2. Basic blocks as provided. 3. Clifford vector+bivector decoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
Union[tuple, list, Tensor]
|
Signature of Clifford algebra. |
required |
block |
Module
|
Choice of basic blocks. |
required |
num_blocks |
list
|
List of basic blocks in each residual block. |
required |
in_channels |
int
|
Number of input channels. |
required |
out_channels |
int
|
Number of output channels. |
required |
activation |
Callable
|
Activation function. Defaults to F.gelu. |
required |
norm |
bool
|
Wether to use Clifford (group) normalization. Defaults to False. |
False
|
num_groups |
int
|
Number of groups when using Clifford (group) normalization. Defaults to 1. |
1
|
Source code in cliffordlayers/models/basic/threed.py
82 83 84 85 86 87 88 89 90 91 92 93 94 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|