Commit 926361c2 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

added weights to least square fitting

parent 181b5dea
...@@ -175,7 +175,21 @@ function hll_dr_dh_i(i,v){ ...@@ -175,7 +175,21 @@ function hll_dr_dh_i(i,v){
*/ */
function hll_w_i(i,v){ function hll_w_i(i,v){
return 1;
var mark = Data.markers[i];
var xi = mark.align.x;
var yi = mark.align.y;
var zi = mark.align.z;
//var arad = 0.0004404;
var D = 100;
var d = Math.sqrt(Math.pow(xi,2)+Math.pow(yi,2)+Math.pow(zi,2));
var res = d/D;
res = (res>1)?1:res;
return res;
} }
/** /**
...@@ -260,8 +274,8 @@ function art_l_i(i){ ...@@ -260,8 +274,8 @@ function art_l_i(i){
} }
function art_w_i(i,v){ function art_w_i(i,v){
return 1; //return 1;
//return 1/art_l_i(i); return 1/art_l_i(i);
} }
/** /**
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @copyright Copyright (C) 2017 Elphel Inc. * @copyright Copyright (C) 2017 Elphel Inc.
* @authors Oleg Dzhimiev <oleg@elphel.com> * @authors Oleg Dzhimiev <oleg@elphel.com>
* *
* @license: GPL-3.0 * @license: GPL-3.0+
* *
* @licstart The following is the entire license notice for the * @licstart The following is the entire license notice for the
* JavaScript code in this page. * JavaScript code in this page.
...@@ -53,6 +53,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -53,6 +53,13 @@ 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++
...@@ -84,8 +91,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -84,8 +91,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
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++){
J = numbers.matrix.rowScale(J,i,wn(i,v))
}
// JtJ // JtJ
J = numbers.matrix.multiply(Jt,J) J = numbers.matrix.multiply(Jt,J)
// (Jt x J)^-1 // (Jt x J)^-1
J = numbers.matrix.inverse(J) J = numbers.matrix.inverse(J)
// (Jt x J)^-1 x Jt // (Jt x J)^-1 x Jt
...@@ -93,7 +105,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -93,7 +105,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([r(i,v)]) V.push([wn(i,v)*r(i,v)])
} }
var delta = numbers.matrix.multiply(J,V) var delta = numbers.matrix.multiply(J,V)
...@@ -114,16 +126,17 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -114,16 +126,17 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
function sigma(v,n,r){ function sigma(v,n,r){
var sum = 0 var sum = 0
var wsum = 0 //var wsum = 0
for(var i=0;i<n;i++){ for(var i=0;i<n;i++){
sum += w(i,v)*r(i,v)*r(i,v) sum += wn(i,v)*r(i,v)*r(i,v)
wsum += w(i,v) //wsum += w(i,v)
} }
//console.log("sum = "+sum+" wsum = "+wsum); //console.log("sum = "+sum+" wsum = "+wsum);
sum = Math.sqrt(sum/wsum) //sum = Math.sqrt(sum/wsum)
sum = Math.sqrt(sum)
return sum return sum
...@@ -137,7 +150,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -137,7 +150,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
var row = [] var row = []
for(var j=0;j<dr.length;j++){ for(var j=0;j<dr.length;j++){
row.push(w(i,v)*dr[j](i,v)) row.push(dr[j](i,v))
} }
J[i] = row J[i] = row
...@@ -147,4 +160,9 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){ ...@@ -147,4 +160,9 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
} }
// normalized weight
function wn(i,v){
return w(i,v)/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