---
title: Dualistic Meta-Learning for Open-Set DG (MEDIC)
url: https://www.emergentmind.com/topics/dualistic-meta-learning-for-open-set-domain-generalization-medic
type: topic
---

# Dualistic Meta-Learning for Open-Set DG (MEDIC)

Dualistic MEta-learning with joint DomaIn-Class matching (MEDIC) is a meta-learning framework designed for the Open-Set Domain Generalization (OSDG) problem. OSDG extends standard Domain Generalization (DG) to the more realistic regime where both domain distribution shift and previously unseen class categories may appear at test time. MEDIC establishes generalizable decision boundaries through dualistic meta-learning that jointly leverages inter-domain and inter-class data splits, optimized to handle the inherent class imbalance of open-set recognition and the challenges of cross-domain transferability [2308.09391].

## 1. Problem Formulation: Open-Set Domain Generalization

In OSDG, the training data comprises $S$ source domains $S = \{D_1, ..., D_S\}$, each drawn from a distinct distribution $P_s$ over input-label pairs $(\mathbf{x}, y) \in X \times C$, with $C$ the set of known classes. During evaluation, a model faces $T$ unseen target domains $T = \{D_{S+1}, ..., D_{S+T}\}$ defined by a distribution $Q$ over $X$ with labels coming from $C \cup U$, where $U$ is a set of unknown classes disjoint from $C$. Crucially, samples with $y \in U$ are never observed during training.

The objective is to train a model $M_\Theta$ to (i) correctly classify target-domain data from $C$ and (ii) reliably reject data from $U$ as unknown, despite never seeing $U$ during training. This scenario encompasses both distribution (domain) shift and class novelty, exceeding the complexity of standard DG or closed-set OOD detection.

## 2. One-vs-All Boundaries and Class Imbalance Challenge

The open-set nature of OSDG motivates the use of one-vs-all classifiers. For each $k \in C$, a binary classifier outputs $p_k(\mathbf{x}) = P(\mathbf{x} \in \text{class } k)$; a test example is declared "unknown" if $\max_k p_k(\mathbf{x}) \leq \mu$ for some detection threshold $\mu$. This approach directly partitions the feature space, allowing explicit rejection of outliers.

However, each one-vs-all binary classifier faces extreme class imbalance: positives are rare (samples from class $k$), while negatives—conceptually the union of all other classes—are much more numerous and diverse. This imbalance tends to bias decision boundaries—either crowding them against the positive region (yielding over-confident, under-generalized boundaries) or expanding them too far (reducing detection sensitivity), which degrades both known-class accuracy and unknown rejection. These limitations are accentuated under domain shift, further complicating OSDG.

## 3. Dualistic Meta-Learning and Joint Domain-Class Matching

MEDIC addresses OSDG via a dualistic, episodic meta-learning protocol combining inter-domain and inter-class splits:

- **Domain-wise split**: Randomly divide source domains into two disjoint sets, $S_F$ and $S_G$.
- **Class-wise split**: Partition known classes $C$ into two subsets, $C_1$ and $C_2$.

This induces four training groups (episodes):

| Episode | Domains  | Classes |
|---------|----------|---------|
| $S_{F1}$ | $S_F$    | $C_1$   |
| $S_{F2}$ | $S_F$    | $C_2$   |
| $S_{G1}$ | $S_G$    | $C_1$   |
| $S_{G2}$ | $S_G$    | $C_2$   |

Meta-training uses $S_{F1}$ and $S_{G2}$ (differing in both domain and class), while meta-testing uses the crossed pair $S_{F2}$ and $S_{G1}$.

At each iteration:
1. Mini-batches $B_{F1}$, $B_{F2}$, $B_{G1}$, $B_{G2}$ are sampled from the four splits.
2. The meta-train loss is $L_1(\Theta) = L_{all}(B_{F1}; \Theta) + L_{all}(B_{G2}; \Theta)$, with $L_{all}$ defined below.
3. Take a virtual gradient step: $\hat{\Theta} = \Theta - \alpha \nabla_\Theta L_1(\Theta)$.
4. Compute the meta-test loss at $\hat{\Theta}$: $L_2(\hat{\Theta}) = L_{all}(B_{F2}; {\hat{\Theta}}) + L_{all}(B_{G1}; {\hat{\Theta}})$.
5. The final update is $\Theta \leftarrow \Theta - \eta [\nabla_\Theta L_1(\Theta) + \beta \nabla_{\hat{\Theta}} L_2(\hat{\Theta})]$.

A first-order Taylor expansion reveals an alignment term $-\beta\alpha \langle\nabla L_1, \nabla L_2\rangle$ in the resulting objective, which encourages the model to discover parameter updates that generalize across both domains and classes. MEDIC's regularizer combines four inner products, each linking episodes that are either same-domain/different-class or same-class/different-domain, which explicitly enforces domain and class generalization and prevents decision boundary skew from class imbalance.

