Skip to content

Instantly share code, notes, and snippets.

@amergin
amergin / dc.problem.seriesChart.js
Created December 30, 2014 16:50
Problem with DC.js series chart grouping and sorting
var createSVG = function($scope, config) {
var getLabel = function(variable, circle) {
return variable + " (" + circle.name() + ")";
};
var getLabels = function() {
var ret = [];
_.each(config.groups, function(group, name) {
_.each( $scope.filterOnSet(group, name).all(), function(obj) {
var circle = obj.key.circle;
this.getReducedSTD = function(dimensionGroup, variable) {
// see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Decremental_algorithm
var reduceAdd = function (p, v) {
var obj = p;
var value = +v.variables[variable];
if( _.isNaN(value) ) {
//pass
} else {
obj.n = obj.n + 1;
var oldM2 = obj.M2;
this.getReducedSTD2 = function(dimensionGroup, variable) {
// see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
var reduceAdd = function (p, v) {
var value = +v.variables[variable];
if( _.isNaN(value) ) {
//pass
}
else {
if( p.n === 0 ) {
p.k = value;
var t = beta / _sqrt;
console.log("degrees", degrees);
console.log("beta", beta, "sqrt", _sqrt);
console.log("t=", t, "tprob=", statDist.tprob(degrees, t));
var pvalue = 2 * (1 - statDist.tprob(degrees, t));
console.log("pvalue=", pvalue);
Tulosteet ylläolevasta:
degrees 82 (program):64
beta 1.0097334538696747 sqrt 0.015688694906613447 (program):65
@amergin
amergin / stretch_colors.js
Last active August 29, 2015 14:24
Stretch available color range to be used based on the values
// Specs:
// - As a default, the colour range should be scaled so, that at least 70% (..ish) of the colour range is available for the data shown.
// Example: we have a map with lowest positive correlation at r=0.85 and highest at r=0.99 while the negative correlations span from r=-0.2 to r=-0.35. The desired colour range would then be as follows:
// 100% red at r=0.99,
// 30% red at r=0.85,
// white at r=0,
// 30% blue at r=-0.2 and
// 100% blue at r=-0.35.
function CustomScale() {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amergin
amergin / grid-config.js
Last active August 29, 2015 14:25
Overlapping grid windows, angular-gridster
$scope.itemMapper = {
sizeX: 'window.grid.size.x',
sizeY: 'window.grid.size.y',
row: 'window.grid.position.row',
col: 'window.grid.position.col'
};
var emitResize = function($element) {
dc.events.trigger( function() {
$rootScope.$emit('gridster.resize', $element);
@amergin
amergin / output.txt
Last active August 29, 2015 14:26
Math.js regression performance problem, code
_xMatrixTransp size = 2,4084
_xMatrix size = 4084
_normalTargetData size = 4084
# -*- coding: utf-8 -*-
# Modified lightsocket import script, based on Lightsocket
# example script by James Thornton (http://jamesthornton.com)
# mundane modification stuff
import os
import commands
import sys
import datetime
import re # regexp
# -*- coding: utf-8 -*-
# Class implementation for importing stuff to Neo4j
# based on Lightsocket examples by
#James Thornton (http://jamesthornton.com)
from java.lang import Long, Double, Integer, String
from com.tinkerpop.rexster.util import ElementHelper
from com.tinkerpop.blueprints.pgm.impls.neo4j import Neo4jGraph
from com.tinkerpop.blueprints.pgm.impls.neo4jbatch import Neo4jBatchGraph