private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataSetFactory.SearchFolder(".");
            // read input data
            var dataset = sds.DataSet.Open("Tutorial2.csv?inferDims=true&appendMetadata=true");

            if (!dataset.Any(var => var.Name == "Model"))
            {
                var x = dataset.GetData <double[]>("X");
                var y = dataset.GetData <double[]>("Observation");
                // compute
                var    xm = x.Sum() / x.Length;
                var    ym = y.Sum() / y.Length;
                double a = 0, d = 0;
                for (int i = 0; i < x.Length; i++)
                {
                    a += (x[i] - xm) * (y[i] - ym);
                    d += (x[i] - xm) * (x[i] - xm);
                }
                a /= d;
                var b     = ym - a * xm;
                var model = x.Select(xx => a * xx + b).ToArray();
                //
                var varid = dataset.Add <double[]>("Model", dataset.Dimensions[0].Name).ID;
                dataset.PutData <double[]>(varid, model);
            }
            Viewer.DataSet = dataset;
        }
Beispiel #2
0
        public void GetAnswer_Success()
        {
            DataSetFactory dataSetFactory = new DataSetFactory();
            AnswerResponse answerResponse = dataSetFactory.GetAndPostAnswer().Result;

            Assert.IsTrue(answerResponse.Success);
        }
Beispiel #3
0
        internal static void backPropogationDemo()
        {
            try
            {
                DataSet              irisDataSet = DataSetFactory.getIrisDataSet();
                INumerizer           numerizer   = new IrisDataSetNumerizer();
                NeuralNetworkDataSet innds       = new IrisNeuralNetworkDataSet();

                innds.CreateExamplesFromDataSet(irisDataSet, numerizer);

                NeuralNetworkConfig config = new NeuralNetworkConfig();
                config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_INPUTS, 4);
                config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_OUTPUTS, 3);
                config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_HIDDEN_NEURONS,
                                 6);
                config.SetConfig(FeedForwardNeuralNetwork.LOWER_LIMIT_WEIGHTS, -2.0);
                config.SetConfig(FeedForwardNeuralNetwork.UPPER_LIMIT_WEIGHTS, 2.0);

                FeedForwardNeuralNetwork ffnn = new FeedForwardNeuralNetwork(config);
                ffnn.SetTrainingScheme(new BackPropagationLearning(0.1, 0.9));

                ffnn.TrainOn(innds, 1000);

                innds.RefreshDataset();
                int[] result = ffnn.TestOnDataSet(innds);
                System.Console.WriteLine(result[0] + " right, " + result[1] + " wrong");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #4
0
        public void testLoadsIrisDataSetWithNumericAndStringAttributes()
        {
            DataSet ds    = DataSetFactory.getIrisDataSet();
            Example first = ds.getExample(0);

            Assert.AreEqual("5,1", first.getAttributeValueAsString("sepal_length"));
        }
        static void decisionListDemo()
        {
            try
            {
                DataSet             ds      = DataSetFactory.getRestaurantDataSet();
                DecisionListLearner learner = new DecisionListLearner("Yes", "No",
                                                                      new DecisionListTestFactory());
                learner.Train(ds);
                System.Console.WriteLine("The Induced DecisionList is");
                System.Console.WriteLine(learner.getDecisionList());
                int[] result = learner.Test(ds);

                System.Console.WriteLine("\nThis Decision List classifies the data set with "
                                         + result[0]
                                         + " successes"
                                         + " and "
                                         + result[1]
                                         + " failures");
                System.Console.WriteLine("\n");
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Decision ListDemo Failed");
                throw e;
            }
        }
Beispiel #6
0
        public void testDataSetPopulation()
        {
            DataSet              irisDataSet = DataSetFactory.getIrisDataSet();
            INumerizer           numerizer   = new IrisDataSetNumerizer();
            NeuralNetworkDataSet innds       = new IrisNeuralNetworkDataSet();

            innds.CreateExamplesFromDataSet(irisDataSet, numerizer);

            NeuralNetworkConfig config = new NeuralNetworkConfig();

            config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_INPUTS, 4);
            config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_OUTPUTS, 3);
            config.SetConfig(FeedForwardNeuralNetwork.NUMBER_OF_HIDDEN_NEURONS, 6);
            config.SetConfig(FeedForwardNeuralNetwork.LOWER_LIMIT_WEIGHTS, -2.0);
            config.SetConfig(FeedForwardNeuralNetwork.UPPER_LIMIT_WEIGHTS, 2.0);

            FeedForwardNeuralNetwork ffnn = new FeedForwardNeuralNetwork(config);

            ffnn.SetTrainingScheme(new BackPropagationLearning(0.1, 0.9));

            ffnn.TrainOn(innds, 10);

            innds.RefreshDataset();
            ffnn.TestOnDataSet(innds);
        }
Beispiel #7
0
        public void testDecisonListWithNoTestsReturnsDefaultValue()
        {
            DecisionList dlist = new DecisionList("Yes", "No");
            DataSet      ds    = DataSetFactory.getRestaurantDataSet();

            Assert.AreEqual("No", dlist.predict(ds.getExample(0)));
        }
Beispiel #8
0
        internal ConstDataSet LoadDataSetFromXml()
        {
            var ds = new ConstDataSet();

            ds.ReadXml(new StringReader(DataSetXml), XmlReadMode.Auto);
            if (DataSetFactory != null)
            {
                var dsWithSchema = new ConstDataSet();
                foreach (DataTable t in ds.Tables)
                {
                    var schemaTblName = t.TableName;
                    if (SchemaMapping.ContainsKey(schemaTblName))
                    {
                        schemaTblName = SchemaMapping[schemaTblName];
                    }
                    var tblDs = DataSetFactory.GetDataSet(schemaTblName);
                    if (tblDs != null)
                    {
                        var schemaTbl = tblDs.Tables[schemaTblName].Clone();
                        schemaTbl.TableName = t.TableName;
                        dsWithSchema.Tables.Add(schemaTbl);
                    }
                }
                dsWithSchema.ReadXml(new StringReader(DataSetXml), XmlReadMode.Auto);
            }
            return(ds);
        }
        public void addNewDataSet()
        {
            DataSet newDataSet = DataSetFactory.create(Globals.ExcelAddIn.getActiveWorksheet(), null, "Data Set " + (model.numberOfDataSets() + 1), COLUMNS, true);

            model.addDataSet(newDataSet);
            view.selectDataSet(newDataSet);
        }
        private void addDataSetOfCurrentSelection()
        {
            _Worksheet workSheet = Globals.ExcelAddIn.getActiveWorksheet();
            Range      range     = Globals.ExcelAddIn.getCurrentSelectionRange();

            if (model.hasIntersectionWith(range))
            {
                if (DataSetManagerForm.ignoreIntersection(model.getFirstIntersectingDataSetWith(range)))
                {
                    return;
                }
            }

            if (range.Rows.Count == 1 && range.Columns.Count == 1)
            {
                range = Globals.ExcelAddIn.getExpandedCurrentRange();
                range.Select();
            }

            bool addNewDataSet = (range.Rows.Count != 1 || range.Columns.Count != 1) && DataSetManagerForm.addNewDataSet(range);

            if (!addNewDataSet)
            {
                return;
            }
            DataSet newDataSet = DataSetFactory.create(workSheet, range, "Data Set " + (model.numberOfDataSets() + 1), COLUMNS, true);

            model.addDataSet(newDataSet);
            view.selectDataSet(newDataSet);
        }
        static void ensembleLearningDemo()
        {
            try
            {
                DataSet ds = DataSetFactory.getRestaurantDataSet();
                ICollection <DecisionTree> stumps   = DecisionTree.getStumpsFor(ds, "Yes", "No");
                ICollection <ILearner>     learners = CollectionFactory.CreateQueue <ILearner>();

                System.Console.WriteLine("\nStump Learners vote to decide in this algorithm");
                foreach (object stump in stumps)
                {
                    DecisionTree sl           = (DecisionTree)stump;
                    StumpLearner stumpLearner = new StumpLearner(sl, "No");
                    learners.Add(stumpLearner);
                }
                AdaBoostLearner learner = new AdaBoostLearner(learners, ds);
                learner.Train(ds);
                var   answer = learner.Predict(ds.getExample(0));
                int[] result = learner.Test(ds);
                System.Console.WriteLine("\nThis Ensemble Learner  classifies the data set with "
                                         + result[0]
                                         + " successes"
                                         + " and "
                                         + result[1]
                                         + " failures");
                System.Console.WriteLine("\n");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #12
0
        public void testDecisionList()
        {
            DataSet       ds      = DataSetFactory.getRestaurantDataSet();
            List <DLTest> dlTests = new DLTestFactory()
                                    .createDLTestsWithAttributeCount(ds, 1);

            Assert.AreEqual(26, dlTests.Count);
        }
Beispiel #13
0
        public MainWindow()
        {
            DataSetFactory.SearchFolder(Environment.CurrentDirectory);

            InitializeComponent();
            InitModel();
            dsvc.DataSet = dataset;
        }
Beispiel #14
0
        public void testNonDestructiveRemoveExample()
        {
            DataSet ds1 = DataSetFactory.getRestaurantDataSet();
            DataSet ds2 = ds1.removeExample(ds1.getExample(0));

            Assert.AreEqual(12, ds1.size());
            Assert.AreEqual(11, ds2.size());
        }
Beispiel #15
0
        public void testStumpCreationForDataSet()
        {
            DataSet             ds = DataSetFactory.getRestaurantDataSet();
            List <DecisionTree> dt = DecisionTree.getStumpsFor(ds, YES,
                                                               "Unable to classify");

            Assert.AreEqual(26, dt.Count);
        }
Beispiel #16
0
        public void testDecisionList()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            ICollection <aima.net.learning.inductive.DecisionListTest> dlTests = new DecisionListTestFactory()
                                                                                 .createDLTestsWithAttributeCount(ds, 1);

            Assert.AreEqual(26, dlTests.Size());
        }
Beispiel #17
0
        public void testDLTestMatchFailsOnMismatchedExample()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            Example e  = ds.getExample(0);

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "Thai");
            Assert.IsFalse(test.matches(e));
        }
