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


C# REngine.CreateNumericVector方法代碼示例

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


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

示例1: calcSDev

		static double calcSDev (REngine engine, double[] arr)
		{
			// Note: only one quick and slightly dirty way to do it
			NumericVector rVector = engine.CreateNumericVector(arr);
			engine.SetSymbol ("x", rVector);
			return engine.Evaluate ("sd(x)").AsNumeric () [0];
		}
開發者ID:narutoswj,項目名稱:rdotnet-onboarding,代碼行數:7,代碼來源:Program.cs

示例2: 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

示例3: UserReported

        private static DataFrame UserReported(REngine engine)
        {
            // Incomplete data and repro info.
             // See https://rdotnet.codeplex.com/discussions/569196
             NumericVector PreprocessedValue = null;
             DataFrame PredictedData = null;

             // Some info was missing. Make up.
             string StartDate = "2001-01-01";
             double[] PreProcessedList = new[] { 1.1, 7.3, 4.5, 7.4, 11.23, 985.44 };
             string days = "2"; string interval = "3";

             PreprocessedValue = engine.CreateNumericVector(PreProcessedList);
             // Assign the Utilization value to R variable UtilValue
             engine.SetSymbol("PreprocessedValue", PreprocessedValue);
             engine.Evaluate("library(forecast)");
             engine.Evaluate("StartDate <- as.Date('" + StartDate + "') + " + days);
             engine.Evaluate("size = length(seq(from=as.Date('" + StartDate + "'), by='" + "day" + "', to=as.Date(StartDate)))");
             engine.Evaluate("startDate <- as.POSIXct('" + StartDate + "')");
             engine.Evaluate("endDate <- StartDate + as.difftime(size, units='" + "days" + "')");
             engine.Evaluate("PredictDate = seq(from=StartDate, by=" + interval + "*60, to=endDate)");
             engine.Evaluate("freq <- ts(PreprocessedValue, frequency = 20)");
             engine.Evaluate("forecastnavie <-snaive(freq, Datapoints)");
             engine.Evaluate("PredictValue = (forecastnavie$mean)");
             engine.Evaluate("PredictedData = cbind(PredictValue, data.frame(PredictDate))");
             PredictedData = engine.Evaluate("PredictedData").AsDataFrame();
             return PredictedData;
        }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:28,代碼來源:Program.cs

示例4: ReproWorkitem43

 private static void ReproWorkitem43(REngine engine)
 {
     Random r = new Random(0);
      int N = 500;
      int n1 = 207;
      int n2 = 623;
      var arGroup1Intensities = new double[N][];
      var arGroup2Intensities = new double[N][];
      for (int i = 0; i < N; i++)
      {
     arGroup1Intensities[i] = new double[n1];
     arGroup2Intensities[i] = new double[n2];
     for (int j = 0; j < n1; j++)
        arGroup1Intensities[i][j] = r.NextDouble();
     for (int j = 0; j < n2; j++)
        arGroup2Intensities[i][j] = r.NextDouble();
      }
      var res = new GenericVector[N];
      NumericVector vGroup1, vGroup2;
      for (int i = 0; i < N; i++)
      {
     vGroup1 = engine.CreateNumericVector(arGroup1Intensities[i]);
     Console.WriteLine(vGroup1.Length);
     if (i % 10 == 4)
     {
        engine.ForceGarbageCollection();
        engine.ForceGarbageCollection();
     }
     vGroup2 = engine.CreateNumericVector(arGroup2Intensities[i]);
     Console.WriteLine(vGroup2.Length);
     engine.SetSymbol("group1", vGroup1);
     engine.SetSymbol("group2", vGroup2);
     GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
     res[i] = testResult;
      }
 }
開發者ID:jmp75,項目名稱:rdotnet-support,代碼行數:36,代碼來源:Program.cs

示例5: CreateNumericVector

 public static void CreateNumericVector(REngine engine, int n, Stopwatch s)
 {
     double[] d = createDoubleArray(n);
     s.Start();
     var nvec = engine.CreateNumericVector(d);
     s.Stop();
 }
開發者ID:mgtstrategies,項目名稱:rdotnet,代碼行數:7,代碼來源:RuntimeDiagnostics.cs

示例6: ToVector

        internal static SymbolicExpression ToVector(REngine engine, IEnumerable values)
        {
            if (values == null) throw new ArgumentNullException("values", "values to transform to an R vector must not be null");
            var ints = values as IEnumerable<int>;
            var chars = values as IEnumerable<string>;
            var cplxs = values as IEnumerable<Complex>;
            var logicals = values as IEnumerable<bool>;
            var nums = values as IEnumerable<double>;
            var raws = values as IEnumerable<byte>;
            var sexpVec = values as SymbolicExpression;

            if (sexpVec != null && sexpVec.IsVector())
                return sexpVec;
            if (ints != null)
                return engine.CreateIntegerVector(ints);
            if (chars != null)
                return engine.CreateCharacterVector(chars);
            if (cplxs != null)
                return engine.CreateComplexVector(cplxs);
            if (logicals != null)
                return engine.CreateLogicalVector(logicals);
            if (nums != null)
                return engine.CreateNumericVector(nums);
            if (raws != null)
                return engine.CreateRawVector(raws);
            throw new NotSupportedException(string.Format("Cannot convert type {0} to an R vector", values.GetType()));
        }
開發者ID:tjaskula,項目名稱:rdotnet,代碼行數:27,代碼來源:REngineExtension.cs


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