forum.alglib.net http://forum.alglib.net/ |
|
Optimization http://forum.alglib.net/viewtopic.php?f=2&t=145 |
Page 1 of 1 |
Author: | ural [ Sat Jan 01, 2011 5:11 pm ] |
Post subject: | Optimization |
Hi, I need to do a linear least squares optimization with bound constraint. Matlab's lsqlin works fine for my problem. Is there any such function in alglib? I found just one package ASA that works with bound constraint but the objective function is not linear least squares. |
Author: | Sergey.Bochkanov [ Mon Jan 03, 2011 10:26 am ] |
Post subject: | Re: Optimization |
Next release of ALGLIB will include bound and linearly constrained version of Levenberg-Marquardt. As for now, you can formulate your problem as the general form optimization problem and use minasa subpackage. |
Author: | crotundo [ Tue Jan 25, 2011 8:37 pm ] |
Post subject: | Re: Optimization |
Hi, Is something like Matlab's fmincon available? When is the next release date? |
Author: | Sergey.Bochkanov [ Wed Jan 26, 2011 11:00 am ] |
Post subject: | Re: Optimization |
There exists BLEIC optimizer, which solves problems with boundary, linear equality/inequality constraints. More general optimizer is planned (somewhere in the first half of this year), which will be able to handle general constraints. Next release is expected in the middle of February. It will include boundary constrained nonlinear fitting and Levenberg-Marquardt, preconditioned and scaled versions of CG/LBFGS/BLEIC, and maybe other improvements. |
Author: | crotundo [ Wed Jan 26, 2011 9:50 pm ] |
Post subject: | Re: Optimization |
Hi, Great. I plan to use BLEIC in VB6. Do you think it would be a big thing to translate it from vb.net to vb6? Do you have a reference, such that I could do that by myself? Cheers |
Author: | Sergey.Bochkanov [ Thu Jan 27, 2011 9:30 am ] |
Post subject: | Re: Optimization |
I think that it is impossible to translate ALGLIB from VB.NET to VB6 because there no such thing as ALGLIB for VB.NET - it is ALGLIB for C# with automatically generated VB.NET wrapper. It is planned to implement ALGLIB for VB6 as interface for the C++ (or C#) version, but it has no definite schedule, because there are always exist projects with higher priority. I think that it can take about several months... |
Author: | crotundo [ Fri Jan 28, 2011 2:29 pm ] |
Post subject: | Re: Optimization |
Hi, Looking at posting.php?f=2&t=154 gave me the inspiration to do the same with my free Microsoft Visual C# 2008 Express Edition. For minBleic I defined following interface: using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Runtime.InteropServices; public class AlglibException : System.ApplicationException { public AlglibException(string message) : base(message) { } } [Guid("6DB79AF2-F441-44AC-8412-22B06BFDD9E4")] public interface INTERFACE_MINBLEIC { double[] GetX(); void SetF(double F_); void SetG(ref double[] G_); void minbleiccreate(int m, ref double[] x); void minbleicsetbc(ref double[] bndl, ref double[] bndu); void minbleicsetlc(ref double[,] c, ref int[] ct, int k); void minbleicsetlc(ref double[,] c, ref int[] ct); void minbleicsetinnercond(double epsg, double epsf, double epsx); void minbleicsetoutercond(double epsx, double epsi); void minbleicsetbarrierwidth(double mu); void minbleicsetbarrierdecay(double mudecay); void minbleicsetmaxits(int maxits); bool minbleiciteration(); void minbleicresults(ref double[] x); } [ClassInterface(ClassInterfaceType.None), Guid("6DB79AF2-F441-63AC-8412-22B06BFDD9E4")] public class MINBLEIC_C : INTERFACE_MINBLEIC { public alglib.minbleicstate csobj; public alglib.minbleicreport rep; public double[] GetX() { return csobj.innerobj.x; } public void SetF(double F_) { csobj.innerobj.f = F_; } public void SetG(ref double[] G_) { csobj.innerobj.g = G_; } public void minbleiccreate(int m, ref double[] x) { try { alglib.minbleiccreate(m, x, out csobj); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetbc(ref double[] bndl, ref double[] bndu) { try { alglib.minbleicsetbc(csobj, bndl, bndu); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetlc(ref double[,] c, ref int[] ct, int k) { try { alglib.minbleicsetlc(csobj, c, ct, k); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetlc(ref double[,] c, ref int[] ct) { try { alglib.minbleicsetlc(csobj, c, ct); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetinnercond(double epsg, double epsf, double epsx) { try { alglib.minbleicsetinnercond(csobj, epsg, epsf, epsx); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetoutercond(double epsx, double epsi) { try { alglib.minbleicsetoutercond(csobj, epsx, epsi); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetbarrierwidth(double mu) { try { alglib.minbleicsetbarrierwidth(csobj, mu); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetbarrierdecay(double mudecay) { try { alglib.minbleicsetbarrierdecay(csobj, mudecay); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public void minbleicsetmaxits(int maxits) { try { alglib.minbleicsetmaxits(csobj, maxits); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } public bool minbleiciteration() { bool functionReturnValue = false; try { functionReturnValue = alglib.minbleiciteration(csobj); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } return functionReturnValue; } public void minbleicresults(ref double[] x) { try { alglib.minbleicresults(csobj, out x, out rep); } catch (alglib.alglibexception _E_Alglib) { throw new AlglibException(_E_Alglib.msg); } } } After successful registration of the assembly, I was able to include the generated object library as a reference to my MS Access VBA Project. Then I slightly (increased to vector dimension in minbleiccreate) modified the test function to: Public Sub TestBLEIC() Dim ALGLIB As MINBLEIC_C Dim N As Integer Dim X() As Double Dim epsf As Double Dim epsx As Double Dim epsg As Double Dim maxits As Long N = 1 ReDim X(0 To N) epsf = 0.00001 epsx = 0.00001 epsg = 0.00001 maxits = 100000 X(0) = 1 X(1) = 1 Set ALGLIB = New MINBLEIC_C ALGLIB.minbleiccreate N + 1, X ALGLIB.minbleicsetinnercond epsg, epsf, epsx ALGLIB.minbleicsetoutercond epsx, epsx ALGLIB.minbleicsetmaxits maxits Do While ALGLIB.minbleiciteration() ALGLIB.SetF Func1(ALGLIB.GetX) ALGLIB.SetG Grad1(ALGLIB.GetX) Loop ALGLIB.minbleicresults X Debug.Print X(0), X(1) 'result -3.00668489998603 3.00013617674979 End Sub Public Function Func1(ByRef X() As Double) As Double Func1 = 100 * (X(0) + 3) ^ 4 + (X(1) - 3) ^ 4 End Function Public Function Grad1(X() As Double) As Double() Dim res(0 To 1) As Double res(0) = 400 * (X(0) + 3) ^ 3 res(1) = 4 * (X(1) - 3) ^ 3 Grad1 = res End Function Apparently, it worked. I got -3.0027738605718, 2.99082160246955 as solution... Many thanks for the great work of you all! |
Author: | hugolove [ Wed Apr 11, 2012 8:30 am ] |
Post subject: | Re: Optimization |
Hello, does ALGLIB already include bound and linearly constrained version of Levenberg-Marquardt as promised? Which function is it? Could someone please help with how to do linear least squares with known upper and lower bounds when I know matrix C (measurements) and vector d (results) and I need to get vector x? Many thanks hugo |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |