Giter Club home page Giter Club logo

Comments (11)

mbostock avatar mbostock commented on July 16, 2024

This is the expected behavior: the records are filtered, not the groups. In your example, the groups are returned in the expected order by descending value, including those groups whose value happens to be zero.

from crossfilter.

eventualbuddha avatar eventualbuddha commented on July 16, 2024

Thanks for the note. I believe this is simply a misunderstanding of the documentation. In your example, the links group definitely is filtered by tokens matching "Jimmy", but it contains empty groups (value == 0). That's why you're seeing three results. From the documentation:

If there are fewer than k groups according to all of the tesseract's filters, then an array smaller than k will be returned. If there are fewer than k non-empty groups, this method may also return empty groups (for example, those with a count of zero).

In your example, k is Infinity, so all the empty groups will be returned. Using this jsfiddle, I got these results:

links.top(Infinity) // no filters
[
  {"key":"http://www.engadget.com/2012/03/17/us-navy-lasr-research-facility-builds-robots-not-ray-guns/",
   "value":20},
  {"key":"http://feedproxy.google.com/~r/oreilly/radar/atom/~3/VUnm8ikk8a4/encyclopaedia-britannica-copyright-paypal-censorship.html",
   "value":10},
  {"key":"http://feeds.arstechnica.com/~r/arstechnica/index/~3/_dcrXs9GTTo/ion-beam-manufacturing-halves-production-cost-of-pv-panels.ars",
   "value":9}
]

links.top(Infinity) // filtering token by "Jimmy"
[
  {"key":"http://www.engadget.com/2012/03/17/us-navy-lasr-research-facility-builds-robots-not-ray-guns/",
   "value":0},
  {"key":"http://feedproxy.google.com/~r/oreilly/radar/atom/~3/VUnm8ikk8a4/encyclopaedia-britannica-copyright-paypal-censorship.html",
   "value":1},
  {"key":"http://feeds.arstechnica.com/~r/arstechnica/index/~3/_dcrXs9GTTo/ion-beam-manufacturing-halves-production-cost-of-pv-panels.ars",
   "value":0}
]

Note that there are the same number of group results in each but the values are different. Also note that I used console.log(JSON.stringify(...)) because tesseract reuses the groups (I think) so inspecting their values after modifying them by filtering is misleading. If I completely misunderstood, please reopen this issue with a clarification. Thanks!

from crossfilter.

cqcallaw avatar cqcallaw commented on July 16, 2024

Thanks to you both for the clarification--I can see now that the behavior is expected. The jsfiddle results were particularly helpful.

Any advice on how I might get obtain only the set of links that contain the token "Jimmy"? For my purposes, the empty groups are just noise.

from crossfilter.

eventualbuddha avatar eventualbuddha commented on July 16, 2024

Just ignore the entries with value == 0.

from crossfilter.

cqcallaw avatar cqcallaw commented on July 16, 2024

Are you suggesting to post-processing of the result set (e.g. a simple iteration through the results of the group function)? I don't see any "ignore entries" function for the group results listed in the API reference.

from crossfilter.

mbostock avatar mbostock commented on July 16, 2024

Correct. This would work:

links.top(Infinity).filter(function(d) { return d.value; })

If you have lots and lots of groups, you could also use bisection (tesseract.bisect) to find the first zero-group and cut the array there. Or, if you're planning on iterating over the groups, just stop iterating when the value is zero.

from crossfilter.

cqcallaw avatar cqcallaw commented on July 16, 2024

Excellent, thanks.

In investigating why group.top(Infinity) was preferable to group.all(), I encountered this in the group.all() documentation:

Unlike top, however, the returned array may contain empty groups, whose value is the return value from the group's reduce initial function.

Doesn't this conflict with the statement (two or three lines above) that eventualbuddha referenced?

If there are fewer than k non-empty groups, this method may also return empty groups (for example, those with a count of zero).

from crossfilter.

mbostock avatar mbostock commented on July 16, 2024

I'll fix the documentation re. group.all(). I don't recall exactly, but I think the behavior may have changed from an earlier (unreleased) version of Tesseract that did not use incremental update for groups.

It might be possible to filter zero-value groups from group.top, but that would either require tracking the count separately (which is a non-significant cost), or by comparing the top groups to the result of the reduceInitial function using the group's order accessor (using bisection, so it'd be fast). It's a bit tricky since the top groups are in descending order, and the bisection assumes ascending order, but in theory it's possible. And, I think it would improve the API.

from crossfilter.

cqcallaw avatar cqcallaw commented on July 16, 2024

I can't speak for others, but filtering zero-value groups would certainly be useful for my usage of the API. :) I can see the zero-value groups being useful in other cases, though, so I think you'd want to make the filter optional.

On the subject of API adjustments, have you considered aliasing top(Infinity) with an overload of the all function? Using group.all(Boolean clone) would be slightly less astonishing to me, compared to top(Infinity).

from crossfilter.

mbostock avatar mbostock commented on July 16, 2024

No; group.top returns groups by descending value, whereas group.all returns groups by ascending key. The top method thus requires selecting + sorting, whereas the all method just returns the groups as-is. Another difference is that group.top returns a copy (of maximum size K), whereas group.all returns the internal array. I don't think it's a good idea to merge these into a single method, given that they do different things.

from crossfilter.

cqcallaw avatar cqcallaw commented on July 16, 2024

Arrr, I must be getting senile--I thought I read both result sets were in descending order. Sorry.

from crossfilter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.