Beispiel #1
0
 protected override bool PinvImpl(Matrix mat, out Matrix pinv, InfoPack extra)
 {
     NamedLock.FuncO <Matrix, bool> func = delegate(out Matrix lpinv)
     {
         Matlab.Clear("HTLib2_Matlab_PinvImpl");
         Matlab.PutMatrix("HTLib2_Matlab_PinvImpl", mat.ToArray());
         if (extra != null)
         {
             extra.SetValue("rank", Matlab.GetValueInt("rank(HTLib2_Matlab_PinvImpl)"));
         }
         Matlab.Execute("HTLib2_Matlab_PinvImpl = pinv(HTLib2_Matlab_PinvImpl);");
         lpinv = Matlab.GetMatrix("HTLib2_Matlab_PinvImpl");
         Matlab.Clear("HTLib2_Matlab_PinvImpl");
         return(true);
     };
     //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.PinvImpl(Matrix, out Matrix, InfoPack)", func, out pinv);
     return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_PinvImpl"), func, out pinv));
 }
Beispiel #2
0
 public static Matrix Pinv(Matrix mat, InfoPack extra = null)
 {
     Matrix pinv; HDebug.Verify(solver.PinvImpl(mat, out pinv, extra)); return(pinv);
 }
Beispiel #3
0
            protected override bool InvEigImpl(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra)
            {
                NamedLock.FuncO <Matrix, bool> func = delegate(out Matrix linv)
                {
                    Matlab.Clear("HTLib2_Matlab_InvEigImpl");
                    Matlab.PutMatrix("HTLib2_Matlab_InvEigImpl.A", mat.ToArray());
                    Matlab.PutValue("HTLib2_Matlab_InvEigImpl.ze", numZeroEigval.GetValueOrDefault(0));
                    Matlab.PutValue("HTLib2_Matlab_InvEigImpl.th", Math.Abs(thresEigval.GetValueOrDefault(0)));
                    Matlab.Execute("[HTLib2_Matlab_InvEigImpl.V, HTLib2_Matlab_InvEigImpl.D] = eig(HTLib2_Matlab_InvEigImpl.A);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.D = diag(HTLib2_Matlab_InvEigImpl.D);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.sortAbsD = sort(abs(HTLib2_Matlab_InvEigImpl.D));");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.sortAbsD0 = [0; HTLib2_Matlab_InvEigImpl.sortAbsD];"); // add zero to the first list, for the case ze=0 (null)
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.ze  = HTLib2_Matlab_InvEigImpl.sortAbsD0(HTLib2_Matlab_InvEigImpl.ze+1);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.th  = max(HTLib2_Matlab_InvEigImpl.th, HTLib2_Matlab_InvEigImpl.ze);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.idx = abs(HTLib2_Matlab_InvEigImpl.D) <= HTLib2_Matlab_InvEigImpl.th;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD = ones(size(HTLib2_Matlab_InvEigImpl.D)) ./ HTLib2_Matlab_InvEigImpl.D;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD(HTLib2_Matlab_InvEigImpl.idx) = 0;");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invD = diag(HTLib2_Matlab_InvEigImpl.invD);");
                    Matlab.Execute("HTLib2_Matlab_InvEigImpl.invA = HTLib2_Matlab_InvEigImpl.V * HTLib2_Matlab_InvEigImpl.invD * inv(HTLib2_Matlab_InvEigImpl.V);");
                    linv = Matlab.GetMatrix("HTLib2_Matlab_InvEigImpl.invA");
                    if (extra != null)
                    {
                        int num_zero_eigvals = Matlab.GetValueInt("sum(HTLib2_Matlab_InvEigImpl.idx)");
                        HDebug.AssertIf(numZeroEigval != null, numZeroEigval.GetValueOrDefault() <= num_zero_eigvals);
                        extra["num_zero_eigvals"] = num_zero_eigvals;
                        extra["eigenvalues"]      = Matlab.GetVector("HTLib2_Matlab_InvEigImpl.D");
                    }
                    Matlab.Clear("HTLib2_Matlab_InvEigImpl");

                    return(true);
                };
                //return NamedLock.LockedCall("bool HTLib2.Matlab.NumericSolver.InvEigImpl(Matrix, double?, int?, out Matrix, InfoPack)", func, out inv);
                return(NamedLock.LockedCall(Matlab.NamedLock.GetName("HTLib2_Matlab_InvEigImpl"), func, out inv));
            }
Beispiel #4
0
 public static bool Pinv(Matrix mat, out Matrix pinv, InfoPack extra = null)
 {
     bool succ = solver.PinvImpl(mat, out pinv, extra); HDebug.Assert(succ); return(succ);
 }
Beispiel #5
0
 protected abstract bool PinvImpl(Matrix mat, out Matrix pinv, InfoPack extra = null);
Beispiel #6
0
        public static Matrix InvEig(Matrix mat, double?thresEigval, int?numZeroEigval, InfoPack extra = null)
        {
            Matrix inv;

            HDebug.Verify(solver.InvEigImpl(mat, thresEigval, numZeroEigval, out inv, extra)); return(inv);
        }
Beispiel #7
0
 public static bool InvEig(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra = null)
 {
     bool succ = solver.InvEigImpl(mat, thresEigval, numZeroEigval, out inv, extra); HDebug.Assert(succ); return(succ);
 }
Beispiel #8
0
 // inverse matrix using eigen-decomposition
 protected abstract bool InvEigImpl(Matrix mat, double?thresEigval, int?numZeroEigval, out Matrix inv, InfoPack extra = null);