Comments (3)
Ok -- found the issue. Array.prototype.sort, as called on line 117 of loess.js, sorts lexicographically by default, not numerically. Occasionally this might not be detectable, as when finding the median, plenty of values that may be randomly returned are "good enough".
from science.js.
Hi @joearasin , is this issue fixed? Actually I still got the same issue of returning NaNs.
Please see my following code,
x = [336, 348, 359, 370, 381, 392, 403, 414, 425, 436, 447, 459, 470, 481, 492, 503, 514, 525, 535, 546, 556, 568, 579, 590, 601, 612, 623, 634, 645, 656, 667, 668, 671];
y = [74424, 80523, 76017, 79656, 80387, 85514, 83565, 82273, 85214, 85977, 71245, 73222, 70282, 73039, 75512, 108677, 83249, 83261, 85322, 85880, 82211, 89690, 85743, 83391, 85897, 106901, 108514, 110311, 89848, 89238, 90288, 96918, 94159];
weight1 = [0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1];
var loess2 = science.stats.loess(); loess2.bandwidth(0.08);
yValuesSmoothed = loess2(x, y, weight1);
This will return all NaNs.
[NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]
Using another weight, it will return several NaNs.
x = [336, 348, 359, 370, 381, 392, 403, 414, 425, 436, 447, 459, 470, 481, 492, 503, 514, 525, 535, 546, 556, 568, 579, 590, 601, 612, 623, 634, 645, 656, 667, 668, 671];
y = [74424, 80523, 76017, 79656, 80387, 85514, 83565, 82273, 85214, 85977, 71245, 73222, 70282, 73039, 75512, 108677, 83249, 83261, 85322, 85880, 82211, 89690, 85743, 83391, 85897, 106901, 108514, 110311, 89848, 89238, 90288, 96918, 94159];
weight2 = [1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1];
var loess2 = science.stats.loess(); loess2.bandwidth(0.08);
yValuesSmoothed = loess2(x, y, weight2);
The result is
[74424, 80523, 76017, 79656, 80387, 85514, NaN, 82273, 82273, 71245, 71245, 73222, 70282, 73039, 75512, 108677, 83249, 83261, 85322, 85880, 82211, 89690, NaN, 83391, 85897, 106901, 108514, 110311, NaN, 89238, 90288, 96918, 94159]
from science.js.
Wow -- I'm probably not the right person to ask, considering this isn't my library (and I haven't looked at this code in 3.5 years, aside to fix the issue I had). My gut feeling looking at the errors you're having is that the 0-weighted points are causing something to divide by 0, but I'm actually not familiar enough with the math to know what's going on unless I dig in further.
from science.js.
Related Issues (20)
- loess example is broken
- Create a release? HOT 2
- errors installing with npm 1.1.13 or newer HOT 2
- Mode of single-element arrays is null HOT 1
- mode of same-element arrays is undefined HOT 3
- Build a Bower package HOT 1
- Documentation HOT 3
- Interactive IDE browser app for science.js HOT 2
- Clustering algorithm for graph
- Documentation needed for functions HOT 1
- Error in initialization of hcluster
- Add an id to clusters created by hcluster HOT 2
- Stata Lpoly: Can this be replicated in science.js?
- Observable: Invalid module HOT 1
- Documentation?
- .stats.kde() doesn't like multiple repeated values HOT 3
- Choice of license? HOT 3
- Actively Maintained Fork? HOT 2
- hcluster distances are incorrect for complete and average linkage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from science.js.