當前位置: 首頁>>代碼示例>>C#>>正文


C# REngine.GetSymbol方法代碼示例

本文整理匯總了C#中RDotNet.REngine.GetSymbol方法的典型用法代碼示例。如果您正苦於以下問題:C# REngine.GetSymbol方法的具體用法?C# REngine.GetSymbol怎麽用?C# REngine.GetSymbol使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在RDotNet.REngine的用法示例。


在下文中一共展示了REngine.GetSymbol方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReproIssue169

 private static void ReproIssue169(REngine engine)
 {
     engine.Evaluate("library(mirt)");
     engine.Evaluate("x=mirt(Science,1)");
     S4Object obj111 = engine.GetSymbol("x").AsS4();
     engine.Evaluate("ff=fscores(x, response.pattern=c(1,0,0,0))");
     GenericVector dataset111 = engine.GetSymbol("ff").AsList();
     NumericVector v = dataset111[0].AsNumeric();
     double firstval = v[0];
 }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:10,代碼來源:Program.cs

示例2: stackoverflow_27597542_2752565

		/// <summary>
		/// http://stackoverflow.com/q/27597542/2752565
		/// </summary>
		static void stackoverflow_27597542_2752565 (REngine engine)
		{
			var createModel = @"
			set.seed(0)
			x <- ts(rnorm(100))
			library(forecast)
			blah <- ets(x)
			# str(blah)
			";
			engine.Evaluate (createModel);
			var m = engine.GetSymbol ("blah").AsList ();
			var components = m ["components"].AsCharacter ().ToArray ();
			for (int i = 0; i < components.Length; i++) {
				Console.WriteLine ("m$components[{0}] = {1}", i + 1, components [i]);
			}
		}
開發者ID:narutoswj,項目名稱:rdotnet-onboarding,代碼行數:19,代碼來源:Program.cs

示例3: TestOptimCsharp

      static void TestOptimCsharp(REngine engine)
      {
         var rand = new Random(0);
         int n = 10000;
         double x, y, r, xb, yb, rb;
         rb = double.MaxValue; xb = yb = double.MaxValue;
         engine.Evaluate("rosen <- function(x, y) { (1-x)**2 + 100*(y-x*x)**2 }");
         Console.WriteLine("*** Try a basic way to call the function in R ***");
         for (int i = 0; i < n; i++)
         {
            x = -1 + rand.NextDouble() * (3 - (-1));
            y = -1 + rand.NextDouble() * (3 - (-1));
            r = engine.Evaluate(string.Format("rosen({0}, {1})", x, y)).AsNumeric().ToArray()[0];
            if (r < rb)
            {
               rb = r;
               xb = x;
               yb = y;
            }
         }
         Console.WriteLine("The best score r={0} is for x={1}, y={2}", rb, xb, yb);
         Console.WriteLine("*** Try an R function 'pointer' with a vectorized function call. Faster, if you can do it this way***");

         var f = engine.GetSymbol("rosen").AsFunction();
         double[] xa = new double[n], ya = new double[n];
         rand = new Random(0);
         for (int i = 0; i < n; i++)
         {
            xa[i] = -1 + rand.NextDouble() * (3 - (-1));
            ya[i] = -1 + rand.NextDouble() * (3 - (-1));
         }
         double[] ra = f.Invoke(new[] { engine.CreateNumericVector(xa), engine.CreateNumericVector(ya) })
             .AsNumeric().ToArray();
         rb = ra.Min();
         int indBest = -1;
         for (int i = 0; i < ra.Length; i++)
         { // no which.min in C#. Should call R here too...
            if (ra[i] <= rb)
               indBest = i;
         }
         Console.WriteLine("The best score r={0} is for x={1}, y={2}", rb, xa[indBest], ya[indBest]);
      }
開發者ID:narutoswj,項目名稱:rdotnet-onboarding,代碼行數:42,代碼來源:Program.cs

