cenreg.pytorch package
Submodules
cenreg.pytorch.copula module
cenreg.pytorch.distribution module
- class cenreg.pytorch.distribution.LinearCDF(boundaries: Tensor, values: Tensor = None, apply_cumsum: bool = True)
Bases:
object
Distribution functions with linear interpolation.
A distribution function is represented as a discrete cumulative distribution function (CDF) at pre-defined quantile levels (boundaries). The values between probabilities are computed by using linear interpolation.
If qk_values are two-dimensional tensor, then each row corresponds to a CDF.
- average_cdf(y, mask=None, add_edge=False)
- cdf(y, mask=None, add_edges=False)
Cumulative distribution function (i.e., inverse of quantile function).
- Parameters:
y (Tensor) – CDF values are computed for values y. If dimension of y is one, then cdf(y) is computed for all CDFs. If dimension of y is two, then cdf(y) is computed for each corresponding CDF.
mask (Tensor) – Mask to compute CDF for a subset of CDFs. Tensor must be one-dimensional and its length must be equal to the number of CDFs.
add_edges (bool) – If True, then the CDF values at the boundaries are added.
- Returns:
cdf_values – Compute CDF values for each value in y. Tensor shape is equal to the shape of y.
- Return type:
Tensor
- get_boundary_lengths()
- icdf(alpha, mask=None, add_edges=False)
Quantile function (i.e., inverse of cumulative distribution function).
- Parameters:
alpha (Tensor) – Quantile values are computed for quantile levels alpha. If dimension of alpha is one, then icdf(alpha) is computed for all CDFs. If dimension of alpha is two, then icdf(alpha) is computed for each corresponding CDF.
mask (Tensor) – Mask to compute CDF for a subset of CDFs. Tensor must be one-dimensional and its length must be equal to the number of CDFs.
add_edges (bool) – If True, then the inverse of the CDF values at the boundaries are added.
- Returns:
y – Compute y. Tensor shape is equal to the shape of alpha.
- Return type:
Tensor
- set_knot_values(values, apply_cumsum=True)
Set values of CDF values.
- Parameters:
values (Tensor) – One or two-dimensional tensor containing the values of CDFs. If cdf_values is two-dimensional tensor, then each row corresponds to a CDF and cdf_values[:,j] stores the value of CDF at boundries[j]. Tensor shape must be [num_CDF, len(boundaries)].
apply_cumsum (bool) – If True, then cdf_values is assumed to be the probablity distribution functions (PDFs) and the cumulative sum of cdf_values is computed.
- class cenreg.pytorch.distribution.LinearQuantileFunction(qk_levels: Tensor, qk_values: Tensor = None, apply_cumsum: bool = True)
Bases:
object
Quantile functions with linear interpolation.
A quantile function is defined by a set of quantile values (qk_values) at pre-defined quantile levels (qk_levels). The values between quantile values are computed by using linear interpolation.
If qk_values are two-dimensional tensor, then each row corresponds to a quantile function.
- average_cdf(y, mask=None, add_edge=False)
- cdf(y, mask=None, add_edges=False)
Cumulative distribution function (i.e., inverse of quantile function).
- Parameters:
y (Tensor) – Quantile levels are computed for quantile values y. If dimension of y is one, then cdf(y) is computed for all quantile functions. If dimension of y is two, then cdf(y) is computed for each corresponding quantile function.
mask (Tensor) – Mask to compute quantile function for a subset of quantile functions. Tensor must be one-dimensional and its length must be equal to the number of quantile functions.
add_edges (bool) – If True, then the CDF values at the boundaries are added.
- Returns:
q_levels – Compute quantile levels for each value in y. Tensor shape is equal to the shape of y.
- Return type:
Tensor
- get_qk_lengths()
- icdf(alpha, mask=None, add_edges=False)
Quantile function (i.e., inverse of cumulative distribution function).
- Parameters:
alpha (Tensor) – Quantile values are computed for quantile levels alpha. If dimension of alpha is one, then icdf(alpha) is computed for all quantile functions. If dimension of alpha is two, then icdf(alpha) is computed for each corresponding quantile function.
mask (Tensor) – Mask to compute quantile function for a subset of quantile functions. Tensor must be one-dimensional and its length must be equal to the number of quantile functions.
add_edges (bool) – If True, then the inverse of the CDF values at the boundaries are added.
- Returns:
y – Compute y. Tensor shape is equal to the shape of alpha.
- Return type:
Tensor
- set_knot_values(qk_values, apply_cumsum=True)
Set values of quantile knots.
- Parameters:
qk_values (Tensor) – One or two-dimensional tensor containing the values of quantile knots. If qk_values is two-dimensional tensor, then each row corresponds to a quantile function and qk_values[:,j] stores the value of quantile function at qk_levels[j]. Tensor shape must be [num_quantile_function, len(qk_levels)].
apply_cumsum (bool) – If True, then qk_values is assumed to be the differences of quantile values and the cumulative sum of qk_values is computed.
cenreg.pytorch.jd2marginal module
cenreg.pytorch.loss_function_cont module
cenreg.pytorch.loss_function_dr module
cenreg.pytorch.loss_function_jd module
cenreg.pytorch.loss_function_jd2m module
cenreg.pytorch.mlp module
- class cenreg.pytorch.mlp.Linear(output_len: int)
Bases:
Module
Single Layer Perceptron
- forward(x: Tensor)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cenreg.pytorch.mlp.MLP(input_len: int, output_len: int, num_neuron: int)
Bases:
Module
Multi Layer Perceptron
- forward(x: Tensor)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cenreg.pytorch.mlp.MLP_MultiHead(input_len: int, output_len: int, output_num: int, num_neuron: int, use_softmax: bool = True)
Bases:
Module
Multi Layer Perceptron with Multiple Outputs
- forward(x: Tensor)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cenreg.pytorch.mlp.SMM(embed_size: int)
Bases:
Module
Fully monotonic neural network. The output y is a function of input x, and the function is monotonic with respect to all dimensions of x.
- forward(x: Tensor) Tensor
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cenreg.pytorch.mlp.SMM_MultiHead(input_len: int, input_monotone_len: int, output_num: int, num_neuron: int)
Bases:
Module
- forward(x: Tensor, t: Tensor) Tensor
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
cenreg.pytorch.util module
- cenreg.pytorch.util.denormalize_pred(pred: Tensor, min_y: float, max_y: float) Tensor
Denormalize the predictions using the min and max values.
- Parameters:
pred (torch.Tensor) – The normalized predictions.
min_y (float) – The minimum values for denormalization.
max_y (float) – The maximum values for denormalization.
- Returns:
denormalized_prediction – The denormalized predictions.
- Return type:
torch.Tensor
- cenreg.pytorch.util.normalize_y(y: Tensor, min_y: float, max_y: float) Tensor
Normalize the input tensor using the min and max values.
- Parameters:
y (torch.Tensor) – The input tensor to be normalized.
min_y (float) – The minimum values for normalization.
max_y (float) – The maximum values for normalization.
- Returns:
normalized_tensor – The normalized tensor.
- Return type:
torch.Tensor