|
From: vaneric on 23 Jul 2008 01:38 hi i am studying linear algebra and was reading thru some code processing image data.i came across a piece of code that does some normalising as below public demoNorm(double[][] eigenfacesArray){ for(int i=0;i<eigenfacesArray.length;i++){ double norm=norm(eigenfacesArray[i]); for(int x=0;x<eigenfacesArray[i].length;x++){ double v=eigenfacesArray[i][x]; eigenfacesArray[i][x]=v/norm; } } } private double norm(double[][] x){ int nr= x.length; int nc= x[0].length; double val=0.0; for(int r= 0; r< nr; r++){ for(int c= 0; c< nc; c++){ val+= (x[r][c])* (x[r][c]) ; } } return val; } when i tried this for a sample double[][] as below double[][]=new double[][]{ {2.4,6.4,1.2,7.6,4.3}, {1.5,3.1,6.4,5.7,2.5}, {7.8,6.8,4.6,3.5,4.3}, {9.8,7.8,6.5,1.2,3.3} }; i found that norm() yields a value equal to square of Frobenius norm ( ie ,norm()==> 586.410 while Frob norm=24.2159) I am no expert in linear algebra,so i want to know if this norm has any particular name.Also,is the above way of normalisation valid? or do i have to find the sq.root of norm before i divide the elements of the double[][]? can some experts help me with this? thanks eric
From: Eric Sosman on 23 Jul 2008 08:58 vaneric wrote: > hi > i am studying linear algebra and was reading thru some code processing > image data.i came across a piece of code that does some normalising as > below > > public demoNorm(double[][] eigenfacesArray){ > for(int i=0;i<eigenfacesArray.length;i++){ > double norm=norm(eigenfacesArray[i]); > for(int x=0;x<eigenfacesArray[i].length;x++){ > double v=eigenfacesArray[i][x]; > eigenfacesArray[i][x]=v/norm; > > } > > } > > } > > private double norm(double[][] x){ Note that this is not the norm() method called by the code above. This one takes a double[][] an argument, but the earlier code uses a different method that takes a double[]. > int nr= x.length; > int nc= x[0].length; > double val=0.0; > for(int r= 0; r< nr; r++){ > for(int c= 0; c< nc; c++){ > val+= (x[r][c])* (x[r][c]) ; > } > } > return val; > } > > > when i tried this for a sample double[][] as below > double[][]=new double[][]{ This won't compile. > {2.4,6.4,1.2,7.6,4.3}, > {1.5,3.1,6.4,5.7,2.5}, > {7.8,6.8,4.6,3.5,4.3}, > {9.8,7.8,6.5,1.2,3.3} > }; > > i found that norm() yields a value equal to square of Frobenius norm > ( ie ,norm()==> 586.410 while Frob norm=24.2159) > > I am no expert in linear algebra,so i want to know if this norm has > any particular name.Also,is the above way of normalisation valid? or > do i have to find the sq.root of norm before i divide the elements of > the double[][]? can some experts help me with this? How can I help you understand code you haven't shown? Look at it this way: You're dealing with some body of code which we'll call X. Instead of posting X and asking about it, you instead post X', an inaccurate paraphrase of X. There's not much I can do with X' as it stands -- as noted above, it won't even compile -- so I change it to turn it into X'', my guess about the nature of the hidden X. What are the chances that X'' is the same as X? If I explain a fine point of X'', will that help you understand what X is doing? "Doctor, look at this X-ray of my foot and tell me why I'm in such pain." "Vaneric, this is an X-ray of a hand." "Oh c'mon, Doc, hands and feet are evolutionary cousins, not really that much different. Hurry up and get on with the diagnosis, will you?" -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: vaneric on 23 Jul 2008 14:12 On Jul 23, 5:58 pm, Eric Sosman <esos...(a)ieee-dot-org.invalid> wrote: > How can I help you understand code you haven't shown? sorry, my mistake in copying the methods there were 2 versions of norm(), one that takes in a double[][] and another that takes in a double[] for the demoNorm() above,the following method was used private double norm(double[] x){ double val=0.0; for(int i=0;i<x.length;i++){ val+=(x[i]*x[i]); } return val; } for my sample double[][] i used the other version (which takes in a double[][]) sorry again for the silly mistake of a beginner eric p.s: great reply..really enjoyed it!
|
Pages: 1 Prev: Problem with Access concatenation Next: Gas Price Database that is java accessible??? |