ContrastiveLossLayer

ContrastiveLossLayer[]

represents a loss layer that computes a loss based on a distance metric and a target that specifies whether the distance should be minimized or maximized.

ContrastiveLossLayer[margin]

specifies a distance above which the loss is zero for True targets.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Create a ContrastiveLossLayer with a given margin:

Create a ContrastiveLossLayer:

Apply it to some data:

If the target is True, the loss is nonzero only when the input distance is less than the default margin of 0.5:

If the target is False, the loss is proportional to the input distance:

Applications  (1)

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:

Create a loss network to measure 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:

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

Text

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

CMS

Wolfram Language. 2017. "ContrastiveLossLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ContrastiveLossLayer.html.

APA

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

BibTeX

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

BibLaTeX

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