Commit 8ad256dd authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fixing sum of weights

parent 814e77cc
...@@ -53,13 +53,6 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -53,13 +53,6 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
}; };
} }
// for normalization
var WSUM = 0;
for(var i=0;i<n;i++){
WSUM += w(i,v)
}
while(!stop){ while(!stop){
counter++ counter++
...@@ -88,11 +81,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -88,11 +81,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
//functions //functions
function iterate(v,n,r,dr){ function iterate(v,n,r,dr){
var wsum = ws(v,n)
var J = jacobian(v,n,dr) var J = jacobian(v,n,dr)
var Jt = numbers.matrix.transpose(J) var Jt = numbers.matrix.transpose(J)
for(var i=0;i<n;i++){ for(var i=0;i<n;i++){
J = numbers.matrix.rowScale(J,i,wn(i,v)) J = numbers.matrix.rowScale(J,i,wn(i,v,wsum))
} }
// JtJ // JtJ
...@@ -105,7 +100,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -105,7 +100,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
var V = [] var V = []
for(var i=0;i<n;i++){ for(var i=0;i<n;i++){
V.push([wn(i,v)*r(i,v)]) V.push([wn(i,v,wsum)*r(i,v)])
} }
var delta = numbers.matrix.multiply(J,V) var delta = numbers.matrix.multiply(J,V)
...@@ -161,12 +156,22 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -161,12 +156,22 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
} }
// normalized weight // normalized weight
function wn(i,v){ function wn(i,v,wsum){
return w(i,v)/wsum
}
// sum of weights for normalization
function ws(v,n){
var wsum = 0;
for(var i=0;i<n;i++){ for(var i=0;i<n;i++){
WSUM += w(i,v) wsum += w(i,v)
} }
return w(i,v)/WSUM
return wsum
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment