public void SaveAndLoad_DocWithChildren()
        {
            var doc = new BinaryVectorDocument();

            doc.Version = 2;

            doc.Vectors.Add(ColumnVector1D.Create(1.2, 7.4));

            var doc1 = new BinaryVectorDocument();

            doc1.Vectors.Add(ColumnVector1D.Create(8.2432, 89.4));
            doc1.Vectors.Add(ColumnVector1D.Create(20, 0.14));

            doc.Children.Add(doc1);

            using (var store = new InMemoryBlobStore())
            {
                store.Store("a", doc);

                var doc2 = store.Restore("a", new BinaryVectorDocument());

                Assert.That(doc.Vectors[0][1], Is.EqualTo(7.4));
                Assert.That(doc.Children[0].Vectors[0][0], Is.EqualTo(8.2432));
                Assert.That(doc.Children[0].Vectors[1][1], Is.EqualTo(0.14));
            }
        }
        public void SaveAndLoad_BasicDoc()
        {
            var doc = new BinaryVectorDocument();

            doc.Version = 1;
            doc.Properties["title"] = "abc";
            doc.Properties["value1"] = "12";
            //doc.Properties["null"] = null;

            doc.Vectors.Add(ColumnVector1D.Create(1.2, 7.4));
            doc.Vectors.Add(ColumnVector1D.Create(0.2, 3.9));
            doc.Vectors.Add(ColumnVector1D.Create(4.6, 5.1, 8.1));

            Console.WriteLine(doc.Checksum);

            using (var store = new InMemoryBlobStore())
            {
                store.Store("a", doc);

                var doc2 = store.Restore("a", new BinaryVectorDocument());

                Assert.That(doc2.Properties.Count, Is.EqualTo(2));
                Assert.That(doc2.Properties["title"], Is.EqualTo("abc"));
                Assert.That(doc2.Properties["value1"], Is.EqualTo("12"));
                //Assert.That(doc2.Properties["null"], Is.EqualTo(""));

                Assert.That(doc.Vectors[1][1], Is.EqualTo(3.9));
            }
        }
        public async Task CreateClassifier_SavesOutput()
        {
            var bytes = BitConverter.GetBytes(0);

            Assert.That(bytes.Length, Is.EqualTo(4));

            var endpoint = new Uri("tcp://localhost:9212");

            var data = Functions.NormalRandomDataset(3, 10).Select(x => new
            {
                x = x,
                y = Math.Log(x)
            }).AsQueryable();

            using (var blobs = new InMemoryBlobStore())
            using (var server = new RemoteClassifierTrainingServer(endpoint, blobs))
            using (var client = new RemoteClassifierTrainingClient(endpoint))
            {
#if DEBUGGING
                client.Timeout = 20000;
#endif
                server.Start();

                var trainingSet = data.CreatePipeline().AsTrainingSet(x => x.x > 10 ? 'a' : 'b');

                var keyAndclassifier = await client.CreateClassifier(trainingSet, true);

                // We should be able to restore the raw blob back into a network

                var nn = new MultilayerNetwork(new NetworkParameters(1, 1));

                blobs.Restore(new string(keyAndclassifier.Key.PathAndQuery.Skip(1).ToArray()), nn);

                // We should receive a valid classifier object back

                var cls = keyAndclassifier.Value.Classify(new
                {
                    x = 12.432,
                    y = Math.Log(12.432)
                });

                foreach (var c in cls)
                {
                    Console.WriteLine(c);
                }

                Assert.That(cls.Any());
            }
        }