<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Posts on eree's blog</title><link>https://blog.ereebay.me/en/posts/</link><description>Recent content in Posts on eree's blog</description><generator>Hugo</generator><language>en</language><copyright>2020-2026 eree&amp;rsquo;s blog</copyright><lastBuildDate>Wed, 24 Jun 2020 18:55:03 +0800</lastBuildDate><atom:link href="https://blog.ereebay.me/en/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>[Paper] TOWARDS FASTER AND BETTER FEDERATED LEARNING: A FEATURE FUSION APPROACH Reading Notes</title><link>https://blog.ereebay.me/en/posts/fedfusion/</link><pubDate>Wed, 24 Jun 2020 18:55:03 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/fedfusion/</guid><description>&lt;h1 id="towards-faster-and-better-federated-learning-a-feature-fusion-approach"&gt;TOWARDS FASTER AND BETTER FEDERATED LEARNING: A FEATURE FUSION APPROACH&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;This paper mainly proposes a feature fusion approach to accelerate and improve the performance of federated learning.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Nowadays many smart devices rely on pretrained models, which makes the machine&amp;rsquo;s inference capability lack personalization and flexibility. At the same time, smart terminals also generate a large amount of valid privacy-sensitive data, which can improve the personalization capability of these models. Federated learning, a distributed training algorithm that can train models directly on terminals, solves this problem. Among federated learning algorithms, those represented by FedAvg effectively alleviate the privacy issues in information exchange, but later research has also shown that federated learning still has problems such as: &lt;strong&gt;computational consumption&lt;/strong&gt;, &lt;strong&gt;model accuracy&lt;/strong&gt;.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="towards-faster-and-better-federated-learning-a-feature-fusion-approach">TOWARDS FASTER AND BETTER FEDERATED LEARNING: A FEATURE FUSION APPROACH</h1>
<h2 id="abstract">Abstract</h2>
<p>This paper mainly proposes a feature fusion approach to accelerate and improve the performance of federated learning.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>Nowadays many smart devices rely on pretrained models, which makes the machine&rsquo;s inference capability lack personalization and flexibility. At the same time, smart terminals also generate a large amount of valid privacy-sensitive data, which can improve the personalization capability of these models. Federated learning, a distributed training algorithm that can train models directly on terminals, solves this problem. Among federated learning algorithms, those represented by FedAvg effectively alleviate the privacy issues in information exchange, but later research has also shown that federated learning still has problems such as: <strong>computational consumption</strong>, <strong>model accuracy</strong>.</p>
<p>This paper proposes a feature-fusion federated learning algorithm, FedFusion, which fuses the features of the global model and the local model. The three main contributions of this paper: 1. introducing a feature fusion mechanism; 2. fusing the features of the local model and the global model in an effective and personalized way; 3. experiments show that the model outperforms the baselines in both accuracy and generalization ability while reducing communication by more than 60%.</p>
<h2 id="related-work">Related Work</h2>
<p>Mainly the FedAvg algorithm of Federated Learning; not much to say here.</p>
<h2 id="methods">Methods</h2>
<p>It is mainly divided into the feature fusion module and the FedFusion algorithm.</p>
<h3 id="feature-fusion-modules">Feature Fusion Modules</h3>
<p><img alt="fedfusion1" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion1.png"></p>
<p>The blue features in the figure are the two-channel features extracted by the local model, and the gray ones are the two-channel features extracted by the global model. The figure shows three feature fusion methods: Conv, Multi, Single.</p>
<p>Conv:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>F</mi><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>v</mi></mrow></msub><mrow><mo fence="true">(</mo><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mo>=</mo><msub><mi>W</mi><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>v</mi></mrow></msub><mrow><mo fence="true">(</mo><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi mathvariant="normal">∥</mi><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">F_{c o n v}\left(E_{l}(x), E_{g}(x)\right)=W_{c o n v}\left(E_{g}(x) \| E_{l}(x)\right)</annotation></semantics></math></span><p>where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>W</mi><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>v</mi></mrow></msub></mrow><annotation encoding="application/x-tex">W_{c o n v}</annotation></semantics></math></span> denotes a learnable weight matrix of shape 2C*C. The concrete operation is to concatenate the global and local features and then apply a convolution.</p>
<p>Multi:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>F</mi><mrow><mi>m</mi><mi>u</mi><mi>l</mi><mi>t</mi><mi>i</mi></mrow></msub><mrow><mo fence="true">(</mo><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mo>=</mo><mi>λ</mi><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>λ</mi><mo stretchy="false">)</mo><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">F_{m u l t i}\left(E_{l}(x), E_{g}(x)\right)=\lambda E_{g}(x)+(1-\lambda) E_{l}(x)</annotation></semantics></math></span><p>The multiplication operation uses a lambda weight matrix to perform a weighted sum of local and global.</p>
<p>Single:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>F</mi><mtext>single</mtext></msub><mrow><mo fence="true">(</mo><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mo>=</mo><mi>λ</mi><msub><mi>E</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>λ</mi><mo stretchy="false">)</mo><msub><mi>E</mi><mi>l</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">F_{\text {single}}\left(E_{l}(x), E_{g}(x)\right)=\lambda E_{g}(x)+(1-\lambda) E_{l}(x)</annotation></semantics></math></span><p>The addition operation uses a scalar lambda weight to perform a weighted sum of local and global.</p>
<h3 id="fedfusion">FedFusion</h3>
<p><img alt="fedfusion2" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion2.png"></p>
<p>The training procedure uses the features of the previous round&rsquo;s global model to participate in this round&rsquo;s model feature aggregation training.</p>
<h2 id="experiment">Experiment</h2>
<h3 id="experiment-setup">Experiment setup</h3>
<p>Datasets: Mnist, Cifar10</p>
<p>Data partition methods:</p>
<ol>
<li>An artificial non-IID partition, where each node contains only two classes</li>
<li>A user-specific non-IID partition, where each node contains similar classes but with different distributions, similar to multi-task learning</li>
<li>IID distribution</li>
</ol>
<h3 id="artificial-non-iid-partition">Artificial Non-IID Partition</h3>
<p><img alt="fedfusion3" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion3.png"></p>
<p>Experimental results of two random runs of the artificial non-IID sampling scheme. The experimental results show that the multi fusion method works best; the conv fusion method converges slightly faster, but its final result is not as good as multi; none and single are both mediocre.</p>
<p>The paper&rsquo;s explanation is that the multi operation allows the model to select the feature maps that are effective for local data for fusion, while the single operation is a scalar and cannot select specific channels of the feature maps.</p>
<h3 id="user-specific-non-iid-partition">User-Specific Non-IID Partition</h3>
<p><img alt="fedfusion4" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion4.png"></p>
<p>In terms of accuracy, FedFusion is much higher than FedAvg, with conv converging faster and also achieving higher accuracy.</p>
<p><img alt="fedfusion5" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion5.png"></p>
<p>The figure above shows the degree of communication reduction of FedFusion compared with FedAvg. From the results, in the user-specific non-IID scenario, the conv fusion method works better. This is because, under the user-specific non-IID partition, the classes of the data are similar, only with different distributions. And the conv fusion method is stronger at integrating the feature maps from the local and global models — that is, the knowledge of the data distributions of different nodes.</p>
<p><img alt="fedfusion6" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion6.png"></p>
<p>For the impact on generalization ability: when a new node joins, FedFusion only needs about 60 local epochs to fit, having a better initialization than the other methods.</p>
<h3 id="iid-partition">IID Partition</h3>
<p>The authors believe that the IID distribution also needs to be evaluated, because if a strategy cannot handle the IID distribution, its effectiveness is questionable.</p>
<p><img alt="fedfusion7" loading="lazy" src="http://cdn.ereebay.me/hexo/fedfusion7.png"></p>
<p>The multi and conv fusion methods can achieve better accuracy with the least communication cost. In terms of the final converged accuracy, there is a great improvement compared with the other methods.</p>
<p>To summarize the three fusion methods:</p>
<p>The multi operation mainly makes a more flexible and more interpretable selection between the local feature maps and the global feature maps. Each channel of the weight vector represents the weight of the corresponding channel of the global feature map. When a gap appears between the classes of the data, the multi operation can select the most effective feature maps for fusion. The conv operation is more effective at integrating the knowledge of the global and local models. If the data on the nodes has similar classes but different distributions, the conv fusion method is better. The single fusion method brings a slight improvement.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Using feature map fusion reduces the communication volume, improves model performance, and also improves the generalization ability for new nodes.</p>
]]></content:encoded></item><item><title>Watermelon Book Reading Notes 1. Introduction</title><link>https://blog.ereebay.me/en/posts/melonbook-1/</link><pubDate>Wed, 24 Jun 2020 18:15:38 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/melonbook-1/</guid><description>&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;
&lt;h2 id="preamble"&gt;Preamble&lt;/h2&gt;
&lt;p&gt;Machine learning: suppose we use P to evaluate the performance of a computer program on a certain class of tasks T; if a program improves its performance on the tasks in T through experience E, then we say that, with respect to T and P, the program has learned from E.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id="basic-terminology"&gt;Basic Terminology&lt;/h2&gt;
&lt;p&gt;Data-related:&lt;/p&gt;
&lt;p&gt;A dataset contains a series of records, and each record is an instance or a sample. That which reflects certain properties is an attribute or a feature. The value an attribute takes is called the attribute value, and the space spanned by the attributes is called the attribute space, the sample space, or the input space. Every point in this space is called a feature vector.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>
<h2 id="preamble">Preamble</h2>
<p>Machine learning: suppose we use P to evaluate the performance of a computer program on a certain class of tasks T; if a program improves its performance on the tasks in T through experience E, then we say that, with respect to T and P, the program has learned from E.</p>
<!-- more -->
<h2 id="basic-terminology">Basic Terminology</h2>
<p>Data-related:</p>
<p>A dataset contains a series of records, and each record is an instance or a sample. That which reflects certain properties is an attribute or a feature. The value an attribute takes is called the attribute value, and the space spanned by the attributes is called the attribute space, the sample space, or the input space. Every point in this space is called a feature vector.</p>
<p>Training-related:</p>
<p>The process of learning a model from data is called learning or training. The data used is called training data, each sample is a training sample, and the whole collection is called the training set. The learned model corresponds to some underlying regularity in the data, which is called a hypothesis. The regularity itself is called the ground truth. The model can also be called a learner.</p>
<p>After training, predictions need to be made. Information about the outcome of an instance is called a label, and an instance with a label is an example. The space spanned by the labels is the label space or the output space.</p>
<p>Classification: the predicted values are discrete. Regression: the predicted values are continuous. Binary classification: the outputs are the positive class and the negative class.</p>
<p>The stage of making predictions with the learned model is called testing; the samples being predicted are called testing samples, and likewise there is a testing set</p>
<p>Supervised learning: training with labeled data, such as classification and regression.</p>
<p>Unsupervised learning: training with unlabeled data, such as clustering, which divides training samples into clusters.</p>
<p>Generalization: the ability of a model to work well on new samples</p>
<p>Independent and identically distributed (iid): the samples are all drawn independently from the same distribution.</p>
<h2 id="hypothesis-space">Hypothesis Space</h2>
<p>Induction: from the specific to the general. (generalization)</p>
<p>Deduction: from the general to the specific. (specialization)</p>
<p>Inductive learning: in the broad sense, learning from samples; in the narrow sense, acquiring concepts from data, which is called concept learning.</p>
<p>Version space: the set of hypotheses consistent with the training set</p>
<h2 id="inductive-bias">Inductive Bias</h2>
<p>Inductive bias: the preference of a machine learning algorithm for a certain type of hypothesis during the learning process; it corresponds to the assumption the learning algorithm itself makes about &ldquo;what kind of model is better&rdquo;</p>
]]></content:encoded></item><item><title>Watermelon Book Reading Notes 2. Model Evaluation and Selection</title><link>https://blog.ereebay.me/en/posts/melonbook-2/</link><pubDate>Wed, 24 Jun 2020 16:06:16 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/melonbook-2/</guid><description>&lt;h1 id="model-evaluation-and-selection"&gt;Model Evaluation and Selection&lt;/h1&gt;
&lt;h2 id="empirical-error-and-overfitting"&gt;Empirical Error and Overfitting&lt;/h2&gt;
&lt;p&gt;Error rate: the overall proportion of misclassified samples&lt;/p&gt;
&lt;p&gt;Accuracy: the proportion of correctly classified samples&lt;/p&gt;
&lt;p&gt;Error: the difference between the actual output and the true output; on training samples it is the empirical error or training error, and on new samples it is the generalization error&lt;/p&gt;
&lt;p&gt;Overfitting: generalization performance degrades&lt;/p&gt;
&lt;p&gt;Underfitting: performs poorly even on the training samples&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id="evaluation-methods"&gt;Evaluation Methods&lt;/h2&gt;
&lt;p&gt;A testing set is typically used to measure a model&amp;rsquo;s performance, with the testing error serving as an approximation of the generalization error&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="model-evaluation-and-selection">Model Evaluation and Selection</h1>
<h2 id="empirical-error-and-overfitting">Empirical Error and Overfitting</h2>
<p>Error rate: the overall proportion of misclassified samples</p>
<p>Accuracy: the proportion of correctly classified samples</p>
<p>Error: the difference between the actual output and the true output; on training samples it is the empirical error or training error, and on new samples it is the generalization error</p>
<p>Overfitting: generalization performance degrades</p>
<p>Underfitting: performs poorly even on the training samples</p>
<!-- more -->
<h2 id="evaluation-methods">Evaluation Methods</h2>
<p>A testing set is typically used to measure a model&rsquo;s performance, with the testing error serving as an approximation of the generalization error</p>
<h3 id="hold-out-method">Hold-Out Method</h3>
<p>Split the dataset D into two mutually exclusive sets, one part as the training set S and the other as the testing set T. When S is large and T is small, the evaluation may not be accurate enough. If T is made larger, then the model trained on S may differ too much from the model that would be trained on D, and the evaluation result will not be accurate enough either.</p>
<h3 id="cross-validation">Cross-Validation</h3>
<p>Split the dataset D into k mutually exclusive subsets, use k-1 of them as the training set and the remaining one as the testing set; this yields k groups of data, and the average of the testing results of these k groups is returned as the final result. The extreme case is leave-one-out, which gives more accurate results but at a greater computational cost.</p>
<h3 id="bootstrap">Bootstrap</h3>
<p>Use bootstrap sampling to draw a new dataset <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>D</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup></mrow><annotation encoding="application/x-tex">D&#x27;</annotation></semantics></math></span> with replacement. Train on this new dataset and test on the rest. Advantage: this method is useful when the dataset is small and it is difficult to split training/testing sets effectively. Disadvantage: it changes the distribution of the initial dataset and introduces estimation bias.</p>
<h3 id="parameter-tuning-and-the-final-model">Parameter Tuning and the Final Model</h3>
<p>Algorithm parameters have a great impact on the algorithm&rsquo;s performance. Besides choosing an algorithm, its parameters also need to be adjusted, i.e., parameter tuning. After the model has been evaluated and selected using a validation set and the model and parameter configuration are determined, the model must be retrained once on the entire dataset D before testing — this is the finally submitted model. To distinguish it, the data used during model evaluation is called the validation set. The validation set is used to evaluate algorithm selection and parameter tuning, while the testing set is used to evaluate the generalization performance of the algorithm.</p>
<h2 id="performance-measures">Performance Measures</h2>
<p>Performance measure: the evaluation criterion used to measure a model&rsquo;s generalization ability</p>
<p>The most commonly used performance measure for regression tasks is MSE, the mean squared error:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><msup><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>−</mo><msub><mi>y</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">E(f ; D)=\frac{1}{m} \sum_{i=1}^{m}\left(f\left(x_{i}\right)-y_{i}\right)^{2}</annotation></semantics></math></span><p>More generally, it can be written as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mo>∫</mo><mrow><mi>x</mi><mo>∼</mo><mi>D</mi></mrow></msub><mo stretchy="false">(</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>−</mo><mi>y</mi><msup><mo stretchy="false">)</mo><mn>2</mn></msup><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>d</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">E(f ; D)=\int_{x \sim D}(f(x)-y)^{2} p(x) d x</annotation></semantics></math></span><h3 id="error-rate-and-accuracy">Error Rate and Accuracy</h3>
<p>The two most commonly used performance measures: error rate and accuracy</p>
<p>Error rate: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo mathvariant="normal">≠</mo><msub><mi>y</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">E(f ; D)=\frac{1}{m} \sum_{i=1}^{m} I\left(f\left(x_{i}\right) \neq y_{i}\right)</annotation></semantics></math></span></p>
<p>Accuracy: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi mathvariant="normal">acc</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></munderover><mi mathvariant="double-struck">I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>=</mo><msub><mi>y</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><mn>1</mn><mo>−</mo><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{aligned} \operatorname{acc}(f ; D) &amp;=\frac{1}{m} \sum_{i=1}^{m} \mathbb{I}\left(f\left(x_{i}\right)=y_{i}\right) \\ &amp;=1-E(f ; D) \end{aligned}</annotation></semantics></math></span></p>
<h3 id="precision-recall-and-f1">Precision, Recall, and F1</h3>
<p>In information retrieval, one usually cares about &ldquo;how much of the retrieved information the user is interested in&rdquo; and &ldquo;how much of what the user is interested in has been retrieved&rdquo;. This motivates the concepts of precision and recall.</p>
<p>For binary classification problems,</p>
<p>Precision = true positives / (true positives + false positives)</p>
<p>Recall = true positives / (true positives + false negatives)</p>
<p>These two metrics usually conflict with each other: when recall is high, precision is relatively low. For example, to select as many good melons as possible, simply selecting every melon guarantees that all the good ones are selected.</p>
<p>P-R curve: the precision-recall curve. If one learner&rsquo;s PR curve can completely envelop another learner&rsquo;s curve, the former learner is better. A more reasonable criterion is the size of the area under the curve, but it is not easy to estimate, so there are three evaluation approaches.</p>
<ol>
<li>Break-Even Point (BEP): the value at which precision equals recall.</li>
<li>F1 measure: F1=2<em>P</em>R/(P+R)= 2*TP/(total number of examples+TP-TN), based on the harmonic mean of P and R <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><msub><mi>F</mi><mn>1</mn></msub></mfrac><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mrow><mo fence="true">(</mo><mfrac><mn>1</mn><mi>P</mi></mfrac><mo>+</mo><mfrac><mn>1</mn><mi>R</mi></mfrac><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\frac{1}{F_{1}}=\frac{1}{2}\left(\frac{1}{P}+\frac{1}{R}\right)</annotation></semantics></math></span></li>
<li>The general form of the F1 measure (when P and R are weighted differently): <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>F</mi><mi>β</mi></msub><mo>=</mo><mfrac><mrow><mrow><mo fence="true">(</mo><mn>1</mn><mo>+</mo><msup><mi>β</mi><mn>2</mn></msup><mo fence="true">)</mo></mrow><mo>×</mo><mi>P</mi><mo>×</mo><mi>R</mi></mrow><mrow><mrow><mo fence="true">(</mo><msup><mi>β</mi><mn>2</mn></msup><mo>×</mo><mi>P</mi><mo fence="true">)</mo></mrow><mo>+</mo><mi>R</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">F_{\beta}=\frac{\left(1+\beta^{2}\right) \times P \times R}{\left(\beta^{2} \times P\right)+R}</annotation></semantics></math></span>, based on the harmonic mean <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><msub><mi>F</mi><mi>β</mi></msub></mfrac><mo>=</mo><mfrac><mn>1</mn><mrow><mn>1</mn><mo>+</mo><msup><mi>β</mi><mn>2</mn></msup></mrow></mfrac><mrow><mo fence="true">(</mo><mfrac><mn>1</mn><mi>P</mi></mfrac><mo>+</mo><mfrac><msup><mi>β</mi><mn>2</mn></msup><mi>R</mi></mfrac><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\frac{1}{F_{\beta}}=\frac{1}{1+\beta^{2}}\left(\frac{1}{P}+\frac{\beta^{2}}{R}\right)</annotation></semantics></math></span>  <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span> represents the relative importance of the two: it degenerates to F1 when equal to 1, recall matters more when it is greater than 1, and precision matters more when it is less than 1.</li>
</ol>
<p>Sometimes P and R need to be computed over n binary confusion matrices and then averaged, giving macro-precision, macro-recall, and macro-F1. Alternatively, the corresponding elements of the confusion matrices can be averaged first to obtain averaged positive and negative counts, from which micro-precision, micro-recall, and micro-F1 are then computed.</p>
<h3 id="roc-and-auc">ROC and AUC</h3>
<p>ROC: Receiver Operating Characteristic curve.</p>
<p>A learner typically outputs a probability prediction for an input sample, which is then compared against a classification threshold. The model ranks the samples most likely to be positive at the front and the least likely at the back, then splits the samples into two parts at a certain cut point: the first part is judged positive and the second part negative.</p>
<p>Different classification tasks adopt different cut points: if precision matters more, the cut point is moved forward; if recall is valued more, it is moved backward.</p>
<p>Sort the samples according to the learner&rsquo;s prediction results, and compute two values in that order.</p>
<p>Vertical axis: True Positive Rate (TPR): <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi><mi>P</mi><mi>R</mi><mo>=</mo><mfrac><mrow><mi>T</mi><mi>P</mi></mrow><mrow><mi>T</mi><mi>P</mi><mo>+</mo><mi>F</mi><mi>N</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">T P R=\frac{T P}{T P+F N}</annotation></semantics></math></span></p>
<p>Horizontal axis: False Positive Rate (FPR): <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>F</mi><mi>P</mi><mi>R</mi><mo>=</mo><mfrac><mrow><mi>F</mi><mi>P</mi></mrow><mrow><mi>T</mi><mi>N</mi><mo>+</mo><mi>F</mi><mi>P</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">FPR=\frac {FP} {TN+FP}</annotation></semantics></math></span>
<img alt="Untitled" loading="lazy" src="http://cdn.ereebay.me/hexo/Untitled.png"></p>
<p>When comparing learners, if one curve can envelop the other, the former is better; if they cross, neither clearly dominates. A more reasonable judgment is to compare the area under the ROC curve, i.e., the AUC.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mi>U</mi><mi>C</mi><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi>m</mi><mo>−</mo><mn>1</mn></mrow></msubsup><mrow><mo fence="true">(</mo><msub><mi>x</mi><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>−</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mrow><mo fence="true">(</mo><msub><mi>y</mi><mi>i</mi></msub><mo>+</mo><msub><mi>y</mi><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">A U C=\frac{1}{2} \sum_{i=1}^{m-1}\left(x_{i+1}-x_{i}\right)\left(y_{i}+y_{i+1}\right)</annotation></semantics></math></span><p>Loss: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal"><msub><mi mathvariant="normal">l</mi><mrow><mi mathvariant="normal">r</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">k</mi></mrow></msub></mi><mo>⁡</mo><mo>=</mo><mfrac><mn>1</mn><mrow><msup><mi>m</mi><mo lspace="0em" rspace="0em">+</mo></msup><msup><mi>m</mi><mo lspace="0em" rspace="0em">−</mo></msup></mrow></mfrac><msub><mo>∑</mo><mrow><msup><mi>x</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo>∈</mo><msup><mi>D</mi><mo lspace="0em" rspace="0em">+</mo></msup></mrow></msub><msub><mo>∑</mo><mrow><mi>x</mi><mo>∈</mo><msup><mi>D</mi><mo lspace="0em" rspace="0em">−</mo></msup></mrow></msub><mrow><mo fence="true">(</mo><mi mathvariant="double-struck">I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo fence="true">)</mo></mrow><mo>&lt;</mo><mi>f</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo lspace="0em" rspace="0em">−</mo></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo>+</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mi mathvariant="double-struck">I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo lspace="0em" rspace="0em">+</mo></msup><mo fence="true">)</mo></mrow><mo>=</mo><mi>f</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo lspace="0em" rspace="0em">−</mo></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\operatorname{l_{rank}}=\frac{1}{m^{+} m^{-}} \sum_{x^{+} \in D^{+}} \sum_{x \in D^{-}}\left(\mathbb{I}\left(f\left(x^{+}\right)&lt;f\left(x^{-}\right)\right)+\frac{1}{2} \mathbb{I}\left(f\left(x^{+}\right)=f\left(x^{-}\right)\right)\right)</annotation></semantics></math></span></p>
<p>AUC= 1-lrank</p>
<p><a href="https://datawhalechina.github.io/pumpkin-book/#/chapter2/chapter2">https://datawhalechina.github.io/pumpkin-book/#/chapter2/chapter2</a> For more details, see the Pumpkin Book</p>
<h3 id="cost-sensitive-error-rate-and-cost-curve">Cost-Sensitive Error Rate and Cost Curve</h3>
<p>To weigh the different losses caused by different types of errors, errors can be assigned &ldquo;unequal costs&rdquo;</p>
<p>Taking binary classification as an example, set up a cost matrix</p>
<p>Binary classification cost matrix</p>
<table>
	<thead>
			<tr>
					<th>True class</th>
					<th>Predicted class 0</th>
					<th>Predicted class 1</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>0</td>
					<td>0</td>
					<td>cost01</td>
			</tr>
			<tr>
					<td>1</td>
					<td>cost10</td>
					<td>0</td>
			</tr>
	</tbody>
</table>
<p>If misclassifying 0 as 1 is considered the greater loss, then cost01 is greater than cost10; the greater the difference in loss, the greater the difference between the values.</p>
<p>The performance measures introduced above all implicitly assume equal costs; under unequal costs, the goal becomes minimizing the total cost overall</p>
<p>The cost-sensitive error rate is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo separator="true">;</mo><mi>cos</mi><mo>⁡</mo><mi>t</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><mrow><mo fence="true">(</mo><msub><mo>∑</mo><mrow><msub><mi>x</mi><mi>i</mi></msub><mo>∈</mo><msup><mi>D</mi><mo lspace="0em" rspace="0em">+</mo></msup></mrow></msub><mi mathvariant="double-struck">I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo mathvariant="normal">≠</mo><msub><mi>y</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>01</mn></msub><mo separator="true">,</mo><mspace width="1em"/><mo>+</mo><msub><mo>∑</mo><mrow><msub><mi>X</mi><mi>i</mi></msub><mo>∈</mo><msup><mi>D</mi><mo lspace="0em" rspace="0em">−</mo></msup></mrow></msub><mi mathvariant="double-struck">I</mi><mrow><mo fence="true">(</mo><mi>f</mi><mrow><mo fence="true">(</mo><msub><mi>x</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo mathvariant="normal">≠</mo><msub><mi>y</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>10</mn></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
E(f ; D ; \cos t)=\frac{1}{m}\left(\sum_{x_{i} \in D^{+}} \mathbb{I}\left(f\left(x_{i}\right) \neq y_{i}\right) \times cost_{01}, \quad+\sum_{X_{i} \in D^{-}} \mathbb{I}\left(f\left(x_{i}\right) \neq y_{i}\right) \times cost_{1 0}\right)
</annotation></semantics></math></span><p>Under unequal costs, the ROC curve cannot reflect the learner&rsquo;s expected total cost, but the cost curve can serve this purpose.</p>
<p>The horizontal axis is the positive-class probability cost over [0,1]:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mo>+</mo><mo stretchy="false">)</mo><mi>c</mi><mi>o</mi><mi>s</mi><mi>t</mi><mo>=</mo><mfrac><mrow><mi>p</mi><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>01</mn></msub></mrow><mrow><mi>p</mi><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>01</mn></msub><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>10</mn></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">
P(+) cost=\frac{p \times cost_{01}}{p \times cost_{01}+(1-p) \times cost_{10}}
</annotation></semantics></math></span><p>where p is the probability that an example is positive</p>
<p>The vertical axis is the normalized cost over [0,1]:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mtext>norm </mtext></msub><mo>=</mo><mfrac><mrow><mi>F</mi><mi>N</mi><mi>R</mi><mo>×</mo><mi>p</mi><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>01</mn></msub><mo>+</mo><mi>F</mi><mi>P</mi><mi>R</mi><mo>×</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mo>×</mo><mi>cos</mi><mo>⁡</mo><msub><mi>t</mi><mn>10</mn></msub></mrow><mrow><mi>p</mi><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>01</mn></msub><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mo>×</mo><mi>c</mi><mi>o</mi><mi>s</mi><msub><mi>t</mi><mn>10</mn></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">
cost_{\text {norm }}=\frac{ F N R \times p \times cost_{01}+FP R \times(1-p) \times \cos t_{10}}{p \times cost_{01} +(1-p) \times cost_{10}}
</annotation></semantics></math></span><p>FNR is the false negative rate, and FPR is the false positive rate. FNR=1-TPR</p>
<h2 id="comparative-tests">Comparative Tests</h2>
<p>Performance comparison in machine learning usually relies on statistical hypothesis tests, for the following reasons:</p>
<ol>
<li>We want to compare generalization performance, but what experiments evaluate is performance on the testing set, and the two comparison results do not necessarily agree</li>
<li>Performance on the testing set depends heavily on the choice of testing set</li>
<li>The algorithm itself involves a certain degree of randomness</li>
</ol>
<h3 id="hypothesis-testing">Hypothesis Testing</h3>
<p>The error rate <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">{\epsilon}</annotation></semantics></math></span> serves as the performance measure.
For a learner with error rate <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">{\epsilon}</annotation></semantics></math></span>, suppose we obtain a testing error of <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{\epsilon}</annotation></semantics></math></span> on the testing set; this means that <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover><mo>×</mo><mi>m</mi></mrow><annotation encoding="application/x-tex">\hat{\epsilon} \times m</annotation></semantics></math></span> of the <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>m</mi></mrow><annotation encoding="application/x-tex">m</annotation></semantics></math></span> samples are misclassified. It is easy to derive that the probability of obtaining testing error <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{\epsilon}</annotation></semantics></math></span> on a test set of <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>m</mi></mrow><annotation encoding="application/x-tex">m</annotation></semantics></math></span> samples, for a learner with generalization error rate <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">{\epsilon}</annotation></semantics></math></span>, is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover><mo separator="true">;</mo><mi>ϵ</mi><mo stretchy="false">)</mo><mo>=</mo><mrow><mo fence="true">(</mo><mtable rowspacing="0.16em" columnalign="center" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mi>m</mi></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover><mo>×</mo><mi>m</mi></mrow></mstyle></mtd></mtr></mtable><mo fence="true">)</mo></mrow><msup><mi>ϵ</mi><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover><mo>×</mo><mi>m</mi></mrow></msup><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>ϵ</mi><msup><mo stretchy="false">)</mo><mrow><mi>m</mi><mo>−</mo><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover><mo>×</mo><mi>m</mi></mrow></msup></mrow><annotation encoding="application/x-tex">
P(\hat{\epsilon} ; \epsilon)=\left(\begin{array}{c}m \\ \hat{\epsilon} \times m\end{array}\right) \epsilon^{\hat{\epsilon} \times m}(1-\epsilon)^{m-\hat{\epsilon} \times m}
</annotation></semantics></math></span><p>A binomial distribution is used for the hypothesis test. The hypothesis takes the form <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi><mo>≤</mo><msub><mi>ϵ</mi><mn>0</mn></msub></mrow><annotation encoding="application/x-tex">\epsilon \leq \epsilon_{0}</annotation></semantics></math></span>, and the maximum error rate we can observe with probability <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>−</mo><mi>α</mi></mrow><annotation encoding="application/x-tex">1-\alpha</annotation></semantics></math></span> is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>ˉ</mo></mover><mo>=</mo><mi>max</mi><mo>⁡</mo><mi>ϵ</mi><mspace width="1em"/><mtext> s.t. </mtext><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><msub><mi>ϵ</mi><mn>0</mn></msub><mo>×</mo><mi>m</mi><mo>+</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mrow><mo fence="true">(</mo><mtable rowspacing="0.16em" columnalign="center" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mi>m</mi></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mi>i</mi></mstyle></mtd></mtr></mtable><mo fence="true">)</mo></mrow><msup><mi>ϵ</mi><mi>i</mi></msup><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>ϵ</mi><msup><mo stretchy="false">)</mo><mrow><mi>m</mi><mo>−</mo><mi>i</mi></mrow></msup><mo>&lt;</mo><mi>α</mi></mrow><annotation encoding="application/x-tex">
\bar{\epsilon}=\max \epsilon \quad \text { s.t. } \sum_{i=\epsilon_{0} \times m+1}^{m}\left(\begin{array}{c}m \\ i\end{array}\right) \epsilon^{i}(1-\epsilon)^{m-i}&lt;\alpha
</annotation></semantics></math></span><p>If the testing error <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{\epsilon}</annotation></semantics></math></span> is smaller than the critical value <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>ϵ</mi><mo>ˉ</mo></mover></mrow><annotation encoding="application/x-tex">\bar{\epsilon}</annotation></semantics></math></span>, we accept the hypothesis at the <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>−</mo><mi>α</mi></mrow><annotation encoding="application/x-tex">1-\alpha</annotation></semantics></math></span> confidence level; otherwise, at the significance level <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi></mrow><annotation encoding="application/x-tex">\alpha</annotation></semantics></math></span>, we conclude that the generalization error rate is greater than <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ϵ</mi></mrow><annotation encoding="application/x-tex">\epsilon</annotation></semantics></math></span>.</p>
<p>If the hold-out method or cross-validation is applied multiple times, k testing error rates are obtained. The mean and variance can then be computed, and a t-test can be used for the hypothesis test. The hypothesis in this case is that the mean equals the error rate. The variable:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>τ</mi><mi>t</mi></msub><mo>=</mo><mfrac><mrow><msqrt><mi>k</mi></msqrt><mrow><mo fence="true">(</mo><mi>μ</mi><mo>−</mo><msub><mi>ϵ</mi><mn>0</mn></msub><mo fence="true">)</mo></mrow></mrow><mi>ϵ</mi></mfrac></mrow><annotation encoding="application/x-tex">
\tau_{t}=\frac{\sqrt{k}\left(\mu-\epsilon_{0}\right)}{\epsilon}
</annotation></semantics></math></span><p>follows a t-distribution with k-1 degrees of freedom.</p>
<p>More test methods are described on p.41 of the Watermelon Book</p>
<h2 id="bias-and-variance">Bias and Variance</h2>
<p>Besides estimating generalization performance, we also want to understand why the model performs the way it does, which calls for bias-variance decomposition. Taking a regression task as an example, y_D is the label of x on the dataset, y is the true label of x, and f(x,D) is the predicted output.</p>
<p>The expected prediction is then: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>f</mi><mo>ˉ</mo></mover><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mi>D</mi></msub><mo stretchy="false">[</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\bar{f}(x)=\mathbb{E}_{D}[f(x ; D)]</annotation></semantics></math></span></p>
<p>Training sets with different numbers of samples give rise to variance. Then perform the decomposition:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>E</mi><mo stretchy="false">(</mo><mi>f</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi>D</mi><mrow><mo fence="true">[</mo><msup><mrow><mo fence="true">(</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo>−</mo><msub><mi>y</mi><mi>D</mi></msub><mo fence="true">)</mo></mrow><mn>2</mn></msup><mo fence="true">]</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi>D</mi><mrow><mo fence="true">[</mo><mo stretchy="false">(</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">;</mo><mi>D</mi><mo stretchy="false">)</mo><mo>−</mo><mover accent="true"><mi>f</mi><mo>ˉ</mo></mover><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><msup><mo stretchy="false">)</mo><mn>2</mn></msup><mo fence="true">]</mo></mrow><mo>+</mo><mo stretchy="false">(</mo><mover accent="true"><mi>f</mi><mo>ˉ</mo></mover><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>−</mo><mi>y</mi><msup><mo stretchy="false">)</mo><mn>2</mn></msup><mo>+</mo><msub><mi mathvariant="double-struck">E</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi>D</mi><mrow><mo fence="true">[</mo><msup><mrow><mo fence="true">(</mo><msub><mi>y</mi><mi>D</mi></msub><mo>−</mo><mi>y</mi><mo fence="true">)</mo></mrow><mn>2</mn></msup><mo fence="true">]</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><msup><mrow><mi mathvariant="normal">bias</mi><mo>⁡</mo></mrow><mn>2</mn></msup><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><mi mathvariant="normal">var</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msup><mi>ε</mi><mn>2</mn></msup></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} E(f ; D) &amp;=\mathbb{E}_{-} D\left[\left(f(x ; D)-y_{D}\right)^{2}\right] \\ &amp;=\mathbb{E}_{-} D\left[(f(x ; D)-\bar{f}(x))^{2}\right]+(\bar{f}(x)-y)^{2}+\mathbb{E}_{-} D\left[\left(y_{D}-y\right)^{2}\right] \\ &amp;=\operatorname{bias}^{2}(x)+\operatorname{var}(x)+\varepsilon^{2} \end{aligned}
</annotation></semantics></math></span><p>The generalization error can be decomposed into the sum of bias, variance, and noise</p>
<ul>
<li>Bias measures the deviation of the algorithm&rsquo;s expected prediction from the true result, characterizing the fitting capability of the learning algorithm itself</li>
<li>Variance measures the change in learning performance caused by changes in training sets of the same size, characterizing the impact of data perturbation</li>
<li>Noise expresses the lower bound of the expected generalization error that any learning algorithm can achieve on the current task, characterizing the difficulty of the learning problem itself.</li>
</ul>
]]></content:encoded></item><item><title>A Survey on Personalization Capabilities in Federated Learning</title><link>https://blog.ereebay.me/en/posts/notes-fl-overview/</link><pubDate>Wed, 29 Apr 2020 12:37:55 +0000</pubDate><guid>https://blog.ereebay.me/en/posts/notes-fl-overview/</guid><description>&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;The goal of federated learning is to obtain a shared global model that all nodes can use. However, due to Non-IID data distributions, local models trained solely on local data often outperform the global model, which makes these nodes reluctant to participate in the federation process. This post introduces techniques currently used to personalize the global model so as to improve its performance on individual nodes.&lt;/p&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Federated learning is a distributed machine learning algorithm designed for Non-IID data. It enables multiple nodes to collaboratively train a shared global model without sharing their own data. At the beginning of each training round, the central server sends the current global model to every node, and each node trains the model on its local data. The central server then collects the model updates from all nodes and applies them to the global model.&lt;/p&gt;</description><content:encoded><![CDATA[<h2 id="abstract">Abstract</h2>
<p>The goal of federated learning is to obtain a shared global model that all nodes can use. However, due to Non-IID data distributions, local models trained solely on local data often outperform the global model, which makes these nodes reluctant to participate in the federation process. This post introduces techniques currently used to personalize the global model so as to improve its performance on individual nodes.</p>
<h2 id="introduction">Introduction</h2>
<p>Federated learning is a distributed machine learning algorithm designed for Non-IID data. It enables multiple nodes to collaboratively train a shared global model without sharing their own data. At the beginning of each training round, the central server sends the current global model to every node, and each node trains the model on its local data. The central server then collects the model updates from all nodes and applies them to the global model.</p>
<p>The main reason for a node to participate in federated learning is to obtain a better model. When a node does not have enough data to train a good local model on its own, it can obtain a decent model through federated learning. But for nodes with abundant data, the benefit of federated learning remains in question. Yu, in Salvaging Federated Learning by Local Adaptation, noted that for many tasks some nodes gain no benefit because the globally shared model underperforms a model trained on their local data. Hanzely, in Federated Learning of a Mixture of Global and Local Models, questioned whether the global model deviates too far from the classical use cases of users.</p>
<p>The purpose of this post is to survey recent techniques for building personalized models on local nodes, where the personalized models are expected to outperform either the shared global model or the model trained locally by the node.</p>
<h2 id="need-for-personalization">Need for Personalization</h2>
<p>Wu, in Personalized federated learning for intelligent iot applications, described the three major challenges federated learning systems face with respect to personalization:</p>
<ol>
<li>Heterogeneity of devices in terms of storage, computation, and communication capabilities.</li>
<li>Data heterogeneity caused by Non-IID distributions.</li>
<li>Model heterogeneity arising from the need for different models due to different user environments.</li>
</ol>
<p>To address the challenges brought by data heterogeneity and Non-IID data, personalizing the global model has become increasingly important. Most personalization techniques consist of two steps: 1. learn a global model collaboratively across the nodes; 2. personalize the global model using each node&rsquo;s private data. Jiang argued that optimizing solely for global-model accuracy hardly produces models that personalize well, and proposed that, for personalization in federated learning to be useful in practice, the following three objectives must be solved simultaneously rather than independently:</p>
<ol>
<li>Build improved personalized models that benefit the majority of nodes</li>
<li>Build a more accurate global model, which enables better personalization for nodes with little data</li>
<li>Achieve fast model convergence within few training rounds</li>
</ol>
<p>In addition, only a fraction of the samples in a node&rsquo;s local data may be relevant to the specific task, while the remaining samples are irrelevant ones that hurt model training. Tuor proposed a method that uses a relevance model built on a small benchmark to distinguish relevant from irrelevant samples, and then uses only the relevant samples during federated learning.</p>
<h2 id="techniques">Techniques</h2>
<h3 id="adding-user-context">Adding User Context</h3>
<p>Before introducing methods for personalizing the global model for each node, it must be pointed out that a shared global model can also make highly personalized predictions, provided that the node&rsquo;s context and personal information are properly featurized and integrated into the dataset. However, most public datasets do not contain contextual features, and developing techniques that can effectively incorporate context remains an important open problem—one with great potential to improve federated learning models. At the same time, whether such contextual featurization can be done without adversely affecting privacy remains to be studied. As an intermediate approach between a single global model and purely local models, Masour, in Three approaches for personalization with applications to federated learning, suggested clustering users—grouping similar clients together—and training a separate model for each group.</p>
<h3 id="transfer-learning">Transfer Learning</h3>
<p>Transfer learning allows deep learning models to leverage the capabilities acquired while solving problem A to solve another related problem. Schneider and Vlachos, in Mass personalization of deep learning, discussed using transfer learning to achieve model personalization in non-federated settings. Transfer learning has likewise been applied in federated settings. Wang, in Federated evalua- tion of on-device personalization, proposed re-learning some or all parameters of the trained global model on local data; the previously cited work provides the theoretical justification. By initializing local training with the parameters of the trained global model, transfer learning exploits the knowledge extracted by the global model instead of learning from scratch. Meanwhile, to avoid catastrophic forgetting, care must be taken not to retrain/finetune on local data for too long. One variant of this technique freezes the base layers of the global model and trains only the top layers on local data (similar to freezing the feature layers and finetuning the fully connected layers).</p>
<h3 id="multi-task-learning">Multi-task Learning</h3>
<p>In multi-task learning, a model exploits the commonalities and differences across tasks through joint learning, so that multiple related tasks can be solved simultaneously. Smith, in Federated multi-task learning, showed that multi-task learning is a natural choice for constructing personalized federated models and developed the MOCHA algorithm. A drawback of using multi-task learning in federated settings, however, is that, because it produces one model per task, all nodes must participate in every round of training.</p>
<h3 id="meta-learning">Meta Learning</h3>
<p>Meta-learning involves training across multiple learning tasks to produce models that adapt quickly—models that can fit and solve a new task with only a few training samples. Finn proposed the Model-Agnostic Meta-Learning algorithm (MAML), which is compatible with any model trained by gradient descent. MAML builds internal representations that work across multiple tasks, so for a new task, fine-tuning the top layers can produce good results.</p>
<p>Jiang pointed out that the federated learning process can be viewed as meta-training, while the personalization process can be viewed as meta-testing; the FedAvg algorithm is then very similar to Reptile. The author also observed that careful fine-tuning can yield accurate global models that are easy to personalize, whereas optimizing purely for global-model accuracy sacrifices the model&rsquo;s subsequent personalization capability. Other personalization approaches in federated learning treat the construction of the global model and personalization as two separate processes; Jiang proposed an improved FedAvg algorithm that achieves both a better global model and better personalized models.</p>
<p>Fallah, in Personalized federated learning: A meta-learning approach, formulated a new version of the standard federated learning problem that incorporates MAML, seeking a global model that performs well on every node after being updated with that node&rsquo;s own loss function; they further proposed Per-FedAvg to solve this problem. Khodak, in Adaptive gradient-based meta-learning methods, proposed ARUBA and demonstrated improved performance by applying it to FedAvg. Chen, in Federated meta-learning for recommendation, proposed a federated meta-learning framework for building personalized recommendation models, in which both the algorithm and the model are parameterized and need to be optimized.</p>
<h3 id="knowledge-distillation">Knowledge Distillation</h3>
<p>Caruana showed that the knowledge of an ensemble of models can be compressed into a single model that is easy to deploy. Knowledge distillation develops this idea further, extracting the knowledge of a large teacher network into a smaller student network by having the student imitate the teacher. Overfitting poses a major obstacle during personalization, especially for nodes with small local datasets. Yu proposed that treating the global model as the teacher and the node&rsquo;s personalized model as the student can alleviate overfitting. Li proposed FedMD, a federated learning framework based on knowledge distillation and transfer learning that allows nodes to independently design their own networks while leveraging both their private data and a global public dataset.</p>
<h3 id="basepersonalization-layers">Base+Personalization Layers</h3>
<p>In the conventional federated learning setting, data is distributed across the multiple devices participating in training. To mitigate the adverse effects of such data heterogeneity, Arivazhagan et al., in Federated learning with personalization layers, proposed the FedPer architecture, in which the base layers are trained with FedAvg while the top layers (the personalization layers) are trained on the local node with a variant of gradient descent. The transfer-learning approach first trains all layers on global data and then retrains some or all layers on the local node&rsquo;s data, whereas FedPer trains the base layers on global data and the personalization layers on local data, separately.</p>
<h3 id="mixtrue-of-global-and-local-models">Mixtrue of Global and Local Models</h3>
<p>Hanzely, in Federated learning of a mixture of global and local models, proposed a new problem formulation that seeks a balance between the global model and local models. Instead of learning a single global model, each node learns a mixture of the global model and its own local model. To solve this problem, the authors proposed LLGD, Loopless Local Gradient Descent (LLGD), a variant of gradient descent. Unlike full averaging, this method only takes averaged steps, because full averaging can be too aggressive.</p>
<h2 id="discussion">Discussion</h2>
<p>In federated learning, when a node&rsquo;s local dataset is small and IID (isn&rsquo;t this similar to the meta-learning scenario?), the global model usually surpasses local models, and most nodes benefit from the federation process. However, when nodes possess sufficiently large private datasets with Non-IID distributions, local models usually outperform the global model, and nodes are generally reluctant to participate in federated learning. <strong>An open theoretical question is: how to determine when the global model will outperform the model on a single node</strong></p>
<p>This post has mainly summarized several techniques for optimizing the personalization of the global model. With a few exceptions, most prior work has focused on measuring the performance of global models on aggregated data rather than on individual nodes. But if the global model is to be personalized before use, aggregate global performance becomes meaningless.</p>
<p>Personalized models usually outperform both the global model and purely local models on individual nodes. In some cases, however, a personalized model cannot reach the same capability as a purely local model, especially under differential privacy and similar conditions.</p>
]]></content:encoded></item><item><title>A Survey on Personalization Capabilities in Federated Learning</title><link>https://blog.ereebay.me/en/posts/survey-personal/</link><pubDate>Wed, 29 Apr 2020 12:37:55 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/survey-personal/</guid><description>&lt;h1 id="a-survey-on-personalization-in-federated-learning"&gt;A Survey on Personalization in Federated Learning&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;The goal of federated learning is to obtain a shared global model that all nodes can use. However, due to Non-IID data distributions, local models trained solely on local data often outperform the global model, which makes these nodes reluctant to participate in the federation process. This post introduces techniques currently used to personalize the global model so as to improve its performance on individual nodes.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="a-survey-on-personalization-in-federated-learning">A Survey on Personalization in Federated Learning</h1>
<h2 id="abstract">Abstract</h2>
<p>The goal of federated learning is to obtain a shared global model that all nodes can use. However, due to Non-IID data distributions, local models trained solely on local data often outperform the global model, which makes these nodes reluctant to participate in the federation process. This post introduces techniques currently used to personalize the global model so as to improve its performance on individual nodes.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>Federated learning is a distributed machine learning algorithm designed for Non-IID data. It enables multiple nodes to collaboratively train a shared global model without sharing their own data. At the beginning of each training round, the central server sends the current global model to every node, and each node trains the model on its local data. The central server then collects the model updates from all nodes and applies them to the global model.</p>
<p>The main reason for a node to participate in federated learning is to obtain a better model. When a node does not have enough data to train a good local model on its own, it can obtain a decent model through federated learning. But for nodes with abundant data, the benefit of federated learning remains in question. Yu, in Salvaging Federated Learning by Local Adaptation, noted that for many tasks some nodes gain no benefit because the globally shared model underperforms a model trained on their local data. Hanzely, in Federated Learning of a Mixture of Global and Local Models, questioned whether the global model deviates too far from the classical use cases of users.</p>
<p>The purpose of this post is to survey recent techniques for building personalized models on local nodes, where the personalized models are expected to outperform either the shared global model or the model trained locally by the node.</p>
<h2 id="need-for-personalization">Need for Personalization</h2>
<p>Wu, in Personalized federated learning for intelligent iot applications, described the three major challenges federated learning systems face with respect to personalization:</p>
<ol>
<li>Heterogeneity of devices in terms of storage, computation, and communication capabilities.</li>
<li>Data heterogeneity caused by Non-IID distributions.</li>
<li>Model heterogeneity arising from the need for different models due to different user environments.</li>
</ol>
<p>To address the challenges brought by data heterogeneity and Non-IID data, personalizing the global model has become increasingly important. Most personalization techniques consist of two steps: 1. learn a global model collaboratively across the nodes; 2. personalize the global model using each node&rsquo;s private data. Jiang argued that optimizing solely for global-model accuracy hardly produces models that personalize well, and proposed that, for personalization in federated learning to be useful in practice, the following three objectives must be solved simultaneously rather than independently:</p>
<ol>
<li>Build improved personalized models that benefit the majority of nodes</li>
<li>Build a more accurate global model, which enables better personalization for nodes with little data</li>
<li>Achieve fast model convergence within few training rounds</li>
</ol>
<p>In addition, only a fraction of the samples in a node&rsquo;s local data may be relevant to the specific task, while the remaining samples are irrelevant ones that hurt model training. Tuor proposed a method that uses a relevance model built on a small benchmark to distinguish relevant from irrelevant samples, and then uses only the relevant samples during federated learning.</p>
<h2 id="techniques">Techniques</h2>
<h3 id="adding-user-context">Adding User Context</h3>
<p>Before introducing methods for personalizing the global model for each node, it must be pointed out that a shared global model can also make highly personalized predictions, provided that the node&rsquo;s context and personal information are properly featurized and integrated into the dataset. However, most public datasets do not contain contextual features, and developing techniques that can effectively incorporate context remains an important open problem—one with great potential to improve federated learning models. At the same time, whether such contextual featurization can be done without adversely affecting privacy remains to be studied. As an intermediate approach between a single global model and purely local models, Masour, in Three approaches for personalization with applications to federated learning, suggested clustering users—grouping similar clients together—and training a separate model for each group.</p>
<h3 id="transfer-learning">Transfer Learning</h3>
<p>Transfer learning allows deep learning models to leverage the capabilities acquired while solving problem A to solve another related problem. Schneider and Vlachos, in Mass personalization of deep learning, discussed using transfer learning to achieve model personalization in non-federated settings. Transfer learning has likewise been applied in federated settings. Wang, in Federated evalua- tion of on-device personalization, proposed re-learning some or all parameters of the trained global model on local data; the previously cited work provides the theoretical justification. By initializing local training with the parameters of the trained global model, transfer learning exploits the knowledge extracted by the global model instead of learning from scratch. Meanwhile, to avoid catastrophic forgetting, care must be taken not to retrain/finetune on local data for too long. One variant of this technique freezes the base layers of the global model and trains only the top layers on local data (similar to freezing the feature layers and finetuning the fully connected layers).</p>
<h3 id="multi-task-learning">Multi-task Learning</h3>
<p>In multi-task learning, a model exploits the commonalities and differences across tasks through joint learning, so that multiple related tasks can be solved simultaneously. Smith, in Federated multi-task learning, showed that multi-task learning is a natural choice for constructing personalized federated models and developed the MOCHA algorithm. A drawback of using multi-task learning in federated settings, however, is that, because it produces one model per task, all nodes must participate in every round of training.</p>
<h3 id="meta-learning">Meta Learning</h3>
<p>Meta-learning involves training across multiple learning tasks to produce models that adapt quickly—models that can fit and solve a new task with only a few training samples. Finn proposed the Model-Agnostic Meta-Learning algorithm (MAML), which is compatible with any model trained by gradient descent. MAML builds internal representations that work across multiple tasks, so for a new task, fine-tuning the top layers can produce good results.</p>
<p>Jiang pointed out that the federated learning process can be viewed as meta-training, while the personalization process can be viewed as meta-testing; the FedAvg algorithm is then very similar to Reptile. The author also observed that careful fine-tuning can yield accurate global models that are easy to personalize, whereas optimizing purely for global-model accuracy sacrifices the model&rsquo;s subsequent personalization capability. Other personalization approaches in federated learning treat the construction of the global model and personalization as two separate processes; Jiang proposed an improved FedAvg algorithm that achieves both a better global model and better personalized models.</p>
<p>Fallah, in Personalized federated learning: A meta-learning approach, formulated a new version of the standard federated learning problem that incorporates MAML, seeking a global model that performs well on every node after being updated with that node&rsquo;s own loss function; they further proposed Per-FedAvg to solve this problem. Khodak, in Adaptive gradient-based meta-learning methods, proposed ARUBA and demonstrated improved performance by applying it to FedAvg. Chen, in Federated meta-learning for recommendation, proposed a federated meta-learning framework for building personalized recommendation models, in which both the algorithm and the model are parameterized and need to be optimized.</p>
<h3 id="knowledge-distillation">Knowledge Distillation</h3>
<p>Caruana showed that the knowledge of an ensemble of models can be compressed into a single model that is easy to deploy. Knowledge distillation develops this idea further, extracting the knowledge of a large teacher network into a smaller student network by having the student imitate the teacher. Overfitting poses a major obstacle during personalization, especially for nodes with small local datasets. Yu proposed that treating the global model as the teacher and the node&rsquo;s personalized model as the student can alleviate overfitting. Li proposed FedMD, a federated learning framework based on knowledge distillation and transfer learning that allows nodes to independently design their own networks while leveraging both their private data and a global public dataset.</p>
<h3 id="basepersonalization-layers">Base+Personalization Layers</h3>
<p>In the conventional federated learning setting, data is distributed across the multiple devices participating in training. To mitigate the adverse effects of such data heterogeneity, Arivazhagan et al., in Federated learning with personalization layers, proposed the FedPer architecture, in which the base layers are trained with FedAvg while the top layers (the personalization layers) are trained on the local node with a variant of gradient descent. The transfer-learning approach first trains all layers on global data and then retrains some or all layers on the local node&rsquo;s data, whereas FedPer trains the base layers on global data and the personalization layers on local data, separately.</p>
<h3 id="mixtrue-of-global-and-local-models">Mixtrue of Global and Local Models</h3>
<p>Hanzely, in Federated learning of a mixture of global and local models, proposed a new problem formulation that seeks a balance between the global model and local models. Instead of learning a single global model, each node learns a mixture of the global model and its own local model. To solve this problem, the authors proposed LLGD, Loopless Local Gradient Descent (LLGD), a variant of gradient descent. Unlike full averaging, this method only takes averaged steps, because full averaging can be too aggressive.</p>
<h2 id="discussion">Discussion</h2>
<p>In federated learning, when a node&rsquo;s local dataset is small and IID (isn&rsquo;t this similar to the meta-learning scenario?), the global model usually surpasses local models, and most nodes benefit from the federation process. However, when nodes possess sufficiently large private datasets with Non-IID distributions, local models usually outperform the global model, and nodes are generally reluctant to participate in federated learning. <strong>An open theoretical question is: how to determine when the global model will outperform the model on a single node</strong></p>
<p>This post has mainly summarized several techniques for optimizing the personalization of the global model. With a few exceptions, most prior work has focused on measuring the performance of global models on aggregated data rather than on individual nodes. But if the global model is to be personalized before use, aggregate global performance becomes meaningless.</p>
<p>Personalized models usually outperform both the global model and purely local models on individual nodes. In some cases, however, a personalized model cannot reach the same capability as a purely local model, especially under differential privacy and similar conditions.</p>
]]></content:encoded></item><item><title>Decoupled Neural Interfaces using Synthetic Gradients</title><link>https://blog.ereebay.me/en/posts/dnisg/</link><pubDate>Tue, 18 Feb 2020 11:04:59 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/dnisg/</guid><description>&lt;h1 id="decoupled-neural-interfaces-using-synthetic-gradients"&gt;Decoupled Neural Interfaces using Synthetic Gradients&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;Training neural networks typically requires pushing the computation graph forward and then backpropagating errors to update the weights. In this sense, all layers of the network are locked, because they must wait for other parts of the network to complete their forward inference and backward pass before they can be updated. In this work, we introduce models of future computation in the network graph, in order to decouple modules and thereby break this constraint. These models use only local information to predict the outcome of a subgraph. In particular, we focus on modeling the error gradients: by replacing the true backpropagated error gradients with modeled synthetic gradients, subgraphs are decoupled and can be updated independently and asynchronously—namely, we realize decoupled neural interfaces. We present results for feed-forward models in which every layer is trained asynchronously; for RNNs, where predicting the future gradients of one layer extends the effective modeling horizon of the RNN; and for hierarchical RNN systems with different timescales. Finally, we show that, beyond predicting gradients, the same framework can also be used to predict inputs, resulting in models that are decoupled in both the forward and backward passes—equivalent to two independent networks that can learn together so as to be composed into a single functional network.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="decoupled-neural-interfaces-using-synthetic-gradients">Decoupled Neural Interfaces using Synthetic Gradients</h1>
<h2 id="abstract">Abstract</h2>
<p>Training neural networks typically requires pushing the computation graph forward and then backpropagating errors to update the weights. In this sense, all layers of the network are locked, because they must wait for other parts of the network to complete their forward inference and backward pass before they can be updated. In this work, we introduce models of future computation in the network graph, in order to decouple modules and thereby break this constraint. These models use only local information to predict the outcome of a subgraph. In particular, we focus on modeling the error gradients: by replacing the true backpropagated error gradients with modeled synthetic gradients, subgraphs are decoupled and can be updated independently and asynchronously—namely, we realize decoupled neural interfaces. We present results for feed-forward models in which every layer is trained asynchronously; for RNNs, where predicting the future gradients of one layer extends the effective modeling horizon of the RNN; and for hierarchical RNN systems with different timescales. Finally, we show that, beyond predicting gradients, the same framework can also be used to predict inputs, resulting in models that are decoupled in both the forward and backward passes—equivalent to two independent networks that can learn together so as to be composed into a single functional network.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>Each layer (or module) in a directed neural network can be viewed as a computation step that transforms its input. These modules are connected by directed edges, forming a feed-forward graph that defines the flow of data from the network&rsquo;s input, through each module, to the network&rsquo;s output. A loss is defined on the output to produce errors, which are backpropagated through the network graph to update each module&rsquo;s weights.</p>
<p>This mechanism leads to the following forms of locking:</p>
<ol>
<li>Forward Locking: no module can process its input before the earlier nodes of the forward computation graph have been executed.</li>
<li>Update Locking: no module can be updated until all relevant modules have finished executing in the forward graph.</li>
<li>Backwards Locking: no module can be updated until all relevant modules have executed both the feed-forward and the backward model—for example, the BP algorithm.</li>
</ol>
<p>Forward, update, and backwards locking force neural networks to run and update sequentially and synchronously. For simple networks this seems benign, but it becomes a serious problem for large, complex, irregular networks, or network systems running in multiple environments with asynchronous timescales.</p>
<p>For example, consider distributed models in which part of the model is shared and used by many downstream clients. This means that all clients must finish executing and pass their error gradients back to the shared model before it can be updated—which means the training speed of the system is dictated by the slowest client. If training of the network could be parallelized, computation time could be greatly reduced.</p>
<p>The goal of this work is to remove update locking from neural networks. This can be achieved by removing backpropagation. To update the weights <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\theta_{i}</annotation></semantics></math></span> of module i, we approximate the backpropagation function as closely as possible:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mfrac><mrow><mi mathvariant="normal">∂</mi><mi>L</mi></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>i</mi></msub></mrow></mfrac></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><msub><mi>f</mi><mtext>Bprop </mtext></msub><mrow><mo fence="true">(</mo><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>x</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>y</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>θ</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo separator="true">,</mo><mo>…</mo><mo fence="true">)</mo></mrow><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>h</mi><mi>i</mi></msub></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>i</mi></msub></mrow></mfrac></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≃</mo><msub><mover accent="true"><mi>f</mi><mo>^</mo></mover><mtext>Bprop </mtext></msub><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>h</mi><mi>i</mi></msub></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>i</mi></msub></mrow></mfrac></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} \frac{\partial L}{\partial \theta_{i}} &amp;=f_{\text {Bprop }}\left(\left(h_{i}, x_{i}, y_{i}, \theta_{i}\right), \ldots\right) \frac{\partial h_{i}}{\partial \theta_{i}} \\ &amp; \simeq \hat{f}_{\text {Bprop }}\left(h_{i}\right) \frac{\partial h_{i}}{\partial \theta_{i}} \end{aligned}
</annotation></semantics></math></span><p>where h denotes the layer&rsquo;s activations, x the input, y the supervision (labels), and L the total loss. The update now depends entirely on h—that is, on information local to module i.</p>
<p>The premise of this method is to allow neural network modules to interact and to be trained without update locking. Here the authors replace the conventional neural interface (the connection between two modules in a network) with a Decoupled Neural Interface (DNI). In short, when one network layer passes activations to another layer, there is an associated model that produces a predicted error gradient for those activations. The predicted gradient is a function of the activation alone and does not depend on other events, states, or losses. The sending layer can then use this synthetic gradient to update immediately. By removing update and backwards locking, we can train networks without synchronization. We also present preliminary results extending this idea to remove forward locking as well, so that the modules of the network can likewise be trained without a synchronized forward pass. When applied to RNNs, we show that using synthetic gradients allows an RNN to model a time horizon far beyond the limit of BPTT. We further show that using synthetic gradients to decouple two RNNs operating at different timescales can greatly improve training.</p>
<h2 id="decoupled-neural-interfaces">Decoupled Neural Interfaces</h2>
<p>We first describe the high-level communication protocol used to allow asynchronous learning agents to communicate.</p>
<p>As shown in Figure 1, Sender A sends a message (activation) <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">h_A</annotation></semantics></math></span> to Receiver B. Intuitively, A can be thought of as the earlier layer and B as the later layer. B has a utility <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>M</mi><mi>B</mi></msub></mrow><annotation encoding="application/x-tex">M_B</annotation></semantics></math></span> that processes the signal <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">h_A</annotation></semantics></math></span> to predict the feedback. The error signal: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>A</mi></msub><mo>=</mo><msub><mi>M</mi><mi>B</mi></msub><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>A</mi></msub><mo separator="true">,</mo><msub><mi>s</mi><mi>B</mi></msub><mo separator="true">,</mo><mi>c</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\hat{\delta}_{A}=M_{B}\left(h_{A}, s_{B}, c\right)</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">h_A</annotation></semantics></math></span> is the message (activation), <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>B</mi></msub></mrow><annotation encoding="application/x-tex">s_B</annotation></semantics></math></span> is B&rsquo;s state, and c is some other potentially relevant information, such as labels or context. A can update immediately using this error signal. B can also, in time, fully evaluate the true <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">\delta_A</annotation></semantics></math></span>; thus B&rsquo;s utility model can be updated to fit the true utility, reducing the discrepancy between the true and synthetic errors.</p>
<p>This protocol allows A to send messages to B in a way that decouples the updates of A and B—A does not have to wait for B to evaluate the true utility before updating—and A can still learn to send messages to B.</p>
<p>We can apply this protocol to the communication process within networks, giving rise to so-called Decoupled Neural Interfaces (DNI). For neural networks, the feedback error signal <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">\hat{\delta}_A</annotation></semantics></math></span> can take different forms: for example, gradients can serve as error signals used together with backpropagation; target information can serve as error signals used together with target propagation; or they can even be used as values incorporated into a reinforcement learning framework. This paper focuses on differentiable networks trained via backpropagation with gradient-based updates. We therefore concentrate on the produced error gradient as the feedback <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>A</mi></msub></mrow><annotation encoding="application/x-tex">\hat{\delta}_A</annotation></semantics></math></span>, called the synthetic gradient.</p>
<p>Notation. We define the function at step i as fi, and the composition of the functions from step i to step j as Fij. The loss at layer i is defined as Li.</p>
<h3 id="synthetic-gradient-for-feed-forward-networks">Synthetic Gradient for Feed-Forward Networks</h3>
<p>Consider the DNI formulation for feed-forward networks: N layers fi, each taking input hi-1 and producing output hi = fi(hi-1), where h0 = x is the input data. The feed-forward graph of the whole network can be written as F1N. See Figure 3(a)</p>
<p><img alt="20200218134533.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218134533.png"></p>
<p>Define the loss function on the network output as L = LN. Each layer fi has parameters thetai, updated by a gradient update rule to minimize L(hN)</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>i</mi></msub><mo>←</mo><msub><mi>θ</mi><mi>i</mi></msub><mo>−</mo><mi>α</mi><msub><mi>δ</mi><mi>i</mi></msub><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>h</mi><mi>i</mi></msub></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>i</mi></msub></mrow></mfrac><mo separator="true">;</mo><mspace width="1em"/><msub><mi>δ</mi><mi>i</mi></msub><mo>=</mo><mfrac><mrow><mi mathvariant="normal">∂</mi><mi>L</mi></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>h</mi><mi>i</mi></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">
\theta_{i} \leftarrow \theta_{i}-\alpha \delta_{i} \frac{\partial h_{i}}{\partial \theta_{i}} ; \quad \delta_{i}=\frac{\partial L}{\partial h_{i}}
</annotation></semantics></math></span><p>α is the learning rate, and the derivative with respect to hi is obtained via backpropagation. The dependence on <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\delta_i</annotation></semantics></math></span> means that layer i&rsquo;s update must wait until the rest of the network has been updated—that is, all of F(i+1)N has executed its feed-forward and feedback phases. Layer i is thus update-locked to F(i+1)N.</p>
<p>To remove update locking, we adopt the communication protocol described earlier. Layer i sends the message hi to the following layer, which has a communication model Mi+1 that produces the synthetic error gradient <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>i</mi></msub><mo>=</mo><msub><mi>M</mi><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub><mo stretchy="false">(</mo><msub><mi>h</mi><mi>i</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\hat{\delta}_{i} = M_{i+1}(h_{i})</annotation></semantics></math></span>. As shown in the figure:</p>
<p><img alt="20200218135141.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218135141.png"></p>
<p>Layer i, as well as the other layers within F1i, can be updated immediately</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>n</mi></msub><mo>←</mo><msub><mi>θ</mi><mi>n</mi></msub><mo>−</mo><mi>α</mi><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>i</mi></msub><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>h</mi><mi>i</mi></msub></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>n</mi></msub></mrow></mfrac><mo separator="true">,</mo><mi>n</mi><mo>∈</mo><mo stretchy="false">{</mo><mn>1</mn><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><mi>i</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">
\theta_{n} \leftarrow \theta_{n}-\alpha \hat{\delta}_{i} \frac{\partial h_{i}}{\partial \theta_{n}}, n \in\{1, \ldots, i\}
</annotation></semantics></math></span><p>To train the parameters of the synthetic gradient model Mi+1, we wait until the true error gradient <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\delta_i</annotation></semantics></math></span> has been computed, and then compute the MSE between the two.</p>
<p>Moreover, for feed-forward networks, we can use synthetic gradients as the communication feedback to decouple every layer in the network. As shown in the figure:</p>
<p><img alt="20200218142500.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218142500.png"></p>
<p>The complete execution of this mechanism:</p>
<p><img alt="20200218150932.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218150932.png"></p>
<p>In this case, the target error gradient <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\delta_i</annotation></semantics></math></span> is produced by backpropagating <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub></mrow><annotation encoding="application/x-tex">\hat{\delta}_{i+1}</annotation></semantics></math></span> through layer i+1. Thus <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\delta_i</annotation></semantics></math></span> is not the true error gradient but an estimate obtained from the synthetic gradient models further downstream. Surprisingly, this does not make the errors worse—learning remains stable even across many layers, as the experiments below show.</p>
<p>In addition, supervision or context c can be incorporated when computing the synthetic gradient.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>δ</mi><mo>^</mo></mover><mi>i</mi></msub><mo>=</mo><mrow><msub><mi>M</mi><mrow><mi>i</mi><mo>+</mo><mn>1</mn></mrow></msub><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>i</mi></msub><mo separator="true">,</mo><mi>c</mi><mo fence="true">)</mo></mrow></mrow></mrow><annotation encoding="application/x-tex">
\hat{\delta}_{i} = {M_{i+1}\left(h_{i}, c\right) }
</annotation></semantics></math></span><p>This procedure allows a layer to be updated immediately after its forward pass has been executed. This paves the way for training sub-parts—or individual layers—of a network in an asynchronous manner.</p>
<h2 id="experiment">Experiment</h2>
<h3 id="feed-forward-networks">Feed-Forward Networks</h3>
<p>We apply DNI to feed-forward networks to allow asynchronous or sporadic training of individual layers, as might arise in distributed training.</p>
<p>As explained earlier, introducing synthetic gradients decouples the network layers, allowing them to communicate with one another without being affected by update locking.</p>
<p><strong>Asynchronous Updates</strong> To demonstrate the improvements brought by the DNI-decoupled layers, we ran experiments on a four-layer fully connected network for MNIST, in which each layer&rsquo;s backward pass and update occur in random order with probability pupdate. (That is, a layer is updated only for a fraction pupdate of the forward passes.) This completely breaks backpropagation—for example, the first layer would only receive error-gradient updates with probability pupdate³—and even then, the system would still be constrained to be synchronous. With DNI, however, the communication gap between layers is bridged, and the randomness of layer updates does not affect downstream layers, because synthetic gradients are used. We sampled different values of pupdate uniformly between 0 and 1. DNI with and without labels is shown in Figure 7.</p>
<p><img alt="20200218170640.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218170640.png"></p>
<p>With pupdate = 0.2, the network can still be trained to 2% error. Incredibly, when DNI is conditioned on the data labels (a reasonable assumption if training is performed in a distributed manner), the network trains perfectly with an update probability of just 5%, albeit more slowly.</p>
<h3 id="complete-unlock">Complete Unlock</h3>
<p>By also eliminating forward locking, feed-forward networks are made fully asynchronous. In this case, every network layer has a synthetic gradient model as well as a synthetic input model used to predict the input data, as shown in the figure below:</p>
<p><img alt="20200218175611.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218175611.png"></p>
<p>Each network layer can then be trained independently, relying on the synthetic gradient and the synthetic input model. The figure below shows the experimental results.</p>
<p><img alt="20200218175713.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218175713.png"></p>
<p>The experiments show that in this setting the model can be trained in a fully asynchronous and independent manner, although it takes somewhat longer to reach the 2% error rate.</p>
<h2 id="discussion--conclusion">Discussion &amp; Conclusion</h2>
<p>This paper introduced DNI, a method that uses synthetic gradients to decouple the communication between network layers, allowing them to update independently. It also demonstrated that the method can fully separate all layers of the network, so that they can train in a completely asynchronous, unordered, and sporadic manner.</p>
<p>It is worth noting that, although this paper presented empirical evidence for the effectiveness of DNI and synthetic gradients, the work of Czarnecki et al. investigated the theoretical understanding in greater depth and established convergence.</p>
]]></content:encoded></item><item><title>Stagewise Knowledge Distillation</title><link>https://blog.ereebay.me/en/posts/skd/</link><pubDate>Mon, 17 Feb 2020 13:15:34 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/skd/</guid><description>&lt;h1 id="stagewise-knowledge-distillation"&gt;Stagewise Knowledge Distillation&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;Most modern deep learning models require high computational power, but embedded devices lack such computing capability. Therefore, for this kind of device, models that can reduce computation while maintaining performance are very important. Knowledge distillation is one of the methods that solves this kind of problem. Traditional knowledge distillation methods directly transfer knowledge from the teacher to the student in a single stage. We propose a stagewise training approach to improve knowledge transfer. This approach can even use only a portion of the data used to train the teacher model without affecting performance. This approach can complement other model compression techniques, and can even be regarded as a universal model compression technique.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="stagewise-knowledge-distillation">Stagewise Knowledge Distillation</h1>
<h2 id="abstract">Abstract</h2>
<p>Most modern deep learning models require high computational power, but embedded devices lack such computing capability. Therefore, for this kind of device, models that can reduce computation while maintaining performance are very important. Knowledge distillation is one of the methods that solves this kind of problem. Traditional knowledge distillation methods directly transfer knowledge from the teacher to the student in a single stage. We propose a stagewise training approach to improve knowledge transfer. This approach can even use only a portion of the data used to train the teacher model without affecting performance. This approach can complement other model compression techniques, and can even be regarded as a universal model compression technique.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>This paper is mainly about model compression techniques based on knowledge distillation, so let me first introduce the categories of model compression.</p>
<p>Model compression can mainly be divided into the following five categories:</p>
<ol>
<li>Parameter Pruning and Sharing: mainly aims to reduce redundancy in network parameters and eliminate unnecessary parameters.</li>
<li>Low Rank Factorization techniques: mainly use tensor/matrix factorization to determine the effective parameters of the network.</li>
<li>Transferred/Compact Convolutional Filters: aim to use specially designed convolutional filters to reduce computation and storage space.</li>
<li>Knowledge Distillation: aims to use a larger pretrained model, the teacher, to train a small model, the student.</li>
<li>Quantization: aims to reduce the number of bits of each weight while preserving network performance.</li>
</ol>
<p>This work focuses mainly on the knowledge distillation approach. Ideally, the teacher should be able to pass on all the knowledge it has learned to the student, but this is not the case. Moreover, not all of the teacher&rsquo;s knowledge is necessarily relevant to the student; the ideal situation is that the student learns the important parts and ignores the unimportant ones. This paper mainly uses ResNet34 as the teacher model, and the student model also uses a ResNet-like model, but is much smaller in storage structure and computational complexity. This paper presents a method of training the student using multiple feature maps of a pretrained teacher model.</p>
<p>This paper mainly adopts a new way of training: the student model is trained using the teacher model&rsquo;s feature maps fixed at a particular layer. For each feature map, the student model is trained in a stagewise manner, and the final classification layer is trained directly on the dataset without the teacher. It is finally demonstrated that this approach can learn directly on a subset of the teacher&rsquo;s training data.</p>
<h2 id="related-work">Related Work</h2>
<h2 id="methodology">Methodology</h2>
<p>This paper mainly uses ResNet networks; the specific structure of ResNet will not be repeated here. It mainly consists of:</p>
<ul>
<li>Basic Block</li>
<li>Downsample Block</li>
<li>ResNet18 or 34 type models</li>
</ul>
<h3 id="teacher-network">Teacher Network</h3>
<p>This paper uses ResNet34 as the teacher model.</p>
<h3 id="student-network">Student Network</h3>
<p>A reduced version of ResNet34 is used as the student model, mainly by reducing the number of basic blocks.</p>
<h3 id="dataset">Dataset</h3>
<p>Three datasets are used: Imagenette, Imagewoof and CIFAR10. The first two datasets are subsets of ImageNet. The first is relatively easy, and the latter is relatively harder. The purpose of this work is not to improve accuracy as much as possible, but to make the student&rsquo;s accuracy as close as possible to the teacher&rsquo;s.</p>
<h3 id="proposed-training-method">Proposed Training Method</h3>
<p>In the early stage of the experiments, we trained the student model&rsquo;s multiple feature maps to simultaneously mimic the corresponding feature maps of the teacher model and the labels. So the mean squared error of each pair of feature maps would be accumulated. In addition, the cross-entropy loss is also accumulated. Therefore the total loss function can be expressed as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>L</mi><mrow><mo fence="true">(</mo><mi>y</mi><mo separator="true">,</mo><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo separator="true">,</mo><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">s</mi></mrow><mo fence="true">)</mo></mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mi>M</mi><mi>N</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></munderover><munderover><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>M</mi></munderover><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">(</mo><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo stretchy="false">)</mo><mo>−</mo><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo stretchy="false">(</mo><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo stretchy="false">)</mo><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>+</mo><mfrac><mn>1</mn><mrow><mi>M</mi><mi>C</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>M</mi></munderover><munderover><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>C</mi></munderover><mrow><mo fence="true">{</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo stretchy="false">(</mo><mi>j</mi><mo separator="true">,</mo><mtext> class </mtext><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow><mrow><munderover><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>C</mi></munderover><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo stretchy="false">(</mo><mi>j</mi><mo separator="true">,</mo><mi>k</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow></mfrac><mo fence="true">)</mo></mrow><mo fence="true">}</mo></mrow></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} L\left(y, \hat{y}, y_{c l s}, \mathrm{class}\right) &amp;=\frac{1}{M N} \sum_{i=1}^{N} \sum_{j=1}^{M}(y(i, j)-\hat{y}(i, j))^{2} \\ &amp;+\frac{1}{M C} \sum_{j=1}^{M} \sum_{k=1}^{C}\left\{-\log \left(\frac{\exp \left(y_{c l s}(j, \text { class })\right)}{\sum_{k=1}^{C} \exp \left(y_{c l s}(j, k)\right)}\right)\right\} \end{aligned}
</annotation></semantics></math></span><p>N denotes the number of blocks, and y(i,j) is the intermediate output of the teacher model&rsquo;s i-th block for the j-th input. Likewise, y-hat is that of the student model. M is the batch size. y_cls(j,k) is the model&rsquo;s output for the j-th input with respect to the k-th class, C is the number of classes, and class is the correct class that each particular input represents.</p>
<p>These early experiments showed a very small improvement of student models trained with the teacher model over those trained without. This can be attributed to the fact that multiple feature maps and labels must be mimicked at the same time, i.e., the conditions imposed on the optimization algorithm are very strict. Assigning weights to each MSE loss and the cross-entropy loss did not help either, because the training process was still very strict. Another possible reason is gradient vanishing and accumulation. To reduce this strictness of training, a stagewise training approach was proposed.</p>
<p>We train the student model in a stagewise manner, i.e., one block at a time. The image is the input to both the teacher and the student model, and the outputs of the first block are taken from both models. The MSE error is applied between the outputs, and then backpropagation is performed on the student model. After training the first block for 100 epochs, training stops. In the next step, the input is again passed to the teacher and the student, but the features of the second block are taken, and the same procedure as in the first stage is followed, i.e., the MSE loss between the outputs of the second block. Then backpropagation for 100 epochs. This operation is repeated for all the blocks. At the end of the student model, the classifier part is trained directly to predict classes from the dataset, i.e., the images are passed through the student model and trained with the cross-entropy loss for class prediction. At this stage, no teacher model is used, and the rest of the student model (the parts of the model other than the classifier part) is frozen. Figure 2 can help understand this point. The training loss function of stage i can be expressed as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>y</mi><mo separator="true">,</mo><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>M</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>M</mi></msubsup><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">(</mo><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo stretchy="false">)</mo><mo>−</mo><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo stretchy="false">(</mo><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo stretchy="false">)</mo><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">
L_{i}(y, \hat{y})=\frac{1}{M} \sum_{j=1}^{M}(y(i, j)-\hat{y}(i, j))^{2}
</annotation></semantics></math></span><p>The classifier uses the standard cross-entropy loss:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mrow><mo fence="true">(</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo separator="true">,</mo><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">s</mi></mrow><mo fence="true">)</mo></mrow><mo>=</mo><mfrac><mn>1</mn><mrow><mi>M</mi><mi>C</mi></mrow></mfrac><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>M</mi></msubsup><msubsup><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>C</mi></msubsup><mrow><mo fence="true">{</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo stretchy="false">(</mo><mi>j</mi><mo separator="true">,</mo><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">s</mi></mrow><mo fence="true">)</mo></mrow></mrow><mrow><msubsup><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>C</mi></msubsup><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>y</mi><mrow><mi>c</mi><mi>l</mi><mi>s</mi></mrow></msub><mo stretchy="false">(</mo><mi>j</mi><mo separator="true">,</mo><mi>k</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow></mfrac><mo fence="true">)</mo></mrow><mo fence="true">}</mo></mrow></mrow><annotation encoding="application/x-tex">
L_{c l s}\left(y_{c l s}, \mathrm{class}\right)=\frac{1}{M C} \sum_{j=1}^{M} \sum_{k=1}^{C}\left\{-\log \left(\frac{\exp \left(y_{c l s}(j, \mathrm{class}\right)}{\sum_{k=1}^{C} \exp \left(y_{c l s}(j, k)\right)}\right)\right\}
</annotation></semantics></math></span><p>We have shown that stagewise training has its own advantages; the main advantage is that the number of parameters to be optimized at a time is limited. Compared with training a larger number of parameters at once, this limited number of parameters can relax the strictness during training. The results show that stagewise training works better than training everything at once.</p>
<h4 id="less-data-approach">Less Data Approach</h4>
<p>Datasets like ImageNet are so large that performing stagewise training of the student model with the teacher model on limited hardware would take a great deal of time. Therefore, it becomes useful if we can perform stagewise training using only a subset of the data while maintaining accuracy. Thus, the stagewise training experiments were repeated using 1/4 of the original training data. Note that the original training data refers to the data on which the teacher model was trained, and the remaining 3/4 of the data is kept as a test set for evaluation.</p>
<h2 id="results">Results</h2>
<p>Figures 3 and 4 give the results of simultaneous training, stagewise training, and stagewise training with partial data.</p>
<p>These figures show that the student model with the entire dataset achieves almost the same accuracy as the teacher. But in the case of less data, there is a huge gap in accuracy between training with and without a teacher. The following paragraphs discuss the possible reasons behind these results. It should be pointed out that the purpose of model compression is to reduce the gap between teacher and student, not to obtain better accuracy. Obviously, if a better teacher is used, the student&rsquo;s accuracy will improve; sometimes the student&rsquo;s accuracy even exceeds that of the teacher model.</p>
<p>The experimental results can be explained as follows. Since the teacher has already learned the complete dataset, it has already learned the features necessary for classifying the entire dataset. When this teacher is used to train the student, even if training uses a small dataset, its &ldquo;knowledge&rdquo; is passed on to the student. Using less data can also be justified by the number of parameters that must be trained in a single stage. Since the proposed method trains only a small part of the network at a time, the number of parameters to be optimized is much smaller than that of the full network mentioned in the preceding paragraphs. The results show that this approach greatly improves accuracy: without a teacher, the accuracy of the student network trained on a small dataset is much lower than that of the student trained on the same dataset with the proposed method. Of course, the main advantage is the reduction in training time, which is very important, because without the teacher, stagewise training would take N+1 times as long. (Because each stage trains the same number of epochs separately.) Here N denotes the number of stages.</p>
<p>Figure 4 shows the experimental results using a smaller amount of data. It can be seen that when using less data and training independently, the student performs very poorly. On the other hand, if a teacher trained on less data is used to train the student stagewise, the prediction accuracy improves greatly. This capability would be very useful when applied to very large datasets.</p>
<p>The results of simultaneous training are close to those of training without a teacher. In particular, for the two ImageNet subsets, simultaneous training is slightly better, but for CIFAR10 it is slightly worse. This again demonstrates that the conditions of simultaneous training are too strict, and there is no obvious advantage over training without a teacher. However, the results of stagewise training are much better than those of both simultaneous training and training without a teacher. Since simultaneous training on the complete dataset did not give optimistic results, it was not performed on smaller datasets.</p>
<h2 id="conclusion">Conclusion</h2>
<p>This work presents a novel method for transferring knowledge from one network to another. Since the number of parameters optimized in one stage is reduced, the method performs better than transferring knowledge directly with the full network all at once. This also allows the student network to be trained with less data than the teacher. It will be very useful when training on larger datasets such as ImageNet.</p>
<p>In addition, the method is very flexible and can be used together with other model compression techniques and with other models. At the same time, it is not limited to image classification and can also be used in applications such as object detection and image segmentation. It can be regarded as a universal compression technique.</p>
]]></content:encoded></item><item><title>Federated Meta-Learning with Fast Convergence and Efficient Communication</title><link>https://blog.ereebay.me/en/posts/fmfe/</link><pubDate>Wed, 05 Feb 2020 18:36:17 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/fmfe/</guid><description>&lt;h1 id="federated-meta-learning-with-fast-convergence-and-efficient-communication"&gt;Federated Meta-Learning with Fast Convergence and Efficient Communication&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;This paper proposes a federated meta-learning framework, FedMeta, which shares a parameterized algorithm (meta learner) instead of the previous global model. It is evaluated on the LEAF datasets and a real-world dataset, and demonstrates that the communication cost required by FedMeta is reduced by 2.82-4.33 times, that it converges faster, and that accuracy is even improved by 3.23~14.84 percentage points compared with FedAvg. Moreover, FedMeta preserves user privacy, since only the parameterized algorithm is shared and no data.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="federated-meta-learning-with-fast-convergence-and-efficient-communication">Federated Meta-Learning with Fast Convergence and Efficient Communication</h1>
<h2 id="abstract">Abstract</h2>
<p>This paper proposes a federated meta-learning framework, FedMeta, which shares a parameterized algorithm (meta learner) instead of the previous global model. It is evaluated on the LEAF datasets and a real-world dataset, and demonstrates that the communication cost required by FedMeta is reduced by 2.82-4.33 times, that it converges faster, and that accuracy is even improved by 3.23~14.84 percentage points compared with FedAvg. Moreover, FedMeta preserves user privacy, since only the parameterized algorithm is shared and no data.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>The well-known FedAvg algorithm in federated learning can flexibly use SGD for local training, achieving high accuracy while balancing computation and communication costs.</p>
<p>In meta-learning, initialization-based meta-learning algorithms such as MAML excel at fast convergence on new tasks and possess good generalization. This makes them well suited to decentralized data that is Non-IID and highly personalized.</p>
<p>Inspired by this, the paper develops a federated meta-learning framework that differs greatly from previous federated learning work. It first connects meta-learning methods with federated learning. In meta-learning, a parameterized algorithm (meta learner) is slowly learned from a large number of tasks through the meta-training process, during which the algorithm quickly trains a specific model within each task.</p>
<p>A task usually consists of a support set and a query set, which are disjoint. The task-specific model is trained on the support set and tested on the query set. The test results are then used to update the algorithm. In federated meta-learning, the algorithm (meta learner) is maintained on the server and distributed to the clients for model training. During each episode of meta-training, a sampled batch of clients receives the parameters of the algorithm (meta learner) and trains their models. The test results on the query sets are then uploaded to the server to update the meta learner. The overall flow is shown in the figure:</p>
<p><img alt="20200218221422.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200218221422.png"></p>
<p><strong>Comparing federated meta-learning with federated learning</strong> A comparison of FML and FL.
Federated meta-learning is similar to federated learning; the main difference is that what is shared is no longer a global model but the parameters of an algorithm (the meta-model parameters). Moreover, meta-learning is conceptually different from distributed model training, and sharing a meta-learning algorithm can be applied more flexibly than sharing a model. For example, in image classification, images of n classes may be unevenly distributed across clients, with each client having at most k classes. Federated learning would need to train a large n-class classifier in order to exploit data from all clients, whereas in fact a k-class classifier suffices, since it only ever makes predictions for a single client. Such a large model in federated learning entails substantial communication cost. One could send only part of the model to a client to update the relevant parameters, but this requires prior knowledge of the client&rsquo;s private data. Meta-learning, on the other hand, allows an algorithm to train on tasks containing different classes. For example, MAML can provide an initialization for a k-class classifier by meta-training on k-class tasks, regardless of what the specific classes are. Therefore, within the FML framework, MAML can be used to meta-train initializations of k-class classifiers over all n classes—that is, letting a k-class classifier be meta-learned for initialization in the context of tasks drawn from n classes. This reduces both the communication and computation costs of FML.</p>
<p><strong>Contributions</strong> The contributions of this paper focus on algorithm design for the federated learning setting; to this end, the paper proposes a new framework and carries out extensive experiments. The contributions are threefold: 1. Proposing the FedMeta framework, which combines meta-learning and federation, integrating MAML and Meta-SGD into federated learning. 2. Conducting experiments on the LEAF datasets with comparisons against FedAvg; the results show that FedMeta reduces overhead while achieving higher accuracy. 3. Applying FedMeta to a recommendation task in which each client has highly personalized records; the experiments demonstrate that meta-learning algorithms achieve higher accuracy than standalone or federated learning methods.</p>
<h2 id="federated-meta-learning">Federated Meta-Learning</h2>
<h3 id="the-meta-learning-approach">The Meta-Learning Approach</h3>
<p>The goal of meta-learning is to meta-train an algorithm (meta learner) A that can train a model quickly—that is, to obtain an initial model that converges fast. The algorithm <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>A</mi><mi>φ</mi></msub></mrow><annotation encoding="application/x-tex">A_{\varphi}</annotation></semantics></math></span> is a parameterized model whose parameters are updated across a series of tasks during meta-training.
During meta-training, a task T consists of a support set and a query set, each with corresponding labels and data. The algorithm (meta learner) A trains the model f on the support set and outputs the parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>T</mi></msub></mrow><annotation encoding="application/x-tex">\theta_T</annotation></semantics></math></span>—this is the inner update. The model <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>f</mi><msub><mi>θ</mi><mi>T</mi></msub></msub></mrow><annotation encoding="application/x-tex">f_{\theta_T}</annotation></semantics></math></span> is then evaluated on the query set, and the test loss <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>T</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{L}_{D_{Q}^{T}}\left(\theta_{T}\right)</annotation></semantics></math></span> is computed to reflect how well algorithm A trains. Finally, A is updated by minimizing the test loss—this step is called the outer update. Note that the query set and the support set are disjoint, so as to maximize the generalization ability of A. During meta-training, each episode samples a batch of tasks from a meta-training set. The optimization objective of algorithm A can thus be expressed as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>φ</mi></msub><msub><mi mathvariant="double-struck">E</mi><mrow><mi>T</mi><mo>∼</mo><mi mathvariant="script">T</mi></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>T</mi></msub><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow><mo>=</mo><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>φ</mi></msub><msub><mi mathvariant="double-struck">E</mi><mrow><mi>T</mi><mo>∼</mo><mi mathvariant="script">T</mi></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><msub><mi mathvariant="script">A</mi><mi>φ</mi></msub><mrow><mo fence="true">(</mo><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">
\min _{\varphi} \mathbb{E}_{T \sim \mathcal{T}}\left[\mathcal{L}_{D_{Q}^{T}}\left(\theta_{T}\right)\right]=\min _{\varphi} \mathbb{E}_{T \sim \mathcal{T}}\left[\mathcal{L}_{D_{Q}^{T}}\left(\mathcal{A}_{\varphi}\left(D_{S}^{T}\right)\right)\right]
</annotation></semantics></math></span><p>MAML is a representative meta-learning algorithm. For MAML, algorithm A is what produces the model&rsquo;s initial state. Concretely, for each task T, the algorithm sets <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>=</mo><mi>θ</mi></mrow><annotation encoding="application/x-tex">\alpha = \theta</annotation></semantics></math></span>, making the algorithm&rsquo;s parameters equal to the parameters of model f. The parameters of model f are then trained on the support set and updated according to the loss: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>:</mo><mo>=</mo><mfrac><mn>1</mn><mrow><mo fence="true">∣</mo><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup><mo fence="true">∣</mo></mrow></mfrac><msub><mo>∑</mo><mrow><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>∈</mo><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup></mrow></msub><mi mathvariant="normal">ℓ</mi><mrow><mo fence="true">(</mo><msub><mi>f</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><mi>y</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{L}_{D_{S}^{T}}(\theta):=\frac{1}{\left|D_{S}^{T}\right|} \sum_{(x, y) \in D_{S}^{T}} \ell\left(f_{\theta}(x), y\right)</annotation></semantics></math></span>. Finally, the model parameters are tested on the query set, and the test loss is computed: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>T</mi></msub><mo fence="true">)</mo></mrow><mo>:</mo><mo>=</mo><mfrac><mn>1</mn><mrow><mo fence="true">∣</mo><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup><mo fence="true">∣</mo></mrow></mfrac><msub><mo>∑</mo><mrow><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo separator="true">,</mo><msup><mi>y</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo fence="true">)</mo></mrow><mo>∈</mo><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></mrow></msub><mi mathvariant="normal">ℓ</mi><mrow><mo fence="true">(</mo><msub><mi>f</mi><msub><mi>θ</mi><mi>T</mi></msub></msub><mrow><mo fence="true">(</mo><msup><mi>x</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo fence="true">)</mo></mrow><mo separator="true">,</mo><msup><mi>y</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{L}_{D_{Q}^{T}}\left(\theta_{T}\right):=\frac{1}{\left|D_{Q}^{T}\right|} \sum_{\left(x^{\prime}, y^{\prime}\right) \in D_{Q}^{T}} \ell\left(f_{\theta_{T}}\left(x^{\prime}\right), y^{\prime}\right)</annotation></semantics></math></span></p>
<p>Equation 1 can be simplified as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>θ</mi></msub><msub><mi mathvariant="double-struck">E</mi><mrow><mi>T</mi><mo>∼</mo><mi mathvariant="script">T</mi></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><mi>θ</mi><mo>−</mo><mi>α</mi><mi mathvariant="normal">∇</mi><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">
\min _{\theta} \mathbb{E}_{T \sim \mathcal{T}}\left[\mathcal{L}_{D_{Q}^{T}}\left(\theta-\alpha \nabla \mathcal{L}_{D_{S}^{T}}(\theta)\right)\right]
</annotation></semantics></math></span><p>Building on MAML, Meta-SGD further learns the initial parameters and the inner-loop learning rate at the same time. The test loss can be viewed as a function of both the model parameters and the learning rate, and both can be updated by taking gradients with SGD in the outer loop. Moreover, the learning rate is a vector of the same dimension as the model parameters, so that the learning rate corresponds to the model parameter vector coordinate-wise.</p>
<p>Therefore the optimization condition can be rewritten as</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mrow><mi>θ</mi><mo separator="true">,</mo><mi>α</mi></mrow></msub><msub><mi mathvariant="double-struck">E</mi><mrow><mi>T</mi><mo>∼</mo><mi mathvariant="script">T</mi></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>Q</mi><mi>T</mi></msubsup></msub><mrow><mo fence="true">(</mo><mi>θ</mi><mo>−</mo><mi>α</mi><mo>∘</mo><mi mathvariant="normal">∇</mi><msub><mi mathvariant="script">L</mi><msubsup><mi>D</mi><mi>S</mi><mi>T</mi></msubsup></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">
\min _{\theta, \alpha} \mathbb{E}_{T \sim \mathcal{T}}\left[\mathcal{L}_{D_{Q}^{T}}\left(\theta-\alpha \circ \nabla \mathcal{L}_{D_{S}^{T}}(\theta)\right)\right]
</annotation></semantics></math></span><h3 id="the-federated-meta-learning-framework">The Federated Meta-Learning Framework</h3>
<p>The goal of FML is to meta-train an algorithm collaboratively from data distributed across clients. Taking MAML as an example, the aim is to use the data of all clients to complete the initialization of a model. MAML involves two levels of optimization: the inner loop trains a task-specific model from the initial parameters, and the outer loop updates the initial parameters according to the test loss. In the federated learning setting, each client u receives the initial parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span> from the server, then trains the model on the support-set data on its device and transmits the test loss to the server. The server mainly maintains the initial parameters and updates them according to the clients&rsquo; test losses.</p>
<p>The information transmitted in this process includes: the model&rsquo;s initial parameters (from server to clients) and the test loss (from clients to server). For the Meta-SGD algorithm, the vector <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi></mrow><annotation encoding="application/x-tex">\alpha</annotation></semantics></math></span> is also part of the transmission, serving as the learning-rate parameters for inner-loop model training.</p>
<p><img alt="20200219111333.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200219111333.png"></p>
<p>Algorithm 1 describes the FedMeta procedure using MAML and Meta-SGD, where each communication round corresponds to an episode. The algorithm is maintained in the AlgorithmUpdate step. In each round of updates, the server collects the test losses obtained by training MAML or Meta-SGD on the sampled clients. The initial parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span> are updated after training on the clients&rsquo; training sets, and the updated parameters are then tested on the test set. After the meta-training process, the model is deployed on the clients.</p>
<h2 id="experiments">Experiments</h2>
<ol>
<li>Experiments on the LEAF datasets demonstrate fast convergence and high accuracy.</li>
<li>Experiments on a recommendation task in a real-world setting show that strong adaptability is maintained even at smaller scales.</li>
</ol>
<h3 id="evaluation-scheme">Evaluation Scheme</h3>
<p>In all experiments, 80% of the clients serve as training clients, 10% as validation clients, and the remainder as test clients. Each client&rsquo;s local data is split into a support set and a query set. The paper also varies the fraction p of each client&rsquo;s data used as the support set, in order to study how effectively FedMeta adapts to new clients with limited data; this is abbreviated psupport hereafter.</p>
<p><img alt="20200219114337.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200219114337.png"></p>
<p>The authors ran experiments with FedAvg, a meta version of FedAvg, and two variants of FedMeta. The meta version of FedAvg uses the support sets of the test clients to finetune the initial model received from the server before testing, whereas during training both use all of the data on the training clients.</p>
<p>As for FML, three methods were tested—MAML, FOMAML, and Meta-SGD—all of which are model-agnostic and easy to implement.</p>
<h3 id="leaf-datasets">LEAF Datasets</h3>
<p><strong>Accuracy and Convergence Comparison</strong> Considering the limited computational capabilities of edge devices, each client&rsquo;s local epoch is set to 1.</p>
<p><img alt="20200219125820.png" loading="lazy" src="http://cdn.ereebay.me/hexo/20200219125820.png"></p>
<p>As shown above, all methods within the FedMeta framework converge faster and more stably, achieving clear improvements. MAML and Meta-SGD reach similar convergence speeds and accuracy on the first two datasets; on Sent140, Meta-SGD performs somewhat better.</p>
<p>The table shows the accuracy of the four methods after several communication rounds. First, it can be seen that FedAvg performs far worse than FedMeta, especially on the image classification task. MAML and Meta-SGD achieve the highest accuracy, with gains of 3.23-14.84 percentage points. It is also found that FedAvg (meta) attains higher accuracy than FedAvg in most cases; there are two exceptions, however, when the support fraction is 20%. Unexpectedly, FedAvg (Meta) even shows a slight drop in accuracy. This may be because, after being finetuned on a small amount of data, the model deviates excessively from the global optimum. Second, as we increase the probability p of the support set, the accuracy of both FedAvg (Meta) and FedMeta improves in almost all cases, but the growth rate of FedAvg (meta) is greater than that of FedMeta. This indicates that FedMeta generalizes better and adapts more effectively to clients with limited data.</p>
<p><strong>Fairness Comparison</strong> The paper also compares FedAvg and FedMeta across multiple runs, using the distribution of final accuracies. The last row of the previous figure shows kernel density estimates for the different methods. For FEMNIST, MAML and Meta-SGD not only yield a higher mean but also lower variance. For the Shakespeare dataset, FedMeta has larger variance but also a larger mean. For Sent140, the accuracy distributions are roughly the same; still, it can be seen that MAML and Meta-SGD have more clients close to 100%. Overall, for image classification tasks, FedMeta&rsquo;s accuracy distribution is more stable and concentrated.</p>
<h2 id="conclusion">Conclusion</h2>
<p>The FedMeta framework outperforms the original FedAvg in accuracy, convergence speed, and communication cost.</p>
]]></content:encoded></item><item><title>CS330 Lecture 1&amp;2 Study Notes (Incomplete)</title><link>https://blog.ereebay.me/en/posts/cs330-1/</link><pubDate>Fri, 10 Jan 2020 11:31:05 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/cs330-1/</guid><description>&lt;h1 id="cs330-lecture-12-notes"&gt;CS330 lecture 1&amp;amp;2 notes&lt;/h1&gt;
&lt;h2 id="informal-problem-definitions"&gt;Informal Problem Definitions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The multi-task learning problem: Learn all of the tasks more quickly or more proficiently than learning them independently.&lt;/li&gt;
&lt;li&gt;The meta-learning problem: Given data/experience on previous tasks, learn a new task more quickly and/or more proficiently.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- more --&gt;
&lt;h2 id="multi-task-learning-basics"&gt;Multi-Task Learning Basics&lt;/h2&gt;
&lt;p&gt;Traditional single-task learning:&lt;/p&gt;
&lt;span class="katex"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mtable rowspacing="0.16em" columnalign="left" columnspacing="1em"&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mstyle scriptlevel="0" displaystyle="false"&gt;&lt;mrow&gt;&lt;mi mathvariant="script"&gt;D&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mrow&gt;&lt;mo fence="true"&gt;{&lt;/mo&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi mathvariant="bold"&gt;x&lt;/mi&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;mi mathvariant="bold"&gt;y&lt;/mi&gt;&lt;msub&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;/msub&gt;&lt;mo fence="true"&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;/mstyle&gt;&lt;/mtd&gt;&lt;/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mstyle scriptlevel="0" displaystyle="false"&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mrow&gt;&lt;mi&gt;min&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;/msub&gt;&lt;mi mathvariant="script"&gt;L&lt;/mi&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;mi mathvariant="script"&gt;D&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/mstyle&gt;&lt;/mtd&gt;&lt;/mtr&gt;&lt;/mtable&gt;&lt;annotation encoding="application/x-tex"&gt;
\begin{array}{l}{\mathscr{D}=\left\{(\mathbf{x}, \mathbf{y})_{k}\right\}} \\ {\min _{\theta} \mathscr{L}(\theta, \mathscr{D})}\end{array}
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;p&gt;Typical loss: negative log likelihood&lt;/p&gt;
&lt;span class="katex"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant="script"&gt;L&lt;/mi&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;mi mathvariant="script"&gt;D&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant="double-struck"&gt;E&lt;/mi&gt;&lt;mrow&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mo&gt;∼&lt;/mo&gt;&lt;mi mathvariant="script"&gt;D&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mrow&gt;&lt;mo fence="true"&gt;[&lt;/mo&gt;&lt;mi&gt;log&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;f&lt;/mi&gt;&lt;mi&gt;θ&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi mathvariant="bold"&gt;y&lt;/mi&gt;&lt;mi mathvariant="normal"&gt;∣&lt;/mi&gt;&lt;mi mathvariant="bold"&gt;x&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mo fence="true"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;annotation encoding="application/x-tex"&gt;
\mathscr{L}(\theta, \mathscr{D})=-\mathbb{E}_{(x, y) \sim \mathscr{D}}\left[\log f_{\theta}(\mathbf{y} | \mathbf{x})\right]
&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;h3 id="whats-a-task"&gt;What&amp;rsquo;s a task?&lt;/h3&gt;
&lt;p&gt;A task: &lt;span class="katex"&gt;&lt;math xmlns="http://www.w3.org/1998/Math/MathML"&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi mathvariant="script"&gt;T&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;≜&lt;/mo&gt;&lt;mrow&gt;&lt;mo fence="true"&gt;{&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi mathvariant="bold"&gt;x&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy="false"&gt;(&lt;/mo&gt;&lt;mi mathvariant="bold"&gt;y&lt;/mi&gt;&lt;mi mathvariant="normal"&gt;∣&lt;/mi&gt;&lt;mi mathvariant="bold"&gt;x&lt;/mi&gt;&lt;mo stretchy="false"&gt;)&lt;/mo&gt;&lt;mo separator="true"&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant="script"&gt;L&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo fence="true"&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;annotation encoding="application/x-tex"&gt;\mathscr{T}_{i} \triangleq\left\{p_{i}(\mathbf{x}), p_{i}(\mathbf{y} | \mathbf{x}), \mathscr{L}_{i}\right\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="cs330-lecture-12-notes">CS330 lecture 1&amp;2 notes</h1>
<h2 id="informal-problem-definitions">Informal Problem Definitions</h2>
<ul>
<li>The multi-task learning problem: Learn all of the tasks more quickly or more proficiently than learning them independently.</li>
<li>The meta-learning problem: Given data/experience on previous tasks, learn a new task more quickly and/or more proficiently.</li>
</ul>
<!-- more -->
<h2 id="multi-task-learning-basics">Multi-Task Learning Basics</h2>
<p>Traditional single-task learning:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.16em" columnalign="left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi mathvariant="script">D</mi><mo>=</mo><mrow><mo fence="true">{</mo><mo stretchy="false">(</mo><mi mathvariant="bold">x</mi><mo separator="true">,</mo><mi mathvariant="bold">y</mi><msub><mo stretchy="false">)</mo><mi>k</mi></msub><mo fence="true">}</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>θ</mi></msub><mi mathvariant="script">L</mi><mo stretchy="false">(</mo><mi>θ</mi><mo separator="true">,</mo><mi mathvariant="script">D</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{array}{l}{\mathscr{D}=\left\{(\mathbf{x}, \mathbf{y})_{k}\right\}} \\ {\min _{\theta} \mathscr{L}(\theta, \mathscr{D})}\end{array}
</annotation></semantics></math></span><p>Typical loss: negative log likelihood</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">L</mi><mo stretchy="false">(</mo><mi>θ</mi><mo separator="true">,</mo><mi mathvariant="script">D</mi><mo stretchy="false">)</mo><mo>=</mo><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>∼</mo><mi mathvariant="script">D</mi></mrow></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><msub><mi>f</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mi mathvariant="normal">∣</mi><mi mathvariant="bold">x</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">
\mathscr{L}(\theta, \mathscr{D})=-\mathbb{E}_{(x, y) \sim \mathscr{D}}\left[\log f_{\theta}(\mathbf{y} | \mathbf{x})\right]
</annotation></semantics></math></span><h3 id="whats-a-task">What&rsquo;s a task?</h3>
<p>A task: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">T</mi><mi>i</mi></msub><mo>≜</mo><mrow><mo fence="true">{</mo><msub><mi>p</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi mathvariant="bold">x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><msub><mi>p</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi mathvariant="bold">y</mi><mi mathvariant="normal">∣</mi><mi mathvariant="bold">x</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><msub><mi mathvariant="script">L</mi><mi>i</mi></msub><mo fence="true">}</mo></mrow></mrow><annotation encoding="application/x-tex">\mathscr{T}_{i} \triangleq\left\{p_{i}(\mathbf{x}), p_{i}(\mathbf{y} | \mathbf{x}), \mathscr{L}_{i}\right\}</annotation></semantics></math></span></p>
<p>data generating distributions</p>
<p>Here a task is defined as the distribution over data samples, the distribution over data labels, and a loss function.</p>
<p>Corresponding datasets: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi mathvariant="script">D</mi><mi>i</mi><mrow><mi>t</mi><mi>r</mi></mrow></msubsup></mrow><annotation encoding="application/x-tex">\mathscr{D}_{i}^{tr}</annotation></semantics></math></span> training set, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi mathvariant="script">D</mi><mi>i</mi><mrow><mi>t</mi><mi>s</mi><mi>t</mi></mrow></msubsup></mrow><annotation encoding="application/x-tex">\mathscr{D}_{i}^{t s t}</annotation></semantics></math></span> test set.</p>
<p>Usually <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">D</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\mathscr{D}_{i}</annotation></semantics></math></span> denotes the training set.</p>
<p>Multi-task classification: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">L</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\mathscr{L}_{i}</annotation></semantics></math></span> same across all tasks. E.g., in handwritten character recognition across different languages, the form of the loss function may be the same.</p>
<p>Multi-label learning: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="script">L</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>p</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\mathscr{L}_{i}, {p}_{i}(x)</annotation></semantics></math></span> same across all tasks. E.g., in the CelebA multi-label recognition task, the samples and the loss function are identical.</p>
<p>The loss function may vary across tasks in the following cases:</p>
<ul>
<li>mixed discrete, continuous labels across tasks</li>
<li>caring more about one task than another (i.e., different weights for different tasks?)</li>
</ul>
<h3 id="conditioning-on-the-task">Conditioning on the task</h3>
<p>The multi-task learning problem requires introducing a task descriptor as a variable that describes the task; the question is how to design this variable.</p>
<p>Assume <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>z</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">{z}_{i}</annotation></semantics></math></span> is the task index. The most straightforward approach is multiplicative gating, which effectively trains each task in the multi-task setting with its own separate network, without sharing parameters.</p>
<p>The other extreme is to directly concat <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>z</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">z_i</annotation></semantics></math></span>, in which case all parameters are shared except those that come after the input <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>z</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">z_i</annotation></semantics></math></span>.</p>
<p>Yet another idea is to split <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span> into shared parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>θ</mi><mrow><mi>s</mi><mi>h</mi></mrow></msup></mrow><annotation encoding="application/x-tex">\theta^{sh}</annotation></semantics></math></span> and task-specific parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>θ</mi><mi>i</mi></msup></mrow><annotation encoding="application/x-tex">\theta^i</annotation></semantics></math></span> — i.e., shared and non-shared parameters.</p>
<p>The optimization objective then becomes</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mrow><msup><mi>θ</mi><mrow><mi>s</mi><mi>h</mi></mrow></msup><mo separator="true">,</mo><msup><mi>θ</mi><mn>1</mn></msup><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msup><mi>θ</mi><mi>T</mi></msup></mrow></msub><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msub><mi mathvariant="script">L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><mrow><mo fence="true">{</mo><msup><mi>θ</mi><mrow><mi>s</mi><mi>h</mi></mrow></msup><mo separator="true">,</mo><msup><mi>θ</mi><mi>i</mi></msup><mo fence="true">}</mo></mrow><mo separator="true">,</mo><msub><mi mathvariant="script">D</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\min _{\theta^{s h}, \theta^{1}, \ldots, \theta^{T}} \sum_{i=1}^{T} \mathscr{L}_{i}\left(\left\{\theta^{s h}, \theta^{i}\right\}, \mathscr{D}_{i}\right)
</annotation></semantics></math></span><p>The problem then becomes which parameters to share and when.</p>
<h4 id="common-choices">Common Choices</h4>
<p>The common choices are mainly concatenation and addition — the figures make them clear at a glance.</p>
<ol>
<li>Concatenation-based conditioning</li>
</ol>
<p><img alt="cs330-1-1.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-1.png"></p>
<ol start="2">
<li>Additive conditioning</li>
</ol>
<p><img alt="cs330-1-2.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-2.png"></p>
<p>In fact, the two are equivalent.</p>
<p><img alt="cs330-1-3.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-3.png"></p>
<ol start="3">
<li>Multi-head architecture</li>
</ol>
<p><img alt="cs330-1-4.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-4.png"></p>
<ol start="4">
<li>Multiplicative conditioning</li>
</ol>
<p><img alt="cs330-1-5.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-5.png"></p>
<p>The multiplicative approach offers:</p>
<ul>
<li>stronger expressive power</li>
<li>multiplication gating for regression tasks</li>
<li>better generalization across independent networks and heads</li>
</ul>
<h4 id="complex-choices">Complex Choices</h4>
<p>There are also many other more complex choices.</p>
<p><img alt="cs330-1-6.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-6.png"></p>
<p>But where the design inspiration comes from is just like choosing the hyperparameters of a neural network:</p>
<ul>
<li>different problems are independent of one another</li>
<li>for any specific problem, it mostly relies on the designer&rsquo;s intuition and background knowledge</li>
<li>current approaches are more art than science</li>
</ul>
<h3 id="optimizing-the-objective">Optimizing the objective</h3>
<p>Objective: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>θ</mi></msub><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msub><mi mathvariant="script">L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><mi>θ</mi><mo separator="true">,</mo><msub><mi mathvariant="script">D</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\min _{\theta} \sum_{i=1}^{T} \mathscr{L}_{i}\left(\theta, \mathscr{D}_{i}\right)</annotation></semantics></math></span></p>
<p>The typical procedure:</p>
<ol>
<li>Sample a minibatch of tasks <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">B</mi><mo>∼</mo><mrow><mo fence="true">{</mo><msub><mi mathvariant="script">T</mi><mi>i</mi></msub><mo fence="true">}</mo></mrow></mrow><annotation encoding="application/x-tex">\mathscr{B} \sim\left\{\mathscr{T}_{i}\right\}</annotation></semantics></math></span></li>
<li>Sample a minibatch of data from each task <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi mathvariant="script">D</mi><mi>i</mi><mi>b</mi></msubsup><mo>∼</mo><msub><mi mathvariant="script">D</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\mathscr{D}_{i}^{b} \sim \mathscr{D}_{i}</annotation></semantics></math></span></li>
<li>Compute the loss on each minibatch-task: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi mathvariant="script">L</mi><mo>^</mo></mover><mo stretchy="false">(</mo><mi>θ</mi><mo separator="true">,</mo><mi mathvariant="script">B</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mo>∑</mo><mrow><msub><mi mathvariant="script">T</mi><mi>k</mi></msub><mo>∈</mo><mi mathvariant="script">B</mi></mrow></msub><msub><mi mathvariant="script">L</mi><mi>k</mi></msub><mrow><mo fence="true">(</mo><mi>θ</mi><mo separator="true">,</mo><msubsup><mi mathvariant="script">D</mi><mi>k</mi><mi>b</mi></msubsup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\hat{\mathscr{L}}(\theta, \mathscr{B})=\sum_{\mathcal{T}_{k} \in \mathscr{B}} \mathscr{L}_{k}\left(\theta, \mathscr{D}_{k}^{b}\right)</annotation></semantics></math></span></li>
<li>Backpropagate to compute gradients <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mover accent="true"><mi mathvariant="script">L</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\nabla_{\theta} \hat{\mathscr{L}}</annotation></semantics></math></span></li>
<li>Update the gradients with your favorite optimizer</li>
</ol>
<p>Note: this ensures that tasks are sampled uniformly regardless of their data size.</p>
<p>Tip: for regression tasks, make sure task labels are on the same scale.</p>
<h3 id="challenge">Challenge</h3>
<ol>
<li>Negative transfer</li>
</ol>
<p>Multi-task training on CIFAR-100 performs worse than training tasks independently.</p>
<p>Possible causes:</p>
<ul>
<li>optimization challenges
<ul>
<li>interference between different tasks</li>
<li>different learning rates across tasks</li>
</ul>
</li>
<li>limited expressive capacity
<ul>
<li>multi-task networks are large</li>
</ul>
</li>
</ul>
<p>Solution:</p>
<p>share less across tasks (soft parameter sharing)</p>
<ul>
<li>allows for more fluid degrees of parameter sharing (advantage)</li>
<li>yet another set of design decisions/hyperparameters (drawback)</li>
</ul>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mrow><msup><mi>θ</mi><mrow><mi>s</mi><mi>h</mi></mrow></msup><mo separator="true">,</mo><msup><mi>θ</mi><mn>1</mn></msup><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msup><mi>θ</mi><mi>T</mi></msup></mrow></msub><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msub><mi mathvariant="script">L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><mrow><mo fence="true">{</mo><msup><mi>θ</mi><mrow><mi>s</mi><mi>h</mi></mrow></msup><mo separator="true">,</mo><msup><mi>θ</mi><mi>i</mi></msup><mo fence="true">}</mo></mrow><mo separator="true">,</mo><msub><mi mathvariant="script">D</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>+</mo><msubsup><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><mrow><mo fence="true">∥</mo><msup><mi>θ</mi><mi>t</mi></msup><mo>−</mo><msup><mi>θ</mi><msup><mi>t</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup></msup><mo fence="true">∥</mo></mrow></mrow><annotation encoding="application/x-tex">
\min _{\theta^{sh}, \theta^{1}, \ldots, \theta^{T}} \sum_{i=1}^{T} \mathscr{L}_{i}\left(\left\{\theta^{s h}, \theta^{i}\right\}, \mathscr{D}_{i}\right)+\sum_{t=1}^{T}\left\|\theta^{t}-\theta^{t&#x27;}\right\|
</annotation></semantics></math></span><p>The latter term is soft parameter sharing: the difference between one task&rsquo;s parameters and the previous one is used as a regularization term, which effectively makes each task&rsquo;s parameters as similar as possible — i.e., the parameters are shared.</p>
<ol start="2">
<li>Overfitting</li>
</ol>
<p>Overfitting is usually caused by not sharing enough parameters; the solution is to share more. Intuitively, insufficient sharing makes each task overfit, which resembles independent training.</p>
<h2 id="meta-learning-basics">Meta-Learning Basics</h2>
<p>Two views of meta-learning:</p>
<ul>
<li>Mechanistic view
<ul>
<li>a deep neural network that can take in an entire dataset and make predictions on new data</li>
<li>the network is trained on a meta-dataset that contains different datasets for different tasks</li>
<li>this view makes it easy to implement a meta-learning algorithm</li>
</ul>
</li>
<li>Probabilistic view
<ul>
<li>extract prior knowledge from a series of meta-learning tasks</li>
<li>use a small amount of data plus prior information to infer a relatively effective posterior</li>
<li>this view leads to a better understanding of meta-learning algorithms</li>
</ul>
</li>
</ul>
<h3 id="problem-definitions">Problem definitions</h3>
<p>First, recall supervised learning:</p>
<p><img alt="cs330-1-7.png" loading="lazy" src="http://cdn.ereebay.me/hexo/cs330-1-7.png"></p>
<p>Existing issues:</p>
<ul>
<li>requires a large amount of labeled data</li>
<li>labels are very limited for some tasks nowadays</li>
</ul>
<p>To be continued</p>
]]></content:encoded></item><item><title>Paper Notes: A Meta-Transfer Objective for Learning to Disentangle Causal Mechanisms [Unfinished]</title><link>https://blog.ereebay.me/en/posts/meta/</link><pubDate>Thu, 09 Jan 2020 16:02:59 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/meta/</guid><description>&lt;h1 id="a-meta-transfer-objective-for-learning-to-disentangle-causal-mechanisms"&gt;A Meta-Transfer Objective for Learning to Disentangle Causal Mechanisms&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;This paper proposes exploiting a meta-learning objective that maximizes the speed of transfer to a changed distribution in order to learn how to acquire knowledge in a modular fashion. In particular, we care about how to factor the joint distribution into appropriate conditionals consistent with the causal relationships. If this is achievable, changes in the distribution are assumed to be localized (distributions are localized) (e.g., one of the marginals changes due to an intervention on one of the variables). We show that, under such localized changes of the assumed causal mechanisms, the correct causal graph will tend to have only a few parameters with non-zero gradients, i.e., the parameters that need to be adjusted (the parameters of the modified variables). This is observed experimentally to lead to faster adaptation, and we exploit this property to define a meta-learning surrogate score which, in addition to a continuous parametrization of the graph, will also favor the correct causal graph. Finally, considering AI agents (e.g., a robot autonomously discovering its environment), we consider how the same objective can discover the causal variables themselves, since the observed low-level variables carry no causal meaning. Experiments on the bivariate case validate the proposed ideas and theoretical results.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="a-meta-transfer-objective-for-learning-to-disentangle-causal-mechanisms">A Meta-Transfer Objective for Learning to Disentangle Causal Mechanisms</h1>
<h2 id="abstract">Abstract</h2>
<p>This paper proposes exploiting a meta-learning objective that maximizes the speed of transfer to a changed distribution in order to learn how to acquire knowledge in a modular fashion. In particular, we care about how to factor the joint distribution into appropriate conditionals consistent with the causal relationships. If this is achievable, changes in the distribution are assumed to be localized (distributions are localized) (e.g., one of the marginals changes due to an intervention on one of the variables). We show that, under such localized changes of the assumed causal mechanisms, the correct causal graph will tend to have only a few parameters with non-zero gradients, i.e., the parameters that need to be adjusted (the parameters of the modified variables). This is observed experimentally to lead to faster adaptation, and we exploit this property to define a meta-learning surrogate score which, in addition to a continuous parametrization of the graph, will also favor the correct causal graph. Finally, considering AI agents (e.g., a robot autonomously discovering its environment), we consider how the same objective can discover the causal variables themselves, since the observed low-level variables carry no causal meaning. Experiments on the bivariate case validate the proposed ideas and theoretical results.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>Data is assumed to be independent and identically distributed (IID). Likewise, a model&rsquo;s performance is typically evaluated with test samples drawn from the same distribution, on the assumption that they represent how the learned system will be used. Although these assumptions are well analyzed from a statistical point of view, they are hard to apply in many practical situations. For example: a medical diagnosis system trained on historical data from one hospital may perform poorly on patients from another hospital because the distribution has shifted. Ideally, we would like our models to generalize well and to <strong>adapt quickly</strong> to out-of-distribution data.</p>
<p>However, successfully transferring to a new distribution calls for more data. In this paper, rather than focusing on assumptions about the data distribution itself, we focus on how the data distribution changes (e.g., the change from the training distribution to the transfer distribution may be caused by the actions of some agents). The assumption we care about is that when knowledge is represented in an appropriately modular way, only one or a few modules change — such changes are sparse. This is especially important when the distribution change is caused by the action of one or more agents, because an agent intervenes at a particular place and time, which takes the form of the interventions discussed in the causal literature, where one of the causal variables is clamped to a particular value or to a random variable. In general, it is hard for an agent to affect more than one of the underlying causal variables at once. Although this paper is not about agent learning per se, this is a property we explore to help discover these variables and the causal relationships between them. In this respect, the causal graph is a powerful tool, because it tells us how a perturbation of the distribution of an intervened variable will propagate to all the other variables and affect their distributions.</p>
<p>Usually, the causal structure is not known in advance. The problem of causal discovery is generally needed to obtain the causal graph, but this is usually achievable only under strong assumptions. One such assumption is that a learner that has captured the correct structure of the true underlying data-generating process should generalize to perturbations of that structure in a specific way. This can be illustrated by considering temperature and altitude: roughly speaking, a learner trained on data from Switzerland should still be valid when tested on data drawn from the distribution of a less mountainous country such as the Netherlands. It is thus proposed to use the out-of-distribution robustness of the predictive model to guide inference about the true causal structure.</p>
<p>So how can we exploit the assumption of local changes? As we explain theoretically and validate experimentally here, if we have the correct representation of knowledge, then starting from a model pre-trained on the training distribution we should be able to adapt very quickly to the transferred data distribution. This happens because we assume the data-generating process is acquired as a set of independent mechanisms, and moving from the training distribution to the transfer distribution requires changing very few of the mechanisms and parameters. A model corresponding to the correct decomposition of knowledge therefore needs only a few updates and examples to adapt to the transfer distribution. As shown below, the expected gradient on the invariant parameters will be close to 0 (if the model has already been well trained on the training distribution), so the effective search space is greatly reduced during adaptation to the transfer distribution, which speeds up adaptation, as the experiments show. <strong>Therefore, based on the assumption of small changes in the space of correct knowledge representations, we can define a meta-learning objective that measures the speed of adaptation — a form of regret — to optimize how knowledge is represented, decomposed, and structured</strong></p>
<p>Back to the earlier temperature and altitude example: if we receive out-of-distribution data from the Netherlands, we expect the model to adapt faster because a small number of transfer samples from the Netherlands have been collected. Similarly to robustness, adaptation speed can be used to guide inference about the true causal structure of the problem at hand, possibly together with other sources of signal about the causal structure.</p>
<p><strong>Main contributions</strong>: We first validate on synthetic data that, after certain interventions are performed on the true bivariate causal graph (unknown to the learner), a model that correctly captures the underlying causal structure adapts faster when samples are provided. This shows that adaptation speed can serve as a score that adequately assesses how well a learner fits the underlying causal graph. We then use a smooth parametrization of the causal graph to directly optimize this score in an end-to-end manner. Finally, we show that, when the mixing of variables is unknown, this score can be used to distinguish the correct causal variables.</p>
<h2 id="which-is-cause-and-which-is-effect">Which is Cause and Which is Effect?</h2>
<p>To be continued</p>
]]></content:encoded></item><item><title>Improving Federated Learning Personalization via MAML Paper Notes (Incomplete)</title><link>https://blog.ereebay.me/en/posts/fl-maml/</link><pubDate>Mon, 02 Dec 2019 15:07:30 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/fl-maml/</guid><description>&lt;h1 id="improving-federated-learning-personalization-via-maml"&gt;Improving Federated Learning Personalization via MAML&lt;/h1&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;FL algorithms share many similarities with MAML and can be interpreted through meta-learning algorithms&lt;/li&gt;
&lt;li&gt;Fine-tuning gives the global model stronger accuracy while making personalization easier&lt;/li&gt;
&lt;li&gt;Models trained on standard centralized datasets are harder to personalize than those trained with FedAvg&lt;/li&gt;
&lt;/ol&gt;
&lt;!-- more --&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Points out the connection between FL and MAML, and interprets the FL algorithm via MAML&lt;/li&gt;
&lt;li&gt;Improves FedAvg with a two-stage approach of training and fine-tuning&lt;/li&gt;
&lt;li&gt;Finds that FedAvg is essentially a meta-learning algorithm that optimizes personalization performance rather than the global model.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="interpreting-fedavg-as-a-meta-learning-algorithm"&gt;Interpreting FedAvg as a Meta Learning Algorithm&lt;/h2&gt;
&lt;p&gt;The figure below shows MAML applied in the FL setting (left), the Reptile algorithm (middle), and FedAvg, the training algorithm of FL (right). Let L be the loss function. In each round of iteration, MAML trains by randomly sampling a batch of tasks T. For each task T there is an inner loop, and the outer loop aggregates the gradient updates obtained from each task. The FL algorithm randomly samples several clients T. For each T and its weight, several rounds of local optimization are performed, and the updated gradients are aggregated into a new global model. If we simplify the setting and assume all clients have the same amount of data, all weights become equal, and Reptile and FedAvg are then effectively the same algorithm.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="improving-federated-learning-personalization-via-maml">Improving Federated Learning Personalization via MAML</h1>
<h2 id="abstract">Abstract</h2>
<ol>
<li>FL algorithms share many similarities with MAML and can be interpreted through meta-learning algorithms</li>
<li>Fine-tuning gives the global model stronger accuracy while making personalization easier</li>
<li>Models trained on standard centralized datasets are harder to personalize than those trained with FedAvg</li>
</ol>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<ol>
<li>Points out the connection between FL and MAML, and interprets the FL algorithm via MAML</li>
<li>Improves FedAvg with a two-stage approach of training and fine-tuning</li>
<li>Finds that FedAvg is essentially a meta-learning algorithm that optimizes personalization performance rather than the global model.</li>
</ol>
<h2 id="interpreting-fedavg-as-a-meta-learning-algorithm">Interpreting FedAvg as a Meta Learning Algorithm</h2>
<p>The figure below shows MAML applied in the FL setting (left), the Reptile algorithm (middle), and FedAvg, the training algorithm of FL (right). Let L be the loss function. In each round of iteration, MAML trains by randomly sampling a batch of tasks T. For each task T there is an inner loop, and the outer loop aggregates the gradient updates obtained from each task. The FL algorithm randomly samples several clients T. For each T and its weight, several rounds of local optimization are performed, and the updated gradients are aggregated into a new global model. If we simplify the setting and assume all clients have the same amount of data, all weights become equal, and Reptile and FedAvg are then effectively the same algorithm.</p>
<p><img loading="lazy" src="http://cdn.ereebay.me/blog/fl-maml/fl-maml-1.png"></p>
<p>Assume the weights in FedAvg are equal, denoted wi. Consider T clients, and let the model parameters be <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span>. For each client i, the loss function is <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">L_{i}(\theta)</annotation></semantics></math></span>; let <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>g</mi><mi>j</mi><mi>i</mi></msubsup></mrow><annotation encoding="application/x-tex">g_{j}^{i}</annotation></semantics></math></span> denote the gradient computed during the <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>j</mi><mrow><mi>t</mi><mi>h</mi></mrow></msup></mrow><annotation encoding="application/x-tex">j^{t h}</annotation></semantics></math></span> local training step.</p>
<p>The gradient update of FedSGD is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>g</mi><mrow><mi>F</mi><mi>e</mi><mi>d</mi><mi>S</mi><mi>G</mi><mi>D</mi></mrow></msub><mo>=</mo><mfrac><mrow><mo>−</mo><mi>β</mi></mrow><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>L</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>g</mi><mn>1</mn><mi>i</mi></msubsup></mrow><annotation encoding="application/x-tex">
g_{F e d S G D}=\frac{-\beta}{T} \sum_{i=1}^{T} \frac{\partial L_{i}(\theta)}{\partial \theta}=\frac{1}{T} \sum_{i=1}^{T} g_{1}^{i}
</annotation></semantics></math></span><p>Now let us express FOMAML in the same terms. Assume the client learning rate is <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span>; after K steps, the personalized model of client i obtains the updated parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>θ</mi><mi>K</mi><mi>i</mi></msubsup><mo>=</mo><msubsup><mi>U</mi><mi>K</mi><mi>i</mi></msubsup><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><mi>θ</mi><mo>−</mo><mi>β</mi><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><msubsup><mi>g</mi><mi>j</mi><mi>i</mi></msubsup><mo>=</mo><mi>θ</mi><mo>−</mo><mi>β</mi><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>j</mi></msub><mo fence="true">)</mo></mrow></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">\theta_{K}^{i}=U_{K}^{i}(\theta)=\theta-\beta \sum_{j=1}^{K} g_{j}^{i}=\theta-\beta \sum_{j=1}^{K} \frac{\partial L_{i}\left(\theta_{j}\right)}{\partial \theta}</annotation></semantics></math></span></p>
<p>Differentiating gives:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mrow><mi mathvariant="normal">∂</mi><msubsup><mi>U</mi><mi>K</mi><mi>i</mi></msubsup><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac><mo>=</mo><mi>I</mi><mo>−</mo><mi>β</mi><mfrac><mrow><mi mathvariant="normal">∂</mi><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><msubsup><mi>g</mi><mi>j</mi><mi>i</mi></msubsup></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac><mo>=</mo><mi>I</mi><mo>−</mo><mi>β</mi><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><mfrac><mrow><msup><mi mathvariant="normal">∂</mi><mn>2</mn></msup><msub><mi>L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>j</mi></msub><mo fence="true">)</mo></mrow></mrow><mrow><mi mathvariant="normal">∂</mi><msup><mi>θ</mi><mn>2</mn></msup></mrow></mfrac></mrow><annotation encoding="application/x-tex">
\frac{\partial U_{K}^{i}(\theta)}{\partial \theta}=I-\beta \frac{\partial \sum_{j=1}^{K} g_{j}^{i}}{\partial \theta}=I-\beta \sum_{j=1}^{K} \frac{\partial^{2} L_{i}\left(\theta_{j}\right)}{\partial \theta^{2}}
</annotation></semantics></math></span><p>After K gradient updates, the whole model is updated:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>g</mi><mrow><mi>M</mi><mi>A</mi><mi>M</mi><mi>L</mi></mrow></msub><mo>=</mo><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>L</mi><mrow><mi>M</mi><mi>A</mi><mi>M</mi><mi>L</mi></mrow></msub></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><mfrac><mrow><mi mathvariant="normal">∂</mi><msub><mi>L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msubsup><mi>U</mi><mi>K</mi><mi>i</mi></msubsup><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow><mrow><mi mathvariant="normal">∂</mi><mi>θ</mi></mrow></mfrac><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>L</mi><mi>i</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msubsup><mrow><mo fence="true">(</mo><msubsup><mi>U</mi><mi>K</mi><mi>i</mi></msubsup><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mrow><mo fence="true">(</mo><mi>I</mi><mo>−</mo><mi>β</mi><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><mfrac><mrow><msup><mi mathvariant="normal">∂</mi><mn>2</mn></msup><msub><mi>L</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>j</mi></msub><mo fence="true">)</mo></mrow></mrow><mrow><mi mathvariant="normal">∂</mi><msup><mi>θ</mi><mn>2</mn></msup></mrow></mfrac><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
g_{M A M L}=\frac{\partial L_{M A M L}}{\partial \theta}=\frac{1}{T} \sum_{i=1}^{T} \frac{\partial L_{i}\left(U_{K}^{i}(\theta)\right)}{\partial \theta}=\frac{1}{T} \sum_{i=1}^{T} L_{i}^{\prime}\left(U_{K}^{i}(\theta)\right)\left(I-\beta \sum_{j=1}^{K} \frac{\partial^{2} L_{i}\left(\theta_{j}\right)}{\partial \theta^{2}}\right)
</annotation></semantics></math></span><p>To avoid the computational cost of second-order derivatives, FOMAML was introduced: after K gradient updates, it directly uses the (K+1)-th gradient as the local update.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>g</mi><mrow><mi>F</mi><mi>O</mi><mi>M</mi><mi>A</mi><mi>M</mi><mi>L</mi></mrow></msub><mo stretchy="false">(</mo><mi>K</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>L</mi><mi>i</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msubsup><mrow><mo fence="true">(</mo><msubsup><mi>U</mi><mi>K</mi><mi>i</mi></msubsup><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mi>I</mi><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>L</mi><mi>i</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msubsup><mrow><mo fence="true">(</mo><msubsup><mi>θ</mi><mi>K</mi><mi>i</mi></msubsup><mo fence="true">)</mo></mrow><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>g</mi><mrow><mi>K</mi><mo>+</mo><mn>1</mn></mrow><mi>i</mi></msubsup></mrow><annotation encoding="application/x-tex">
g_{F O M A M L}(K)=\frac{1}{T} \sum_{i=1}^{T} L_{i}^{\prime}\left(U_{K}^{i}(\theta)\right) I=\frac{1}{T} \sum_{i=1}^{T} L_{i}^{\prime}\left(\theta_{K}^{i}\right)=\frac{1}{T} \sum_{i=1}^{T} g_{K+1}^{i}
</annotation></semantics></math></span><p>From the formulas above, it is easy to see that the FedAvg update — the average of all clients&rsquo; updates — is essentially a linear combination of the two ideas above.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>g</mi><mrow><mi>F</mi><mi>e</mi><mi>d</mi><mi>A</mi><mi>v</mi><mi>g</mi></mrow></msub><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><msubsup><mi>g</mi><mi>j</mi><mi>i</mi></msubsup><mo>=</mo><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>g</mi><mn>1</mn><mi>i</mi></msubsup><mo>+</mo><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi>K</mi><mo>−</mo><mn>1</mn></mrow></msubsup><mfrac><mn>1</mn><mi>T</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>T</mi></msubsup><msubsup><mi>g</mi><mrow><mi>j</mi><mo>+</mo><mn>1</mn></mrow><mi>i</mi></msubsup><mo>=</mo><msub><mi>g</mi><mrow><mi>F</mi><mi>e</mi><mi>d</mi><mi>S</mi><mi>G</mi><mi>D</mi></mrow></msub><mo>+</mo><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi>K</mi><mo>−</mo><mn>1</mn></mrow></msubsup><msub><mi>g</mi><mrow><mi>F</mi><mi>O</mi><mi>M</mi><mi>A</mi><mi>M</mi><mi>L</mi></mrow></msub><mo stretchy="false">(</mo><mi>j</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
g_{F e d A v g}=\frac{1}{T} \sum_{i=1}^{T} \sum_{j=1}^{K} g_{j}^{i}=\frac{1}{T} \sum_{i=1}^{T} g_{1}^{i}+\sum_{j=1}^{K-1} \frac{1}{T} \sum_{i=1}^{T} g_{j+1}^{i}=g_{F e d S G D}+\sum_{j=1}^{K-1} g_{F O M A M L}(j)
</annotation></semantics></math></span><h2 id="personalized-fedavg">Personalized FedAvg</h2>
<p><img loading="lazy" src="http://cdn.ereebay.me/blog/fl-maml/fl-maml-2.png"></p>
<p>As shown in the figure above, FedAvg E in Algorithm 1 trains for E local epochs, weighting the gradient updates by the local data volume. Then, in the FL setting, Reptile (K) trains for K local steps, ignoring the local data volume.</p>
<p>Generally speaking, in terms of the number of communication rounds, FedAvg with several local epochs converges quickly within just a few rounds of communication. Due to the complexity of production environments, this metric is used to measure the convergence speed of FL algorithms. This paper finds that using momentum SGD as the server optimizer already benefits the personalized model, whereas the initial model remains relatively unstable. Previous approaches reduced the number of local training epochs or the learning rate.</p>
<p>This paper proposes using Reptile (K) for fine-tuning and then Adam as the server optimizer, which improves the initial model while also stabilizing the personalized model.</p>
<p>To be continued</p>
]]></content:encoded></item><item><title>Federated Adversarial Domain Adaptation Paper Notes (Incomplete)</title><link>https://blog.ereebay.me/en/posts/flpaper/</link><pubDate>Sun, 24 Nov 2019 14:04:02 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/flpaper/</guid><description>&lt;h1 id="federated-adversarial-domain-adaptation"&gt;Federated Adversarial Domain Adaptation&lt;/h1&gt;
&lt;p&gt;Federated learning currently has the problem of knowledge domain shift, which prevents it from having good generalization ability. Domain shift occurs when the labeled data of the source nodes and the unlabeled data of the target node are different.&lt;/p&gt;
&lt;p&gt;This paper mainly proposes a way to address the use of knowledge domains in federated learning, so that the knowledge learned by different nodes can be aligned with the data distribution of the target node.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="federated-adversarial-domain-adaptation">Federated Adversarial Domain Adaptation</h1>
<p>Federated learning currently has the problem of knowledge domain shift, which prevents it from having good generalization ability. Domain shift occurs when the labeled data of the source nodes and the unlabeled data of the target node are different.</p>
<p>This paper mainly proposes a way to address the use of knowledge domains in federated learning, so that the knowledge learned by different nodes can be aligned with the data distribution of the target node.</p>
<p>The paper&rsquo;s method mainly applies adversarial adaptation techniques to federated learning. In addition, a dynamic attention mechanism is designed, and feature disentanglement is used to enhance knowledge transfer.</p>
<!-- more -->
<h2 id="introduction">Introduction</h2>
<p>Traditional federated learning has a problem: since the data on each node is collected in a non-IID manner, a domain shift problem arises. For example, the images taken by one device are mostly indoor scenes, while those taken by another are mostly outdoor scenes. The method proposed in this paper is: <strong>transferring the knowledge in the data of decentralized nodes to a node of a new and different data domain, without requiring additional user supervision.</strong> This method is also known as Unsupervised Federated Domain Adaptation.</p>
<p>There are currently many unsupervised domain adaptation methods, but the federated learning setting gives rise to the following problems:</p>
<ol>
<li>Data is stored locally and cannot be shared.</li>
<li>Model parameters are trained independently on different nodes and converge at different rates, and the contribution to the global model depends on the correlation between the two domains.</li>
<li>Since the knowledge learned from the source nodes is highly integrated and difficult to disentangle, it may cause negative transfer.</li>
</ol>
<p>The method proposed in this paper is named Federated Adversarial Domain Adaptation (FADA), which uses adversarial techniques to solve the domain shift problem in federated learning systems.</p>
<p>The main steps of the method are:</p>
<ol>
<li>First, the federated domain adaptation problem is analyzed from a theoretical perspective, and a general, universal bound is provided.</li>
<li>Inspired by the theoretical results, an effective adaptation algorithm is proposed, based on adversarial adaptation and representation disentanglement techniques applied to the federated learning setting.</li>
<li>A dynamic attention model is designed to cope with the constantly changing convergence rates in federated learning systems.</li>
</ol>
<p><img alt="png1" loading="lazy" src="http://cdn.ereebay.me/FADAfada-1.png"></p>
<h2 id="related-work">Related Work</h2>
<p><strong>Unsupervised Domain Adaptation</strong>: The goal of UDA is to transfer knowledge from a labeled data domain to an unlabeled data domain.</p>
<p><strong>Federated Learning</strong>: I will not go into detail here.</p>
<p><strong>Feature Disentanglement</strong>: The features extracted by neural networks through complex hidden layers are usually highly integrated. Therefore, learning disentangled features can help remove irrelevant or domain-specific knowledge, and then model the needed domain knowledge.</p>
<h2 id="generalization-bound-for-fda">Generalization Bound for FDA</h2>
<ol>
<li>First, recall the definition of the theoretical error bound for the adaptation problem in the single-data-source setting.</li>
<li>Then describe the definition of the error bound in the unsupervised federated domain adaptation setting.</li>
</ol>
<h2 id="federated-adversarial-domain-adaptation-1">Federated Adversarial Domain Adaptation</h2>
<p><img loading="lazy" src="http://cdn.ereebay.me/flpaper-2.png"></p>
<p>From the theory in the previous section, it is not difficult to see the importance of the weight <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi></mrow><annotation encoding="application/x-tex">\alpha</annotation></semantics></math></span> and the distance. The method of this paper learns the weights by proposing a dynamic attention mechanism, and reduces the distance between the source domains and the target domain through a federated adversarial alignment mechanism. In addition, a feature disentanglement method is adopted to extract domain-invariant features to strengthen knowledge transfer.</p>
<p><strong>Dynamic Attention Mechanism</strong>:</p>
<p>The principle of this mechanism is mainly to increase the weights of nodes with high contributions and decrease the weights of nodes with low contributions. So how do we judge the degree of a node&rsquo;s contribution? This paper uses the gap statistics method to evaluate how well the target features can be clustered.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>I</mi><mo>=</mo><msubsup><mo>∑</mo><mrow><mi>r</mi><mo>=</mo><mn>1</mn></mrow><mi>k</mi></msubsup><mfrac><mn>1</mn><mrow><mn>2</mn><msub><mi>n</mi><mi>r</mi></msub></mrow></mfrac><msub><mo>∑</mo><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>∈</mo><msub><mi>C</mi><mi>r</mi></msub></mrow></msub><msub><mrow><mo fence="true">∥</mo><msubsup><mi>f</mi><mi>i</mi><mi>t</mi></msubsup><mo>−</mo><msubsup><mi>f</mi><mi>j</mi><mi>t</mi></msubsup><mo fence="true">∥</mo></mrow><mn>2</mn></msub></mrow><annotation encoding="application/x-tex">
I=\sum_{r=1}^{k} \frac{1}{2 n_{r}} \sum_{i, j \in C_{r}}\left\|f_{i}^{t}-f_{j}^{t}\right\|_{2}
</annotation></semantics></math></span><p>Assume there are <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mn>1</mn></msub><mo separator="true">,</mo><msub><mi>C</mi><mn>2</mn></msub><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msub><mi>C</mi><mi>k</mi></msub></mrow><annotation encoding="application/x-tex">C_{1}, C_{2}, \ldots, C_{k}</annotation></semantics></math></span> clusters, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mi>r</mi></msub></mrow><annotation encoding="application/x-tex">C_r</annotation></semantics></math></span> denotes the indices of the objects in the r-th cluster, and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>n</mi><mi>r</mi></msub><mo>=</mo><mrow><mo fence="true">∣</mo><msub><mi>C</mi><mi>r</mi></msub><mo fence="true">∣</mo></mrow></mrow><annotation encoding="application/x-tex">n_{r}=\left|C_{r}\right|</annotation></semantics></math></span>.</p>
<p>Intuitively, a smaller gap statistics value indicates that the feature distribution has smaller intra-class variance. The degree of contribution of each source node is measured by computing the difference between the gap statistics of two iterations.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>I</mi><mi>i</mi><mrow><mi>g</mi><mi>a</mi><mi>i</mi><mi>n</mi></mrow></msubsup><mo>=</mo><msubsup><mi>I</mi><mi>i</mi><mrow><mi>p</mi><mo>−</mo><mn>1</mn></mrow></msubsup><mo>−</mo><msubsup><mi>I</mi><mi>i</mi><mi>p</mi></msubsup></mrow><annotation encoding="application/x-tex">
I_{i}^{g a i n}=I_{i}^{p-1}-I_{i}^{p}
</annotation></semantics></math></span><p>It represents how much the clusters can be improved after the target domain is updated with a source domain&rsquo;s gradient. For the gradient updates, the following is used to decide how much each gradient contributes:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext> Softmax </mtext><mrow><mo fence="true">(</mo><msubsup><mi>I</mi><mn>1</mn><mtext>gain </mtext></msubsup><mo separator="true">,</mo><msubsup><mi>I</mi><mn>2</mn><mtext>gain </mtext></msubsup><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msubsup><mi>I</mi><mi>N</mi><mtext>gain</mtext></msubsup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\text { Softmax }\left(I_{1}^{\text {gain }}, I_{2}^{\text {gain }}, \ldots, I_{N}^{\text {gain}}\right)
</annotation></semantics></math></span><p><strong>Federated Adversarial Alignment</strong>:</p>
<p>Machine learning models can suffer greatly degraded performance due to domain distance. To solve this problem, this paper improves the traditional adversarial training method in the federated learning setting. In the federated learning context, this paper divides the adversarial alignment optimization process into two steps: 1. For each domain, train a local feature extractor, with <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>G</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">G_i</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>G</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">G_t</annotation></semantics></math></span> corresponding to <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>D</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">D_i</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>D</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">D_t</annotation></semantics></math></span> respectively. 2. For each (<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>D</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>D</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">D_i, D_t</annotation></semantics></math></span>) source-target domain pair, train an adversarial domain discriminator DI to align the two distributions in an adversarial learning way. First, train DI to recognize which feature domain a feature comes from; then train the generator, i.e., the feature extractors (<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>G</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>G</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">G_i, G_t</annotation></semantics></math></span>), to fool DI. Note: D can only access the outputs of <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>G</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">G_i</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>G</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">G_t</annotation></semantics></math></span>.</p>
<p>Given the i-th source data domain <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi mathvariant="bold">X</mi><msub><mi>S</mi><mi>i</mi></msub></msup></mrow><annotation encoding="application/x-tex">\mathbf{X}^{S_{i}}</annotation></semantics></math></span> and the target domain <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi mathvariant="bold">X</mi><mi>T</mi></msup></mrow><annotation encoding="application/x-tex">\mathbf{X}^T</annotation></semantics></math></span>, the optimization objective of <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">D I_{i}</annotation></semantics></math></span> is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi><munder><mo><msub><mi>L</mi><mrow><mi>a</mi><mi>d</mi><msub><mi>v</mi><mrow><mi>D</mi><mi>I</mi></mrow></msub></mrow></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">X</mi><msub><mi>S</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="bold">X</mi><mi>T</mi></msup><mo separator="true">,</mo><msub><mi>G</mi><mi>i</mi></msub><mo separator="true">,</mo><msub><mi>G</mi><mi>t</mi></msub><mo fence="true">)</mo></mrow><mo>=</mo><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><msup><mi mathvariant="bold">x</mi><mrow><msub><mi>s</mi><mi>i</mi></msub><mo>∼</mo><msup><mi mathvariant="bold">X</mi><msub><mi>s</mi><mi>i</mi></msub></msup></mrow></msup></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>G</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><msup><mi mathvariant="bold">x</mi><mi>t</mi></msup><mo>∼</mo><msup><mi mathvariant="bold">x</mi><mi>t</mi></msup></mrow></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>G</mi><mi>t</mi></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><mi>t</mi></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mo><mrow><msup><mi mathvariant="normal">Θ</mi><mrow><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub></mrow></msup><mi>L</mi></mrow></munder></mi></mrow><annotation encoding="application/x-tex">
\underset{\Theta^{D I_{i}}{L}}{L_{a d v_{D I}}\left(\mathbf{X}^{S_{i}}, \mathbf{X}^{T}, G_{i}, G_{t}\right)=-\mathbb{E}_{\mathbf{x}^{s_{i} \sim \mathbf{X}^{s_{i}}}}\left[\log D I_{i}\left(G_{i}\left(\mathbf{x}^{s_{i}}\right)\right)\right]-\mathbb{E}_{\mathbf{x}^{t} \sim \mathbf{x}^{t}}\left[\log \left(1-D I_{i}\left(G_{t}\left(\mathbf{x}^{t}\right)\right)\right)\right]}
</annotation></semantics></math></span><p>Then, keeping D fixed, the objective function for updating G is:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi><munder><mo><mi>L</mi></mo><mrow><msup><mi mathvariant="normal">Θ</mi><mi>G</mi></msup><msub><mi>G</mi><mi>i</mi></msub><mo separator="true">,</mo><msup><mi mathvariant="normal">Θ</mi><msub><mi>G</mi><mi>t</mi></msub></msup></mrow></munder></mi><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">X</mi><msub><mi>S</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="bold">X</mi><mi>T</mi></msup><mo separator="true">,</mo><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>=</mo><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><msup><mi mathvariant="bold">x</mi><mrow><msub><mi>s</mi><mi>i</mi></msub><mo>∼</mo><msup><mi mathvariant="bold">X</mi><msub><mi>s</mi><mi>i</mi></msub></msup></mrow></msup><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>G</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><msup><mi mathvariant="bold">x</mi><mi>t</mi></msup><mo>∼</mo><msup><mi mathvariant="bold">X</mi><mi>t</mi></msup></mrow></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>G</mi><mi>t</mi></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><mi>t</mi></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow></msub></mrow><annotation encoding="application/x-tex">
\underset{\Theta^{G}{G}_{i}, \Theta^{G_{t}}}{L}\left(\mathbf{X}^{S_{i}}, \mathbf{X}^{T}, D I_{i}\right)=-\mathbb{E}_{\mathbf{x}^{s_{i} \sim \mathbf{X}^{s_{i}}}\left[\log D I_{i}\left(G_{i}\left(\mathbf{x}^{s_{i}}\right)\right)\right]-\mathbb{E}_{\mathbf{x}^{t} \sim \mathbf{X}^{t}}\left[\log D I_{i}\left(G_{t}\left(\mathbf{x}^{t}\right)\right)\right]}
</annotation></semantics></math></span><p><strong>Feature Disentanglement</strong>:</p>
<p>Under the adversarial learning framework, this paper also adopts adversarial disentanglement to extract domain-invariant features. The paper argues that the extracted features can be divided into domain-specific features and domain-invariant features. As shown in the first figure, the feature disentangler D divides the features into two categories. First, a K-class classifier and a K-class category recognizer are trained to predict labels from the features.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtable rowspacing="0.16em" columnalign="center" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><msub><mi>L</mi><mrow><mi>c</mi><mi>r</mi><mi>o</mi><mi>s</mi><mi>s</mi><mi>e</mi><mi>n</mi><mi>t</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>y</mi></mrow></msub></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msup><mi mathvariant="normal">Θ</mi><msub><mi>G</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="normal">Θ</mi><msub><mi>D</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="normal">Θ</mi><msub><mi>C</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="normal">Θ</mi><mrow><mi>C</mi><msub><mi>I</mi><mi>i</mi></msub></mrow></msup></mrow></mstyle></mtd></mtr></mtable><mo>=</mo><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo separator="true">,</mo><msup><mi mathvariant="bold">y</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">)</mo></mrow><mo>∼</mo><msub><mover accent="true"><mi mathvariant="script">D</mi><mo stretchy="true">^</mo></mover><msub><mi>s</mi><mi>i</mi></msub></msub></mrow></msub><msubsup><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><mn mathvariant="double-struck">1</mn><mrow><mo fence="true">[</mo><mi>k</mi><mo>=</mo><msup><mi mathvariant="bold">y</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">]</mo></mrow><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>C</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>f</mi><mrow><mi>d</mi><mi>i</mi></mrow></msub><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo>−</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><mi>s</mi></msup><mi>i</mi><mo separator="true">,</mo><msup><mi mathvariant="bold">y</mi><mi>s</mi></msup><mi>i</mi><mo fence="true">)</mo></mrow><mo>∼</mo><msub><mover accent="true"><mi mathvariant="script">D</mi><mo stretchy="true">^</mo></mover><msub><mi>s</mi><mi>i</mi></msub></msub></mrow></msub><msubsup><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>K</mi></msubsup><mn mathvariant="double-struck">1</mn><mrow><mo fence="true">[</mo><mi>k</mi><mo>=</mo><msup><mi mathvariant="bold">y</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">]</mo></mrow><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mi>C</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>f</mi><mrow><mi>d</mi><mi>s</mi></mrow></msub><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\begin{array}{c}{L_{cross entropy}} \\ {\Theta^{G_i}, \Theta^{D_i}, \Theta^{C_i}, \Theta^{CI_i}}\end{array}=-\mathbb{E}_{\left(\mathbf{x}^{s_i}, \mathbf{y}^{s_i}\right) \sim \widehat{\mathcal{D}}_{s_i}} \sum_{k=1}^{K} \mathbb{1}\left[k=\mathbf{y}^{s_{i}}\right] \log \left(C_{i}\left(f_{d i}\right)\right)-\mathbb{E}_{\left(\mathbf{x}^{s} i, \mathbf{y}^{s} i\right) \sim \widehat{\mathcal{D}}_{s_{i}}} \sum_{k=1}^{K} \mathbb{1}\left[k=\mathbf{y}^{s_{i}}\right] \log \left(C I_{i}\left(f_{d s}\right)\right)
</annotation></semantics></math></span><p>Then, with the category classifier fixed, only the feature disentangler is trained, producing domain-specific features to fool the category classifier.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi><munder><mo><msub><mi>L</mi><mrow><mi>e</mi><mi>n</mi><mi>t</mi></mrow></msub></mo><mrow><msup><mi mathvariant="normal">Θ</mi><mi>D</mi></msup><mi>i</mi><mo separator="true">,</mo><msup><mi mathvariant="normal">Θ</mi><msub><mi>G</mi><mi>i</mi></msub></msup></mrow></munder></mi><mo>=</mo><mo>−</mo><mfrac><mn>1</mn><msub><mi>N</mi><msub><mi>s</mi><mi>i</mi></msub></msub></mfrac><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><msub><mi>N</mi><msub><mi>s</mi><mi>i</mi></msub></msub></msubsup><mi>log</mi><mo>⁡</mo><mi>C</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msubsup><mi>f</mi><mrow><mi>d</mi><mi>s</mi></mrow><mi>j</mi></msubsup><mo fence="true">)</mo></mrow><mo>=</mo><mo>−</mo><mfrac><mn>1</mn><msub><mi>N</mi><msub><mi>s</mi><mi>i</mi></msub></msub></mfrac><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><msub><mi>N</mi><msub><mi>s</mi><mi>i</mi></msub></msub></msubsup><mi>log</mi><mo>⁡</mo><mi>C</mi><msub><mi>I</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>D</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msub><mi>G</mi><mi>i</mi></msub><mrow><mo fence="true">(</mo><msup><mi mathvariant="bold">x</mi><msub><mi>s</mi><mi>i</mi></msub></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\underset{\Theta^{D} i, \Theta^{G_{i}}}{L_{e n t}}=-\frac{1}{N_{s_{i}}} \sum_{j=1}^{N_{s_{i}}} \log C I_{i}\left(f_{d s}^{j}\right)=-\frac{1}{N_{s_{i}}} \sum_{j=1}^{N_{s_{i}}} \log C I_{i}\left(D_{i}\left(G_{i}\left(\mathbf{x}^{s_{i}}\right)\right)\right)
</annotation></semantics></math></span><p>The feature disentanglement method transfers knowledge by keeping the class-invariant features and removing the class-specific features. To enhance the disentanglement effect, this paper minimizes the mutual information between the two.</p>
<p>Mutual information is defined as <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>I</mi><mrow><mo fence="true">(</mo><msub><mi>f</mi><mrow><mi>d</mi><mi>i</mi></mrow></msub><mo separator="true">;</mo><msub><mi>f</mi><mrow><mi>d</mi><mi>s</mi></mrow></msub><mo fence="true">)</mo></mrow><mo>=</mo><msub><mo>∫</mo><mrow><mi mathvariant="script">P</mi><mo>×</mo><mi mathvariant="script">Q</mi></mrow></msub><mi>log</mi><mo>⁡</mo><mfrac><mrow><mi>d</mi><msub><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi>Q</mi></mrow></msub></mrow><mrow><mi>d</mi><msub><mi mathvariant="double-struck">P</mi><mi mathvariant="script">P</mi></msub><mo>⊗</mo><msub><mi mathvariant="double-struck">P</mi><mi mathvariant="script">Q</mi></msub></mrow></mfrac><mi>d</mi><msub><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi mathvariant="script">Q</mi></mrow></msub></mrow><annotation encoding="application/x-tex">I\left(f_{d i} ; f_{d s}\right)=\int_{\mathcal{P} \times \mathcal{Q}} \log \frac{d \mathbb{P}_{\mathcal{P} Q}}{d \mathbb{P}_{\mathcal{P}} \otimes \mathbb{P}_{\mathcal{Q}}} d \mathbb{P}_{\mathcal{P} \mathcal{Q}}</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi mathvariant="script">Q</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\mathbb{P}_{\mathcal{P} \mathcal{Q}}</annotation></semantics></math></span> is the joint probability distribution of the two kinds of features, and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="double-struck">P</mi><mi mathvariant="script">P</mi></msub><mo>=</mo><msub><mo>∫</mo><mi mathvariant="script">P</mi></msub><mi>d</mi><msub><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi mathvariant="script">Q</mi></mrow></msub><mo separator="true">,</mo><msub><mi mathvariant="double-struck">P</mi><mi mathvariant="script">Q</mi></msub><mo>=</mo><msub><mo>∫</mo><mi mathvariant="script">Q</mi></msub><mi>d</mi><msub><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi mathvariant="script">Q</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\mathbb{P}_{\mathcal{P}}=\int_{\mathcal{P}} d \mathbb{P}_{\mathcal{P} \mathcal{Q}}, \mathbb{P}_{\mathcal{Q}}=\int_{\mathcal{Q}} d \mathbb{P}_{\mathcal{P} \mathcal{Q}}</annotation></semantics></math></span> are the corresponding marginal probability distributions.</p>
<p>The Mutual Information Neural Estimator (MINE) is used to estimate the mutual information:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>T</mi><mi>θ</mi></msub><mo>:</mo><msub><mover accent="true"><mrow><mi>I</mi><mo stretchy="false">(</mo><mi mathvariant="script">P</mi><mo separator="true">;</mo><mi mathvariant="script">Q</mi><mo stretchy="false">)</mo></mrow><mo stretchy="true">^</mo></mover><mi>n</mi></msub><mo>=</mo><msub><mrow><mi>sup</mi><mo>⁡</mo></mrow><mrow><mi>θ</mi><mo>∈</mo><mi mathvariant="normal">Θ</mi></mrow></msub><msub><mi mathvariant="double-struck">E</mi><msubsup><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi>Q</mi></mrow><mrow><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo></mrow></msubsup></msub><mrow><mo fence="true">[</mo><msub><mi>T</mi><mi>θ</mi></msub><mo fence="true">]</mo></mrow><mo>−</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi mathvariant="double-struck">E</mi><mrow><msubsup><mi mathvariant="double-struck">P</mi><mi>P</mi><mrow><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo></mrow></msubsup><mo>⊗</mo><msubsup><mi mathvariant="double-struck">P</mi><mi>Q</mi><mrow><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo></mrow></msubsup></mrow></msub><mrow><mo fence="true">[</mo><msup><mi>e</mi><msub><mi>T</mi><mi>θ</mi></msub></msup><mo fence="true">]</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
T_{\theta}: \widehat{I(\mathcal{P} ; \mathcal{Q})}_{n}=\sup _{\theta \in \Theta} \mathbb{E}_{\mathbb{P}_{\mathcal{P} Q}^{(n)}}\left[T_{\theta}\right]-\log \left(\mathbb{E}_{\mathbb{P}_{P}^{(n)} \otimes \mathbb{P}_{Q}^{(n)}}\left[e^{T_{\theta}}\right]\right)
</annotation></semantics></math></span><p>In practice, it can be computed by:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>I</mi><mo stretchy="false">(</mo><mi mathvariant="script">P</mi><mo separator="true">;</mo><mi mathvariant="script">Q</mi><mo stretchy="false">)</mo><mo>=</mo><mo>∬</mo><msubsup><mi mathvariant="double-struck">P</mi><mrow><mi mathvariant="script">P</mi><mi mathvariant="script">Q</mi></mrow><mi>n</mi></msubsup><mo stretchy="false">(</mo><mi>p</mi><mo separator="true">,</mo><mi>q</mi><mo stretchy="false">)</mo><mi>T</mi><mo stretchy="false">(</mo><mi>p</mi><mo separator="true">,</mo><mi>q</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mo>∬</mo><msubsup><mi mathvariant="double-struck">P</mi><mi mathvariant="script">P</mi><mi>n</mi></msubsup><mo stretchy="false">(</mo><mi>p</mi><mo stretchy="false">)</mo><msubsup><mi mathvariant="double-struck">P</mi><mi mathvariant="script">Q</mi><mi>n</mi></msubsup><mo stretchy="false">(</mo><mi>q</mi><mo stretchy="false">)</mo><msup><mi>e</mi><mrow><mi>T</mi><mo stretchy="false">(</mo><mi>p</mi><mo separator="true">,</mo><mi>q</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow></msup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
I(\mathcal{P} ; \mathcal{Q})=\iint \mathbb{P}_{\mathcal{P} \mathcal{Q}}^{n}(p, q) T(p, q, \theta)-\log \left(\iint \mathbb{P}_{\mathcal{P}}^{n}(p) \mathbb{P}_{\mathcal{Q}}^{n}(q) e^{T(p, q, \theta)}\right)
</annotation></semantics></math></span><p>To avoid computing integrals, the Monte Carlo method is adopted:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>I</mi><mo stretchy="false">(</mo><mi mathvariant="script">P</mi><mo separator="true">,</mo><mi mathvariant="script">Q</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><mi>T</mi><mo stretchy="false">(</mo><mi>p</mi><mo separator="true">,</mo><mi>q</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mn>1</mn><mi>n</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><msup><mi>e</mi><mrow><mi>T</mi><mrow><mo fence="true">(</mo><mi>p</mi><mo separator="true">,</mo><msup><mi>q</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo separator="true">,</mo><mi>θ</mi><mo fence="true">)</mo></mrow></mrow></msup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
I(\mathcal{P}, \mathcal{Q})=\frac{1}{n} \sum_{i=1}^{n} T(p, q, \theta)-\log \left(\frac{1}{n} \sum_{i=1}^{n} e^{T\left(p, q^{\prime}, \theta\right)}\right)
</annotation></semantics></math></span><p>where (p, q) are sampled from the joint distribution, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>q</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup></mrow><annotation encoding="application/x-tex">q^{\prime}</annotation></semantics></math></span> is sampled from the marginal distribution, and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi><mo stretchy="false">(</mo><mi>p</mi><mo separator="true">,</mo><mi>q</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">T(p, q, \theta)</annotation></semantics></math></span> is a neural network determined by <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span> that estimates the mutual information between the P and Q distributions.</p>
<p>The domain-invariant features and the domain-specific features are fed into a reconstructor to obtain recombined features; the loss function uses an L2 loss to reconstruct the original features, in order to preserve the composability of the representation. The L2 constraint and the mutual information loss constraint can be balanced by tuning the hyperparameters.</p>
<p>To be continued</p>
]]></content:encoded></item><item><title>MemoryGAN Paper Notes (Incomplete)</title><link>https://blog.ereebay.me/en/posts/memorygan/</link><pubDate>Mon, 22 Apr 2019 14:05:02 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/memorygan/</guid><description>&lt;h1 id="memory-gan-reading-notes"&gt;Memory GAN Reading Notes&lt;/h1&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;This paper mainly solves two problems in training unsupervised GANs.&lt;/p&gt;
&lt;p&gt;First, since generative adversarial networks use only a continuous latent distribution to represent multiple classes or clusters of data, they usually cannot correctly handle the structurally discontinuous nature between different classes in the latent space. (Caused by the mode collapse problem.) For example, if a GAN embeds buildings and cats in the same continuous latent distribution, the GAN may generate realistic images in the transition region between the two classes.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="memory-gan-reading-notes">Memory GAN Reading Notes</h1>
<h2 id="introduction">Introduction</h2>
<p>This paper mainly solves two problems in training unsupervised GANs.</p>
<p>First, since generative adversarial networks use only a continuous latent distribution to represent multiple classes or clusters of data, they usually cannot correctly handle the structurally discontinuous nature between different classes in the latent space. (Caused by the mode collapse problem.) For example, if a GAN embeds buildings and cats in the same continuous latent distribution, the GAN may generate realistic images in the transition region between the two classes.</p>
<p>Second, the discriminator of a generative adversarial network very easily forgets the samples generated in the past, which causes instability during adversarial training.</p>
<p>The authors believe that these two main problems can be solved by a learnable memory network accessible to both the generator and the discriminator. The generator can effectively learn representations of the training samples to understand the underlying clustering distribution of the data, thereby alleviating the structural discontinuity problem. Meanwhile, the discriminator can better memorize the clusters of previously generated samples, which can alleviate the forgetting problem.</p>
<p>This paper proposes an end-to-end generative adversarial network model, Memory GAN, which involves an unsupervised memory network integrated with existing generative adversarial network models.</p>
<!-- more -->
<p>Von Mises-Fisher (vMF) mixture model.
The memory module can effectively alleviate the instability problem. First, to alleviate the structural discontinuity problem, the memory can learn representations of the training samples, helping the generator better understand the class and cluster distributions. Therefore, we can separate the modeling of discrete clusters from the embedding of data attributes on the continuous latent space, which can alleviate the discontinuity problem.</p>
<p>Second, the memory network can alleviate the forgetting problem by learning to memorize the clusters of previously generated sample data, including very rare samples.</p>
<h2 id="architecture">Architecture</h2>
<p>The overall architecture is divided into the memory discriminative network (DMN) and the memory conditional generative network (MCGN).</p>
<h3 id="memory-discriminative-network">Memory Discriminative Network</h3>
<p>The memory discriminative network consists of a feedforward network <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> and a memory network.</p>
<p>The feedforward network <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> is a convolutional neural network, whose input is <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>D</mi></msup></mrow><annotation encoding="application/x-tex">x \in \mathbb{R}^{D}</annotation></semantics></math></span> and whose output is a normalized vector <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mo>=</mo><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>M</mi></msup></mrow><annotation encoding="application/x-tex">q=\mu(x) \in \mathbb{R}^{M}</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∥</mi><mi>q</mi><mi mathvariant="normal">∥</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">\|q\|=1</annotation></semantics></math></span>. This is then used as the input of the memory module, which outputs the discriminative result.</p>
<p>The memory network is formulated as <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">M</mi><mo>=</mo><mo stretchy="false">(</mo><mi>K</mi><mo separator="true">,</mo><mi>v</mi><mo separator="true">,</mo><mi>a</mi><mo separator="true">,</mo><mi>h</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\mathcal{M}=(K, v, a, h)</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>K</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mrow><mi>N</mi><mo>×</mo><mi>M</mi></mrow></msup></mrow><annotation encoding="application/x-tex">K \in \mathbb{R}^{N \times M}</annotation></semantics></math></span> is the memory key matrix, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi></mrow><annotation encoding="application/x-tex">N</annotation></semantics></math></span> is the memory size and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>M</mi></mrow><annotation encoding="application/x-tex">M</annotation></semantics></math></span> is the dimension. <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mo>∈</mo><mo stretchy="false">{</mo><mn>0</mn><mo separator="true">,</mo><mn>1</mn><msup><mo stretchy="false">}</mo><mi>N</mi></msup></mrow><annotation encoding="application/x-tex">v \in\{0,1\}^{N}</annotation></semantics></math></span> is the memory value matrix. Conceptually, each key vector stores a representation of a clustering center learned through the vMF mixture model, and its corresponding key value is the real/fake judgment. <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>N</mi></msup></mrow><annotation encoding="application/x-tex">a \in \mathbb{R}^{N}</annotation></semantics></math></span> denotes the age of the object stored in each memory block. And <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>h</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>N</mi></msup></mrow><annotation encoding="application/x-tex">h \in \mathbb{R}^{N}</annotation></semantics></math></span> denotes the slot histogram, where each <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">h_{i}</annotation></semantics></math></span> represents the amount of valid data belonging to the i-th memory slot.</p>
<h3 id="related-mechanisms">Related Mechanisms:</h3>
<p>life-long memory network: the memory space can grow freely, and there is no need to reset it during training.</p>
<p>k-nearest neighbor indexing for efficient memory lookup:
k-nearest neighbor indexing is used for lookup.</p>
<p>least recently used (LRU) scheme for memory update.
The LRU scheme is used for memory update.</p>
<h3 id="innovations">Innovations:</h3>
<ul>
<li>Probabilistic derivation: the data likelihood, as well as the prior and posterior distributions of the categorical distribution over memory indices, can be computed.</li>
<li>The memory learns an approximate distribution of queries by maximizing the likelihood with an incremental EM algorithm.</li>
<li>The memory is optimized through the GAN loss rather than through a memory loss.</li>
<li>The contribution of each sample is decided by tracking the slot histogram.</li>
</ul>
<h3 id="discriminator-output">Discriminator Output</h3>
<p>For each input <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span>, we first need to decide which memory slot to use to compute the discriminative probability.</p>
<p><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo>∈</mo><mo stretchy="false">{</mo><mn>1</mn><mo separator="true">,</mo><mn>2</mn><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><mi>N</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">c \in\{1,2, \ldots, N\}</annotation></semantics></math></span> denotes the memory slot index.</p>
<p>A Von Mises-Fisher (vMF) mixture model is used to represent the posterior distribution of the memory index.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo></mrow><mrow><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>j</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>j</mi><mo stretchy="false">)</mo></mrow></mfrac><mo>=</mo><mfrac><mrow><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mi>κ</mi><msubsup><mi>K</mi><mi>i</mi><mi>T</mi></msubsup><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo></mrow><mrow><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mi>κ</mi><msubsup><mi>K</mi><mi>j</mi><mi>T</mi></msubsup><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>j</mi><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">p(c=i | x)=\frac{p(x | c=i) p(c=i)}{\sum_{j=1}^{N} p(x | c=j) p(c=j)}=\frac{\exp \left(\kappa K_{i}^{T} \mu(x)\right) p(c=i)}{\sum_{j=1}^{N} \exp \left(\kappa K_{j}^{T} \mu(x)\right) p(c=j)}</annotation></semantics></math></span><p>In <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo><mo>=</mo><mi>C</mi><mo stretchy="false">(</mo><mi>κ</mi><mo stretchy="false">)</mo><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mi>κ</mi><msubsup><mi>K</mi><mi>i</mi><mi>T</mi></msubsup><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">p(x | c=i)=C(\kappa) \exp \left(\kappa K_{i}^{T} \mu(x)\right)</annotation></semantics></math></span>, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>κ</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">\kappa=1</annotation></semantics></math></span> is a constant attention parameter.</p>
<p>The vMF is effectively equivalent to a properly normalized Gaussian distribution defined on the unit sphere.</p>
<p>The categorical distribution over the memory index, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(c)</annotation></semantics></math></span>, is obtained by normalizing the slot histogram, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><msub><mi>h</mi><mi>i</mi></msub><mo>+</mo><mi>β</mi></mrow><mrow><msubsup><mo>∑</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>j</mi></msub><mo>+</mo><mi>β</mi><mo fence="true">)</mo></mrow></mrow></mfrac></mrow><annotation encoding="application/x-tex">p(c=i)=\frac{h_{i}+\beta}{\sum_{j=1}^{N}\left(h_{j}+\beta\right)}</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mrow><mo fence="true">(</mo><mo>=</mo><msup><mn>10</mn><mrow><mo>−</mo><mn>8</mn></mrow></msup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\beta\left(=10^{-8}\right)</annotation></semantics></math></span> is a smoothing constant for numerical stability. By using <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mo>=</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>i</mi><mo separator="true">,</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi>v</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">p(y=1 | c=i, x)=v_{i}</annotation></semantics></math></span>, we marginalize the joint probability <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mo>=</mo><mn>1</mn><mo separator="true">,</mo><mi>c</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(y=1, c | x)</annotation></semantics></math></span> over c to obtain <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mo>=</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(y=1 | x)</annotation></semantics></math></span>:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mo>=</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mo>=</mo><mn>1</mn><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>i</mi><mo separator="true">,</mo><mi>x</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><msub><mi>v</mi><mi>i</mi></msub><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>i</mi><mo>∼</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow></msub><mrow><mo fence="true">[</mo><msub><mi>v</mi><mi>i</mi></msub><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">
p(y=1 | x)=\sum_{i=1}^{N} p(y=1 | c=i, x) p(c=i | x)=\sum_{i=1}^{N} v_{i} p(c=i | x)=\mathbb{E}_{i \sim p(c | x)}\left[v_{i}\right]
</annotation></semantics></math></span><p>However, for each sample x, this is not scalable for the whole memory of size N.</p>
<p>The maximum a posteriori probability is adopted to consider the top-k slots <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>S</mi><mo>=</mo><mrow><mo fence="true">{</mo><msub><mi>s</mi><mn>1</mn></msub><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msub><mi>s</mi><mi>k</mi></msub><mo fence="true">}</mo></mrow></mrow><annotation encoding="application/x-tex">S=\left\{s_{1}, 
\dots, s_{k}\right\}</annotation></semantics></math></span>:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>S</mi><mo>=</mo><mi><munder><mo><mi mathvariant="normal">argmax</mi><mo>⁡</mo></mo><mrow><msub><mi>c</mi><mn>1</mn></msub><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msub><mi>c</mi><mi>k</mi></msub></mrow></munder></mi><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi><munder><mo><mi mathvariant="normal">argmax</mi><mo>⁡</mo></mo><mrow><msub><mi>c</mi><mn>1</mn></msub><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msub><mi>c</mi><mi>k</mi></msub></mrow></munder></mi><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>=</mo><mi><munder><mo><mi mathvariant="normal">argmax</mi><mo>⁡</mo></mo><mrow><msub><mi>c</mi><mn>1</mn></msub><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msub><mi>c</mi><mi>k</mi></msub></mrow></munder></mi><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mi>κ</mi><msubsup><mi>K</mi><mi>c</mi><mi>T</mi></msubsup><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mrow><mo fence="true">(</mo><msub><mi>h</mi><mi>c</mi></msub><mo>+</mo><mi>β</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
S=\underset{c_{1}, \ldots, c_{k}}{\operatorname{argmax}} p(c | x)=\underset{c_{1}, \ldots, c_{k}}{\operatorname{argmax}} p(x | c) p(c)=\underset{c_{1}, \ldots, c_{k}}{\operatorname{argmax}} \exp \left(\kappa K_{c}^{T} \mu(x)\right)\left(h_{c}+\beta\right)
</annotation></semantics></math></span><p>where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(x | c)</annotation></semantics></math></span> is the vMF likelihood and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(c)</annotation></semantics></math></span> is the prior distribution of the memory index.</p>
<p>Here we omit the normalization of the vMF likelihood and the denominator of the prior, because they are both constants. Once we have obtained S, we can compute</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo><mo>≈</mo><mfrac><mrow><msub><mo>∑</mo><mrow><mi>i</mi><mo>∈</mo><mi>S</mi></mrow></msub><msub><mi>v</mi><mi>i</mi></msub><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mo>∑</mo><mrow><mi>j</mi><mo>∈</mo><mi>S</mi></mrow></msub><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mi mathvariant="normal">∣</mi><mi>c</mi><mo>=</mo><mi>j</mi><mo stretchy="false">)</mo><mi>p</mi><mo stretchy="false">(</mo><mi>c</mi><mo>=</mo><mi>j</mi><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">
p(y | x) \approx \frac{\sum_{i \in S} v_{i} p(x | c=i) p(c=i)}{\sum_{j \in S} p(x | c=j) p(c=j)}
</annotation></semantics></math></span><h3 id="memory-update-mechanism">Memory Update Mechanism</h3>
<p>The memory keys and values are updated during training. The update mechanism includes a traditional memory update mechanism and an incremental EM algorithm.</p>
<p>Let the sample be <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span> with label <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>y</mi></mrow><annotation encoding="application/x-tex">y</annotation></semantics></math></span>, where real is 1 and fake is 0. For each x, we first find the k-nearest slots <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>S</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">S_{y}</annotation></semantics></math></span>, but using the conditional posterior <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mrow><mo fence="true">(</mo><mi>c</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>v</mi><mi>c</mi></msub><mo>=</mo><mi>y</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">p\left(c | x, v_{c}=y\right)</annotation></semantics></math></span>. This is so that in the subsequent EM algorithm, only the slots belonging to the same class as y are considered.</p>
<p>After that, we update the memory in different ways depending on whether <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>S</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">S_y</annotation></semantics></math></span> contains the correct label.</p>
<h4 id="without-the-correct-label">Without the correct label:</h4>
<p>The oldest memory slot is found via <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>n</mi><mi>a</mi></msub><mo>=</mo><msub><mrow><mi mathvariant="normal">argmax</mi><mo>⁡</mo></mrow><mrow><mi>i</mi><mo>∈</mo><mo stretchy="false">{</mo><mn>1</mn><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><mi>N</mi><mo stretchy="false">}</mo></mrow></msub><msub><mi>a</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">n_{a}=\operatorname{argmax}_{i \in\{1, \ldots, N\}} a_{i}</annotation></semantics></math></span>, and the information of x is copied to the corresponding position: <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>K</mi><msub><mi>n</mi><mi>a</mi></msub></msub><mo>←</mo><mi>q</mi><mo>=</mo><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">K_{n_{a}} \leftarrow q=\mu(x)</annotation></semantics></math></span>, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>v</mi><msub><mi>n</mi><mi>a</mi></msub></msub><mo>←</mo><mi>y</mi></mrow><annotation encoding="application/x-tex">v_{n_{a}} \leftarrow y</annotation></semantics></math></span>, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>a</mi><msub><mi>n</mi><mi>a</mi></msub></msub><mo>←</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">a_{n_{a}} \leftarrow 0</annotation></semantics></math></span>, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><msub><mi>n</mi><mi>a</mi></msub></msub><mo>←</mo><mfrac><mn>1</mn><mi>N</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></msubsup><msub><mi>h</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">h_{n_{a}} \leftarrow \frac{1}{N} \sum_{i=1}^{N} h_{i}</annotation></semantics></math></span>.</p>
<h4 id="with-the-correct-label">With the correct label:</h4>
<p>The memory keys are updated through the following custom incremental EM algorithm run for T iterations, which partly incorporates the information of the new sample.</p>
<p>In the inference step, by applying the keys of the previous moment <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msubsup></mrow><annotation encoding="application/x-tex">\hat{K}_{i}^{t-1}</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msubsup></mrow><annotation encoding="application/x-tex">\hat{h}_{i}^{t-1}</annotation></semantics></math></span> to Equation 1, the posterior distribution <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>γ</mi><mi>i</mi><mi>t</mi></msubsup><mo>=</mo><mi>p</mi><mrow><mo fence="true">(</mo><msub><mi>c</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\gamma_{i}^{t}=p\left(c_{i} | x\right)</annotation></semantics></math></span> is computed, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>∈</mo><msub><mi>S</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">i \in S_{y}</annotation></semantics></math></span>. In the maximization step, the following updates are performed:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup><mo>←</mo><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msubsup><mo>+</mo><msup><mi>γ</mi><mi>t</mi></msup><mo>−</mo><msup><mi>γ</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msup><mo separator="true">,</mo><mspace width="1em"/><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup><mo>←</mo><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msubsup><mo>+</mo><mfrac><mrow><msup><mi>γ</mi><mi>t</mi></msup><mo>−</mo><msup><mi>γ</mi><mrow><mi>t</mi><mo>−</mo><mn>1</mn></mrow></msup></mrow><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup></mfrac><mrow><mo fence="true">(</mo><msub><mi>q</mi><mi>i</mi></msub><mo>−</mo><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\hat{h}_{i}^{t} \leftarrow \hat{h}_{i}^{t-1}+\gamma^{t}-\gamma^{t-1}, \quad \hat{K}_{i}^{t} \leftarrow \hat{K}_{i}^{t-1}+\frac{\gamma^{t}-\gamma^{t-1}}{\hat{h}_{i}^{t}}\left(q_{i}-\hat{K}_{i}^{t}\right)
</annotation></semantics></math></span><p>where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi><mo>∈</mo><mn>1</mn><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><mi>T</mi><mo separator="true">,</mo><msup><mi>γ</mi><mn>0</mn></msup><mo>=</mo><mn>0</mn><mo separator="true">,</mo><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mn>1</mn></msubsup><mo>=</mo><msub><mi>K</mi><mi>i</mi></msub><mo separator="true">,</mo><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mn>1</mn></msubsup><mo>=</mo><mi>α</mi><msub><mi>h</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">t \in 1, \ldots, T, \gamma^{0}=0, \hat{K}_{i}^{1}=K_{i}, \hat{h}_{i}^{1}=\alpha h_{i}</annotation></semantics></math></span>, and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi><mo>=</mo><mn>0.5</mn></mrow><annotation encoding="application/x-tex">\alpha=0.5</annotation></semantics></math></span>.</p>
<p>After T iterations, the slots of <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>S</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">S_y</annotation></semantics></math></span> are updated through <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>K</mi><mi>i</mi></msub><mo>←</mo><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup></mrow><annotation encoding="application/x-tex">K_{i} \leftarrow \hat{K}_{i}^{t}</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>i</mi></msub><mo>←</mo><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><mi>i</mi><mi>t</mi></msubsup></mrow><annotation encoding="application/x-tex">h_{i} \leftarrow \hat{h}_{i}^{t}</annotation></semantics></math></span>.</p>
<p>The decay rate <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi></mrow><annotation encoding="application/x-tex">\alpha</annotation></semantics></math></span> controls the degree to which the contribution of old queries to the slot position in the average direction of the mixture component is exponentially reduced.</p>
<p><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>α</mi></mrow><annotation encoding="application/x-tex">\alpha</annotation></semantics></math></span> is crucial for performance, because the old queries used to update the keys no longer fit the current mixture distribution, as the feedforward network itself is also being updated.</p>
<p>Finally, it is worth noting that this memory update mechanism is orthogonal to the adversarial training algorithm, because when the discriminator is updated, the memory update is carried out independently. In addition, adding the memory module does not affect the speed of the model at test time, because the memory is only updated during training.</p>
<h2 id="memory-conditional-generative-network">Memory Conditional Generative Network</h2>
<p>The memory conditional generative network is based on the generator of InfoGAN. The difference is that it is conditioned not only on random noise but also on memory information.</p>
<p>In other words, the generator not only samples randomly from the noise distribution, but also samples the memory index <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span> from <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mrow><mo fence="true">(</mo><mi>c</mi><mo>=</mo><mi>i</mi><mi mathvariant="normal">∣</mi><msub><mi>v</mi><mi>c</mi></msub><mo>=</mo><mn>1</mn><mo fence="true">)</mo></mrow><mo>=</mo><mfrac><mrow><msub><mi>h</mi><mi>i</mi></msub><msub><mi>v</mi><mi>i</mi></msub></mrow><mrow><msubsup><mo>∑</mo><mi>j</mi><mi>N</mi></msubsup><msub><mi>h</mi><mi>j</mi></msub><msub><mi>v</mi><mi>j</mi></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">P\left(c=i | v_{c}=1\right)=\frac{h_{i} v_{i}}{\sum_{j}^{N} h_{j} v_{j}}</annotation></semantics></math></span>. The formula above represents the frequency of occurrence of the unit i that stores real data. The final input is <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">[</mo><msub><mi>K</mi><mi>i</mi></msub><mo separator="true">,</mo><mi>z</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">[K_i, z]</annotation></semantics></math></span>, where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>K</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">K_i</annotation></semantics></math></span> is the key vector of memory index i.</p>
<p>The difference from other CGANs is that MCGN does not require extra annotations or an extra encoder. Instead, MCGN can make full use of the memory information learned by the DMN in an unsupervised way. The DMN learns the vMF mixture memory using only each sample in the sequence and its label.</p>
<p>The training procedure of the whole MemoryGAN is:</p>
<p>for number of training iterations do
Sample a minibatch of samples from the training set
Sample a minibatch from the noise distribution and the memory indices
Update the discriminator loss
Find S_y for each sample in the minibatch
Initialize the key, h and gamma for each slot in S_y
for number of EM iterations do
Estimate <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>γ</mi><mi>s</mi></msub></mrow><annotation encoding="application/x-tex">\gamma_s</annotation></semantics></math></span> for each s
Update <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><mi>s</mi></msub></mrow><annotation encoding="application/x-tex">h_s</annotation></semantics></math></span>
Update <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>K</mi><mi>s</mi></msub></mrow><annotation encoding="application/x-tex">K_s</annotation></semantics></math></span>
Update the vMF mixture model, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>h</mi><msub><mi>s</mi><mi>y</mi></msub></msub><mo>←</mo><msubsup><mover accent="true"><mi>h</mi><mo>^</mo></mover><msub><mi>s</mi><mi>y</mi></msub><mi>T</mi></msubsup><mo separator="true">,</mo><msub><mi>K</mi><msub><mi>s</mi><mi>y</mi></msub></msub><mo>←</mo><msubsup><mover accent="true"><mi>K</mi><mo>^</mo></mover><msub><mi>s</mi><mi>y</mi></msub><mi>T</mi></msubsup></mrow><annotation encoding="application/x-tex">h_{s_{y}} \leftarrow \hat{h}_{s_{y}}^{T}, K_{s_{y}} \leftarrow \hat{K}_{s_{y}}^{T}</annotation></semantics></math></span> for <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>y</mi></msub><mo>∈</mo><msub><mi>S</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">s_{y} \in S_{y}</annotation></semantics></math></span>
Sample a minibatch from the noise distribution and the memory indices
Update the generator loss</p>
<h2 id="objective-function">objective function</h2>
<p>The goal of MemoryGAN is based on the objective of InfoGAN, which is to maximize the mutual information between the latent variables and the observed content. (For details, see InfoGAN.)</p>
<p>A mutual information loss is added between <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>K</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">K_i</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo stretchy="false">(</mo><mi>z</mi><mo separator="true">,</mo><msub><mi>K</mi><mi>i</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">G(z, K_i)</annotation></semantics></math></span> to ensure the continuity between the sampled memory information and the structured information of the generated samples:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>I</mi><mrow><mo fence="true">(</mo><msub><mi>K</mi><mi>i</mi></msub><mo separator="true">;</mo><mi>G</mi><mrow><mo fence="true">(</mo><mi>z</mi><mo separator="true">,</mo><msub><mi>K</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo>≥</mo><mi>H</mi><mrow><mo fence="true">(</mo><msub><mi>K</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo>−</mo><mover accent="true"><mi>I</mi><mo>^</mo></mover><mo>−</mo><mi>log</mi><mo>⁡</mo><mi>C</mi><mo stretchy="false">(</mo><mi>κ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
I\left(K_{i} ; G\left(z, K_{i}\right)\right) \geq H\left(K_{i}\right)-\hat{I}-\log C(\kappa)
</annotation></semantics></math></span><p>where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>I</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{I}</annotation></semantics></math></span> denotes the expectation of the negative cosine similarity, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>I</mi><mo>^</mo></mover><mo>=</mo><mo>−</mo><msub><mi>E</mi><mrow><mi>x</mi><mo>∼</mo><mi>G</mi><mrow><mo fence="true">(</mo><mi>z</mi><mo separator="true">,</mo><msub><mi>K</mi><mi>i</mi></msub><mo fence="true">)</mo></mrow></mrow></msub><mrow><mo fence="true">[</mo><mi>κ</mi><msubsup><mi>K</mi><mi>i</mi><mi>T</mi></msubsup><mi>μ</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\hat{I}=-E_{x \sim G\left(z, K_{i}\right)}\left[\kappa K_{i}^{T} \mu(x)\right]</annotation></semantics></math></span>.</p>
<p>To be continued</p>
]]></content:encoded></item><item><title>Getting Started with Kettle</title><link>https://blog.ereebay.me/en/posts/kettle%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/</link><pubDate>Sat, 23 Mar 2019 12:44:49 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/kettle%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/</guid><description>&lt;h1 id="getting-started-with-kettle"&gt;Getting Started with Kettle&lt;/h1&gt;
&lt;p&gt;Since I was still one credit short in my final semester, I had to take one more course, and looking at the schedule the only option was OLAP — yet another completely unfamiliar subject. Tutorials about Kettle online are scarce, so I gathered some materials and jotted down these notes on the tool this course requires&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id="introduction-to-kettle"&gt;Introduction to Kettle&lt;/h2&gt;
&lt;p&gt;Kettle is an ETL (Extract, Transform and Load) tool for data extraction, transformation, and loading. ETL tools are used very frequently in data warehouse projects, and Kettle can also be applied in the following scenarios:&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="getting-started-with-kettle">Getting Started with Kettle</h1>
<p>Since I was still one credit short in my final semester, I had to take one more course, and looking at the schedule the only option was OLAP — yet another completely unfamiliar subject. Tutorials about Kettle online are scarce, so I gathered some materials and jotted down these notes on the tool this course requires</p>
<!-- more -->
<h2 id="introduction-to-kettle">Introduction to Kettle</h2>
<p>Kettle is an ETL (Extract, Transform and Load) tool for data extraction, transformation, and loading. ETL tools are used very frequently in data warehouse projects, and Kettle can also be applied in the following scenarios:</p>
<ul>
<li>
<p>Integrating data across different applications or databases</p>
</li>
<li>
<p>Exporting data from a database to text files</p>
</li>
<li>
<p>Loading bulk data into a database</p>
</li>
<li>
<p>Data cleansing</p>
</li>
</ul>
<p>It is also used in projects involving application integration</p>
<p>Kettle is very easy to use: you design what business logic to implement through a graphical interface, with no need to write code; therefore, Kettle is designed in a metadata-oriented way</p>
<p>Kettle supports many input and output formats, including text files, data tables, and both commercial and free database engines. In addition, Kettle&rsquo;s powerful transformation features make it very convenient to manipulate data.</p>
<h2 id="installing-kettle">Installing Kettle</h2>
<p><a href="https://community.hitachivantara.com/docs/DOC-1009855">Download link</a></p>
<p>Since my platform is macOS and there is a bug that prevents it from launching on double-click, I could only extract the archive and then run in the terminal</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sh spoon.sh
</span></span></code></pre></div><p>to start Spoon</p>
<h2 id="data-transformation---exporting-to-excel">Data Transformation - Exporting to Excel</h2>
<ol>
<li>Connect to the database</li>
<li>Export to Excel</li>
</ol>
<p>First, create a new transformation as shown in the figure below, and set up the database connection.</p>
<p><img loading="lazy" src="/images/kettle/kettle-1.png"></p>
<p><img loading="lazy" src="/images/kettle/kettle-2.png"></p>
<p>Once the database connection is set up, you can configure the input source; here we use a table in the database as the input source</p>
<p><img loading="lazy" src="/images/kettle/kettle-3.png"></p>
<p>With the input source configured, you can click preview to take a look at the data first</p>
<p><img loading="lazy" src="/images/kettle/kettle-4.png"></p>
<p>After setting up the input source, likewise drag the Excel output onto the workspace, but don&rsquo;t rush to configure the output source yet: in the View pane, add a hop to connect the input and output sources</p>
<p><img loading="lazy" src="/images/kettle/kettle-5.png"></p>
<p>This way, when you configure the output source, you can directly fetch and select the fields to export in the Fields tab</p>
<p><img loading="lazy" src="/images/kettle/kettle-6.png"></p>
<p>Finally, click Start to run the transformation</p>
<p><img loading="lazy" src="/images/kettle/kettle-7.png"></p>
<p>Let&rsquo;s take a look at the exported file</p>
<p><img loading="lazy" src="/images/kettle/kettle-8.png"></p>
<h2 id="hello-world">Hello World</h2>
<p>Alright, now that you have learned how transformations work, let&rsquo;s do a Hello World example. I came across this tutorial online and found it pretty good — it lets you get in touch with more of Kettle&rsquo;s features, unlike my very basic walkthrough above.</p>
<p>This Hello World outputs a corresponding greeting for each name in the database and exports the result to a file.</p>
<p>First, set up the input source the same way, but the SQL statement needs a small change: here I selected only their names, ordered by id, limited to the first ten.</p>
<p>Then write a small JavaScript script to automatically add a &ldquo;hello&rdquo;</p>
<p><img loading="lazy" src="/images/kettle/kettle-9.png"></p>
<p>Finally, link the three steps with hops; you can run preview first to check the result</p>
<p><img loading="lazy" src="/images/kettle/kettle-10.png"></p>
<p><img loading="lazy" src="/images/kettle/kettle-11.png"></p>
<p>Then take a look at the result</p>
<p><img loading="lazy" src="/images/kettle/kettle-12.png"></p>
<p>The above only demonstrates the most basic features of data transformation; other, more detailed features can all be found in the Design tab
In short, Kettle&rsquo;s operating logic is steps + hops: a step is an operation you perform, and hops are the links between them.</p>
<h2 id="jobs">Jobs</h2>
<p>The above covered transformations, one of Kettle&rsquo;s core features; now let&rsquo;s introduce another Kettle feature, the job.</p>
<p>A job is essentially an automated workflow: when you need to run multiple transformations or add some logical control conditions, you need a job.</p>
<p>Here, following the earlier Hello World example, we build a simple job that detects when the file does not exist in the folder and then automatically exports data from the database and adds &ldquo;hello&rdquo;.</p>
<p><img loading="lazy" src="/images/kettle/kettle-13.png"></p>
<p>Find the widget shown in the figure above in the toolbar on the right, drag it into the workspace, connect things with hops, and configure it — that&rsquo;s it. The operations are similar to those for creating a transformation; it just combines several of them together</p>
<p>The figure below shows the transformation configuration interface, where you enter the path of the transformation script</p>
<p><img loading="lazy" src="/images/kettle/kettle-14.png"></p>
<h2 id="kitchen-and-pan">Kitchen and Pan</h2>
<p>The kitchen and pan commands are used to execute job and transformation scripts.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-zsh" data-lang="zsh"><span class="line"><span class="cl">./kitch.sh -file ./scripts/demo.kjb
</span></span><span class="line"><span class="cl">./pan.sh -file ./scripts/demo.ktr
</span></span></code></pre></div><p>From now on, just save the jobs and transformations designed in Spoon and run them directly from the command line — much more convenient.</p>
<p>I&rsquo;ll update these notes whenever I get to use new features.</p>
<h2 id="references">References</h2>
<p><a href="http://www.cnblogs.com/limengqiang/archive/2013/01/16/KettleApply1.html#syzj">The ETL Powerhouse Kettle in Practice, Part 1 [Introduction to Kettle]</a></p>
<p><a href="https://blog.csdn.net/u012637358/article/details/82593492">KETTLE Tutorial</a></p>
<p><a href="https://blog.csdn.net/neweastsun/article/details/38845795">Using Kettle Jobs</a></p>
<p><a href="https://ask.hellobi.com/blog/yuguiyang1990/category/1532">Kettle Tutorials</a></p>
<p><a href="http://www.kettle.net.cn/">Kettle Chinese Community</a></p>
]]></content:encoded></item><item><title>One-shot Learning with Memory-Augmented Neural Networks Paper Notes (Incomplete)</title><link>https://blog.ereebay.me/en/posts/mann/</link><pubDate>Fri, 22 Mar 2019 08:47:11 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/mann/</guid><description>&lt;h1 id="one-shot-learning-with-memory-augmented-neural-networks-paper-notes"&gt;One-shot Learning with Memory-Augmented Neural Networks Paper Notes&lt;/h1&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Traditional gradient-based deep learning methods require large amounts of data to learn. When confronted with new data, the model has to relearn new parameters and cannot quickly adapt to it.&lt;/p&gt;
&lt;p&gt;This paper proposes a memory-augmented neural network that can rapidly assimilate new data and, after learning from only a few samples, use that data to make accurate predictions.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;For the design of the MANN model, the authors had two requirements:&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="one-shot-learning-with-memory-augmented-neural-networks-paper-notes">One-shot Learning with Memory-Augmented Neural Networks Paper Notes</h1>
<h2 id="introduction">Introduction</h2>
<p>Traditional gradient-based deep learning methods require large amounts of data to learn. When confronted with new data, the model has to relearn new parameters and cannot quickly adapt to it.</p>
<p>This paper proposes a memory-augmented neural network that can rapidly assimilate new data and, after learning from only a few samples, use that data to make accurate predictions.</p>
<!-- more -->
<p>For the design of the MANN model, the authors had two requirements:</p>
<ol>
<li>The stored information must be stable and addressed element-wise.</li>
<li>The number of parameters must not be tied to the size of the memory.</li>
</ol>
<p>In the end, the model combines the following two advantages:</p>
<ol>
<li>It can learn a general way of learning by extracting useful information from raw data via gradient descent.</li>
<li>It can rapidly learn never-before-seen information by relying on an additional memory module.</li>
</ol>
<h2 id="meta-learning-method-design">Meta-Learning Method Design</h2>
<p>Usually, parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>θ</mi></mrow><annotation encoding="application/x-tex">\theta</annotation></semantics></math></span> are chosen on some dataset <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>D</mi></mrow><annotation encoding="application/x-tex">D</annotation></semantics></math></span> to minimize a learning cost <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">L</mi></mrow><annotation encoding="application/x-tex">\mathcal{L}</annotation></semantics></math></span>.</p>
<p>In meta-learning, however, what is minimized is the expected cost with respect to a distribution over datasets <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">p(D)</annotation></semantics></math></span>:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>θ</mi><mo lspace="0em" rspace="0em">∗</mo></msup><mo>=</mo><msub><mrow><mi mathvariant="normal">argmin</mi><mo>⁡</mo></mrow><mi>θ</mi></msub><msub><mi>E</mi><mrow><mi>D</mi><mo>∼</mo><mi>p</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></msub><mo stretchy="false">[</mo><mi mathvariant="script">L</mi><mo stretchy="false">(</mo><mi>D</mi><mo separator="true">;</mo><mi>θ</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">
\theta^{*}=\operatorname{argmin}_{\theta} E_{D \sim p(D)}[\mathcal{L}(D ; \theta)]
</annotation></semantics></math></span><p>To achieve this, the paper makes the following design choices:</p>
<ol>
<li>First, the inputs are presented as a sequence, where each input carries the label of the previous input:</li>
</ol>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mo fence="true">(</mo><msub><mi mathvariant="bold">x</mi><mn>1</mn></msub><mo separator="true">,</mo><mtext> null </mtext><mo fence="true">)</mo></mrow><mo separator="true">,</mo><mrow><mo fence="true">(</mo><msub><mi mathvariant="bold">x</mi><mn>2</mn></msub><mo separator="true">,</mo><msub><mi>y</mi><mn>1</mn></msub><mo fence="true">)</mo></mrow><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><mrow><mo fence="true">(</mo><msub><mi mathvariant="bold">x</mi><mi>T</mi></msub><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>T</mi><mo>−</mo><mn>1</mn></mrow></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\left(\mathbf{x}_{1}, \text { null }\right),\left(\mathbf{x}_{2}, y_{1}\right), \ldots,\left(\mathbf{x}_{T}, y_{T-1}\right)
</annotation></semantics></math></span><ol start="2">
<li>Across different datasets, the labels are shuffled (to prevent the network from gradually learning a fixed mapping between samples and labels). Instead, this forces the network to learn the trick of holding a data sample in memory until the correct label arrives, so that sample-label information is bound together and stored for later use.</li>
</ol>
<p><img loading="lazy" src="/images/mann/mann-1.png"></p>
<p>Without relying on the actual content of the data and labels, the meta-learning model learns to bind the data distribution to the corresponding labels, and generalizes into a universal model that captures the data-label relationship for prediction.</p>
<h2 id="memory-augmented-model">Memory-Augmented Model</h2>
<h3 id="neural-turing-machine">Neural Turing Machine</h3>
<p>The composition of the Neural Turing Machine is largely similar to the MANN in this paper. An NTM consists of a controller, such as an LSTM or a feedforward network, which interacts with an external memory module through a set of read/write heads.</p>
<p>In this model, the controller likewise uses an LSTM or a feedforward network.</p>
<p>To be continued</p>
]]></content:encoded></item><item><title>Notes on Generative Adversarial Networks (GAN)</title><link>https://blog.ereebay.me/en/posts/gan-notes/</link><pubDate>Fri, 01 Mar 2019 17:00:22 +0800</pubDate><guid>https://blog.ereebay.me/en/posts/gan-notes/</guid><description>&lt;h1 id="generative-adversarial-network"&gt;Generative Adversarial Network&lt;/h1&gt;
&lt;h2 id="overview-of-gan"&gt;Overview of GAN&lt;/h2&gt;
&lt;p&gt;The idea behind GAN is a two-player zero-sum game in which the sum of the two players&amp;rsquo; interests is a constant. Consider arm wrestling: assuming the total space is fixed, if your strength is greater, you gain more space and I get less; conversely, if I am stronger, I gain more. But one thing is certain — our total space is fixed. This is a two-player game in which the total interest is constant.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="generative-adversarial-network">Generative Adversarial Network</h1>
<h2 id="overview-of-gan">Overview of GAN</h2>
<p>The idea behind GAN is a two-player zero-sum game in which the sum of the two players&rsquo; interests is a constant. Consider arm wrestling: assuming the total space is fixed, if your strength is greater, you gain more space and I get less; conversely, if I am stronger, I gain more. But one thing is certain — our total space is fixed. This is a two-player game in which the total interest is constant.</p>
<!-- more -->
<p>A vivid analogy: GAN is like a large network containing two smaller networks. One is the generative network, which can be regarded as a counterfeiter producing fake banknotes, and the other is the discriminative network, i.e., the person authenticating the banknotes. The goal of the generative network is to fool the discriminator, while the discriminator strives not to be fooled by the generator. Through alternating optimization during training, both networks improve. It is theoretically proven that, at best, the generative model makes the discriminator unable to tell real from fake, i.e., the probability of real versus fake is fifty-fifty.</p>
<!-- ![](../res/img/img1.jpg) -->
<p>The figure above is a structural diagram of a generative adversarial network: the discriminator takes in both real samples and fake samples produced by the generator, and outputs a real/fake verdict. The generator takes noise as input and produces fake samples.</p>
<h2 id="the-principle-of-gan">The Principle of GAN</h2>
<p>The following is the objective function of GAN:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mi>min</mi><mo>⁡</mo></mrow><mi>G</mi></msub><msub><mrow><mi>max</mi><mo>⁡</mo></mrow><mi>D</mi></msub><mi>V</mi><mo stretchy="false">(</mo><mi>D</mi><mo separator="true">,</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi mathvariant="bold-italic">x</mi><mo>∼</mo><msub><mi>p</mi><mrow><mi mathvariant="normal">d</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi></mrow></msub><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo></mrow></msub><mo stretchy="false">[</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>+</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi mathvariant="bold-italic">z</mi><mo>∼</mo><msub><mi>p</mi><mi mathvariant="bold-italic">z</mi></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow></msub><mo stretchy="false">[</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">(</mo><mi mathvariant="bold-italic">z</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">
\min _ { G } \max _ { D } V ( D , G ) = \mathbb { E } _ { \boldsymbol { x } \sim p _ { \mathrm { data } } ( \boldsymbol { x } ) } [ \log D ( \boldsymbol { x } ) ] + \mathbb { E } _ { \boldsymbol { z } \sim p _ { \boldsymbol { z } } ( z ) } [ \log ( 1 - D ( G ( \boldsymbol { z } ) ) ) ]
</annotation></semantics></math></span><p>From the objective function we can see that the overall cost function minimizes the generator and maximizes the discriminator. When tackling this optimization problem, we can first fix G, maximize D, and then minimize G to obtain the optimal solution. Here, for a given G, maximizing V(D,G) measures the divergence or distance between P_G and P_data.</p>
<p>First, after fixing G, the optimal D can be expressed as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>D</mi><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msubsup><mo>=</mo><msub><mrow><mi mathvariant="normal">argmax</mi><mo>⁡</mo></mrow><mi>D</mi></msub><mi>V</mi><mo stretchy="false">(</mo><mi>G</mi><mo separator="true">,</mo><mi>D</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
D _ { G } ^ { * } = \operatorname { argmax } _ { D } V ( G , D )
</annotation></semantics></math></span><p>The problem of optimizing G can then be expressed as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msup><mo>=</mo><msub><mrow><mi mathvariant="normal">argmin</mi><mo>⁡</mo></mrow><mi>G</mi></msub><mi>V</mi><mrow><mo fence="true">(</mo><mi>G</mi><mo separator="true">,</mo><msubsup><mi>D</mi><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msubsup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
G ^ { * } = \operatorname { argmin } _ { G } V \left( G , D _ { G } ^ { * } \right)
</annotation></semantics></math></span><h2 id="theoretical-derivation">Theoretical Derivation</h2>
<p>The original paper&rsquo;s derivation uses the JS divergence to describe the similarity between two distributions, and the JS divergence is in turn built from the KL divergence. Therefore, before carrying out the full derivation, we first introduce some theoretical foundations, derive the conditions required for the optimal discriminator and the optimal generator, and finally use the derived results to restate the training procedure.</p>
<h3 id="kl-divergence">KL Divergence</h3>
<p>For a single random variable <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span> with two separate probability distributions <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(x)</annotation></semantics></math></span> and <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Q</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">Q(x)</annotation></semantics></math></span>, the KL divergence can measure the difference between the two distributions (the appendix proves why the KL divergence reflects the difference between two distributions):</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>D</mi><mrow><mi mathvariant="normal">K</mi><mi mathvariant="normal">L</mi></mrow></msub><mo stretchy="false">(</mo><mi>P</mi><mi mathvariant="normal">∥</mi><mi>Q</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi mathvariant="normal">x</mi><mo>∼</mo><mi>P</mi></mrow></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><mfrac><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><mi>Q</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">]</mo></mrow><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi mathvariant="normal">x</mi><mo>∼</mo><mi>P</mi></mrow></msub><mo stretchy="false">[</mo><mi>log</mi><mo>⁡</mo><mi>P</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mi>Q</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">
D _ { \mathrm { KL } } ( P \| Q ) = \mathbb { E } _ { \mathrm { x } \sim P } \left[ \log \frac { P ( x ) } { Q ( x ) } \right] = \mathbb { E } _ { \mathrm { x } \sim P } [ \log P ( x ) - \log Q ( x ) ]
</annotation></semantics></math></span><p>Properties of the KL divergence:</p>
<ol>
<li>Non-negativity (used later in the derivation); moreover, the KL divergence equals 0 if and only if P and Q are the same distribution. Because of this non-negativity, it is often used to measure the difference between two distributions. (The appendix proves its non-negativity.)</li>
<li>Asymmetry. Although it can measure the difference between distributions, this difference is not a symmetric distance: the KL divergence of P with respect to Q differs from that of Q with respect to P.</li>
</ol>
<h3 id="issues-in-the-papers-derivation">Issues in the Paper&rsquo;s Derivation</h3>
<p>In the original paper, one idea differs from many other approaches: the generator G is not required to satisfy an invertibility condition, and in practice G is indeed non-invertible. However, in the proof, the change-of-variables formula for integrals was incorrectly used, while this change of variables is valid only when G is invertible. So the proof should be based on the validity of the following equality:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>E</mi><mrow><mi>z</mi><mo>∼</mo><msub><mi>p</mi><mi>x</mi></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow></msub><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo>=</mo><msub><mi>E</mi><mrow><mi>x</mi><mo>∼</mo><msub><mi>p</mi><mi>c</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></msub><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
E _ { z \sim p _ { x } ( z ) } \log ( 1 - D ( G ( z ) ) ) = E _ { x \sim p _ { c } ( x ) } \log ( 1 - D ( x ) )
</annotation></semantics></math></span><p>This equality comes from the Radon-Nikodym theorem in measure theory; it is presented as Proposition 1 in the original paper and expressed as the following equality:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.16em" columnalign="center" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi><mo>+</mo><msub><mo>∫</mo><mi>z</mi></msub><mi>p</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>z</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo>=</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{array} { c } { \int _ { x } p _ { d a t a } ( x ) \log D ( x ) \mathrm { d } x + \int _ { z } p ( z ) \log ( 1 - D ( G ( z ) ) ) \mathrm { d } z } \\ { = \int _ { x } p _ { d a t a } ( x ) \log D ( x ) + p _ { G } ( x ) \log ( 1 - D ( x ) ) \mathrm { d } x } \end{array}
</annotation></semantics></math></span><p>This formula uses the change-of-variables formula for integrals, but doing so requires computing the inverse of G, whose existence is not assumed. Moreover, in the practice of neural networks it does not exist. However, this practice is so common in ML that it is simply overlooked.</p>
<h3 id="optimal-discriminator">Optimal Discriminator</h3>
<p>In the minimax game, we first fix the generator G and maximize the value function, which yields the optimal discriminator D. The maximized value function measures the divergence between the distribution produced by the generator and the distribution of the dataset (proven later).</p>
<p>The expectations in the original paper&rsquo;s value function can be expanded into integral form:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>V</mi><mo stretchy="false">(</mo><mi>G</mi><mo separator="true">,</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi mathvariant="normal">d</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi></mrow></msub><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mi>g</mi></msub><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi mathvariant="bold-italic">x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi>d</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">
V ( G , D ) = \int _ { x } p _ { \mathrm { data } } ( \boldsymbol { x } ) \log ( D ( \boldsymbol { x } ) ) + p _ { g } ( \boldsymbol { x } ) \log ( 1 - D ( \boldsymbol { x } ) ) d x
</annotation></semantics></math></span><p>Maximizing the integral can be converted into maximizing the integrand. Maximizing the integrand yields the optimal discriminator D, so all terms not involving the discriminator can be treated as constants. Letting the discriminator D(x) be y, the integrand can be written as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mi>a</mi><mi>log</mi><mo>⁡</mo><mi>y</mi><mo>+</mo><mi>b</mi><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
f ( y ) = a \log y + b \log ( 1 - y )
</annotation></semantics></math></span><p>To find the optimal extreme point, if <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo>+</mo><mi>b</mi><mo mathvariant="normal">≠</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">a + b \neq 0</annotation></semantics></math></span>, we can solve using the first-order derivative:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn><mo>⇒</mo><mfrac><mi>a</mi><mi>y</mi></mfrac><mo>−</mo><mfrac><mi>b</mi><mrow><mn>1</mn><mo>−</mo><mi>y</mi></mrow></mfrac><mo>=</mo><mn>0</mn><mo>⇒</mo><mi>y</mi><mo>=</mo><mfrac><mi>a</mi><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">
f ^ { \prime } ( y ) = 0 \Rightarrow \frac { a } { y } - \frac { b } { 1 - y } = 0 \Rightarrow y = \frac { a } { a + b }
</annotation></semantics></math></span><p>Taking the second derivative at the stationary point gives:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mo mathvariant="normal">′</mo><mo mathvariant="normal">′</mo></mrow></msup><mrow><mo fence="true">(</mo><mfrac><mi>a</mi><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfrac><mo fence="true">)</mo></mrow><mo>=</mo><mo>−</mo><mfrac><mi>a</mi><msup><mrow><mo fence="true">(</mo><mfrac><mi>a</mi><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfrac><mo fence="true">)</mo></mrow><mn>2</mn></msup></mfrac><mo>−</mo><mfrac><mi>b</mi><mrow><mn>1</mn><mo>−</mo><msup><mrow><mo fence="true">(</mo><mfrac><mi>a</mi><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfrac><mo fence="true">)</mo></mrow><mn>2</mn></msup></mrow></mfrac><mo>&lt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">
f ^ { \prime \prime } \left( \frac { a } { a + b } \right) = - \frac { a } { \left( \frac { a } { a + b } \right) ^ { 2 } } - \frac { b } { 1 - \left( \frac { a } { a + b } \right) ^ { 2 } } &lt; 0
</annotation></semantics></math></span><p>where <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo separator="true">,</mo><mi>b</mi><mo>∈</mo><mo stretchy="false">(</mo><mn>0</mn><mo separator="true">,</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">a , b \in ( 0,1 )</annotation></semantics></math></span>. Since the first derivative equals 0 and the second derivative is less than 0, <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mi>a</mi><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">\frac { a } { a + b }</annotation></semantics></math></span> is a maximum.</p>
<p>Finally, the value function can be written as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>V</mi><mo stretchy="false">(</mo><mi>G</mi><mo separator="true">,</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>≤</mo><mo>∫</mo><munder><mrow><mi>max</mi><mo>⁡</mo></mrow><mi>y</mi></munder><munder><mrow><mi>max</mi><mo>⁡</mo></mrow><mi>y</mi></munder><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mi>y</mi><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>y</mi><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} V ( G , D ) = &amp; \int _ { x } p _ { d a t a } ( x ) \log D ( x ) + p _ { G } ( x ) \log ( 1 - D ( x ) ) \mathrm { d } x \\ &amp; \leq \int \max _ { y } \max _ { y } p _ { d a t a } ( x ) \log y + p _ { G } ( x ) \log ( 1 - y ) \mathrm { d } x \end{aligned}
</annotation></semantics></math></span><p>Letting D(x)=P_data/(P_data+p_G) attains the maximum, because f(y) has a unique maximum on its domain; that is, the optimal D is unique, and no other D can attain the maximum.</p>
<p>In fact, the optimal D cannot be computed in practice, but it is mathematically important. Moreover, we do not know the prior Pdata, so we cannot use it directly in training. On the other hand, the existence of the optimal D implies that of the optimal G, and it suffices that we approach the optimal D.</p>
<h3 id="optimal-generator">Optimal Generator</h3>
<p>The training process of GAN aims to make P_G=P_data, in which case the optimal D can be written as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>D</mi><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msubsup><mo>=</mo><mfrac><msub><mi>p</mi><mtext>data</mtext></msub><mrow><msub><mi>p</mi><mtext>data</mtext></msub><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub></mrow></mfrac><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow><annotation encoding="application/x-tex">
D _ { G } ^ { * } = \frac { p _ { \text {data} } } { p _ { \text {data} } + p _ { G } } = \frac { 1 } { 2 }
</annotation></semantics></math></span><p>That is, the optimal generator makes the discriminator unable to distinguish P_data from P_G. Based on this observation, the authors proved that G is the solution of the minimax game.</p>
<p>Theorem: The global minimum of C(G)=maxV(G,D) is attained if and only if P_G=P_data.</p>
<p>The theorem states an if-and-only-if result, so we prove it from both directions. First we work backwards to derive the value of C(G), then we prove it forward.</p>
<p>Assume P_G=P_data (deriving backwards from the known result). We can derive:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>V</mi><mrow><mo fence="true">(</mo><mi>G</mi><mo separator="true">,</mo><msubsup><mi>D</mi><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msubsup><mo fence="true">)</mo></mrow><mo>=</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mn>1</mn><mo>−</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">
V \left( G , D _ { G } ^ { * } \right) = \int _ { x } p _ { d a t a } ( x ) \log \frac { 1 } { 2 } + p _ { G } ( x ) \log \left( 1 - \frac { 1 } { 2 } \right) \mathrm { d } x
</annotation></semantics></math></span><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>V</mi><mrow><mo fence="true">(</mo><mi>G</mi><mo separator="true">,</mo><msubsup><mi>D</mi><mi>G</mi><mo lspace="0em" rspace="0em">∗</mo></msubsup><mo fence="true">)</mo></mrow><mo>=</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi mathvariant="normal">d</mi><mi>x</mi><mo>=</mo><mo>−</mo><mn>2</mn><mi>log</mi><mo>⁡</mo><mn>2</mn><mo>=</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>4</mn></mrow><annotation encoding="application/x-tex">
V \left( G , D _ { G } ^ { * } \right) = - \log 2 \int _ { x } p _ { G } ( x ) \mathrm { d } x - \log 2 \int _ { x } p _ { d a t a } ( x ) \mathrm { d } x = - 2 \log 2 = - \log 4
</annotation></semantics></math></span><p>So -log4 is a candidate for the minimum, since it arises only when P_G=P_data. Now we must prove forward that this value is always the minimum, i.e., that the if-and-only-if condition is fully satisfied.</p>
<p>Now drop the condition P_G=P_data, pick any G, and rewrite the formula as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">
C ( G ) = \int _ { x } p _ { d a t a } ( x ) \log \left( \frac { p _ { d a t a } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) + p _ { G } ( x ) \log \left( \frac { p _ { G } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) \mathrm { d } x
</annotation></semantics></math></span><p>Next we apply a trick: add a zero to the equation. It does not change the value of the equation, but it lets us construct a log2, since we know -log4 is the candidate global minimum.</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><msub><mo>∫</mo><mi>x</mi></msub><mo stretchy="false">(</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo stretchy="false">)</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>+</mo><mo stretchy="false">(</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo stretchy="false">)</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} C ( G ) &amp; = \int _ { x } ( \log 2 - \log 2 ) p _ { d a t a } ( x ) + p _ { d a t a } ( x ) \log \left( \frac { p _ { d a t a } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) \\ &amp; + ( \log 2 - \log 2 ) p _ { G } ( x ) + p _ { G } ( x ) \log \left( \frac { p _ { G } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) \mathrm { d } x \end{aligned}
</annotation></semantics></math></span><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.16em" columnalign="center" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>d</mi><mi>x</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo>+</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mrow><mo fence="true">(</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo>+</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mrow><mo fence="true">(</mo><mi>log</mi><mo>⁡</mo><mn>2</mn><mo>+</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{array} { c } { C ( G ) = - \log 2 \int _ { x } p _ { G } ( x ) + p _ { d a t a } ( x ) d x } \\ { + \int _ { x } p _ { d a t a } ( x ) \left( \log 2 + \log \left( \frac { p _ { d a t a } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) \right) } \\ { + p _ { G } ( x ) \left( \log 2 + \log \left( \frac { p _ { G } ( x ) } { p _ { G } ( x ) + p _ { d a t a } ( x ) } \right) \right) \mathrm { d } x } \end{array}
</annotation></semantics></math></span><p>Finally, simplification yields:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable rowspacing="0.25em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>4</mn><mo>+</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><mrow><mo fence="true">(</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mtext>data</mtext></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mi mathvariant="normal">/</mi><mn>2</mn></mrow></mfrac><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>+</mo><msub><mo>∫</mo><mi>x</mi></msub><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><mrow><mo fence="true">(</mo><msub><mi>p</mi><mi>G</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">)</mo></mrow><mi mathvariant="normal">/</mi><mn>2</mn></mrow></mfrac><mo fence="true">)</mo></mrow><mi mathvariant="normal">d</mi><mi>x</mi></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex">
\begin{aligned} C ( G ) = &amp; - \log 4 + \int _ { x } p _ { d a t a } ( x ) \log \left( \frac { p _ { d a t a } ( x ) } { \left( p _ { G } ( x ) + p _ { \text {data} } ( x ) \right) / 2 } \right) \mathrm { d } x \\ &amp; + \int _ { x } p _ { G } ( x ) \log \left( \frac { p _ { G } ( x ) } { \left( p _ { G } ( x ) + p _ { d a t a } ( x ) \right) / 2 } \right) \mathrm { d } x \end{aligned}
</annotation></semantics></math></span><p>If you have read the earlier section on KL divergence, you will notice that this can be simplified into the form of KL divergences:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>4</mn><mo>+</mo><mi>K</mi><mi>L</mi><mrow><mo fence="true">(</mo><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mi mathvariant="normal">∣</mi><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub></mrow><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mo>+</mo><mi>K</mi><mi>L</mi><mrow><mo fence="true">(</mo><msub><mi>p</mi><mi>G</mi></msub><mi mathvariant="normal">∣</mi><mfrac><mrow><msub><mi>p</mi><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mrow></msub><mo>+</mo><msub><mi>p</mi><mi>G</mi></msub></mrow><mn>2</mn></mfrac><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
C ( G ) = - \log 4 + K L \left( p _ { d a t a } | \frac { p _ { d a t a } + p _ { G } } { 2 } \right) + K L \left( p _ { G } | \frac { p _ { d a t a } + p _ { G } } { 2 } \right)
</annotation></semantics></math></span><p>Since the KL divergence is non-negative, -log4 is the global minimum.</p>
<p>It remains to show that only one G can attain this value, so that P_G=P_data is the unique solution, completing the proof.</p>
<p>From the earlier discussion we know the KL divergence is asymmetric and can only measure the similarity of distribution a with respect to distribution b. But after adding the second term, their sum becomes symmetric, and this sum of the two terms can be expressed as the JS divergence:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">JSD</mi><mo>⁡</mo><mo stretchy="false">(</mo><mi>P</mi><mi mathvariant="normal">∥</mi><mi>Q</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mi>D</mi><mo stretchy="false">(</mo><mi>P</mi><mi mathvariant="normal">∥</mi><mi>M</mi><mo stretchy="false">)</mo><mo>+</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mi>D</mi><mo stretchy="false">(</mo><mi>Q</mi><mi mathvariant="normal">∥</mi><mi>M</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
\operatorname { JSD } ( P \| Q ) = \frac { 1 } { 2 } D ( P \| M ) + \frac { 1 } { 2 } D ( Q \| M )
</annotation></semantics></math></span><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>M</mi><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo stretchy="false">(</mo><mi>P</mi><mo>+</mo><mi>Q</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">
M = \frac { 1 } { 2 } ( P + Q )
</annotation></semantics></math></span><p>Suppose there are two distributions P and Q whose average distribution is M=(P+Q)/2; then the JS divergence between the two distributions is the KL divergence between P and M plus the KL divergence between Q and M, divided by 2.</p>
<p>Therefore, the JS divergence ranges from 0 to log2. It equals log2 when the two distributions have no overlap at all, and reaches the minimum 0 when they are identical.</p>
<p>Hence C(G) can be rewritten as:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mo>=</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><mn>4</mn><mo>+</mo><mn>2</mn><mo>⋅</mo><mi>J</mi><mi>S</mi><mi>D</mi><mrow><mo fence="true">(</mo><msub><mi>p</mi><mtext> data </mtext></msub><mi mathvariant="normal">∣</mi><msub><mi>p</mi><mi>G</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
C ( G ) = - \log 4 + 2 \cdot J S D \left( p _ { \text { data } } | p _ { G } \right)
</annotation></semantics></math></span><p>This proves that the JSD is 0 when P_G=P_data. In summary, we obtain the optimal generator if and only if the generated distribution equals the true data distribution.</p>
<h3 id="convergence">Convergence</h3>
<p>Regarding whether the training process converges to the optimal generator, the original paper gives an additional proof that, with sufficient training data and sufficient capacity of d and g, training converges to the optimal G. Since this part is not particularly important, I will put the proof in the appendix (mainly because my own understanding of it is only partial).</p>
<h3 id="training-procedure">Training Procedure</h3>
<ol>
<li>Parameter optimization process</li>
</ol>
<p>If we want to find the optimal generator, then after fixing a discriminator D, we can treat the original value function as the loss function L(G) for training the generator. With a loss function, we can update the generator using optimization algorithms such as SGD or Adam. The gradient descent update is as follows:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>G</mi></msub><mo>←</mo><msub><mi>θ</mi><mi>G</mi></msub><mo>−</mo><mi>η</mi><mi mathvariant="normal">∂</mi><mi>L</mi><mo stretchy="false">(</mo><mi>G</mi><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mi>G</mi></msub></mrow><annotation encoding="application/x-tex">
\theta _ { G } \leftarrow \theta _ { G } - \eta \partial L ( G ) / \partial \theta _ { G }
</annotation></semantics></math></span><p>Now, given an initial G_0, we need to find the D_0* that maximizes V(G_0,D); thus the discriminator&rsquo;s update process amounts to minimizing the loss function -V(G,D). Moreover, from the earlier derivation, V(G,D) differs from the JS divergence between the distributions P_data(x) and P_G(x) only by a constant term. Therefore this alternating adversarial process can be described as:</p>
<ul>
<li>Given G_0, maximize V(G_0,D) to obtain D_0*, i.e., max[JSD(P_data(x)||P_G0(x))];</li>
<li>Fix D_0*, compute <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi mathvariant="normal">G</mi><mn>1</mn><mo>←</mo><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mrow><mi mathvariant="normal">G</mi><mn>0</mn></mrow><mo>−</mo><mi>η</mi><mrow><mo fence="true">(</mo><mi mathvariant="normal">∂</mi><mi mathvariant="normal">V</mi><mrow><mo fence="true">(</mo><mi mathvariant="normal">G</mi><mo separator="true">,</mo><msub><mi mathvariant="normal">D</mi><mo lspace="0em" rspace="0em">−</mo></msub><msup><mn>0</mn><mo lspace="0em" rspace="0em">∗</mo></msup><mo fence="true">)</mo></mrow><mi mathvariant="normal">/</mi><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi mathvariant="normal">G</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\mathrm { \theta } _ { - } \mathrm { G } 1 \leftarrow \theta _ { - } \mathrm { G0 } - \mathrm { \eta } \left( \partial \mathrm { V } \left( \mathrm { G } , \mathrm { D } _ { - } \mathrm { 0 } ^ { * } \right) / \partial \theta _ { - } \mathrm { G } \right)</annotation></semantics></math></span> to obtain the updated G_1;</li>
<li>Fix G_1, maximize V(G_1,D_0*) to obtain D_1*, i.e., max[JSD(P_data(x)||P_G1(x)];</li>
<li>Fix D_1*, compute <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi mathvariant="normal">G</mi><mn>2</mn><mo>←</mo><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi mathvariant="normal">G</mi><mn>1</mn><mo>−</mo><mi>η</mi><mrow><mo fence="true">(</mo><mi mathvariant="normal">∂</mi><mi mathvariant="normal">V</mi><mrow><mo fence="true">(</mo><mi>G</mi><mo separator="true">,</mo><msub><mi>D</mi><mo lspace="0em" rspace="0em">−</mo></msub><msup><mn>0</mn><mo lspace="0em" rspace="0em">∗</mo></msup><mo fence="true">)</mo></mrow><mi mathvariant="normal">/</mi><mi mathvariant="normal">∂</mi><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi mathvariant="normal">G</mi><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\theta _ { - } \mathrm { G } 2 \leftarrow \theta _ { - } \mathrm { G } 1 - \eta \left( \partial \mathrm { V } \left( G , D _ { - } \mathrm { 0 } ^ { * } \right) / \partial \theta _ { - } \mathrm { G } \right)</annotation></semantics></math></span> to obtain the updated G_2;</li>
</ul>
<p>And so the loop continues.</p>
<ol start="2">
<li>Practical training process</li>
</ol>
<p>According to the definition of the value function V(G,D) above, we need to compute two expectations, E[log(D(x))] and E[log(1-D(G(z)))], where x follows the real data distribution and z follows the initialization distribution. In practice, there is no way to compute these two expectations by integration, so we generally approximate them by sampling from the infinite real data and an infinite generator.</p>
<p>Suppose the generator G is given and we wish to compute maxV(G,D) to find the discriminator D. First we need to sample m samples from P_data(x) and m samples from the generator P_G(x). Maximizing the value function can then be replaced by the following expression:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext> Maximize </mtext><mover accent="true"><mi>V</mi><mo>~</mo></mover><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>log</mi><mo>⁡</mo><mi>D</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mi>i</mi></msup><mo fence="true">)</mo></mrow><mo>+</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mrow><mo fence="true">(</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mi>i</mi></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\text { Maximize } \tilde { V } = \frac { 1 } { m } \sum _ { i = 1 } ^ { m } \log D \left( x ^ { i } \right) + \frac { 1 } { m } \sum _ { i = 1 } ^ { m } \log \left( 1 - D \left( \tilde { x } ^ { i } \right) \right)
</annotation></semantics></math></span><p>Now we treat the samples drawn from P_data(x) as positive samples and those drawn from P_G(x) as negative samples, while using an approximation of the negative V(G,D) as the loss function. This can therefore be formulated as the standard training procedure of a binary classifier:</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext> Minimize </mtext><mi>L</mi><mo>=</mo><mo>−</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>log</mi><mo>⁡</mo><mi>D</mi><mrow><mo fence="true">(</mo><msup><mi>x</mi><mi>i</mi></msup><mo fence="true">)</mo></mrow><mo>−</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mrow><mo fence="true">(</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mi>i</mi></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">
\text { Minimize } L = - \frac { 1 } { m } \sum _ { i = 1 } ^ { m } \log D \left( x ^ { i } \right) - \frac { 1 } { m } \sum _ { i = 1 } ^ { m } \log \left( 1 - D \left( \tilde { x } ^ { i } \right) \right)
</annotation></semantics></math></span><p>In practice, we must implement the minimax game with iterative and numerical methods. Fully optimizing D in the inner loop of training is computationally prohibitive, and a finite dataset would lead to overfitting. Therefore, we can alternate between k steps of optimizing D and one step of optimizing G. As long as G is updated slowly, D stays near its optimal solution.</p>
<p>In summary, over the whole training procedure, for each iteration:</p>
<ul>
<li>Draw m samples from the real data distribution P_data</li>
<li>Draw m noise samples from the prior distribution P_prior(z)</li>
<li>Feed the noise samples into the generator G to produce data <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mo fence="true">{</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mn>1</mn></msup><mo separator="true">,</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mn>2</mn></msup><mo separator="true">,</mo><mo>…</mo><mo separator="true">,</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mi>m</mi></msup><mo fence="true">}</mo></mrow><mo separator="true">,</mo><msup><mover accent="true"><mi>x</mi><mo>~</mo></mover><mi>i</mi></msup><mo>=</mo><mi>G</mi><mrow><mo fence="true">(</mo><msup><mi>z</mi><mi>i</mi></msup><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\left\{ \tilde { x } ^ { 1 } , \tilde { x } ^ { 2 } , \ldots , \tilde { x } ^ { m } \right\} , \tilde { x } ^ { i } = G \left( z ^ { i } \right)</annotation></semantics></math></span>, and update the discriminator parameters <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mo lspace="0em" rspace="0em">−</mo></msub><mi>d</mi></mrow><annotation encoding="application/x-tex">\theta _ { - } d</annotation></semantics></math></span> by maximizing the approximation of V; the discriminator&rsquo;s update rule is <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>d</mi></msub><mo>←</mo><msub><mi>θ</mi><mi>d</mi></msub><mo>+</mo><mi>η</mi><mi mathvariant="normal">∇</mi><mover accent="true"><mi>V</mi><mo>~</mo></mover><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>d</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\theta _ { d } \leftarrow \theta _ { d } + \eta \nabla \tilde { V } \left( \theta _ { d } \right)</annotation></semantics></math></span></li>
</ul>
<p>The above is the process of learning the discriminator D. The process computes the JS divergence and is repeated k times, because we want to maximize the value function.</p>
<ul>
<li>Draw another m noise samples from the prior distribution P_prior(z)</li>
<li>Update the generator by minimizing V, i.e., <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>V</mi><mo>~</mo></mover><mo>=</mo><mfrac><mn>1</mn><mi>m</mi></mfrac><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>m</mi></msubsup><mi>log</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mn>1</mn><mo>−</mo><mi>D</mi><mrow><mo fence="true">(</mo><mi>G</mi><mrow><mo fence="true">(</mo><msup><mi>z</mi><mi>i</mi></msup><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\tilde { V } = \frac { 1 } { m } \sum _ { i = 1 } ^ { m } \log \left( 1 - D \left( G \left( z ^ { i } \right) \right) \right)</annotation></semantics></math></span>, with the generator&rsquo;s update rule <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>θ</mi><mi>g</mi></msub><mo>←</mo><msub><mi>θ</mi><mi>g</mi></msub><mo>−</mo><mi>η</mi><mi mathvariant="normal">∇</mi><mover accent="true"><mi>V</mi><mo>~</mo></mover><mrow><mo fence="true">(</mo><msub><mi>θ</mi><mi>g</mi></msub><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">\theta _ { g } \leftarrow \theta _ { g } - \eta \nabla \tilde { V } \left( \theta _ { g } \right)</annotation></semantics></math></span></li>
</ul>
<p>The above is the learning process of the generator&rsquo;s parameters. This process occurs only once per iteration, which avoids excessive updates that would make the JS divergence rise.</p>
<p>This concludes the complete derivation and argumentation of GAN.</p>
<h2 id="several-issues-in-gan-training">Several Issues in GAN Training</h2>
<h3 id="training-instability">Training Instability</h3>
<p>Training the original GAN is very difficult. This mainly manifests as the training process failing to converge, or the trained generator being unable to produce meaningful content, among other issues. On the other hand, although our optimization objective is the JS divergence, which should reflect the distance between the two distributions, ideally this distance should be relatively large at the start and gradually shrink as the training of G progresses.</p>
<p>In practice, the discriminator&rsquo;s loss function very easily drops to 0 and then stays at 0 thereafter. The JS divergence measures the distance between two distributions, but in practice two situations can cause the JS divergence to deem the distance between the two distributions infinite, making the loss function forever 0.</p>
<p>Case 1: the discriminator D is too strong, causing overfitting.</p>
<p>Solution: try regularization, or reduce the number of model parameters.</p>
<p>Case 2: properties of the data itself. The low-dimensional manifold produced by the generator indeed does not overlap easily with the data distribution.</p>
<p>Solution: one option is to add noise to the data so that the generator&rsquo;s distribution and the real data distribution overlap more easily.
Another is the GAN to be discussed next time.</p>
<h3 id="mode-collapse">Mode Collapse</h3>
<p>All outputs are the same! This phenomenon is known as Mode Collapse. A likely cause is that the real data has large probability mass in many places in the space, but our generative model has not directly learned the characteristics of the real distribution. To guarantee minimal loss, it would rather always produce the same but certainly correct output than try other, different but possibly wrong outputs. In other words, our generator sometimes cannot cover all internal modes of the data distribution and conservatively picks just one mode that is certainly correct.</p>
<h2 id="summary">Summary</h2>
<ul>
<li>GAN combines a generative model with a discriminative model, eliminating the difficulty of defining a loss function for generative models</li>
<li>It operates on probability distributions and is not constrained by the dimensionality of the generation</li>
<li>It can be used for semi-supervised learning</li>
</ul>
]]></content:encoded></item></channel></rss>