accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.49k stars 1.99k forks source link

Need Help Porting Nonlinear Regression Example into VB.Net #711

Closed womblepc closed 7 years ago

womblepc commented 7 years ago

I'm unsure how to port the second parameter of the Nonlinearregression Class into VB.Net from the example in the documentation. The parameter is function: (w, x) => w[0] x[0] x[0] + w[1] x[0] + w[2], Would this (in VB.NET) be [function]:= w[0] x[0] x[0] + w[1] x[0] + w[2], ? If so, what does the gradient constraint function look like?

A VB.NET version of that example would be fantastic!

womblepc commented 7 years ago

I think that the VB.Net syntax for the above is Function (w,x) return w[0] x[0] x[0] + w[1] * x[0] + w[2] end function

cesarsouza commented 7 years ago

Hi @womblepc,

Thanks for opening the issue.

Sorry, I do not have much experience with VB.NET (and even less with its syntax for lambda functions). However, I assume that, just like in C#, it should be possible to pass a real, non-lambda function there. You might have to create a new method in your class that accepts two double[] array parameters and returns a double to serve as the function to be optimized, and another one that accepts three double[] arrays and has no return (is void) to specify the gradient calculation.

Then you might be able to pass those two methods as the second and third arguments of the NonlinearRegression class constructor.

Regards, Cesar

womblepc commented 7 years ago

I think that I have figured it out using the Function and Sub statements. They are equivalent to the lambda expressions.

But I have another problem: the Nonlinear Least Squares Example uses the Run method not the Learn method. What is the correct syntax for that statement in C#?

cesarsouza commented 7 years ago

For the time being, please use the .Run version. The support and documentation for .Learn() in Least Squares and NonlinearLeastSquares methods is something that is still being worked on. In any case, please note that the previous method based on .Run() will also keep working even after the new .Learn() version is finished, so there shouldn't be a problem in using it.

cesarsouza commented 7 years ago

Examples showing how to learn a non-linear regression in Visual Basic .NET have been added in release v3.7.0