public void TestConstructor_ValidMatlab() { MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); Assert.AreEqual(matlab, session.Matlab); Assert.IsTrue(session.Valid); }
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(); }
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"); }
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); }
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); }
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()); }
/// <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; }
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)); }
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(); }
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"); }
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(); }
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()); }
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); }
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); }
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); }
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)); }
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; }
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); }
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); }
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; }
public void TestConstructor_NullCommand() { MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); CompositeMatlabCommand cmd = new CompositeMatlabCommand(session, null); }
public void TestConstructor_NullCommand() { MLAppClass matlab = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(matlab); SingleStatementMatlabCommand cmd = new SingleStatementMatlabCommand(session, null); }
public void TestConstructor_EmptyName() { MLAppClass app = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(app); Workspace space = new Workspace(session, string.Empty); }
public void TestConstructor_NullName() { MLAppClass app = MatlabTestInstance.Instance; MatlabSession session = new MatlabSession(app); Workspace space = new Workspace(session, null); }
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); }
public static void Initialize(TestContext context) { Instance = new MLAppClass(); }
/// <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; }