## 4. Objective Functions, Losses, and Decision Strategy

The core losses are:

- **Closed-set cross-entropy:** $L_{ce}(\mathbf{x}, y; \Theta) = -\log p_\Theta(y | \mathbf{x})$ (softmax classifier).
- **One-vs-all binary loss (Ovanet style):**
  $$
  L_{ova}(\mathbf{x}, y; \Theta) = -\log p_y(\mathbf{x}) - \min_{j \neq y} \log [1 - p_j(\mathbf{x})]
  $$
  This encourages the correct class output to be high while pushing down the strongest negative class.
- **Combined open-set loss:** $L_{all} = L_{ce} + L_{ova}$.

The per-iteration meta-objective is:
- $L_1(\Theta) = L_{all}(B_{F1}; \Theta) + L_{all}(B_{G2}; \Theta)$,
- $\hat{\Theta} = \Theta - \alpha \nabla_\Theta L_1(\Theta)$,
- $L_2(\hat{\Theta}) = L_{all}(B_{F2}; {\hat{\Theta}}) + L_{all}(B_{G1}; {\hat{\Theta}})$,
- Update toward minimizing $L_1 + \beta L_2 - \beta\alpha (\nabla L_1 \cdot \nabla L_2)$.

**Rejection at test time:** For an input $\mathbf{x}$, compute class confidence by either $conf_{cls}(\mathbf{x}) = \max_k p_{softmax, k}(\mathbf{x})$ or $conf_{bcls}(\mathbf{x}) = p_{bclf, k^*}(\mathbf{x})$ where $k^* = \arg\max_k p_{softmax, k}(\mathbf{x})$. Classify as "known" if $conf \geq \mu$, "unknown" otherwise.

## 5. Addressing Class Imbalance and Generalization

MEDIC's distinct class-wise and domain-wise splits during episodic meta-learning enforce decision boundaries that are robust to the relative proportion of positives and negatives—mitigating the dominant-negative effect and ensuring that boundaries are not distorted due to imbalance. Simultaneous domain-wise splitting fosters invariance to domain shift, preventing collapse of known classes when faced with novel target domains.

In practice, this yields emphatic improvements on open-set metrics such as OSCR (Open Set Classification Rate) and H-score, while maintaining or very marginally improving closed-set recognition compared to standard DG algorithms. A plausible implication is that MEDIC's principled matching approach is particularly suited for applications where previously unseen categories are expected under domain shift [2308.09391].

## 6. Experimental Evaluation

Performance metrics are reported primarily on PACS (6 known, 1 unknown class splits; Deep ResNet-18/50) and Digits-DG (6 known, 4 unknown classes; ConvNet). Key results are summarized as follows:

| Method         | Dataset   | OSCR        | H-score    |
|----------------|-----------|-------------|------------|
| ERM-bcls       | PACS-R18  | 70.3%       | 70.6%      |
| MVDG-bcls      | PACS-R18  | 75.82%      | 70.9%      |
| MEDIC-bcls     | PACS-R18  | 77.89%      | 75.98%     |
| MVDG-bcls      | PACS-R50  | 83.21%      | —          |
| MEDIC-bcls     | PACS-R50  | 84.85%      | —          |
| ERM-bcls       | Digits-DG | 66.03%      | —          |
| MEDIC-bcls     | Digits-DG | 71.15%      | —          |

MEDIC consistently outperforms ERM-bcls and MVDG-bcls on both OSCR and H-score. In all considered regimes, it also matches or slightly outperforms strong closed-domain generalization (SWAD) in closed-set recognition [2308.09391].

## 7. Algorithm Workflow Summary

The per-iteration workflow is as follows:

1. Randomly split source domains into $(S_F, S_G)$ and classes into $(C_1, C_2)$.
2. Sample mini-batches: $B_{F1}$ from $(S_F, C_1)$, $B_{F2}$ from $(S_F, C_2)$, $B_{G1}$ from $(S_G, C_1)$, $B_{G2}$ from $(S_G, C_2)$.
3. Compute meta-train loss $L_1 = L_{all}(B_{F1}; \Theta) + L_{all}(B_{G2}; \Theta)$.
4. Take a virtual update: $\hat{\Theta} = \Theta - \alpha \nabla_\Theta L_1$.
5. Compute meta-test loss $L_2 = L_{all}(B_{F2}; \hat{\Theta}) + L_{all}(B_{G1}; \hat{\Theta})$.
6. Final update: $\Theta \leftarrow \Theta - \eta [\nabla_\Theta L_1 + \beta \nabla_{\hat{\Theta}} L_2]$.
7. Repeat until convergence.

This episodic, dual-split procedure underpins MEDIC's generalizability to novel domains and unknown classes [2308.09391].

Source: https://www.emergentmind.com/topics/dualistic-meta-learning-for-open-set-domain-generalization-medic