. NET call R language

Source: Internet
Author: User

 Load your own Write R language algorithm library public list<double> GETZTFB (double[] data) {list<double> par = new list&lt            ;d ouble> ();                try {//Call R language algorithm rengine.setenvironmentvariables ();                Rengine engine = Rengine.getinstance (null, true, NULL, NULL); Numericvector x = engine.                Createnumericvector (data); Engine.                Setsymbol ("x", x); String path = System.Windows.Forms.Application.StartupPath + "\\R_FILE\\ZTFB.                R ";                Path = "Source (\" "+ Path +" \ ")"; Path = path. Replace ("\ \", "\\\\");//This step is critical, otherwise it will error engine.                Evaluate (path); Engine.                Evaluate ("a<-ztfb (x)"); Engine.                Evaluate (@ "Normal <-function (theta) {//MU <-theta[1]             Sigma <-Theta[2]//                                 n <-Length (x)//LOGL &lt                                              ;- -0.5*n*log (2*PI)-N*log (Sigma)-sum (0.5* (X-MU) ^2/sigma^2)// Return (-LOGL)//}//A&lt                ;-Nlminb (C (0,1), normal) "); Numericvector a = engine. Evaluate ("a$par[1]").                Asnumeric (); Numericvector B = engine. Evaluate ("a$par[2]").                Asnumeric (); Par.                ADD (Convert.todouble (a[0)); Par.            ADD (Convert.todouble (b[0)); } catch (Exception ex) {throw new Exception (ex).            Message);        } return par; }///load r language Download library public list<double> GETZTFB (double[] data) {list<double> par = new List<dou            Ble> (); try {//Call R language algorithm Rengine.seteNvironmentvariables (); Rengine engine = Rengine.getinstance (null, true, NULL, NULL),///Load R language Library Engine.evaluate ("library (\" bit\ ", lib.loc=\" c:/ Program files/r/r-3.3.2/library\ ")") Numericvector x = engine.                Createnumericvector (data); Engine.                Setsymbol ("x", x); String path = System.Windows.Forms.Application.StartupPath + "\\R_FILE\\ZTFB.                R ";                Path = "Source (\" "+ Path +" \ ")"; Path = path. Replace ("\ \", "\\\\");//This step is critical, otherwise it will error engine.                Evaluate (path); Engine.                Evaluate ("a<-ztfb (x)"); Engine.                Evaluate (@ "Normal <-function (theta) {//MU <-theta[1]                                              Sigma <-Theta[2]// n <-Length (x)//LOGL <--0.5*n*log (2*PI)-N*log (Sigma)-sum (0.5* (X-MU) ^2/sigma^2)// Return (-LOGL)//}//a<-                NLMINB (c (0,1), normal) "); Numericvector a = engine. Evaluate ("a$par[1]").                Asnumeric (); Numericvector B = engine. Evaluate ("a$par[2]").                Asnumeric (); Par.                ADD (Convert.todouble (a[0)); Par.            ADD (Convert.todouble (b[0)); } catch (Exception ex) {throw new Exception (ex).            Message);        } return par; }

  

. NET call R language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.