示例4: TestMultiThreads

        private static void TestMultiThreads(REngine engine)
        {
            engine.Evaluate("x <- rnorm(10000)");
             var blah = engine.GetSymbol("x").AsNumeric().ToArray();

             double[][] res = new double[2][];
             // Can two threads access in parallel the same
             Parallel.For(0, 2, i => readNumericX(i, res, engine));

             engine.Evaluate("x <- list()");
             engine.Evaluate("x[[1]] <- rnorm(10000)");
             engine.Evaluate("x[[2]] <- rnorm(10000)");

             // Can two threads access in parallel the same list
             // Usually bombs, though passes sometimes.
             // The console output would report the following:
             //Error: unprotect_ptr: pointer not found
             //Error: R_Reprotect: only 3 protected items, can't reprotect index 9
             //Error: unprotect_ptr: pointer not found
             //Parallel.For(0, 2, i => readNumericList(i, res, engine));

             // And in seqence, but from other threads - seems to work consistently
             Parallel.For(0, 1, i => readNumericList(i, res, engine));
             Parallel.For(1, 2, i => readNumericList(i, res, engine));

             Console.WriteLine(res[1][1]);
        }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:27,代碼來源:Program.cs

示例5: ReproDiscussion532760

        private static void ReproDiscussion532760(REngine engine)
        {
            // https://rdotnet.codeplex.com/discussions/532760
             //> x <- data.frame(1:1e6, row.names=format(1:1e6))
             //> object.size(x)
             //60000672 bytes
             //> object.size(rownames(x))
             //56000040 bytes

             engine.Evaluate("x <- data.frame(1:1e6, row.names=format(1:1e6))");
             var x = engine.GetSymbol("x").AsDataFrame();
             engine.ForceGarbageCollection();
             engine.ForceGarbageCollection();
             var memoryInitial = engine.Evaluate("memory.size()").AsNumeric().First();

             var netMemBefore = GC.GetTotalMemory(true);

             var blah = x.RowNames;
             //var blah = engine.Evaluate("rownames(x)").AsCharacter().ToArray();
             blah = null;

             GC.Collect();
             engine.ForceGarbageCollection();
             engine.ForceGarbageCollection();
             var memoryAfterAlloc = engine.Evaluate("memory.size()").AsNumeric().First();

             var netMemAfter = GC.GetTotalMemory(false);
        }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:28,代碼來源:Program.cs

示例6: ReproDiscussion528955

 private static void ReproDiscussion528955(REngine engine)
 {
     engine.Evaluate("a <- 1");
      engine.Evaluate("a <- a+1");
      NumericVector v1 = engine.GetSymbol("a").AsNumeric();
      bool eq = 2.0 == v1[0];
      engine.Evaluate("a <- a+1");
      NumericVector v2 = engine.GetSymbol("a").AsNumeric();
      eq = 3.0 == v2[0];
 }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:10,代碼來源:Program.cs

示例7: readNumericX

 private static void readNumericX(long i, double[][] res, REngine engine)
 {
     res[i] = engine.GetSymbol("x").AsNumeric().ToArray();
 }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:4,代碼來源:Program.cs

示例8: ReproStackOverflow_34355201

        private static void ReproStackOverflow_34355201(REngine engine)
        {
            engine.AutoPrint = true;
            //samples taken from ?fscores man page in package mirt
            engine.Evaluate("library(mirt)");
            // 'Science' is a prepackage sample data in mirt; you can use 'engine.CreateDataFrame' in C# to create your own if need be.
            engine.Evaluate("mod <- mirt(Science, 1)");
            engine.Evaluate("class(mod)");
            S4Object modcs = engine.GetSymbol("mod").AsS4();

            // TODO - noticed 2015-12 that R.NET 1.6.5, HasSlot causes a stack imbalance warning. To unit test.
            // Normally should do:
            // if (modcs.HasSlot("Fit"))

            IDictionary<string, string> slotTypes = modcs.GetSlotTypes();
            if (slotTypes.Keys.Contains("Fit"))
            {
                GenericVector fit = modcs["Fit"].AsList();
                // should check logLik in fit.Names;
                double logLik = fit["logLik"].AsNumeric()[0];
            }
            engine.Evaluate("tabscores <- fscores(mod, full.scores = FALSE)");
            engine.Evaluate("head(tabscores)");
            engine.Evaluate("class(tabscores)");
            NumericMatrix tabscorescs = engine.GetSymbol("tabscores").AsNumericMatrix();
        }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:26,代碼來源:Program.cs


注:本文中的RDotNet.REngine.GetSymbol方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。