I am currently working on a Project where I pass a vector to R.Net from a C# Application in order to perform Holt-Winters on the data. In most cases (~99 of 100) it works, but sometimes it won´t work via R.NET.. If I take the used values and perform the same steps in the R Console, everything works fine.
I am quite clueless what is causing the problem. I get an "Optimization failed" Error from R when calling from R.NET.
My code is:
```
var salesIn = R.CreateNumericVector(product.Value);
R.SetSymbol("sales", salesIn);
R.Evaluate("istm =ts(sales, freq=52)");
try
{
R.Evaluate("t = HoltWinters(istm)");
R.Evaluate("p = predict(t,3)");
R.Evaluate("output = as.numeric(p)");
var salesPrediction = R.GetSymbol("output").AsInteger().ToArray();
predictions.Add(product.Key, salesPrediction);
}
catch
{
predictions.Add(product.Key, null);
}
```
product.Value is a double vector with 148 values, in the case where it works on the console but not with R.NET the values are (here as integers from the database, i tried both, the datatype does´nt seem to be the problem):
37
58
25
25
57
50
38
68
14
21
45
24
11
54
46
54
38
45
52
49
31
53
32
31
24
50
66
30
20
58
61
34
42
37
52
37
42
45
58
51
50
65
63
54
44
37
28
44
113
27
43
35
43
59
43
112
37
40
28
26
47
75
59
49
44
21
47
62
66
62
47
117
56
47
34
65
81
79
114
47
10
51
65
69
64
44
72
61
90
64
78
69
76
108
60
87
73
87
100
58
69
44
41
92
83
55
68
79
69
67
44
92
66
38
95
34
79
63
84
59
73
100
102
84
83
84
90
58
110
61
37
50
55
70
17
31
81
68
43
105
104
94
80
115
54
61
47
54
117
Comments: I can't replicate the issue. I'm using the latest source of R.Net and not the NuGet package. Can you post the exception and stacktrace that gets thrown? using System; using System.Collections.Generic; using System.Diagnostics; using RDotNet; namespace WintersTest { class Program { private static readonly List<double> Product = new List<double> { 37, 58, 25, 25, 57, 50, 38, 68, 14, 21, 45, 24, 11, 54, 46, 54, 38, 45, 52, 49, 31, 53, 32, 31, 24, 50, 66, 30, 20, 58, 61, 34, 42, 37, 52, 37, 42, 45, 58, 51, 50, 65, 63, 54, 44, 37, 28, 44, 11, 27, 43, 35, 43, 59, 43, 112, 37, 40, 28, 26, 47, 75, 59, 49, 44, 21, 47, 62, 66, 62, 47, 117, 56, 47, 34, 65, 81, 79, 114, 47, 10, 51, 65, 69, 64, 44, 72, 61, 90, 64, 78, 69, 76, 108, 60, 87, 73, 87, 100, 58, 69, 44, 41, 92, 83, 55, 68, 79, 69, 67, 44, 92, 66, 38, 95, 34, 79, 63, 84, 59, 73, 100, 102, 84, 83, 84, 90, 58, 110, 61, 37, 50, 55, 70, 17, 31, 81, 68, 43, 105, 104, 94, 80, 115, 54, 61, 47, 54, 117 }; static void Main(string[] args) { var r = REngine.GetInstance(); for (var i = 0; i <= 2000; i++) { DoTest(r); } } private static void DoTest(REngine r) { var salesIn = r.CreateNumericVector(Product); r.SetSymbol("sales", salesIn); r.Evaluate("istm =ts(sales, freq=52)"); try { r.Evaluate("t = HoltWinters(istm)"); r.Evaluate("p = predict(t,3)"); r.Evaluate("output = as.numeric(p)"); var salesPrediction = r.GetSymbol("output").AsInteger().ToArray(); Console.WriteLine("Prediction: {0}, ", string.Join(",", salesPrediction)); } catch (Exception ex) { Console.WriteLine("EXCEPTION: {0}", ex.Message); Debugger.Break(); } } } }
I am quite clueless what is causing the problem. I get an "Optimization failed" Error from R when calling from R.NET.
My code is:
```
var salesIn = R.CreateNumericVector(product.Value);
R.SetSymbol("sales", salesIn);
R.Evaluate("istm =ts(sales, freq=52)");
try
{
R.Evaluate("t = HoltWinters(istm)");
R.Evaluate("p = predict(t,3)");
R.Evaluate("output = as.numeric(p)");
var salesPrediction = R.GetSymbol("output").AsInteger().ToArray();
predictions.Add(product.Key, salesPrediction);
}
catch
{
predictions.Add(product.Key, null);
}
```
product.Value is a double vector with 148 values, in the case where it works on the console but not with R.NET the values are (here as integers from the database, i tried both, the datatype does´nt seem to be the problem):
37
58
25
25
57
50
38
68
14
21
45
24
11
54
46
54
38
45
52
49
31
53
32
31
24
50
66
30
20
58
61
34
42
37
52
37
42
45
58
51
50
65
63
54
44
37
28
44
113
27
43
35
43
59
43
112
37
40
28
26
47
75
59
49
44
21
47
62
66
62
47
117
56
47
34
65
81
79
114
47
10
51
65
69
64
44
72
61
90
64
78
69
76
108
60
87
73
87
100
58
69
44
41
92
83
55
68
79
69
67
44
92
66
38
95
34
79
63
84
59
73
100
102
84
83
84
90
58
110
61
37
50
55
70
17
31
81
68
43
105
104
94
80
115
54
61
47
54
117
Comments: I can't replicate the issue. I'm using the latest source of R.Net and not the NuGet package. Can you post the exception and stacktrace that gets thrown? using System; using System.Collections.Generic; using System.Diagnostics; using RDotNet; namespace WintersTest { class Program { private static readonly List<double> Product = new List<double> { 37, 58, 25, 25, 57, 50, 38, 68, 14, 21, 45, 24, 11, 54, 46, 54, 38, 45, 52, 49, 31, 53, 32, 31, 24, 50, 66, 30, 20, 58, 61, 34, 42, 37, 52, 37, 42, 45, 58, 51, 50, 65, 63, 54, 44, 37, 28, 44, 11, 27, 43, 35, 43, 59, 43, 112, 37, 40, 28, 26, 47, 75, 59, 49, 44, 21, 47, 62, 66, 62, 47, 117, 56, 47, 34, 65, 81, 79, 114, 47, 10, 51, 65, 69, 64, 44, 72, 61, 90, 64, 78, 69, 76, 108, 60, 87, 73, 87, 100, 58, 69, 44, 41, 92, 83, 55, 68, 79, 69, 67, 44, 92, 66, 38, 95, 34, 79, 63, 84, 59, 73, 100, 102, 84, 83, 84, 90, 58, 110, 61, 37, 50, 55, 70, 17, 31, 81, 68, 43, 105, 104, 94, 80, 115, 54, 61, 47, 54, 117 }; static void Main(string[] args) { var r = REngine.GetInstance(); for (var i = 0; i <= 2000; i++) { DoTest(r); } } private static void DoTest(REngine r) { var salesIn = r.CreateNumericVector(Product); r.SetSymbol("sales", salesIn); r.Evaluate("istm =ts(sales, freq=52)"); try { r.Evaluate("t = HoltWinters(istm)"); r.Evaluate("p = predict(t,3)"); r.Evaluate("output = as.numeric(p)"); var salesPrediction = r.GetSymbol("output").AsInteger().ToArray(); Console.WriteLine("Prediction: {0}, ", string.Join(",", salesPrediction)); } catch (Exception ex) { Console.WriteLine("EXCEPTION: {0}", ex.Message); Debugger.Break(); } } } }