Giter Site home page Giter Site logo

2D cubic interpolation about libinterpolate HOT 5 CLOSED

cd3 avatar cd3 commented on August 18, 2024
2D cubic interpolation

from libinterpolate.

Comments (5)

Leersmaekers avatar Leersmaekers commented on August 18, 2024

I think I may have found the issue. Lines 198 to 204 now are:

      fp = (*Z)(i,jp);
      fm = (*Z)(i,jm);
      fy01 = (fp - fm) / yL; // <<<<<<

      fp = (*Z)(i+1,jp);
      fm = (*Z)(i+1,jm);
      fy11 = (fp - fm) / yL; // <<<<<<

And should be replaced by:

      fp = (*Z)(i,jp);
      fm = (*Z)(i,jm);
      fy01 = (fp - fm) / dy; // <<<<<<

      fp = (*Z)(i+1,jp);
      fm = (*Z)(i+1,jm);
      fy11 = (fp - fm) / dy; // <<<<<<

Kind regards,
Laurent Keersmaekers

from libinterpolate.

CD3 avatar CD3 commented on August 18, 2024

Thank you for the issue, the 2D interpolators are not nearly as well tested as 1D.

I will not be able to look at this very soon, but when I have time I will go back through the derivation of the 2D cubic spline method.

In the mean time, would you be able to implement a unit test that fails on this bug so I can implement a fix that gives the desired behavior?

from libinterpolate.

Leersmaekers avatar Leersmaekers commented on August 18, 2024
#include "pch.h"
#include "CppUnitTest.h"
#include <libInterpolate/Interpolate.hpp>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest1
{
	TEST_CLASS(UnitTest1)
	{
	public:

		TEST_METHOD(TestMethod1)
		{
			std::vector<double> x2, y2, z2;
			double valTest = 2.5;

			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					x2.push_back((double)i);
					y2.push_back((double)j);
					z2.push_back((double)i * (double)j);
				}
			}

			_2D::BicubicInterpolator<double> interpBiCub;
			interpBiCub.setData(x2, y2, z2);

			double valBiCub = interpBiCub(valTest, valTest);
			double valBiTh = valTest * valTest;

			bool success = false;

			if (fabs(valBiTh - valBiCub) < 1.0e-8)
			{
				success = true;
			}

			Assert::AreEqual(success, true);
		}
	};
}

from libinterpolate.

Leersmaekers avatar Leersmaekers commented on August 18, 2024

In the above code, I used a tolerance of 1.0e-8. Since the function I used is quadratic w.r.t. to the combination of x and y, the cubic interpolator should always be able to stay within this accuracy without any issues. The original interpolator will fail, because the difference between the theoretical value and the interpolated value will exceed 1.0e-8 (by far).

from libinterpolate.

CD3 avatar CD3 commented on August 18, 2024

Thanks for reporting the issue. I went through the method this weekend and implemented your fix.

from libinterpolate.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.