public void TestTimeSeriesFloatPerfectTrended() { var inputs = new[] { new InputOutput() { X = 5f, time = 0f }, new InputOutput() { X = 7f, time = 1f }, new InputOutput() { X = 9f, time = 2f }, new InputOutput() { X = 11f, time = 3f }, }; using (var host = EnvHelper.NewTestEnvironment()) { var data = host.CreateStreamingDataView(inputs); var args = new DeTrendTransform.Arguments { columns = new[] { new Scikit.ML.PipelineHelper.Column1x1() { Source = "X", Name = "Y" } }, timeColumn = "time" }; var scaled = new DeTrendTransform(host, args, data); using (var cursor = scaled.GetRowCursor(i => true)) { var outValues = new List <float>(); int pos = SchemaHelper.GetColumnIndex(cursor.Schema, "Y"); var type = cursor.Schema[pos].Type; if (type != NumberType.R4) { throw new Exception("Unexpected type"); } var colGetter = cursor.GetGetter <float>(pos); float got = -1f; while (cursor.MoveNext()) { colGetter(ref got); outValues.Add(got); } if (outValues.Count != 4) { throw new Exception("expected 4"); } for (int i = 0; i < outValues.Count; ++i) { if (Math.Abs(outValues[i]) > 5e-2) { throw new Exception(string.Format("Unexpected value {0}!={1}", outValues[i], 0)); } } } } }
public void TestTimeSeriesFloatUnPerfectTrended2() { var inputs = new[] { new InputOutput() { X = 3740f, time = 1f }, new InputOutput() { X = 2880f, time = 2f }, new InputOutput() { X = 2620f, time = 3f }, new InputOutput() { X = 2860f, time = 4f }, new InputOutput() { X = 2640f, time = 5f }, new InputOutput() { X = 2740f, time = 6f }, new InputOutput() { X = 2940f, time = 7f }, new InputOutput() { X = 4040f, time = 8f }, new InputOutput() { X = 3800f, time = 9f }, new InputOutput() { X = 3640f, time = 10f }, }; /*using (*/ var host = EnvHelper.NewTestEnvironment(); { var data = DataViewConstructionUtils.CreateFromEnumerable(host, inputs); var args = new DeTrendTransform.Arguments { columns = new[] { new Scikit.ML.PipelineHelper.Column1x1() { Source = "X", Name = "Y" } }, timeColumn = "time" }; var scaled = new DeTrendTransform(host, args, data); using (var cursor = scaled.GetRowCursor(scaled.OutputSchema)) { var outValues = new List <float>(); int pos = SchemaHelper.GetColumnIndex(cursor.Schema, "Y"); var type = cursor.Schema[pos].Type; if (type != NumberDataViewType.Single) { throw new Exception("Unexpected type"); } var colGetter = cursor.GetGetter <float>(SchemaHelper._dc(pos, cursor)); float got = -1f; while (cursor.MoveNext()) { colGetter(ref got); outValues.Add(got); } if (outValues.Count != inputs.Length) { throw new Exception("unexpected size"); } for (int i = 0; i < outValues.Count; ++i) { if (Math.Abs(outValues[i]) > 2000) { throw new Exception(string.Format("Unexpected value {0}", outValues[i])); } } } } }