GithubHelp home page GithubHelp logo

knut0815 / loci Goto Github PK

View Code? Open in Web Editor NEW

This project forked from glis-glis/loci

0.0 0.0 0.0 80 KB

Smooth Cubic Multivariate Local Interpolations

License: Mozilla Public License 2.0

Makefile 0.46% C 80.02% Python 19.34% C++ 0.18%

loci's Introduction

loci

Smooth Cubic Multivariate Local Interpolations

travis-ci

loci is a shared library for interpolations in up to 4 dimensions. In order to calculate the coefficients of the cubic polynom, only local values are used: The data itself and its first-order derivatives. This is in contrast to splines, where the coefficients are not calculated using derivatives, but non-local data, which can leed to over-smoothing the result.

Developement

The library has been developed using test-driven developement (TDD), i.e. a test case is written before the actual function is implemented. That way, one makes sure every test can fail, and that the actual function passes the test.

The library has been tested with double precision. It is possible to compile with single precision, by defining the variable REAL=float. This has however not been tested yet.

The library can be linked both statically and dynamically. A python-wrapper is available in python/loci, which is only working with double precision at this moment.

Usage

Clone a copy of loci to your local computer and make the shared library:

git clone https://github.com/AFueglistaler/loci.git
cd loci
make

The shared library will be in lib/libloci.so, the header-files in include/, the python module in python/loci.

Testing

To test the statically linked test-files, type

make test

To test the dynamically linked python-test-files, type

make pytest

Examples

The C-testfiles in test/ and the python-testfiles in python/test are commented and show the functionality of all functions.

Python Usage

In order to use loci in Python, you first need to set the LD_LIBRARY_PATH and PYTHONPATH variables:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_to_loci/lib
export PYTHONPATH=$PYTHONPATH:path_to_loci/python

The following code shows the basic usage of the library in two dimensions. The usage in other dimensions is identical.

#import numpy and scipy
from numpy import *
from scipy import *
# import classes
from loci import Interpolation, Range

# Define functions and derivative
A=2.
B=0.5
def f(x, y):    return log(A*x**2 + B*y**2 + 1)
def f_x(x, y):  return 2*A*x/(A*x**2 + B*y**2 + 1)
def f_y(x, y):  return 2*B*y/(A*x**2 + B*y**2 + 1)
def f_xy(x, y): return -4*A*B*x*y/(A*x**2 + B*y**2 + 1)**2

# Define interpolation ranges
rx  = Range(1., 0.1, 10)    #x0 =1., dx=0.1, lenght=10
ry  = Range(-2., 0.5, 20)

# Create interpolation
ip  = Interpolation(rx, ry, f, f_x, f_y, f_xy)

# Interpolate at a given point
ip.interpolate(rx.x0 + 0.4, ry.x0 + 7.3)
# Interpolate derivatives in x and y
ip.diff_x(rx.x0 + 0.4, ry.x0 + 7.3)
ip.diff_y(rx.x0 + 0.4, ry.x0 + 7.3)
# Interpolate 2nd-order x and 3rd-order y derivative
ip.diff(2, 3, rx.x0 + 0.4, ry.x0 + 7.3)

# Interpolate out of bounds
ip.interpolate(rx.x0 - 1, ry.x0 - 1)    #returns nan

# create random points in ranges rx and ry
N   = int(1e7)
xs  = (rx.dx*rx.len)*rand(N) + rx.x0
ys  = (ry.dx*ry.len)*rand(N) + ry.x0

# Map interpolation on points
ip.map(xs, ys)
# Map derivativews in x and y on points
ip.map_x(xs, ys)
ip.map_y(xs, ys)
# Map 2nd-order x and 3rd-order y derivative on points
ip.map_diff(2, 3, xs, ys)

loci's People

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.