-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add common infrastructure config files (#1)
- Loading branch information
qlba
authored
Jul 1, 2020
1 parent
6ef25cc
commit e7759ad
Showing
14 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "dvpnt" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.tgz | ||
node_modules/ | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.tgz | ||
.eslintignore | ||
.eslintrc.json | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
test.js | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
save-exact=true | ||
package-lock=false | ||
|
||
@dvpnt:registry=https://registry.npmjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12.13.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
|
||
sudo: false | ||
|
||
node_js: | ||
- 12 | ||
- stable | ||
|
||
script: | ||
- npm run lint | ||
- npm run test -- --coverage-report=text-lcov --color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 dvpnt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# math | ||
# @dvpnt/math | ||
[](https://travis-ci.org/dvpnt/math) | ||
[](https://coveralls.io/github/dvpnt/math?branch=master) | ||
[](https://www.npmjs.com/package/@dvpnt/math) | ||
|
||
Mathware of dvpnt | ||
|
||
## Installation | ||
|
||
$ npm install @dvpnt/math | ||
|
||
|
||
## License | ||
|
||
[The MIT License (MIT)](/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const _ = require('underscore'); | ||
|
||
class Interpolator { | ||
constructor(coeffs) { | ||
this._coeffs = coeffs; | ||
} | ||
|
||
of(x) { | ||
return _(this._coeffs).reduce((sum, coeff, i) => sum + coeff * x ** i, 0); | ||
} | ||
|
||
error(xs, ys) { | ||
return _(xs).reduce((error, x, i) => error + Math.abs(this.of(x) - ys[i]), 0); | ||
} | ||
} | ||
|
||
module.exports = Interpolator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const _ = require('underscore'); | ||
const math = require('mathjs'); | ||
const Interpolator = require('./Interpolator'); | ||
|
||
function createLsmInterpolator({xs, ys, coeffsCount}) { | ||
const coeffsRange = _(coeffsCount).isObject() ? | ||
_.range(coeffsCount.min, coeffsCount.max + 1) : | ||
_.range(coeffsCount, coeffsCount + 1); | ||
|
||
const interpolators = _(coeffsRange) | ||
.chain() | ||
.map((coeffsCount) => { | ||
const line = _.range(0, coeffsCount); | ||
|
||
const lsmMatrix = _(line).map( | ||
(i) => _(line).map( | ||
(j) => _(xs).reduce((sum, x) => sum + x ** (i + j), 0) | ||
) | ||
); | ||
|
||
if (Math.abs(math.det(lsmMatrix)) < 1e-5) return; | ||
|
||
const lsmVector = _(line).map( | ||
(i) => _(xs).reduce((sum, x, j) => sum + x ** i * ys[j], 0) | ||
); | ||
|
||
return new Interpolator(math.lusolve(lsmMatrix, lsmVector)); | ||
}) | ||
.compact() | ||
.value(); | ||
|
||
if (_(interpolators).isEmpty()) { | ||
throw new Error('Failed to fit interpolator'); | ||
} | ||
|
||
return _(interpolators).min((interpolator) => interpolator.error(xs, ys)); | ||
} | ||
|
||
module.exports = createLsmInterpolator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const _ = require('underscore'); | ||
const t = require('tap'); | ||
const {createLsmInterpolator} = require('..'); | ||
|
||
function interpolate(interpolator, xs) { | ||
return _(xs).map((x) => Number(interpolator.of(x).toFixed(3))); | ||
} | ||
|
||
t.test('LsmInterpolator', (t) => { | ||
const xs = [0.5, 1, 1.5, 2, 2.5, 3]; | ||
const ys = [0.35, 0.8, 1.7, 1.85, 3.51, 1.02]; | ||
|
||
t.test('with specific coeffs count', (t) => { | ||
const interpolator = createLsmInterpolator({xs, ys, coeffsCount: 2}); | ||
|
||
t.strictSame( | ||
interpolate(interpolator, [0.5, 1.75, 3]), | ||
[0.708, 1.538, 2.369], | ||
'check interpolation' | ||
); | ||
|
||
t.end(); | ||
}); | ||
|
||
t.test('with autofit coeffs count', (t) => { | ||
const interpolator = | ||
createLsmInterpolator({xs, ys, coeffsCount: {min: 2, max: 10}}); | ||
|
||
t.strictSame( | ||
interpolate(interpolator, [0.5, 1.75, 3]), | ||
[0.35, 1.675, 1.02], | ||
'check interpolation' | ||
); | ||
|
||
t.end(); | ||
}); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.createLsmInterpolator = require('./LsmInterpolator'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@dvpnt/math", | ||
"version": "0.0.0", | ||
"description": "mathematical achievements of dvpnt", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"lint": "eslint --ext js,jsx --cache ./lib/", | ||
"test": "tap lib/**/__tests__/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dvpnt/math.git" | ||
}, | ||
"keywords": [ | ||
"dvpnt", | ||
"math" | ||
], | ||
"author": "dvpnt", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/dvpnt/math/issues" | ||
}, | ||
"homepage": "https://github.com/dvpnt/math#readme", | ||
"dependencies": { | ||
"mathjs": "6.5.0", | ||
"nrun": "1.0.0", | ||
"underscore": "1.9.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "6.8.0", | ||
"eslint-config-dvpnt": "4.0.8", | ||
"eslint-plugin-import": "2.22.0", | ||
"tap": "14.6.1" | ||
} | ||
} |