2

I've declared a MathNet Matrix and Vector type as follows ...

Matrix<double> X = Matrix<double>.Build.Dense(sampleSize,2);
Vector<double> yObserved = Vector<double>.Build.Dense(sampleSize);

but when I call ...

Vector<double> p = MultipleRegression.NormalEquations(X, yObserved, true);

Visual Studio gives the error

Error CS0411 The type arguments for method 'MultipleRegression.NormalEquations(T[][], T[], bool)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

So how am I suppose to call the MultipleRegression class with Matrix and Vector arguments if not like this? And why does Visual Studio find my type coding ambiguous?

I got my code to work fine with a jagged array for the matrix; now I want to get it running with the Matrix/Vector types instead.

  • Try this: `double[] p = MultipleRegression.NormalEquations(X.ToColumnArrays(), yObserved.ToArray(), true);` – jsanalytics Dec 29 '17 at 11:15
  • Your solution works, but the goal here is to use **native** MathNet data types (like Matrix and Vector) to maximize performance. So we are trying to avoid arrays as arguments in this solution. Simply removing the third argument as suggested in the Answer below solves the problem. – superticker Dec 31 '17 at 14:35
  • 1
    Please mark that answer as **accepted** then so people know your problem has been solved. Read this: [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). – jsanalytics Jan 01 '18 at 13:38

1 Answers1

1

The overload for MultipleRegression.NormalEquations() only has 2 parameters for the Matrix and Vector parameter set combination.

Adding the boolean parameter is confusing it and making it think you're trying to provide the parameters of T[][], T[], bool instead of Matrix, Vector.

I don't know what intercept means but you'll have to look into what it does without it. Either convert your parameters to T[][] and T[] or call it without the boolean (see below).

var p = MultipleRegression.NormalEquations(X, yObserved);

OR

var p = MultipleRegression.NormalEquations<double>(X, yObserved);
Shelby115
  • 2,816
  • 3
  • 36
  • 52
  • Thanks. Yes, apparently the APIs are different for the (Matrix,Vector) argument overload verses the (T[][],T[]) jagged-array argument overload. The Boolean=true tells the latter to include the x^0 (intercept) term. With the former overload, you need to include a column of 1s in the Matrix if you want the x^0 term, which is too bad because you're now multiplying by 1 some of the time. (Recall, x^0 always evaluates to 1.) – superticker Dec 27 '17 at 22:41