示例#1
0
        public void TestConstructor_ValidMatlab()
        {
            MLAppClass    matlab  = MatlabTestInstance.Instance;
            MatlabSession session = new MatlabSession(matlab);

            Assert.AreEqual(matlab, session.Matlab);
            Assert.IsTrue(session.Valid);
        }
示例#2
0
 public Plot_ThreeDim(string file_path, string page, string block, int fram)
 {
     FILE_PATH = file_path;
     Input_SheetName = page;
     PlotBlock = block;
     iframe = fram;
     matlab = new MLAppClass();
 }
示例#3
0
        public void TestGetVariable_NotSet()
        {
            string        workspaceName = "base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            space.GetVariable("obj");
        }
示例#4
0
        public void TestConstructor_ValidArgs()
        {
            string        workspaceName = "Base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            Assert.AreEqual(workspaceName, space.WorkspaceName);
        }
示例#5
0
        public void TestConstructor_ValidArgs()
        {
            string        cmdInput           = "b=a*a";
            MLAppClass    matlab             = MatlabTestInstance.Instance;
            MatlabSession session            = new MatlabSession(matlab);
            SingleStatementMatlabCommand cmd = new SingleStatementMatlabCommand(session, cmdInput);

            Assert.AreEqual(cmdInput, cmd.Input);
        }
示例#6
0
        public void TestPutObject_NullName()
        {
            string        workspaceName = "Base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            space.PutObject(null, new object());
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MatlabSession"/>
        /// class.
        /// </summary>
        /// <param name="matlab">The <see cref="IMLApp"/> instance
        /// used in the current session.</param>
        /// <exception cref="ArgumentNullException">matlab is null.</exception>
        public MatlabSession(MLAppClass matlab)
        {
            if (matlab == null)
            {
                throw new ArgumentNullException("matlab");
            }

            Matlab = matlab;
            Valid  = true;
        }
示例#8
0
        public void TestExecute_ValidSession()
        {
            IEnumerable <string>   cmds    = new[] { "a=1", "b=a*2", "c=b*b" };
            MLAppClass             matlab  = MatlabTestInstance.Instance;
            MatlabSession          session = new MatlabSession(matlab);
            CompositeMatlabCommand cmd     = new CompositeMatlabCommand(session, cmds);

            cmd.Execute();
            Assert.IsFalse(cmd.Outputs.Any(x => x == null));
        }
示例#9
0
        public void TestExecute_InvalidSession()
        {
            MLAppClass             matlab  = MatlabTestInstance.Instance;
            MatlabSession          session = new MatlabSession(matlab);
            CompositeMatlabCommand cmd     = new CompositeMatlabCommand(session, new string[] {});

            session.Valid = false;

            cmd.Execute();
        }
示例#10
0
        public void TestGetVariable_ExpiredSession()
        {
            string        workspaceName = "base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            session.Valid = false;

            space.GetVariable("Obj");
        }
示例#11
0
        public void TestExecute_InvalidSession()
        {
            string        cmdInput           = "b=a*a";
            MLAppClass    matlab             = MatlabTestInstance.Instance;
            MatlabSession session            = new MatlabSession(matlab);
            SingleStatementMatlabCommand cmd = new SingleStatementMatlabCommand(session, cmdInput);

            session.Valid = false;

            cmd.Execute();
        }
示例#12
0
        public void TestPutObject_ExpiredSession()
        {
            string        workspaceName = "Base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            session.Valid = false;

            space.PutObject("Obj", new object());
        }
示例#13
0
        public void TestInvalidate()
        {
            MLAppClass    matlab  = MatlabTestInstance.Instance;
            MatlabSession session = new MatlabSession(matlab);
            bool          validityChangedFired = true;

            session.SessionValidityChanged += (s, e) => validityChangedFired = true;

            session.Valid = false;
            Assert.IsFalse(session.Valid);
            Assert.IsTrue(validityChangedFired);
        }
示例#14
0
        public void TestPutObject_ValidArgs()
        {
            string        workspaceName = "Base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            space.PutObject("Obj", new object());
            string output = app.Execute("exist Obj");

            Debug.Write(output);
        }
示例#15
0
        public void TestGetVariable_Set()
        {
            string        workspaceName = "base";
            MLAppClass    app           = MatlabTestInstance.Instance;
            MatlabSession session       = new MatlabSession(app);
            Workspace     space         = new Workspace(session, workspaceName);

            space.PutObject("a", 1d);
            app.Execute("b=a*2");
            object output = space.GetVariable("b");

            Assert.IsNotNull(output);
            Assert.AreEqual(2d, output);
        }
示例#16
0
        public void TestExecute_ValidConditions()
        {
            string        cmdInput           = "b=a*a";
            MLAppClass    matlab             = MatlabTestInstance.Instance;
            MatlabSession session            = new MatlabSession(matlab);
            SingleStatementMatlabCommand cmd = new SingleStatementMatlabCommand(session, cmdInput);

            cmd.Execute();

            // So long as Matlab tried to run something this should be regarded
            // as a success. It's up the client to make sure they called everything
            // correctly.
            Assert.IsFalse(string.IsNullOrEmpty(cmd.Output));
        }
示例#17
0
        public double[,] ExeAlgorithm3(double[] inputData, string algType)
        {
            MLAppClass matlab2 = new MLAppClass();
            double[,] outputData = new double[inputData.Length, 1];

            if (algType == "dbp")
            {
                matlab2.PutWorkspaceData("n1", "base", inputData);
                matlab2.Execute("n2=funBP(n1)");

                var n = matlab2.GetVariable("n2", "base");

                outputData = (double[,])n;
            }
            return outputData;
        }
示例#18
0
        public double[,] ExeAlgorithm(double[] inputData, string algType)
        {
            MLAppClass matlab1 = new MLAppClass();

            double[,] outputData = new double[inputData.Length, 1];

            if (algType == "bp")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=funBP(a)");

                var b = matlab1.GetVariable("b", "base");

                outputData = (double[, ])b;
            }
            return(outputData);
        }
