You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

regression_dataset.py 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from typing import Any, List, Tuple
  2. from torch.utils.data import Dataset
  3. class RegressionDataset(Dataset):
  4. """
  5. Dataset used for regression task.
  6. Parameters
  7. ----------
  8. X : List[Any]
  9. A list of objects representing the input data.
  10. Y : List[Any]
  11. A list of objects representing the output data.
  12. """
  13. def __init__(self, X: List[Any], Y: List[Any]):
  14. if (not isinstance(X, list)) or (not isinstance(Y, list)):
  15. raise ValueError("X and Y should be of type list.")
  16. if len(X) != len(Y):
  17. raise ValueError("Length of X and Y must be equal.")
  18. self.X = X
  19. self.Y = Y
  20. def __len__(self):
  21. """Return the length of the dataset.
  22. Returns
  23. -------
  24. int
  25. The length of the dataset.
  26. """
  27. return len(self.X)
  28. def __getitem__(self, index: int) -> Tuple[Any, Any]:
  29. """Get an item from the dataset.
  30. Parameters
  31. ----------
  32. index : int
  33. The index of the item to retrieve.
  34. Returns
  35. -------
  36. Tuple[Any, Any]
  37. A tuple containing the input and output data at the specified index.
  38. """
  39. if index >= len(self):
  40. raise ValueError("index range error")
  41. x = self.X[index]
  42. y = self.Y[index]
  43. return x, y

An efficient Python toolkit for Abductive Learning (ABL), a novel paradigm that integrates machine learning and logical reasoning in a unified framework.