Frequently Asked Questions

This page answers common questions about Neural Causal Regularization.

General Questions

What is Neural Causal Regularization?

Neural Causal Regularization (NCR) is a framework that extends causal invariance principles to deep neural networks. It penalizes the variance of prediction risks across environments, encouraging models to learn stable, invariant relationships that generalize better to new, unseen environments.

How does NCR differ from standard machine learning approaches?

Standard machine learning approaches typically minimize the average prediction error on training data, which can lead to models that learn spurious correlations that don't hold in new environments. NCR, on the other hand, explicitly encourages invariance across environments, leading to models that focus on stable, causal relationships.

What are the main advantages of using NCR?

The main advantages of NCR include:

When should I use NCR?

NCR is particularly useful in scenarios where:

Technical Questions

How many environments do I need for NCR?

NCR requires data from at least two different environments to identify invariant relationships. However, having more diverse environments can lead to better identification of causal features. In practice, even with just two environments, NCR can provide benefits over standard empirical risk minimization.

How do I choose the regularization parameter λ?

The regularization parameter λ controls the trade-off between average performance and invariance. A larger λ puts more emphasis on invariance, which can lead to better out-of-distribution generalization but potentially worse in-distribution performance. In practice, λ can be chosen using cross-validation on a validation set from a different environment than the training environments.

Can NCR be used with any neural network architecture?

Yes, NCR can be applied to any neural network architecture. However, the choice of architecture can affect the model's ability to capture invariant relationships. In general, deeper networks with sufficient capacity are recommended.

How does NCR handle hidden confounders?

NCR assumes that all relevant causal variables are observed. If there are hidden confounders, NCR may not identify the true causal features. However, in practice, NCR can still provide benefits over standard approaches even in the presence of hidden confounders, especially if the confounding effect is similar across environments.

Is NCR computationally expensive?

NCR requires training on data from multiple environments, which can increase the computational cost compared to standard training. However, the additional cost is typically modest, especially for smaller models. The main computational overhead comes from computing the variance of risks across environments, which scales linearly with the number of environments.

Implementation Questions

How do I prepare my data for NCR?

To use NCR, you need to organize your data by environment. Each environment should have its own set of covariates (X) and target variables (Y). In the ncausalreg package, this is typically represented as lists of matrices or tensors, where each element corresponds to a different environment.

Can I use NCR with categorical variables?

Yes, but categorical variables need to be properly encoded (e.g., using one-hot encoding) before being passed to the model. The ncausalreg package works with numerical inputs, so any preprocessing of categorical variables should be done beforehand.

How do I interpret the feature importance from NCR?

Feature importance in NCR models can be interpreted similarly to other machine learning models. Features with higher importance scores have a stronger influence on the model's predictions. In the context of NCR, features with high importance across environments are more likely to be causally related to the target variable.

Can NCR be used for classification problems?

Yes, NCR can be adapted for classification problems by using an appropriate loss function (e.g., cross-entropy loss) and output activation (e.g., sigmoid or softmax). The core principle of penalizing the variance of risks across environments remains the same.

How do I save and load NCR models?

NCR models in the ncausalreg package are based on torch models, so they can be saved and loaded using torch's standard functions:

# Save model
torch::torch_save(model, "path/to/model.pt")

# Load model
model <- torch::torch_load("path/to/model.pt")

Comparison with Other Methods

How does NCR compare to Invariant Risk Minimization (IRM)?

NCR and IRM both aim to learn invariant predictors, but they use different approaches. IRM uses a bi-level optimization or gradient penalties, while NCR directly penalizes the variance of risks across environments. In practice, NCR can be easier to optimize and may provide more stable results, especially with deep neural networks.

How does NCR compare to Domain Adaptation methods?

Domain Adaptation methods typically focus on aligning feature distributions across domains, while NCR focuses on learning invariant predictors. NCR can be more effective when the relationship between features and the target variable changes across domains, as it explicitly encourages invariance in this relationship.

Can NCR be combined with other regularization techniques?

Yes, NCR can be combined with other regularization techniques like L1/L2 regularization, dropout, or batch normalization. These techniques can complement NCR by preventing overfitting and improving generalization.

Troubleshooting

My NCR model is not performing better than standard models. What might be wrong?

There could be several reasons:

Try experimenting with different values of λ, using more diverse environments, or using a more expressive model architecture.

I'm getting NaN losses during training. What should I do?

NaN losses can occur if the gradients become too large or if there are numerical instabilities. Try:

The variance penalty is always zero. What might be wrong?

If the variance penalty is always zero, it could mean that the risks are identical across environments, which might happen if:

Check that your environments are indeed different and that the model is being trained correctly.

Additional Resources

Where can I learn more about causal inference?

Here are some recommended resources:

Are there any tutorials or courses on NCR?

Check out our Examples page for tutorials on using NCR. For more general resources on causal machine learning, we recommend:

How can I contribute to the ncausalreg package?

We welcome contributions! Check out our GitHub repository for information on how to contribute. You can help by: