-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
246 additions
and
0 deletions.
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,14 @@ | ||
ecmaFeatures: | ||
modules: true | ||
|
||
env: | ||
es6: true | ||
browser: true | ||
node: true | ||
|
||
extends: | ||
"eslint:recommended" | ||
|
||
rules: | ||
no-cond-assign: 0 | ||
no-floating-decimal: 2 |
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,19 @@ | ||
# javascript | ||
node_modules | ||
dist | ||
build | ||
|
||
# docs | ||
giottoweb/docs/_build/ | ||
|
||
.idea | ||
.project | ||
.pydevproject | ||
.grunt | ||
.coveralls.yml | ||
clean.py | ||
*.log | ||
*.pyc | ||
__pycache__ | ||
.DS_Store | ||
coverage |
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,2 @@ | ||
build/*.zip | ||
test/ |
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,9 @@ | ||
language: node_js | ||
|
||
install: | ||
- npm install | ||
|
||
before_script: grunt build | ||
|
||
notifications: | ||
email: false |
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,2 @@ | ||
export {default as sobol} from "./src/sobol"; | ||
export {default as version} from "./src/version"; |
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,38 @@ | ||
{ | ||
"version": "0.1.0", | ||
"name": "d3-quant", | ||
"title": "d3-quant", | ||
"description": "D3 library fron quantitative data analisys", | ||
"homepage": "https://github.com/quantmind/d3-quant", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/quantmind/d3-quant.git" | ||
}, | ||
"keywords": [ | ||
"d3", | ||
"math" | ||
], | ||
"license": "BSD-3-Clause", | ||
"author": { | ||
"name": "quantmind.com", | ||
"email": "message@quantmind.com" | ||
}, | ||
"main": "build/d3-quant.js", | ||
"jsnext:main": "index", | ||
"devDependencies": { | ||
"faucet": "0.0", | ||
"rollup": "0.25", | ||
"rollup-plugin-babel": "", | ||
"rollup-plugin-json": "", | ||
"babel-preset-es2015-rollup": "", | ||
"tape": "4", | ||
"uglify-js": "2", | ||
"eslint": "" | ||
}, | ||
"scripts": { | ||
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export default version;\");' > src/version.js && rollup -c", | ||
"test": "eslint index.js src test && faucet `find test -name '*-test.js'`", | ||
"prepublish": "npm run test && uglifyjs build/d3-quant.js -c -m -o build/d3-quant.min.js && rm -f build/d3-quant.zip && zip -j build/d3-quant.zip -- LICENSE README.md build/d3-quant.js build/d3-quant.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-quant.js" | ||
} | ||
} |
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,10 @@ | ||
import json from 'rollup-plugin-json'; | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
export default { | ||
entry: 'index.js', | ||
"format": "umd", | ||
"moduleName": "d3_quant", | ||
plugins: [ json(), babel({"presets": ["es2015-rollup"]}) ], | ||
dest: 'build/d3-quant.js' | ||
}; |
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,10 @@ | ||
// <%= pkg.title || pkg.name %> - v<%= pkg.version %> | ||
// | ||
// Compiled <%= grunt.template.today("yyyy-mm-dd") %>. | ||
// | ||
// Copyright (c) <%= grunt.template.today("yyyy") %> - <%= pkg.author.name %> | ||
// All rights reserved. | ||
// License: <%= pkg.license %> | ||
// For all details and documentation: | ||
// <%= pkg.homepage %> | ||
// |
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,113 @@ | ||
'use strict'; | ||
const | ||
BITS = 52, | ||
SCALE = 2 << 51, | ||
COEFFICIENTS = [ | ||
'd s a m_i', | ||
'2 1 0 1', | ||
'3 2 1 1 3', | ||
'4 3 1 1 3 1', | ||
'5 3 2 1 1 1', | ||
'6 4 1 1 1 3 3', | ||
'7 4 4 1 3 5 13', | ||
'8 5 2 1 1 5 5 17', | ||
'9 5 4 1 1 5 5 5', | ||
'10 5 7 1 1 7 11 1' | ||
]; | ||
|
||
class Sobol { | ||
|
||
constructor (dimension) { | ||
_sobol.set(this, new SobolImpl(dimension)); | ||
} | ||
|
||
get dimension () { | ||
return _sobol.get(this).dimension; | ||
} | ||
|
||
get count () { | ||
return _sobol.get(this).count; | ||
} | ||
|
||
next () { | ||
return _sobol.get(this).next(); | ||
} | ||
} | ||
|
||
let i; | ||
|
||
// Simulate a WeekMap for now | ||
var _sobol = { | ||
get: function (obj) { | ||
return obj._self; | ||
}, | ||
set: function (obj, value) { | ||
obj._self = value; | ||
} | ||
}; | ||
|
||
class SobolImpl { | ||
|
||
constructor(dimension) { | ||
if (dimension < 1 || dimension > COEFFICIENTS.length) throw new Error("Out of range dimension"); | ||
this.dimension = dimension | ||
this.count = 0; | ||
this.direction = []; | ||
this.x = []; | ||
this.zero = []; | ||
|
||
let tmp = [], | ||
direction = this.direction, | ||
zero = this.zero, | ||
x = this.x, | ||
lines = COEFFICIENTS; | ||
|
||
for (i = 0; i <= BITS; i++) tmp.push(0); | ||
for (i = 0; i < this.dimension; i++) { | ||
direction[i] = tmp.slice(); | ||
x[i] = 0; | ||
zero[i] = 0; | ||
} | ||
|
||
for (i = 1; i <= BITS; i++) direction[0][i] = 1 << (BITS - i); | ||
for (var d = 1; d < this.dimension; d++) { | ||
var cells = lines[d].split(/\s+/); | ||
var s = +cells[1]; | ||
var a = +cells[2]; | ||
var m = [0]; | ||
for (i = 0; i < s; i++) m.push(+cells[3 + i]); | ||
for (i = 1; i <= s; i++) direction[d][i] = m[i] << (BITS - i); | ||
for (i = s + 1; i <= BITS; i++) { | ||
direction[d][i] = direction[d][i - s] ^ (direction[d][i - s] >> s); | ||
for (var k = 1; k <= s - 1; k++) | ||
direction[d][i] ^= ((a >> (s - 1 - k)) & 1) * direction[d][i - k]; | ||
} | ||
} | ||
} | ||
|
||
next() { | ||
if (this.count === 0) { | ||
this.count++; | ||
return this.zero.slice(); | ||
} | ||
let v = []; | ||
let c = 1; | ||
let value = this.count - 1; | ||
while ((value & 1) == 1) { | ||
value >>= 1; | ||
c++; | ||
} | ||
for (i = 0; i < this.dimension; i++) { | ||
this.x[i] ^= this.direction[i][c]; | ||
v[i] = this.x[i] / SCALE; | ||
} | ||
this.count++; | ||
return v; | ||
} | ||
} | ||
|
||
function sobol(dim) { | ||
return new Sobol(dim); | ||
} | ||
|
||
export default sobol; |
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 @@ | ||
var version = "0.1.0"; export default version; |
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 @@ | ||
var tape = require("tape"), | ||
quant = require('../'); | ||
|
||
|
||
tape('quant version', function(test) { | ||
test.ok(quant.version); | ||
test.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,20 @@ | ||
var tape = require("tape"), | ||
quant = require('../'); | ||
|
||
|
||
tape('test sobol constructor', function(test) { | ||
var sobol = quant.sobol(1); | ||
test.equal(sobol.dimension, 1); | ||
test.equal(sobol.count, 0); | ||
test.end(); | ||
}); | ||
|
||
tape('test sobol next', function(test) { | ||
var sobol = quant.sobol(1); | ||
var v = sobol.next(); | ||
test.ok(v); | ||
test.equal(sobol.count, 1); | ||
test.notEqual(v, sobol.next()); | ||
test.end(); | ||
}); | ||
|