Re: [eigen] Unsupported Polynomial solver

[ Thread Index | Date Index | More Archives ]


the modification happened in the default (i.e., "development") branch, after the initial 3.3 release. Usually, we don't backport added features, but only bug-fixes to the stable branch. However, there is no strict rule about this, especially if this is not too complicated.

So no objections from me to backport this.


On 21/03/2019 07.20, Oleg Shirokobrod wrote:
Hi Gael,

I mean that this modification was made in some branch but is not included
in any release 3.3.0 - 3.3.7. Would it be possible to make this
modification in the next 3.3.8 release?

On Thu, Mar 21, 2019 at 12:35 AM Gael Guennebaud <gael.guennebaud@xxxxxxxxx>

Hi Oleg,

do you mean a backport to 3.3?


On Wed, Mar 20, 2019 at 3:51 PM Oleg Shirokobrod <
oleg.shirokobrod@xxxxxxxxx> wrote:

Hi Gael,

You finally modified PolynomialSolver.h code for finding roots of
polynomial with complex coefficients and wrote unit test. This enhancement
is very important for signal processing application. This modification of
PolynomialSolver.h and Companion.h are rather trivial and localized. So it
is safe to modify existing code. Would it be possible to include them to
the next release?

Best regards,


On Wed, Nov 23, 2016 at 5:09 PM Gael Guennebaud <
gael.guennebaud@xxxxxxxxx> wrote:



On Wed, Nov 23, 2016 at 3:39 PM, Gael Guennebaud <
gael.guennebaud@xxxxxxxxx> wrote:

Sorry for late reply, but thanks for the patches.

Regarding the eigen-solver choice issue, it's possible to automatically
use the right one based on NumTraits<Scalar>::IsComplex and conditional<>.

We would also need to extended the unit test to cover complexes.


On Tue, Nov 8, 2016 at 3:41 PM, Oleg Shirokobrod <
oleg.shirokobrod@xxxxxxxxx> wrote:

Dear list,

Polynomial solver currently finds roots only for real polynomial
coefficients. Having Eigen::ComplexEigenSolver lets Polynomial module to
compute roots for complex polynomial coefficients. I have made necessary
modifications. I have attached corresponding patch files. Unfortunately
module cannot deduce type of the solver from partial specialization of
corresponding matrix type, such that

template<typename RealScalar> class EigenSolver {};

template<typenameRealScalar> class
EigenSolver<Eigen::Matrix<RealScalar,_Deg,_Deg> > {// EigenSolver };

template<typename  RealScalar> class
EigenSolver<Eigen::Matrix<std::complex<RealScalar>,_Deg,_Deg > > {

So I have to add additional template parameter EigenSolverType with
default value for real coefficients:

template< typename _Scalar, int _Deg , typename EigenSolverType =
EigenSolver<Matrix<_Scalar,_Deg,_Deg> > >
class PolynomialSolver : public PolynomialSolverBase<_Scalar,_Deg>{};

I have to replace in number of places in the file Companion.h (mainly
in functions balanced() and balance()) Scalar with RealScalar, where
variables are really real.

With this code I have run test against Matlab and it gave similar

VectorXcd roots = VectorXcd::Random(4);
VectorXcd polynomialCoefficients;
roots_to_monicPolynomial(roots, polynomialCoefficients);

cout << "roots : " << endl;
cout << setprecision(14) << roots << endl;
cout << "polynomialCoefficients : " << endl;
cout << setprecision(14)  << polynomialCoefficients << endl;

PolynomialSolver<std::complex<double>, Dynamic,
ComplexEigenSolver<MatrixXcd> > psolve(polynomialCoefficients);

VectorXcd computedRoots = psolve.roots();

cout << "computedRoots : " << endl;
cout << setprecision(14) << computedRoots << endl;

for(int index = 0; index < computedRoots.size(); ++index)
     cout << setprecision(14) << "polynom at  computedRoots * 1.0 e-11:
" << poly_eval(polynomialCoefficients, computedRoots(index))*1.0e11 << endl;

roots :

polynomialCoefficients :

computedRoots :

polynom at  computedRoots * 1.0 e-11:
polynom at  computedRoots * 1.0 e-11:
polynom at  computedRoots * 1.0 e-11:
polynom at  computedRoots * 1.0 e-11:

Matlab for the same coefficients gives following roots (remember that
matlab array of coefficients and Eigen one are reversed to each other)

computedRoots :
0.127170628986480 - 0.997497482222969i
0.617481002227849 - 0.613391521958071i
0.791924802392650 - 0.299417096469009i
-0.040253913998840 + 0.170018616290780i

Best regards,

Oleg Shirokobrod

 Dr.-Ing. Christoph Hertzberg

 Besuchsadresse der Nebengeschäftsstelle:
 Robotics Innovation Center
 Robert-Hooke-Straße 5
 28359 Bremen, Germany

 Postadresse der Hauptgeschäftsstelle Standort Bremen:
 Robotics Innovation Center
 Robert-Hooke-Straße 1
 28359 Bremen, Germany

 Tel.:     +49 421 178 45-4021
 Zentrale: +49 421 178 45-0
 E-Mail:   christoph.hertzberg@xxxxxxx

 Weitere Informationen:
  Deutsches Forschungszentrum für Künstliche Intelligenz GmbH
  Trippstadter Strasse 122, D-67663 Kaiserslautern, Germany

  Prof. Dr. Jana Koehler (Vorsitzende)
  Dr. Walter Olthoff

  Vorsitzender des Aufsichtsrats:
  Prof. Dr. h.c. Hans A. Aukes
  Amtsgericht Kaiserslautern, HRB 2313

Mail converted by MHonArc 2.6.19+