[docs]@define(frozen=True,slots=False)classCustomDiscreteParameter(DiscreteParameter):"""Custom parameters. For these parameters, the user can read in a precomputed representation for labels, e.g. from quantum chemistry. """# class variablesis_numerical:ClassVar[bool]=False# See base class.# object variablesdata:pd.DataFrame=field(validator=min_len(2),eq=eq_dataframe)"""A mapping that provides the encoding for all available parameter values."""decorrelate:bool|float=field(default=True,validator=validate_decorrelation)"""Specifies the used decorrelation mode for the parameter encoding. - ``False``: The encoding is used as is. - ``True``: The encoding is decorrelated using a default correlation threshold. - float in (0, 1): The encoding is decorrelated using the specified threshold. """encoding:CustomEncoding=field(init=False,default=CustomEncoding.CUSTOM)# See base class.@data.validatordef_validate_custom_data(# noqa: DOC101, DOC103self,_:Any,value:pd.DataFrame)->None:"""Validate the dataframe with the custom representation. Raises: ValueError: If the dataframe contains non-numeric values. ValueError: If the dataframe index contains non-string values. ValueError: If the dataframe index contains empty strings. ValueError: If the dataframe contains ``NaN``. ValueError: If the dataframe index contains duplicates. ValueError: If the dataframe contains columns with only one unique value. """ifvalue.select_dtypes("number").shape[1]!=value.shape[1]:raiseValueError(f"The custom dataframe for parameter {self.name} contains "f"non-numeric values.")ifnotall(isinstance(x,str)forxinvalue.index):raiseValueError(f"The custom dataframe for parameter {self.name} contains non-string "f"index values.")ifnotall(len(x)>0forxinvalue.index):raiseValueError(f"The custom dataframe for parameter {self.name} contains empty string "f"index values.")ifnotnp.isfinite(value.values).all():raiseValueError(f"The custom dataframe for parameter {self.name} contains nan/infinity "f"entries.")iflen(value)!=len(set(value.index)):raiseValueError(f"The custom dataframe for parameter {self.name} contains "f"duplicated indices.")ifany(value.nunique()==1):raiseValueError(f"The custom dataframe for parameter {self.name} has columns ""that contain only a single value and hence carry no information.")@propertydefvalues(self)->tuple:"""Returns the representing labels of the parameter."""returntuple(self.data.index)@cached_propertydefcomp_df(self)->pd.DataFrame:# noqa: D102# See base class.# The encoding is directly provided by the user# We prepend the parameter name to the columns names to avoid potential# conflicts with other parameterscomp_df=self.data.rename(columns=lambdax:f"{self.name}_{x}").astype(DTypeFloatNumpy)# Get a decorrelated subset of the provided featuresifself.decorrelate:ifisinstance(self.decorrelate,bool):comp_df=df_uncorrelated_features(comp_df)else:comp_df=df_uncorrelated_features(comp_df,threshold=self.decorrelate)returncomp_df