lh solved (#55)
This commit is contained in:
@@ -5,6 +5,8 @@ from torch.utils.data import DataLoader, default_collate, ConcatDataset
|
||||
|
||||
from .label_tensor import LabelTensor
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
def number_parameters(model, aggregate=True, only_trainable=True): # TODO: check
|
||||
"""
|
||||
@@ -49,6 +51,40 @@ def merge_two_tensors(tensor1, tensor2):
|
||||
return tensor1.append(tensor2)
|
||||
|
||||
|
||||
def torch_lhs(n, dim):
|
||||
"""Latin Hypercube Sampling torch routine.
|
||||
Sampling in range $[0, 1)^d$.
|
||||
|
||||
:param int n: number of samples
|
||||
:param int dim: dimensions of latin hypercube
|
||||
:return: samples
|
||||
:rtype: torch.tensor
|
||||
"""
|
||||
|
||||
if not isinstance(n, int):
|
||||
raise TypeError('number of point n must be int')
|
||||
|
||||
if not isinstance(dim, int):
|
||||
raise TypeError('dim must be int')
|
||||
|
||||
if dim < 1:
|
||||
raise ValueError('dim must be greater than one')
|
||||
|
||||
samples = torch.rand(size=(n, dim))
|
||||
|
||||
perms = torch.tile(torch.arange(1, n + 1), (dim, 1))
|
||||
|
||||
for row in range(dim):
|
||||
idx_perm = torch.randperm(perms.shape[-1])
|
||||
perms[row, :] = perms[row, idx_perm]
|
||||
|
||||
perms = perms.T
|
||||
|
||||
samples = (perms - samples) / n
|
||||
|
||||
return samples
|
||||
|
||||
|
||||
class PinaDataset():
|
||||
|
||||
def __init__(self, pinn) -> None:
|
||||
@@ -108,4 +144,4 @@ class PinaDataset():
|
||||
return {self._location: tensor}
|
||||
|
||||
def __len__(self):
|
||||
return self._len
|
||||
return self._len
|
||||
Reference in New Issue
Block a user