Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Projector infinite loop issue #1481

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions tensorboard/plugins/projector/vz_projector/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,18 @@ export class DataSet {
if (dim > PCA_SAMPLE_DIM) {
vectors = vector.projectRandom(vectors, PCA_SAMPLE_DIM);
}
let sampledVectors = vectors.slice(0, PCA_SAMPLE_SIZE);

let sigma = numeric.div(
numeric.dot(numeric.transpose(sampledVectors), sampledVectors),
sampledVectors.length);
let svd = numeric.svd(sigma);

let variances: number[] = svd.S;
const sampledVectors = vectors.slice(0, PCA_SAMPLE_SIZE);
const {dot, transpose, svd: numericSvd} = numeric;
// numeric dynamically generates `numeric.div` and Closure compiler has
// incorrectly compiles `numeric.div` property accessor. We use below
// signature to prevent Closure from mangling and guessing.
const div = numeric['div'];

const scalar = dot(transpose(sampledVectors), sampledVectors);
const sigma = div(scalar, sampledVectors.length);
const svd = numericSvd(sigma);

const variances: number[] = svd.S;
let totalVariance = 0;
for (let i = 0; i < variances.length; ++i) {
totalVariance += variances[i];
Expand All @@ -277,7 +281,6 @@ export class DataSet {
variances[i] /= totalVariance;
}
this.fracVariancesExplained = variances;

let U: number[][] = svd.U;
let pcaVectors = vectors.map(vector => {
let newV = new Float32Array(NUM_PCA_COMPONENTS);
Expand Down Expand Up @@ -392,7 +395,7 @@ export class DataSet {
let sampledIndices =
this.shuffledDataIndices.slice(0, TSNE_SAMPLE_SIZE);
let labels = new Array(sampledIndices.length);
sampledIndices.forEach((index, i) =>
sampledIndices.forEach((index, i) =>
labels[i] = this.points[index].metadata[superviseColumn].toString());
this.superviseLabels = labels;
}
Expand Down