You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
6.8 KiB
JavaScript

/**
return max ;
/**
}
jx.math.normalize = function(lvalues){
mean = jx.math.mean(lvalues) ;
sd = jx.math.sd(lvalues) ;
return jx.utils.patterns.visitor(lvalues,function(x){
return ((x - mean) / sd)
})
}
/**
* This function will scale a feature vector over it's range
*/
jx.math.scale = function(lvalues,percent){
max = jx.math.max(lvalues) ;
min = jx.math.min(lvalues) ;
return jx.utils.patterns.visitor(lvalues,function(x){
var value = (x - min ) / max ;
if(percent == true){
return (100*value).toFixed(2)
}else{
return value ;
}
})
}
/**
* This is a lightweight map reduce infrastructure
*/
jx.mr = {} ;
/**
* This function will perform a map on a given id in rec, then will call emit with the
*/
jx.mr.map = null
/**
* @param keys
* @param values array of values that were mapped
*/
jx.mr.reduce = null;
jx.mr.mapreduce = function(data,fn_map,fn_reduce){
if (fn_map == null){
throw new "Map function is not defined"
}
map = {} ;
emit = function(id,values){
if(map[id] == null){
map[id] = []
}
map[id].push(values);
}
if(data.constructor != Array){
for (id in data){
//rec = data[id] ;
rec = {}
rec['__id'] = id;
rec['data'] = data[id] ;
fn_map(rec,emit)
}
}else{
for (var i=0; i < data.length; i++){
rec = data[i];
fn_map(rec,emit);
//if(i == 2)break;
}
}
if(fn_reduce != null){
keys = jx.utils.keys(map) ;
m = {}
for(var i=0; i < keys.length; i++){
id = keys[i] ;
values = map[id] ;
value = fn_reduce(id,values) ;
id = keys[i] ;
m[id] = value;
}
map = m
}
return map ;
}