Beispiel #1
0
        public void Initialize()
        {
            IForecastingModel model = null;

            Models = new List <IForecastingModel>();

            AnnModelParameter annPara = new AnnModelParameter();

            model = new NeuralNetworkModel(annPara);
            Models.Add(model);

            Heiflow.AI.SVM.Parameter p = new Heiflow.AI.SVM.Parameter();
            model = new SVMModel(p);
            Models.Add(model);

            ModelParameter mp = new ModelParameter();

            model = new MLRModel(mp);
            Models.Add(model);

            Recognizers = new List <IRecognizer>();

            foreach (var mm in Models)
            {
                var recognizer = new ImageRecognizer(mm, _IImageSetsBuilder, _IColorClassification);
                Recognizers.Add(recognizer);
            }
        }
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        /// A test for GenerateInputAndOutput
        ///</summary>
        //[TestMethod()]
        public void GenerateInputAndOutputTest()
        {
            uint           iLag        = 1;
            uint           iWindowSize = 5;
            int            pointsNum   = 360;
            IInputProvider target      = new WindowingInputProvider(iLag, iWindowSize);
            Random         rnd         = new Random();

            double[] iTimeSeries = new double[pointsNum];
            for (int i = 0; i < pointsNum; i++)
            {
                iTimeSeries[i] = 1 * Math.Sin(2 * i * Math.PI / 180.0) + (Convert.ToDouble(rnd.Next(-2, 2)) / 5) * ((i % 3 == 0) ? 1 : 0);
            }
            double[][] oInput  = null;
            double[][] oOutput = null;
            target.GenerateInputAndOutput(iTimeSeries, out oInput, out oOutput);
            IForecastingModelBuilder modelBuilder = new ANNmodelBuilder();
            IForecastingModel        model        = modelBuilder.TrainNewModel(oInput, oOutput);

            double[] forecast = new double[oInput.LongLength], actual = new double[oInput.LongLength];
            for (int i = 0; i < oInput.LongLength; ++i)
            {
                forecast[i] = model.CalculateOutput(oInput[i])[0]; actual[i] = oOutput[i][0];
            }

            BSDataObject forecastDO = new BSDataObject(forecast, "Forecast"), actualDO = new BSDataObject(actual, "Actual");

            SimpleVisualizationHandler handler = new SimpleVisualizationHandler();


            handler.AddToGraph(actualDO);
            handler.AddToGraph(forecastDO);
            handler._TestShow();
        }
            public static double CalculateMSE(IForecastingModel iModel, double[][] iInput, double[][] iOutput)
            {
                if (null == iModel || null == iInput || null == iOutput)
                {
                    throw new ArgumentNullException();
                }
                long length = iInput.LongLength;

                if (length != iOutput.LongLength)
                {
                    throw new ArgumentException();
                }

                double error = 0;

                for (int i = 0; i < length; ++i)
                {
                    double[] row = iInput[i], expectedOutput = iOutput[i];
                    if (row.LongLength != iModel.InputSize)
                    {
                        throw new ArgumentException();
                    }
                    double[] modelOutput = iModel.CalculateOutput(row);
                    error += CalculateMSE(modelOutput, expectedOutput);
                }
                return(error / length);
            }
Beispiel #4
0
        public static IForecastingModel CreateForecastingModel(string name)
        {
            IForecastingModel model = null;

            switch (name)
            {
            case "Artificial Neural Network":
                AnnModelParameter annPara = new AnnModelParameter();
                model = new NeuralNetworkModel(annPara);
                break;

            case "HIGANN":
                AnnModelParameter annPara1 = new AnnModelParameter();
                model = new NeuralNetworkModel(annPara1);
                break;

            case "Support Vector Machine":
                Heiflow.AI.SVM.Parameter p = new Heiflow.AI.SVM.Parameter();
                model = new SVMModel(p);
                break;

            case "Multiple Linear Regression":
                ModelParameter mp = new ModelParameter();
                model = new MLRModel(mp);
                break;

            case "Genetic Programming":
                GPModelParameter para = new GPModelParameter();
                model = new GPModel(para);
                break;

            case "Model Tree":
                Rule root  = new Rule(5, 0.47035, RuleType.Interior);
                Rule right = new Rule(RuleType.RightLeaf);
                root.RightChild = right;
                Rule left = new Rule(5, 0.30445, RuleType.Interior);
                root.LeftChild = left;
                Rule left1 = new Rule(RuleType.LeftLeaf);
                left.LeftChild = left1;
                Rule right1 = new Rule(9, 0.156, RuleType.Interior);
                left.RightChild = right1;

                Rule right1_left = new Rule(RuleType.LeftLeaf);
                right1.LeftChild = right1_left;

                Rule right1_right = new Rule(RuleType.RightLeaf);
                right1.RightChild = right1_right;

                HybridModelParameter hmp = new HybridModelParameter(root);
                model = new HybridModel(hmp);
                break;
            }
            return(model);
        }
        public override void Start()
        {
            CheckIfInputsAreProvided();
            DataObjects.BSDataObject tmp;
            Inputs.TryPop(out tmp);
            double[][] modelTrainInput, modelTrainOutput;
            inputProvider = new WindowingInputProvider(kDefaultLag, _windowSize);
            inputProvider.GenerateInputAndOutput(tmp.DataArray, out modelTrainInput, out modelTrainOutput);
            IForecastingModel model = _modelBuilder.TrainNewModel(modelTrainInput, modelTrainOutput);

            model.InputProvider = inputProvider;
            Output = (DataObjects.BSDataObject)model;
        }
            public static double CalculateMSE(IForecastingModel iModel, double[][] iInput, double[][] iOutput)
            {
                if (null == iModel || null == iInput || null == iOutput)
                    throw new ArgumentNullException();
                long length = iInput.LongLength;
                if (length != iOutput.LongLength)
                    throw new ArgumentException();

                double error = 0;
                for (int i = 0;i < length;++i)
                {
                    double[] row = iInput[i], expectedOutput = iOutput[i];
                    if (row.LongLength != iModel.InputSize)
                        throw new ArgumentException();
                    double[] modelOutput = iModel.CalculateOutput(row);
                    error += CalculateMSE(modelOutput, expectedOutput);
                }
                return error / length;
            }
Beispiel #7
0
 public PredicationSchema(IVariable[] stimulus, IVariable[] responses, IForecastingModel iModel) : base(stimulus, responses)
 {
     mIModel            = iModel;
     NormalizationMehod = NormalizationModelType.Range;
     SelectionMehod     = DataSelectionMethod.Rolling;
 }
Beispiel #8
0
 public ImageRecognizer(IForecastingModel model, IImageSetsBuilder builder, IColorClassifier classifier)
 {
     _Model              = model;
     _Builder            = builder;
     _Builder.Classifier = classifier;
 }
 public BasicForecaster(IForecastingModel iModel)
 {
     model = iModel;
 }
 public BasicForecaster(IForecastingModel iModel)
 {
     model = iModel;
 }