Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atlassubbed/atlas-cubic-smoothing
https://github.com/atlassubbed/atlas-cubic-smoothing
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/atlassubbed/atlas-cubic-smoothing
- Owner: atlassubbed
- License: other
- Created: 2018-06-29T02:11:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-30T01:26:33.000Z (over 6 years ago)
- Last Synced: 2024-04-25T01:08:11.696Z (9 months ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# atlas-cubic-smoothing
A commonly used cubic smoothing function for values in the domain [0,1].
[![Travis](https://img.shields.io/travis/atlassubbed/atlas-cubic-smoothing.svg)](https://travis-ci.org/atlassubbed/atlas-cubic-smoothing)
---
## install
```
npm install --save atlas-cubic-smoothing
```## why
When generating values between an interval, it can be helpful to use a smoothing function to ease values which are close to the endpoints of the interval.
The smoothing function used here is a 3rd order polynomial of the form:
## examples
#### using smoothing
```javascript
const smooth = require("atlas-cubic-smoothing");// create a vector of input values
const inputs = [];
for (let x = 0; x <= 1; x+=.001) inputs.push(x);// apply smoothing
const smoothed = inputs.map(x => smooth(x));
```#### output function visualized
Your output values will fall along the following curve:
#### understanding smoothing
Smoothing works by changing how the input values *change* over their interval. For example, `x = .01` and `x = .02` are `delta = .01` units away from each other. When these values are smoothed, they are squeezed together in the output space.
For many smoothing functions (including this one), values in the center of the input range are spread apart. For example `x = .50` and `x = .51` are `delta = .01` units away from each other. However, when they are smoothed, they are almost twice as far away in the output space. Higher order smoothing functions tend to squeeze and stretch values to a greater extent.
A derivative is just a fancy way to say "slope" at some point in our function. First, recall that the derivative of `f(x) = x` is `1`, meaning its slope never changes as a function of `x`. To understand whether values will be squeezed or stretched in the output space, we can take the first derivative of the smoothing function:
We want to ask ourselves whether or not the smoothing function will squeeze or stretch our input values at a certain point. All we need to do is plug our point into the derivative above. For example, plugging in the point `x = .1` tells us that the derivative is `s'(.1) = .54`, meaning it grows at roughly half the rate of `f(x) = x` at the same point (hence, squeezing). If we input `x = .5`, we'll find that the derivative is `s'(.5) = 1.5`, which means it grows 50% faster in the center than `f(x) = x` (hence, stretching).
#### derivative visualized
Another interesting property of smoothing functions is that they tend to have *even* derivatives around the center of the input interval, meaning that values will be smoothed symmetrically around the middle (`x = .5`, in this case). If you transform coordinates of the smoothing function such that `a = x - .5`, you'll find that the derivative of the result is even, or that `s'(a) = s'(-a)`.
## caveats
The exported function should take input in the range `[0,1]`, otherwise it doesn't make much sense for smoothing. Be sure to normalize your input!