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){
*/
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){
}
function art_w_i(i,v){
return 1;
//return 1/art_l_i(i);
//return 1;
return 1/art_l_i(i);
}
/**
......
......@@ -4,7 +4,7 @@
* @copyright Copyright (C) 2017 Elphel Inc.
* @authors Oleg Dzhimiev <oleg@elphel.com>
*
* @license: GPL-3.0
* @license: GPL-3.0+
*
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
......@@ -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){
counter++
......@@ -84,8 +91,13 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
var J = jacobian(v,n,dr)
var Jt = numbers.matrix.transpose(J)
for(var i=0;i<n;i++){
J = numbers.matrix.rowScale(J,i,wn(i,v))
}
// JtJ
J = numbers.matrix.multiply(Jt,J)
// (Jt x J)^-1
J = numbers.matrix.inverse(J)
// (Jt x J)^-1 x Jt
......@@ -93,7 +105,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
var V = []
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)
......@@ -114,16 +126,17 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
function sigma(v,n,r){
var sum = 0
var wsum = 0
//var wsum = 0
for(var i=0;i<n;i++){
sum += w(i,v)*r(i,v)*r(i,v)
wsum += w(i,v)
sum += wn(i,v)*r(i,v)*r(i,v)
//wsum += w(i,v)
}
//console.log("sum = "+sum+" wsum = "+wsum);
sum = Math.sqrt(sum/wsum)
//sum = Math.sqrt(sum/wsum)
sum = Math.sqrt(sum)
return sum
......@@ -137,7 +150,7 @@ numbers.calculus.GaussNewton = function(v,n,r,dr,eps,w){
var row = []
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
......@@ -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