public virtual void testAddObject() { DataFrame frame = new DataFrame(); Assert.NotNull(frame); Assert.True(frame.Size == 0); DataFrame child = new DataFrame(); frame.Add(child); Assert.True(frame.Size == 1); }
public void Run() { DataField datefield = new DataField("DATE", DateTime.UtcNow); byte[] data = datefield.Bytes; Console.WriteLine(ByteUtil.Dump(data)); Console.WriteLine("\r\n*************************************************************\r\n"); MemoryStream stream = new MemoryStream(data); BinaryReader reader = new BinaryReader(stream); DataField newfield = new DataField(reader); byte[] otherdata = newfield.Bytes; Console.WriteLine(ByteUtil.Dump(otherdata)); Console.WriteLine("\r\n*************************************************************\r\n"); DateTime time = (DateTime)newfield.ObjectValue; Console.WriteLine(time.ToShortDateString() + " " + time.ToShortTimeString()); Console.WriteLine(ByteUtil.Dump(datefield.Value)); long millis = ByteUtil.RetrieveLong(datefield.Value, 0); Console.WriteLine("Millis: " + millis); Console.WriteLine("\r\n*************************************************************\r\n"); DataFrame frame = new DataFrame(); frame.Add(datefield); DataFrame newframe = new DataFrame(); newframe.Add("NewDate", newfield); frame.Add("newframe", newframe); Console.WriteLine(frame.ToString()); }
public static void LoadData() { featureShape = new Shape(2); labelShape = new Shape(1); DataFrame frameX = new DataFrame(featureShape); DataFrame frameY = new DataFrame(labelShape); /* * //One approach of building dataset * trainData.Add(new List<float>() { 0, 0 }, 0); * trainData.Add(new List<float>() { 0, 1 }, 1); * trainData.Add(new List<float>() { 1, 0 }, 1); * trainData.Add(new List<float>() { 1, 1 }, 0); * trainData.YFrame.OneHotEncode(); */ //Second approach frameX.Add(0, 0); frameY.Add(0); frameX.Add(0, 1); frameY.Add(1); frameX.Add(1, 0); frameY.Add(1); frameX.Add(1, 1); frameY.Add(0); trainData = new DataFrameList(frameX, frameY); }
public void TestAddNewIndexGetIndex() { Pair col = new Pair("Column1", new Series(new NDArray(1, 2, 3))); Pair col1 = new Pair("Column2", new Series(new NDArray(4, 5, 6))); DataFrame df = new DataFrame(col, col1); NDArray i = new NDArray(new NDArray(7, 8), new NDArray(9, 10)); NDArray index = new NDArray("Hat", "Cat"); df.Add(i, index, null); NDArray t = df.GetIndex(); Assert.True(t.Equals(new NDArray(0, 1, 2, "Hat", "Cat")), "Arrays are not equal."); }
private static void RunTest() { Random Rnd = new Random(); DataFrame trnX_fin = new DataFrame(); DataFrame trnY_fin = new DataFrame(); for (int cc = 0; (cc < 100); cc++) { float[] sngLst = new float[100]; for (int indx = 0; (indx < 100); indx++) { sngLst[indx] = (float)Rnd.NextDouble(); } trnX_fin.Add(sngLst); } for (int cc = 0; (cc < 100); cc++) { float[] sngLst = new float[3]; // fake one hot just for check sngLst[0] = 0; sngLst[1] = 1; sngLst[2] = 0; trnY_fin.Add(sngLst); } XYFrame XYfrm = new XYFrame(); XYfrm.XFrame = trnX_fin; XYfrm.YFrame = trnY_fin; // Split TrainTestFrame trainTestFrame = XYfrm.SplitTrainTest(0.3); // init some values int shape_of_input = XYfrm.XFrame.Shape[1]; int embval = 100; int seed = 2; Sequential model = new Sequential(); model.Add(new Reshape(Shape.Create(1, embval), Shape.Create(shape_of_input))); model.Add(new LSTM(64, returnSequence: false, cellDim: 4, weightInitializer: new SiaNet.Model.Initializers.GlorotUniform(0.05, seed), recurrentInitializer: new SiaNet.Model.Initializers.GlorotUniform(0.05, seed), biasInitializer: new SiaNet.Model.Initializers.GlorotUniform(0.05, seed))); model.Add(new Dense(3, act: "sigmoid", useBias: true, weightInitializer: new SiaNet.Model.Initializers.GlorotUniform(0.05, seed))); model.Compile(OptOptimizers.Adam, OptLosses.MeanSquaredError, OptMetrics.Accuracy); model.Train(trainTestFrame.Train, 200, 8, trainTestFrame.Test); }
public void TestAddSingle() { Pair col = new Pair("Column1", new Series(new NDArray(1, 2, 3))); Pair col1 = new Pair("Column2", new Series(new NDArray(4, 5, 6))); DataFrame df = new DataFrame(col, col1); NDArray i = new NDArray(7, 8); df.Add(i); Pair col3 = new Pair("Column1", new Series(new NDArray(1, 2, 3, 7))); Pair col4 = new Pair("Column2", new Series(new NDArray(4, 5, 6, 8))); DataFrame df1 = new DataFrame(col3, col4); Assert.True(df.Equals(df1), "Arrays are not equal."); }
public void TestAddGetIndex() { Pair col = new Pair("Column1", new Series(new NDArray(1, 2, 3))); Pair col1 = new Pair("Column2", new Series(new NDArray(4, 5, 6))); DataFrame df = new DataFrame(col, col1); NDArray i = new NDArray(new NDArray(7, 8), new NDArray(9, 10)); df.Add(i); Pair col3 = new Pair("Column1", new Series(new NDArray(1, 2, 3, 7, 8))); Pair col4 = new Pair("Column2", new Series(new NDArray(4, 5, 6, 9, 10))); NDArray index = df.GetIndex(); Assert.True(index.Equals(new NDArray(0, 1, 2, 3, 4)), "Arrays are not equal."); }
public void TestAddColumn() { Pair col = new Pair("Column1", new Series(new NDArray(1, 2, 3))); Pair col1 = new Pair("Column2", new Series(new NDArray(4, 5, 6))); DataFrame df = new DataFrame(col, col1); NDArray i = new NDArray(new NDArray(7, 8), new NDArray(9, 10)); NDArray columns = new NDArray("Column1", "Column2"); df.Add(i, null, columns); Pair col3 = new Pair("Column1", new Series(new NDArray(1, 2, 3, 7, 8))); Pair col4 = new Pair("Column2", new Series(new NDArray(4, 5, 6, 9, 10))); DataFrame df1 = new DataFrame(col3, col4); Assert.True(df.Equals(df1), "Arrays are not equal."); }
public void TestBinaryOperationsOnBoolColumn() { var df = new DataFrame(); var dataFrameColumn1 = new PrimitiveColumn <bool>("Bool1", Enumerable.Range(0, 10).Select(x => true)); var dataFrameColumn2 = new PrimitiveColumn <bool>("Bool2", Enumerable.Range(0, 10).Select(x => true)); df.InsertColumn(0, dataFrameColumn1); df.InsertColumn(1, dataFrameColumn2); // bool + int should throw Assert.Throws <NotSupportedException>(() => df.Add(5)); // Left shift should throw Assert.Throws <NotSupportedException>(() => df.LeftShift(5)); IReadOnlyList <bool> listOfBools = new List <bool>() { true, false }; // bool equals and And should work var newdf = df.Equals(true); Assert.Equal(true, newdf[4, 0]); var newdf1 = df.Equals(listOfBools); Assert.Equal(false, newdf1[4, 1]); newdf = df.And(true); Assert.Equal(true, newdf[4, 0]); newdf1 = df.And(listOfBools); Assert.Equal(false, newdf1[4, 1]); newdf = df.Or(true); Assert.Equal(true, newdf[4, 0]); newdf1 = df.Or(listOfBools); Assert.Equal(true, newdf1[4, 1]); newdf = df.Xor(true); Assert.Equal(false, newdf[4, 0]); newdf1 = df.Xor(listOfBools); Assert.Equal(true, newdf1[4, 1]); }
public void GetRow() { NDArray index = new NDArray(DateTime.Parse("2018-03-12"), DateTime.Parse("2018-03-13"), DateTime.Parse("2018-03-14")); Pair col1 = new Pair("Open", new Series(new NDArray(1592.599976, 1615.959961, 1597.000000), index)); Pair col2 = new Pair("High", new Series(new NDArray(1605.329956, 1617.540039, 1606.439941), index)); Pair col3 = new Pair("Low", new Series(new NDArray(1586.699951, 1578.010010, 1590.890015), index)); Pair col4 = new Pair("Close", new Series(new NDArray(1598.390015, 1588.180054, 1591.000000), index)); Pair col5 = new Pair("Adj Close", new Series(new NDArray(1598.390015, 1588.180054, 1591.000000), index)); Pair col6 = new Pair("Volume", new Series(new NDArray(5174200, 6531900, 4175400), index)); DataFrame df1 = new DataFrame(col1, col2, col3, col4, col5, col6); DataFrame t = df1.GetRow(DateTime.Parse("2018-03-13")); DataFrame t2 = new DataFrame(); NDArray cols = new NDArray("Open", "High", "Low", "Close", "Adj Close", "Volume"); t2.Add(new NDArray(1615.959961, 1617.540039, 1578.010010, 1588.180054, 1588.180054, 6531900), new NDArray(DateTime.Parse("2018-03-13")), cols); Assert.True(t.Equals(t2), "Arrays are not equal."); }