Giter VIP home page Giter VIP logo

vectfit's Introduction

Fast Relaxed Vector Fitting Implementation in C++

Travis CI build status

The vectfit function approximates a response fs (generally a vector) with a rational function:

vf

where pj and rj are poles and residues in the complex plane and cn are the polynomial coefficients. When fs is a vector, all elements become fitted with a common pole set.

The identification is done using the pole relocating method known as Vector Fitting [1] with relaxed non-triviality constraint for faster convergence and smaller fitting errors [2], and utilization of matrix structure for fast solution of the pole identifion step [3].

  • [1] B. Gustavsen and A. Semlyen, "Rational approximation of frequency domain responses by Vector Fitting", IEEE Trans. Power Delivery, vol. 14, no. 3, pp. 1052-1061, July 1999.
  • [2] B. Gustavsen, "Improving the pole relocating properties of vector fitting", IEEE Trans. Power Delivery, vol. 21, no. 3, pp. 1587-1592, July 2006.
  • [3] D. Deschrijver, M. Mrozowski, T. Dhaene, and D. De Zutter, "Macromodeling of Multiport Systems Using a Fast Implementation of the Vector Fitting Method", IEEE Microwave and Wireless Components Letters, vol. 18, no. 6, pp. 383-385, June 2008.

All credit goes to Bjorn Gustavsen for his MATLAB implementation. (http://www.sintef.no/Projectweb/VECTFIT/)

Implementation

The vectfit functions are implemented in C++, using xtensor for multi-dimensional arrays and xtensor-blas for linear-algebra operations. The C++ functions are wrapped into a Python extension module through xtensor-python and pybind11.

import vectfit as m
import numpy as np

s = np.array([3., 3.5, 4., 4.5, 5., 5.5, 6.])
f = np.array([[4.98753117e-02, 3.09734513e-01, 1.18811881e+00,
               6.53846154e+00, 2.20000000e+02, 1.03846154e+01,
               3.16831683e+00],
             [-4.98753117e-01,-2.21238938e-01, 9.90099010e-01,
               9.61538462e+00, 4.00000000e+02, 2.11538462e+01,
               6.93069307e+00]])
weight = 1.0/f
init_poles = [4.5 + 0.045j, 4.5 - 0.045j]
poles, residues, cf, fit, rms = m.vectfit(f, s, init_poles, weight)

Installation

Prerequisites

  • C++ compiler such as g++

    sudo apt install g++

  • Necessary libraries including xtensor, xtensor-blas(>=0.15), xtensor-python, and pybind11

    Refer to 'installation steps on Ubuntu' for building necessary libraries from source, or, it is convenient to install all the libraries through conda package manager:

    conda install -c conda-forge xtensor-blas xtensor-python

Build and install

On Unix (Linux, OS X)

  • clone this repository
  • git clone https://github.com/liangjg/vectfit.git
  • pip install ./vectfit

On Windows (Requires Visual Studio 2015)

  • For Python 3.5:

    • clone this repository
    • pip install ./vectfit
  • For earlier versions of Python, including Python 2.7:

    xtensor requires a C++14 compliant compiler (i.e. Visual Studio 2015 on Windows). Running a regular pip install command will detect the version of the compiler used to build Python and attempt to build the extension with it. We must force the use of Visual Studio 2015.

    • clone this repository
    • "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64
    • set DISTUTILS_USE_SDK=1
    • set MSSdk=1
    • pip install ./vectfit

    Note that this requires the user building vectfit to have registry edition rights on the machine, to be able to run the vcvarsall.bat script.

Windows runtime requirements

On Windows, the Visual C++ 2015 redistributable packages are a runtime requirement for this project. It can be found here.

If you use the Anaconda python distribution, you may require the Visual Studio runtime as a platform-dependent runtime requirement for you package:

requirements:
  build:
    - python
    - setuptools
    - pybind11

  run:
   - python
   - vs2015_runtime  # [win]

Building the documentation

Documentation for the example project is generated using Sphinx. Sphinx has the ability to automatically inspect the signatures and documentation strings in the extension module to generate beautiful documentation in a variety formats. The following command generates HTML-based reference documentation; for other formats please refer to the Sphinx manual:

  • cd vectfit/docs
  • make html

Running the tests

Running the tests requires pytest.

py.test .

vectfit's People

Contributors

liangjg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vectfit's Issues

Need to allow complex inputs

The main application for vectfit is when the input values s are imaginary, and the output values f are complex. But your program only allows s and f to be real. Do you think you could modify the program so that it can do this?

The original matlab program can do this. And the examples given in the original paper are of this form.

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.