. Net calls the R language and. net calls the r language.

Source: Internet
Author: User

. Net calls the R language and. net calls the r language.

/// Load the self-written R Language Algorithm Library public List <double> GetZTFB (double [] data) {List <double> par = new List <double> (); try {// call the 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 crucial; otherwise, an error is reported. 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;} // load the R language download library public List <double> GetZTFB (double [] data) {List <double> par = new List <double> (); try {// call the R Language Algorithm REngine. setEnvironmentVariables (); REngine engine = REngine. getInstance (null, true, null, null); // load the 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 crucial; otherwise, an error is reported. 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 ;}

  

Related Article

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.