Beispiel #18
0
        public void testDLTestMatchSucceedsWithMatchedExample()
        {
            DataSet ds   = DataSetFactory.getRestaurantDataSet();
            Example e    = ds.getExample(0);
            DLTest  test = new DLTest();

            test.add("type", "French");
            Assert.IsTrue(test.matches(e));
        }
Beispiel #19
0
        public void HasRoleは引数のクラスがDataSetでありかつInitializeで指定されたテストケースにパラメタセクションがあればtrueを返す()
        {
            // setup
            Sheet          sheet   = TempActors.Book.GetSheet("HasRole");
            DataSetFactory factory = GetDataSetFactory(sheet.GetCase("ロールあり"));

            // expect
            Assert.IsTrue(factory.HasRole <DataSet>(null));
        }
Beispiel #20
0
        public void HasRoleは引数のクラスがDictionaryでなければfalseを返す()
        {
            // setup
            Sheet          sheet   = TempActors.Book.GetSheet("HasRole");
            DataSetFactory factory = GetDataSetFactory(sheet.GetCase("ロールあり"));

            // expect
            Assert.IsFalse(factory.HasRole <object>(null));
        }
Beispiel #21
0
        public void HasRoleはInitializeで指定されたテストケースにパラメタセクションがなければfalseを返す()
        {
            // setup
            Sheet          sheet   = TempActors.Book.GetSheet("HasRole");
            DataSetFactory factory = GetDataSetFactory(sheet.GetCase("ロールなし"));

            // expect
            Assert.IsFalse(factory.HasRole <object>(null));
        }
Beispiel #22
0
        public void testDLTestMatchFailsOnMismatchedExample()
        {
            DataSet ds   = DataSetFactory.getRestaurantDataSet();
            Example e    = ds.getExample(0);
            DLTest  test = new DLTest();

            test.add("type", "Thai");
            Assert.IsFalse(test.matches(e));
        }
Beispiel #23
0
        public void testDLTestMatchesEvenOnMismatchedTargetAttributeValue()
        {
            DataSet ds   = DataSetFactory.getRestaurantDataSet();
            Example e    = ds.getExample(0);
            DLTest  test = new DLTest();

            test.add("type", "French");
            Assert.IsTrue(test.matches(e));
        }
Beispiel #24
0
        public void testInducedDecisionTreeClassifiesRestaurantDataSetCorrectly()
        {
            DecisionTreeLearner learner = new DecisionTreeLearner(
                createInducedRestaurantDecisionTree(), "Unable to clasify");

            int[] results = learner.test(DataSetFactory.getRestaurantDataSet());
            Assert.AreEqual(12, results[0]);
            Assert.AreEqual(0, results[1]);
        }
Beispiel #25
0
        public void testGainCalculation()
        {
            DataSet ds   = DataSetFactory.getRestaurantDataSet();
            double  gain = ds.calculateGainFor("patrons");

            Assert.AreEqual(0.541, gain, 0.001);
            gain = ds.calculateGainFor("type");
            Assert.AreEqual(0.0, gain, 0.001);
        }
Beispiel #26
0
        public void testDLTestMatchSucceedsWithMatchedExample()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            Example e  = ds.getExample(0);

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "French");
            Assert.IsTrue(test.matches(e));
        }
Beispiel #27
0
        public void testMajorityLearner()
        {
            MajorityLearner learner = new MajorityLearner();
            DataSet         ds      = DataSetFactory.getRestaurantDataSet();

            learner.train(ds);
            int[] result = learner.test(ds);
            Assert.AreEqual(6, result[0]);
            Assert.AreEqual(6, result[1]);
        }
Beispiel #28
0
        public void testInducedTreeClassifiesDataSetCorrectly()
        {
            DataSet             ds      = DataSetFactory.getRestaurantDataSet();
            DecisionTreeLearner learner = new DecisionTreeLearner();

            learner.train(ds);
            int[] result = learner.test(ds);
            Assert.AreEqual(12, result[0]);
            Assert.AreEqual(0, result[1]);
        }
        public void testBasicDataSetInformationCalculation()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            double  infoForTargetAttribute = ds.getInformationFor();// this should

            // be the
            // generic
            // distribution
            Assert.AreEqual(1.0, infoForTargetAttribute, 0.001);
        }
        public void setVariableNamesInFirstRowOrColumn(DataSet dataSet, bool variableNamesInFirstRowOrColumn)
        {
            if (dataSet == null)
            {
                return;
            }
            DataSet newDataSet = DataSetFactory.create(dataSet.getWorksheet(), dataSet.getRange(), dataSet.getName(), dataSet.getRangeLayout(),
                                                       variableNamesInFirstRowOrColumn);

            model.swapDataSets(dataSet, newDataSet);
        }