NetPairEmbeddingOperator

NetPairEmbeddingOperator[net]

represents a net that takes a pair of arrays, embeds them into a vector space using net, and outputs the distance under the embedding.

NetPairEmbeddingOperator[net,opts]

includes options for distance function to use and other parameters.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Create a NetPairEmbeddingOperator that embeds inputs using a NetChain:

Create a NetPairEmbeddingOperator that embeds a pair of length-2 vectors using a randomly initialized NetChain:

Apply the net to a pair of input vectors:

Thread the layer across a batch of input vectors:

Scope  (1)

Create a NetGraph with one input and output:

Create a NetPairEmbeddingOperator that embeds vectors using a NetGraph:

The embedding network in NetPairEmbeddingOperator[net] can be extracted using NetExtract:

Options  (1)

DistanceFunction  (1)

Create a NetPairEmbeddingOperator that uses the CosineDistance function to calculate the distance between the two embedded arrays:

Apply the layer to a pair of input vectors:

Applications  (2)

Train a multilayer perceptron to embed a synthetic dataset based only on its topology. First, create the training data on a spiral-like manifold that is dense in the plane:

Create the perceptron:

Use NetPairEmbeddingOperator to define a loss network that measures the performance of the embedding:

Create a generator that will sample pairs of points and associate them with True if their parameterization on the manifold differs by more than Pi:

Train the network, using a generator to sample pairs of points, and classify them as the same if their original parameterization was close:

Extract the embedding from the net:

Plot the 1D embedding learned by the net as a color map:

Learn an embedding of the digits in the MNIST dataset. First, import the data and take only those examples with labels between 0 and 4:

Create a training set by sampling pairs of images and associating them with True if their labels are different and False if their labels are the same:

Define a convolutional network to use as an embedding network:

Construct the pair-embedding net:

Train the network:

Apply the network to a list of pairs of digits to compute their distances under the embedding. Digits with the same label have small distances:

Extract the embedding network:

Compute the embedding of a digit:

Sample 500 digits and group them by their labels:

Compute their embeddings and plot them. Digits with the same label are clustered under the learned embedding:

Properties & Relations  (1)

NetMapOperator can be used to implement NetPairEmbeddingOperator. Create an initialized LinearLayer:

Create NetPairEmbeddingOperator using the linear layer as its embedding net, and evaluate it on an input:

Define a NetGraph with a NetMapOperator that is equivalent to the previous NetPairEmbeddingOperator, and evaluate it on the same input:

Possible Issues  (1)

Nets with multiple inputs or outputs cannot be used as the embedding network in NetPairEmbeddingOperator[net]:

Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).

Text

Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).

CMS

Wolfram Language. 2017. "NetPairEmbeddingOperator." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html.

APA

Wolfram Language. (2017). NetPairEmbeddingOperator. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html

BibTeX

@misc{reference.wolfram_2024_netpairembeddingoperator, author="Wolfram Research", title="{NetPairEmbeddingOperator}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_netpairembeddingoperator, organization={Wolfram Research}, title={NetPairEmbeddingOperator}, year={2020}, url={https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}, note=[Accessed: 22-November-2024 ]}