[docs]defstandardize(targets:Union[np.ndarray,Tensor],mean:Union[np.ndarray,Tensor,float],std:Union[np.ndarray,Tensor,float],center_at:Optional[float]=None,)->Union[np.ndarray,Tensor]:"""Standardize the targets to the z-domain."""ifisinstance(targets,np.ndarray):targets=np.log(targets)elifisinstance(targets,Tensor):targets=torch.log(targets)else:raiseValueError(f"Targets must be either Tensor or Numpy array. Received {type(targets)}")standardized=(targets-mean)/stdifcenter_at:standardized-=(center_at-mean)/stdreturnstandardized
[docs]defnormalize(targets:Union[np.ndarray,Tensor],threshold:Union[np.ndarray,Tensor,float])->Union[np.ndarray,Tensor]:"""Normalize the targets by using the cumulative density function."""ifisinstance(targets,Tensor):returnnormalize_torch(targets,threshold)ifisinstance(targets,np.ndarray):returnnormalize_numpy(targets,threshold)raiseValueError(f"Targets must be either Tensor or Numpy array. Received {type(targets)}")
[docs]defnormalize_torch(targets:Tensor,threshold:Tensor)->Tensor:"""Normalize the targets by using the cumulative density function, PyTorch version."""device=targets.deviceimage_threshold=threshold.cpu()dist=Normal(torch.Tensor([0]),torch.Tensor([1]))normalized=dist.cdf(targets.cpu()-image_threshold).to(device)returnnormalized
[docs]defnormalize_numpy(targets:np.ndarray,threshold:Union[np.ndarray,float])->np.ndarray:"""Normalize the targets by using the cumulative density function, Numpy version."""returnnorm.cdf(targets-threshold)