示例#19
0
        public double[,] ExeAlgorithm3(double[] inputData, string algType)
        {
            MLAppClass matlab2 = new MLAppClass();

            double[,] outputData = new double[inputData.Length, 1];

            if (algType == "dbp")
            {
                matlab2.PutWorkspaceData("n1", "base", inputData);
                matlab2.Execute("n2=funBP(n1)");

                var n = matlab2.GetVariable("n2", "base");

                outputData = (double[, ])n;
            }
            return(outputData);
        }
示例#20
0
        public double[,] ExeAlgorithm(string algType, double[] inputData)
        {
            MLAppClass matlab1 = new MLAppClass();

            double[,] outputData = new double[inputData.Length, 1];

            if (algType == "bp")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=2*a");//matlab1.Execute("b=funBP(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[,])b;
                Console.WriteLine("This is the first algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "rbf")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=4*a");//matlab1.Execute("b=funRBF(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[,])b;
                Console.WriteLine("This is the second algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "multi_regression")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=10*a");// matlab1.Execute("b=funMultiRegression(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[,])b;
                Console.WriteLine("This is the third algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "BF_RBF_15")
            {
                matlab1.Execute("path(path,'K:\\Users\\kevin\\Desktop\\现有算法\\TestAlg')");
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=BF_RBF_15()");// matlab1.Execute("b=funMultiRegression(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[,])b;
                //Console.WriteLine("This is the third algorithm");
                //foreach (var i in outputData)
                //{
                //    Console.Write(i);
                //}
            }

            return outputData;
        }
示例#21
0
 public void TestConstructor_NullCommand()
 {
     MLAppClass             matlab  = MatlabTestInstance.Instance;
     MatlabSession          session = new MatlabSession(matlab);
     CompositeMatlabCommand cmd     = new CompositeMatlabCommand(session, null);
 }
示例#22
0
 public void TestConstructor_NullCommand()
 {
     MLAppClass    matlab             = MatlabTestInstance.Instance;
     MatlabSession session            = new MatlabSession(matlab);
     SingleStatementMatlabCommand cmd = new SingleStatementMatlabCommand(session, null);
 }
示例#23
0
 public void TestConstructor_EmptyName()
 {
     MLAppClass    app     = MatlabTestInstance.Instance;
     MatlabSession session = new MatlabSession(app);
     Workspace     space   = new Workspace(session, string.Empty);
 }
示例#24
0
 public void TestConstructor_NullName()
 {
     MLAppClass    app     = MatlabTestInstance.Instance;
     MatlabSession session = new MatlabSession(app);
     Workspace     space   = new Workspace(session, null);
 }
示例#25
0
        public double[,] ExeAlgorithm(string algType, double[] inputData)
        {
            MLAppClass matlab1 = new MLAppClass();

            double[,] outputData = new double[inputData.Length, 1];

            if (algType == "bp")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=2*a");//matlab1.Execute("b=funBP(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[, ])b;
                Console.WriteLine("This is the first algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "rbf")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=4*a");//matlab1.Execute("b=funRBF(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[, ])b;
                Console.WriteLine("This is the second algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "multi_regression")
            {
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=10*a");// matlab1.Execute("b=funMultiRegression(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[, ])b;
                Console.WriteLine("This is the third algorithm");
                foreach (var i in outputData)
                {
                    Console.Write(i);
                }
            }
            if (algType == "BF_RBF_15")
            {
                matlab1.Execute("path(path,'K:\\Users\\kevin\\Desktop\\现有算法\\TestAlg')");
                matlab1.PutWorkspaceData("a", "base", inputData);
                matlab1.Execute("b=BF_RBF_15()");// matlab1.Execute("b=funMultiRegression(a)");
                var b = matlab1.GetVariable("b", "base");

                outputData = (double[, ])b;
                //Console.WriteLine("This is the third algorithm");
                //foreach (var i in outputData)
                //{
                //    Console.Write(i);
                //}
            }


            return(outputData);
        }
示例#26
0
 public static void Initialize(TestContext context)
 {
     Instance = new MLAppClass();
 }
示例#27
0
 /// <summary>
 /// 使用matlab库运算矩阵乘法
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public Matrix MultiplyByMatrix_MATLAB(Matrix m)
 {
     MLAppClass matlab = new MLAppClass();
     double[,] pia = new double[m.nRows, m.nColumns];
     double[,] pib = new double[this.nRows, this.nColumns];
     matlab.PutFullMatrix("A", "base", m.Cell, pia);
     matlab.PutFullMatrix("B", "base", this.Cell, pib);
     matlab.Execute("C = A*B;");
     Matrix result =new Matrix(m.nRows, this.nColumns);
     System.Array pir = new double[m.nRows,this.nColumns];
     System.Array prr = new double[m.nRows, this.nColumns];
     matlab.GetFullMatrix("C", "base",ref prr,ref pir);
     for(int i =0;i<prr.GetLength(0);i++)
     {
         for (int j = 0; j < prr.GetLength(1); j++) result.Cell[i, j] = (double)(prr.GetValue(i, j));
     }
     return result;
 }