Update on dom.js and math functions

master
Steve L. Nyemba 10 years ago
parent fb014406a4
commit 14b54aded0

@ -35,12 +35,13 @@ jx.dom.exists = function(id){
* @returns {undefined} * @returns {undefined}
*/ */
jx.dom.remove = function(id){ jx.dom.remove = function(id){
var _item = null;
if (id.constructor == String){ if (id.constructor == String){
item = jx.dom.get.instance(id) _item = jx.dom.get.instance(id)
}else{ }else{
item = id ; _item = id ;
} }
item.parentNode.removeChild(item) ; _item.parentNode.removeChild(_item) ;
} }
@ -51,7 +52,7 @@ jx.dom.remove = function(id){
* @param _child child dom object * @param _child child dom object
*/ */
jx.dom.append = function(id,_child){ jx.dom.append = function(id,_child){
_parent = jx.dom.get.instance(id) ; var _parent = jx.dom.get.instance(id) ;
_parent.appendChild(_child) ; _parent.appendChild(_child) ;
} }

@ -95,6 +95,17 @@ jx.math.avg = function(lxi,lni){
} }
}; };
/**
* This function will repete a value a given number of times
* @pre times > 0
*/
jx.math.rep = function(value,times){
var lvalues = []
for(var i=0; i < times; i++){
lvalues.push(value) ;
}
return lvalues;
}
jx.math.mean = jx.math.avg ; jx.math.mean = jx.math.avg ;
jx.math.pow = Math.pow jx.math.pow = Math.pow
jx.math.sd = function(lxi,lni){ jx.math.sd = function(lxi,lni){
@ -103,7 +114,6 @@ jx.math.sd = function(lxi,lni){
sqr = [] ; sqr = [] ;
for(var i=0; i < lxi.length ;i++){ for(var i=0; i < lxi.length ;i++){
console.log(lxi[i])
sqr[i] = jx.math.pow((Number(lxi[i])-mean),2 ) ; sqr[i] = jx.math.pow((Number(lxi[i])-mean),2 ) ;
} }
@ -111,6 +121,27 @@ jx.math.sd = function(lxi,lni){
return jx.math.sqrt(total/(N-1)) ; return jx.math.sqrt(total/(N-1)) ;
} ; } ;
/**
* This function computes the correlation between two vectors
* @pre x1.length == x2.length
*/
jx.math.cor = function(x1,x2){
return jx.math.cov(x1,x2) / (jx.math.sd(x1)*jx.math.sd(x2))
}
/**
* This function will compute the covariance of 2 vectors
* @pre x1.length == x2.length
*/
jx.math.cov = function(x1,x2){
var u1 = jx.math.mean(x1) ;
var u2 = jx.math.mean(x2) ;
var N = x1.length ;
var value = 0
for(var i in x1){
value += (x1[i] - u1) * (x2[i] - u2)
}
return value / (N - 1)
}
/** /**
* Computes the factorial of a given value * Computes the factorial of a given value

Loading…
Cancel
Save