src/graphnet/models/task/task.py
def _validate_and_set_transforms(
        self,
        transform_prediction_and_target: Union[Callable, None],
        transform_target: Union[Callable, None],
        transform_inference: Union[Callable, None],
        transform_support: Union[Callable, None],
    ):
        """Assert that a valid combination of transformation arguments are passed and update the corresponding functions"""
        # Checks
        assert not (
            (transform_prediction_and_target is not None)
            and (transform_target is not None)
        ), "Please specify at most one of `transform_prediction_and_target` and `transform_target`"
        assert (transform_target is not None) == (
            transform_inference is not None
        ), "Please specify both `transform_inference` and `transform_target`"

        if transform_target is not None:
            if transform_support is not None:
                assert (
                    len(transform_support) == 2
                ), "Please specify min and max for transformation support."
                x_test = torch.from_numpy(
                    np.linspace(transform_support[0], transform_support[1], 10)
                )
            else:
                x_test = np.logspace(-6, 6, 12 + 1)
                x_test = torch.from_numpy(
                    np.concatenate([-x_test[::-1], [0], x_test])
                )

            # Add feature dimension before inference transformation to make it match the dimensions of a standard prediction. Remove it again before comparison. Temporary
            t_test = torch.unsqueeze(transform_target(x_test), -1)
            t_test = torch.squeeze(transform_inference(t_test), -1)
            valid = torch.isfinite(t_test)

            assert torch.allclose(
                t_test[valid], x_test[valid]
            ), "The provided transforms for targets during training and predictions during inference are not inverse. Please adjust transformation functions or support."
            del x_test, t_test, valid

        # Set transforms
        if transform_prediction_and_target is not None:
            self._transform_prediction_training = (
                transform_prediction_and_target
            )
            self._transform_target = transform_prediction_and_target
        elif transform_target is not None:
            self._transform_prediction_inference = transform_inference
            self._transform_target = transform_target
Assert that a valid combination of transformation arguments are passed and update the corresponding functions
Assert that a valid combination of transformation arguments are passed and update the corresponding functions
Assert that a valid combination of transformation arguments are passed and update the corresponding functions
def _validate_and_set_transforms(
        self,
        transform_prediction_and_target: Union[Callable, None],
        transform_target: Union[Callable, None],
        transform_inference: Union[Callable, None],
        transform_support: Union[Callable, None],
    ):
        assert not (
            (transform_prediction_and_target is not None)
            and (transform_target is not None)
        ), "Please specify at most one of `transform_prediction_and_target` and `transform_target`"
        assert (transform_target is not None) == (
            transform_inference is not None
        ), "Please specify both `transform_inference` and `transform_target`"
        if transform_target is not None:
            if transform_support is not None:
                assert (
                    len(transform_support) == 2
                ), "Please specify min and max for transformation support."
                x_test = torch.from_numpy(
                    np.linspace(transform_support[0], transform_support[1], 10)
                )
            else:
                x_test = np.logspace(-6, 6, 12 + 1)
                x_test = torch.from_numpy(
                    np.concatenate([-x_test[::-1], [0], x_test])
                )
            t_test = torch.unsqueeze(transform_target(x_test), -1)
            t_test = torch.squeeze(transform_inference(t_test), -1)
            valid = torch.isfinite(t_test)
            assert torch.allclose(
                t_test[valid], x_test[valid]
            ), "The provided transforms for targets during training and predictions during inference are not inverse. Please adjust transformation functions or support."
            del x_test, t_test, valid
        if transform_prediction_and_target is not None:
            self._transform_prediction_training = (
                transform_prediction_and_target
            )
            self._transform_target = transform_prediction_and_target
        elif transform_target is not None:
            self._transform_prediction_inference = transform_inference
            self._transform_target = transform_target
def _validate_and_set_transforms ( self , transform_prediction_and_target : Union [ Callable , None ] , transform_target : Union [ Callable , None ] , transform_inference : Union [ Callable , None ] , transform_support : Union [ Callable , None ] , ) : assert not ( ( transform_prediction_and_target is not None ) and ( transform_target is not None ) ) , "Please specify at most one of `transform_prediction_and_target` and `transform_target`" assert ( transform_target is not None ) == ( transform_inference is not None ) , "Please specify both `transform_inference` and `transform_target`" if transform_target is not None : if transform_support is not None : assert ( len ( transform_support ) == 2 ) , "Please specify min and max for transformation support." x_test = torch . from_numpy ( np . linspace ( transform_support [ 0 ] , transform_support [ 1 ] , 10 ) ) else : x_test = np . logspace ( - 6 , 6 , 12 + 1 ) x_test = torch . from_numpy ( np . concatenate ( [ - x_test [ : : - 1 ] , [ 0 ] , x_test ] ) ) t_test = torch . unsqueeze ( transform_target ( x_test ) , - 1 ) t_test = torch . squeeze ( transform_inference ( t_test ) , - 1 ) valid = torch . isfinite ( t_test ) assert torch . allclose ( t_test [ valid ] , x_test [ valid ] ) , "The provided transforms for targets during training and predictions during inference are not inverse. Please adjust transformation functions or support." del x_test , t_test , valid if transform_prediction_and_target is not None : self . _transform_prediction_training = ( transform_prediction_and_target ) self . _transform_target = transform_prediction_and_target elif transform_target is not None : self . _transform_prediction_inference = transform_inference self . _transform_target = transform_target
Assert that a valid combination of transformation arguments are passed and update the corresponding functions
Assert that a valid combination of transformation arguments are passed and update the corresponding functions
"""Assert that a valid combination of transformation arguments are passed and update the corresponding functions""" # Checks # Add feature dimension before inference transformation to make it match the dimensions of a standard prediction. Remove it again before comparison. Temporary # Set transforms
self
transform_prediction_and_target
Union[Callable, None]
transform_target
Union[Callable, None]
transform_inference
Union[Callable, None]
transform_support
Union[Callable, None]