-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #621 ### Summary of Changes added input and output conversion Interface also added this functionality for Table --------- Co-authored-by: Alexander Gréus <alexgreus51@gmail.com> Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com> Co-authored-by: WinPlay02 <winplay02_gh@woberlaender.de> Co-authored-by: Simon <s6snbreu@uni-bonn.de> Co-authored-by: Simon Breuer <86068340+sibre28@users.noreply.github.com>
- Loading branch information
1 parent
e01ad89
commit fd723f7
Showing
12 changed files
with
384 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING, Generic, TypeVar | ||
|
||
if TYPE_CHECKING: | ||
from torch.utils.data import DataLoader | ||
|
||
from safeds.data.tabular.containers import Table, TaggedTable, TimeSeries | ||
|
||
FT = TypeVar("FT", TaggedTable, TimeSeries) | ||
PT = TypeVar("PT", Table, TimeSeries) | ||
|
||
|
||
class _InputConversion(Generic[FT, PT], ABC): | ||
"""The input conversion for a neural network, defines the input parameters for the neural network.""" | ||
|
||
@property | ||
@abstractmethod | ||
def _data_size(self) -> int: | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def _data_conversion_fit(self, input_data: FT, batch_size: int, num_of_classes: int = 1) -> DataLoader: | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def _data_conversion_predict(self, input_data: PT, batch_size: int) -> DataLoader: | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def _is_fit_data_valid(self, input_data: FT) -> bool: | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def _is_predict_data_valid(self, input_data: PT) -> bool: | ||
pass # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from torch.utils.data import DataLoader | ||
|
||
from safeds.data.tabular.containers import Table, TaggedTable | ||
from safeds.ml.nn._input_conversion import _InputConversion | ||
|
||
|
||
class InputConversionTable(_InputConversion[TaggedTable, Table]): | ||
"""The input conversion for a neural network, defines the input parameters for the neural network.""" | ||
|
||
def __init__(self, feature_names: list[str], target_name: str) -> None: | ||
""" | ||
Define the input parameters for the neural network in the input conversion. | ||
Parameters | ||
---------- | ||
feature_names | ||
The names of the features for the input table, used as features for the training. | ||
target_name | ||
The name of the target for the input table, used as target for the training. | ||
""" | ||
self._feature_names = feature_names | ||
self._target_name = target_name | ||
|
||
@property | ||
def _data_size(self) -> int: | ||
return len(self._feature_names) | ||
|
||
def _data_conversion_fit(self, input_data: TaggedTable, batch_size: int, num_of_classes: int = 1) -> DataLoader: | ||
return input_data._into_dataloader_with_classes( | ||
batch_size, | ||
num_of_classes, | ||
) | ||
|
||
def _data_conversion_predict(self, input_data: Table, batch_size: int) -> DataLoader: | ||
return input_data._into_dataloader(batch_size) | ||
|
||
def _is_fit_data_valid(self, input_data: TaggedTable) -> bool: | ||
return (sorted(input_data.features.column_names)).__eq__(sorted(self._feature_names)) | ||
|
||
def _is_predict_data_valid(self, input_data: Table) -> bool: | ||
return (sorted(input_data.column_names)).__eq__(sorted(self._feature_names)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.