Skip to content

Commit c0e7447

Browse files
authored
Embedding Projector: Adds UMAP minDist hyperparameter (#6300)
## Motivation for features / changes Re-introduces #2912 by @cannoneyed ## Technical description of changes ## Screenshots of UI changes ![image](https://user-images.githubusercontent.com/31378877/232667145-5c01f97a-8fb1-41fa-a855-50d7e3d2721d.png) ## Detailed steps to verify changes work correctly (as executed by you) Tested with the lastest master to ensure the new param works as expected ## Alternate designs / implementations considered
1 parent 8cdf209 commit c0e7447

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

tensorboard/plugins/projector/vz_projector/data.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,11 @@ export class DataSet {
374374
async projectUmap(
375375
nComponents: number,
376376
nNeighbors: number,
377+
minDist: number,
377378
stepCallback: (iter: number) => void
378379
) {
379380
this.hasUmapRun = true;
380-
this.umap = new UMAP({nComponents, nNeighbors});
381+
this.umap = new UMAP({nComponents, nNeighbors, minDist});
381382
let currentEpoch = 0;
382383
const epochStepSize = 10;
383384
const sampledIndices = this.shuffledDataIndices.slice(0, UMAP_SAMPLE_SIZE);
@@ -677,6 +678,7 @@ export class State {
677678
/** UMAP parameters */
678679
umapIs3d: boolean = true;
679680
umapNeighbors: number = 15;
681+
umapMinDist: number = 0.1;
680682
/** PCA projection component dimensions */
681683
pcaComponentDimensions: number[] = [];
682684
/** Custom projection parameters */

tensorboard/plugins/projector/vz_projector/vz-projector-projections-panel.html.ts

+28
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,34 @@ export const template = html`
234234
></paper-slider>
235235
<span>[[umapNeighbors]]</span>
236236
</div>
237+
<div class="slider umap-min-dist">
238+
<label>
239+
MinDist
240+
<paper-icon-button
241+
icon="help"
242+
class="help-icon"
243+
></paper-icon-button>
244+
<paper-tooltip
245+
position="right"
246+
animation-delay="0"
247+
fit-to-visible-bounds
248+
>
249+
Controls how tightly UMAP is allowed to pack points together.
250+
Provides the minimum distance apart that points are allowed to
251+
be in the low dimensional representation. The default value is
252+
0.1.
253+
</paper-tooltip>
254+
</label>
255+
<paper-slider
256+
id="umap-mindist-slider"
257+
value="{{umapMinDist}}"
258+
pin
259+
min="0"
260+
max="0.99"
261+
step="0.01"
262+
></paper-slider>
263+
<span>[[umapMinDist]]</span>
264+
</div>
237265
<p>
238266
<button
239267
id="run-umap"

tensorboard/plugins/projector/vz_projector/vz-projector-projections-panel.ts

+21-11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class ProjectionsPanel extends LegacyElementMixin(PolymerElement) {
6666
umapIs3d: boolean = true;
6767
@property({type: Number})
6868
umapNeighbors: number = 15;
69+
@property({type: Number})
70+
umapMinDist: number = 0.1;
6971
// PCA projection.
7072
@property({type: Array})
7173
pcaComponents: Array<{
@@ -262,6 +264,7 @@ class ProjectionsPanel extends LegacyElementMixin(PolymerElement) {
262264
// UMAP
263265
this.umapIs3d = bookmark.umapIs3d;
264266
this.umapNeighbors = bookmark.umapNeighbors;
267+
this.umapMinDist = bookmark.umapMinDist;
265268
// custom
266269
this.customSelectedSearchByMetadataOption =
267270
bookmark.customSelectedSearchByMetadataOption;
@@ -319,6 +322,7 @@ class ProjectionsPanel extends LegacyElementMixin(PolymerElement) {
319322
// UMAP
320323
bookmark.umapIs3d = this.umapIs3d;
321324
bookmark.umapNeighbors = this.umapNeighbors;
325+
bookmark.umapMinDist = this.umapMinDist;
322326
// custom
323327
bookmark.customSelectedSearchByMetadataOption =
324328
this.customSelectedSearchByMetadataOption;
@@ -542,20 +546,26 @@ class ProjectionsPanel extends LegacyElementMixin(PolymerElement) {
542546
this.runUmapButton.disabled = true;
543547
const nComponents = this.umapIs3d ? 3 : 2;
544548
const nNeighbors = this.umapNeighbors;
545-
this.dataSet.projectUmap(nComponents, nNeighbors, (iteration: number) => {
546-
if (iteration != null) {
547-
this.runUmapButton.disabled = false;
548-
this.projector.notifyProjectionPositionsUpdated();
549-
if (!projectionChangeNotified && this.dataSet.projections['umap']) {
549+
const minDist = this.umapMinDist;
550+
this.dataSet.projectUmap(
551+
nComponents,
552+
nNeighbors,
553+
minDist,
554+
(iteration: number) => {
555+
if (iteration != null) {
556+
this.runUmapButton.disabled = false;
557+
this.projector.notifyProjectionPositionsUpdated();
558+
if (!projectionChangeNotified && this.dataSet.projections['umap']) {
559+
this.projector.onProjectionChanged();
560+
projectionChangeNotified = true;
561+
}
562+
} else {
563+
this.runUmapButton.innerText = 'Re-run';
564+
this.runUmapButton.disabled = false;
550565
this.projector.onProjectionChanged();
551-
projectionChangeNotified = true;
552566
}
553-
} else {
554-
this.runUmapButton.innerText = 'Re-run';
555-
this.runUmapButton.disabled = false;
556-
this.projector.onProjectionChanged();
557567
}
558-
});
568+
);
559569
}
560570
@observe('pcaX', 'pcaY', 'pcaZ')
561571
private showPCAIfEnabled() {

0 commit comments

Comments
 (0)