# forum.alglib.net

ALGLIB forum
 It is currently Mon Jun 24, 2024 3:10 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.

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: NullReferenceException when running minqpoptimizePosted: Tue Feb 15, 2022 3:46 pm

Joined: Tue Feb 15, 2022 3:25 pm
Posts: 3
Hi,

I'm getting a NullReferenceException when running the following
code multiple times:

Code:
// Using ALGLIB to solve a quadratic program
// cf. example_minqp_d_lc1 example on ALGLIBs page
double[,] a = C.ToArray(); // <-- quadratic term in objective function
double[] b = new double[C.RowCount]; // <-- no linear term in objective function
double[] bndl = new double[C.RowCount]; // <-- lower box bound
double[] bndu = Enumerable.Repeat<double>(Double.PositiveInfinity, C.RowCount).ToArray();
double[] cnstrRow = gainPredictorsAt.Append(1.0).ToArray(); // <-- expected gain = 1 constraint coeffs
double[,] cnstr = new double[1, cnstrRow.Length]; // <-- expected gain = 1 constraint
for (var i = 0; i < cnstrRow.Length; i++) cnstr[0, i] = cnstrRow[i];
int[] cnstrType = new int[] { 0 }; // <-- linear constraint type - equality
double[] ret;
alglib.minqpstate state;
alglib.minqpreport rep;

// create solver, set quadratic/linear terms
alglib.minqpcreate(C.RowCount, out state);
alglib.minqpsetlinearterm(state, b);
alglib.minqpsetbc(state, bndl, bndu);
alglib.minqpsetlc(state, cnstr, cnstrType);
// set scale
alglib.minqpsetscaleautodiag(state);
// optimize using BLEIC-based QP solver
alglib.minqpsetalgobleic(state, 0.0, 1e-5, 0.0, 10000);
alglib.minqpoptimize(state);

C is a MathNet matrix.

The crash is not deterministic with respect to the inputs. Several first input data sets give
me a definite answer, then the exception is thrown. If I permute the input data sets, again a
few first input data sets give me a definite answer, though these often correspond to inputs
that have previously yielded the exception.

The code runs on a single thread as far as I know.

Stack trace looks the following way:

Quote:
at alglib.ablasf.rgemv(Int32 m, Int32 n, Double alpha, Double[,] a, Int32 opa, Double[] x, Double beta, Double[] y, xparams _params)
at alglib.optserv.feasibilityerror(Double[,] ce, Double[] x, Int32 nmain, Int32 nslack, Int32 k, Double[]& tmp0, xparams _params)
at alglib.optserv.findfeasiblepoint(Double[]& x, Double[] bndl, Boolean[] havebndl, Double[] bndu, Boolean[] havebndu, Int32 nmain, Int32 nslack, Double[,] ce, Int32 k, Double epsi, Int32& qpits, Int32& gpaits, xparams _params)
at alglib.sactivesets.sasstartoptimization(sactiveset state, Double[] x, xparams _params)
at alglib.minbleic.minbleiciteration(minbleicstate state, xparams _params)
at alglib.qpbleicsolver.qpbleicoptimize(convexquadraticmodel a, sparsematrix sparsea, Int32 akind, Boolean sparseaupper, Double absasum, Double absasum2, Double[] b, Double[] bndl, Double[] bndu, Double[] s, Double[] xorigin, Int32 n, Double[,] cleic, Int32 nec, Int32 nic, qpbleicsettings settings, qpbleicbuffers sstate, Boolean& firstcall, Double[]& xs, Int32& terminationtype, xparams _params)
at alglib.minqp.minqpoptimize(minqpstate state, xparams _params)
at alglib.minqpoptimize(minqpstate state)
at QuantTools.Portfolios.PortfolioWeightAllocationMethods.InverseCovarianceMatrixAlloc

Is there any important detail I'm missing about how alglib should be used?

Ćukasz

Top

 Post subject: Re: NullReferenceException when running minqpoptimizePosted: Wed Feb 16, 2022 12:15 pm

Joined: Tue Feb 15, 2022 3:25 pm
Posts: 3
An additional word of explanation: Just checked this error only shows when compiling my code using dotnet compiler on Linux. On my colleague's Windows machine all the calculations run successfully.

Top

 Post subject: Re: NullReferenceException when running minqpoptimizePosted: Wed Feb 16, 2022 12:43 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 918
Hi!

I don't see any obvious mistakes in your coding. Just need some time to think about possible reasons why it happens so unpredictably. The code was tested at both Windows and Linux, by the way.

I will come back tomorrow, need some time to study the sources...

Top

 Post subject: Re: NullReferenceException when running minqpoptimizePosted: Thu Feb 17, 2022 10:37 pm

Joined: Fri May 07, 2010 7:06 am
Posts: 918
What exactly ALGLIB version you used - fully managed NET5/etc or NET5 with SIMD intrinsics?

I want to add debug logging to rgemv() - a function that raises an exception - so we will be able to know more about its arguments. The unpredictable nature of this fault is still completely unexplainable. I do not pretend to be a perfect programmer, but heisenbugs like this are unlikely to appear in this specific part of the program.

Top

 Post subject: Re: NullReferenceException when running minqpoptimizePosted: Mon Feb 21, 2022 10:59 am

Joined: Tue Feb 15, 2022 3:25 pm
Posts: 3
Thank you for the response. I'm running managed code as far as I know. I imported alglib.net 3.18.2 using NuGet, and my dotnet SDK is 3.1.416, installed using snap (dotnet-sdk package). By the way, I'm not a C#/programming expert - I might be missing some important point.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for: