![Hands-On Meta Learning with Python](https://wfqqreader-1252317822.image.myqcloud.com/cover/8/36699008/b_36699008.jpg)
上QQ阅读APP看书,第一时间看更新
Algorithm
Now, we will better understand the Gaussian prototypical network by going through it step by step:
- Let's say we have a dataset, D = {(x1, y1,), (x2, y2), ... (xi, yi)}, where x is the feature and y is the label. Let's say we have a binary label, which means we have only two classes, 0 and 1. We will sample data points at random without replacement from each of the classes from our dataset, D, and create our support set, S.
- Similarly, we sample data points at random per class and create the query set, Q.
- We will pass the support set to our embedding function, f(). The embedding function will generate the embeddings for our support set, along with the covariance matrix.
- We calculate the inverse of the covariance matrix.
- We compute the prototype of each class in the support set as follows:
![](https://epubservercos.yuewen.com/35CBBA/19470383201513106/epubprivate/OEBPS/Images/242c7e0b-a5d4-4bb0-849b-135dc2ce6e66.png?sign=1738760261-ozbctimA4dBWIC8g84mnZr3gzQLBphB4-0-78aae0f18bb473c4f4bcf4fc417618a0)
In this equation, is the diagonal of the inverse covariance matrix,
denotes the embeddings of the support set and superscript c denotes the class.
- After computing the prototype of each class in the support set, we learn the embeddings for the query set, Q. Let's say x' is the embedding of the query point.
- We calculate the distance of the query point embeddings to the class prototypes as follows:
![](https://epubservercos.yuewen.com/35CBBA/19470383201513106/epubprivate/OEBPS/Images/53bbc979-6829-4074-a1c2-f8f227bbcda5.png?sign=1738760261-VhRoiGJtGc5i1I8XDddPvPvbC7tvm6S1-0-cb2a15ffeb74b1afeaee10ae347203ef)
- After calculating the distance between the class prototype and query set embeddings, we predict the class of the query set as a class that has a minimum distance, as follows:
![](https://epubservercos.yuewen.com/35CBBA/19470383201513106/epubprivate/OEBPS/Images/c9423651-8ab6-46c9-a4f1-3a03d2bd0307.png?sign=1738760261-QCkTnpzegqLkeG5h0IAFDsqPWysZWkPi-0-ec940a0f48b71d8656d0df91bf1b77dc)