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

Fix saliency viewing in example viewer #1472

Merged
merged 22 commits into from
Oct 1, 2018
Merged

Conversation

jameswex
Copy link
Contributor

  • Fix issues for vz_example_viewer saliency viewing introduced with WIT changes
  • Sort features by saliency when it is provided
  • Visual change to saliency legend to match previous visual changes to overall example viewer

@jameswex jameswex requested a review from nfelt September 28, 2018 19:39
haveSaliency: function() {
if (!this.featuresList || !this.saliency ||
if (!this.filteredFeaturesList || !this.saliency ||
Object.keys(this.saliency).length === 0 || !this.colors) {
return;
}

// TODO(jwexler): Find a way to do this without requestAnimationFrame.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saying, this seems to happen because of _debounceTemplate in dom-repeat: https://github.com/Polymer/polymer/blob/1.x/src/lib/template/dom-repeat.html#L492

.style('background', 'lightgrey');

this.selectAll('.value-pill')
.style('background', '#e8eaed');
Copy link
Contributor

@stephanwlee stephanwlee Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this code relates to the comment in L373. Are they related? Also, would it be possible to hoist this constant color value as a module level constant (i.e., neutralSaliencyColor)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed comment and changed to use neutralSaliencyColor as it should

const moreButton = this.selectAll(
`paper-button.${this.sanitizeFeature(feat.name)}.value-pill`);
let mostExtremeSal = 0;
for (let i = 1; i < valArray.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no action required: an alternative to write this is, Math.max(...valArray.map(Math.abs))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this way so as to keep the most extreme true value from valArray instead of the abs value of it.

@@ -326,29 +349,33 @@ Polymer({
]);
},

selectAll: function(query: string) {
return d3.selectAll(
Polymer.dom(this.root).querySelectorAll(query) as any);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, how does this differ from this.querySelectorAll?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably no different, was just following what i saw in the doc at https://www.polymer-project.org/1.0/docs/devguide/local-dom

// its feature values, to sort features with the most salienct features at
// the top.
const saliencyTotals = checkSal ?
Object.assign({}, ...Object.keys(saliency).map(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing Object.assign on objects that you map out of keys of saliency. I think you can do this either by cloning saliency object and transforming its values or

Object.entries(saliency)
	.map(([key, value]) => [key, typeof value == 'number' ? [value] : value])
	.map(([key, value]) => [key, value.map(Math.abs).reduce((total, cur) => total + cur, 0)])
        .reduce((obj, [key, value]) => {
           obj[key] = value;
           return obj;
        }, {})

though I am not sure if this has any better readability.

@jameswex jameswex merged commit c9c5c6b into tensorflow:master Oct 1, 2018
@jameswex jameswex deleted the saliency branch October 1, 2018 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants