forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 10:56 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to use modified Shepard method
PostPosted: Mon Sep 13, 2010 1:27 am 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi

It is my first using of AlgLib. So sorry if I'll wrong.

I have nonuniform mesh with data in some point and I need to recieve approximated value in other point of mesh. And if I understand right I need to use Shepard method ("idwbuildmodifiedshepard") for my purpose.

I have 2D arrary m_Array with double values

Code:
double m_Array[iArrayWidth][iArrayHeight];
//.....
// filling m_Array with value
//....


Then I've created:

Code:
ap::real_2d_array xy;
xy.setlength(iArrayWidth, iArrayHeight);

for ( int i = 0; i < iArrayHeight; i++ )
{
   for ( int j = 0; j < iArrayWidth; j++ )
   {
      xy(i,j) = m_Array[i][j];
   }
}

// pass to the idwbuildmodifiedshepard


Is it true when I fill xy array with my values?

Thanks a lot.
Best regards, Aleksey.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Mon Sep 13, 2010 2:05 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
You should store your points in rows, one row = one point. First iArrayWidth-1 columns store coordinates, last column stores function value.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Mon Sep 13, 2010 4:20 pm 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Thanks for reply! ;)
Did you mean that should I write something like that

Code:
ap::real_2d_array xy;
xy.setlength(m_iArrayHeight, m_iArrayWidth);

for ( int i = 0; i < m_iArrayHeight; i++ )
{
   for ( int j = 0; j < m_iArrayWidth; j++ )
   {
      xy(i*j,0) = XXX;
      xy(i*j,1) = m_ppArray[i][j].dValue;
   }
}


And if it true, what is XXX ?

Thanks
Best regards, Aleksey.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Mon Sep 13, 2010 7:48 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
It should be something like

Code:
ap::real_2d_array xy;
xy.setlength(NumberOfPoints, NumberOfCoordinates+1); // NumberOfCoordinates=3, for example

for ( int i = 0; i < NumberOfPoints; i++ )
{
    xy(i,0) = x[i]; // x-value
    xy(i,1) = y[i]; // y-value
    xy(i,2) = z[i]; // z-value
    xy(i,3) = f[i]; // function value
}
}


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Tue Sep 14, 2010 1:13 am 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi, Sergey. Thank you very much! :) It is now clearly for me.

Now I fill my array with following way
Code:
xy.setlength(m_iArrayHeight * m_iArrayWidth, 3);

int k = 0;
for ( int i = 0; i < m_iArrayHeight; i++ )
{
   for ( int j = 0; j < m_iArrayWidth; j++ )
   {
      xy(k, 0) = m_ppArray[i][j].point.x;
      xy(k, 1) = m_ppArray[i][j].point.y;
      xy(k, 2) = m_ppArray[i][j].dValue;
      k++;
   }
}

Now I have another question. Then I pass "xy" to "idwbuildmodifiedshepard" method, which returns IDW interpolant - Z. And if I see right, Z will contain approximated values. So which field of Z contains these values? I've tried following code:
Code:
k = 0;
for ( int i = 0; i < m_iArrayHeight; i++ )
{
   for ( int j = 0; j < m_iArrayWidth; j++ )
   {
      double val = Z.q(k++, 2);
   }
}

But values of "val" are the same as in m_ppArray[i][j].dValue, i.e. it no changed. Maybe I've made something wrong again?

Thanks a lot!
Best regards, Aleksey.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Tue Sep 14, 2010 4:50 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
You should use idwcalc() function to calculate the value of the interpolant at the points you need. Never try to work with its fields directly.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Tue Sep 14, 2010 2:56 pm 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi Sergey. Thank you again! :)

To calculate the value of the interpolant I use following code:
Code:
ap::real_1d_array x;
idwinterpolant z1;
int n = m_iArrayWidth * m_iArrayHeight;

idwbuildmodifiedshepard(xy, n, 2, 1, 15, 25, z1);

x.setlength(nx);

for( int i = 0; i < n; i++ )
{
   x(0) = xy(i, 2);
   //ap::vmove(&x(0), 1, &xy(i, 2), 1, ap::vlen(0,nx-1));
   double val = idwcalc(z1, x);
   idwerrors = ap::fp_neq(val, xy(i,nx));
}

In my case method idwcalc almost always returns 0 and sometimes -1.7054547436862421e+073. So I think I've made something wrong again. Could you help me once again please?

Thanks
Best regards, Aleksey.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Wed Sep 15, 2010 7:40 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Can you post here (as zip-file) your program with all its data? It is hard to tell what's wrong without looking into it. I think that IDW is too robust to produce such large deviations (1E+73), but I have to look at it myself.


Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Thu Sep 16, 2010 1:22 am 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hi, Sergey

I've added to archive "signal.txt" file with my data and cpp file with one method which reads signal.txt file and calcs interpolant.

Thank for your attention paid!
Best regards, Aleksey.


Attachments:
IDWInterpolation.zip [1.2 KiB]
Downloaded 1554 times
Top
 Profile  
 
 Post subject: Re: How to use modified Shepard method
PostPosted: Fri Sep 17, 2010 3:29 pm 
Offline

Joined: Mon Sep 13, 2010 12:58 am
Posts: 14
Hey Sergey.

Did you see my example code? Is it wrong? Or may be did you want something else?

Thanks!
Best regards, Aleksey.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group