コード例 #1
0
ファイル: CandidateClassifier.cs プロジェクト: wushian/MLEA
        public CandidateClassifier(string name, int tp, int sl, char dealType, int hour, CandidateParameter cp)
        {
            this.Name = name;
            this.Tp = tp;
            this.Sl = sl;
            this.DealType = dealType;
            this.Hour = hour;
            this.Deals = new DealsInfo(cp.DealInfoLastMinutes);

            this.WekaData = new WekaData(dealType, tp, sl, cp);
        }
コード例 #2
0
ファイル: TestManager.cs プロジェクト: wushian/MLEA
        public string BuildPricePatternDeals(bool withPrice = false)
        {
            WekaUtils.Instance.WriteLog("Now BuildPricePatternDeals");

            var cp = TestParameters2.CandidateParameter;
            string resultFile = TestParameters.GetBaseFilePath(string.Format("IncrementTest_{0}_{1}_{2}.txt",
                cp.MainSymbol, "Price", cp.MainPeriod));
            if (File.Exists(resultFile))
                return string.Empty;

            TestParameters.EnablePerhourTrain = false;
            TestParameters.UseFilter = false;

            cp.DeleteUnusedIndicators();

            var dataDates = TestManager.GetDataDateRange();
            SetTrainTime(dataDates[0], dataDates[1]);
            WekaData wekaData = new WekaData(cp);

            string arffFileName = TestParameters.GetBaseFilePath(string.Format("{0}_{1}_{2}.arff",
                cp.MainSymbol, "Price", cp.MainPeriod));
            weka.core.Instances allInstances;
            if (!System.IO.File.Exists(arffFileName))
            {
                WekaData.GenerateArffTemplate(true, false, cp);

                wekaData.UseNullHp = true;
                wekaData.GenerateData(true, false);

                allInstances = wekaData.CurrentTrainInstances;

                var hps = HpData.Instance.GetHpSum(cp.MainSymbol, cp.MainPeriod);
                DateTime nextHpDate = DateTime.MinValue;
                weka.core.Instances newAllInstances = new weka.core.Instances(allInstances, 0);
                //java.util.LinkedList deleteList = new java.util.LinkedList();
                for (int i = 0; i < allInstances.numInstances(); ++i)
                {
                    DateTime nowDate = WekaUtils.GetDateValueFromInstances(allInstances, 0, i);

                    if (TestParameters2.RealTimeMode && i == allInstances.numInstances() - 1)
                    {
                        allInstances.instance(i).setClassValue(0);
                        allInstances.instance(i).setValue(1, WekaUtils.GetTimeFromDate(Parameters.MaxDate) * 1000);

                        newAllInstances.add(allInstances.instance(i));
                    }
                    else if (hps.ContainsKey(nowDate))
                    {
                        int selectedDeal = hps[nowDate].Item1;
                        // 此时还不知道hp,不能滤
                        //if (TxtTest.Filter(nowDate, selectedDeal))
                        //{
                        //    deleteList.Add(allInstances.instance(i));
                        //}
                        //else
                        {
                            allInstances.instance(i).setClassValue(hps[nowDate].Item1);
                            allInstances.instance(i).setValue(1, hps[nowDate].Item2 * 1000);
                        }

                        //if (nowDate < nextHpDate)
                        //{
                        //    deleteList.Add(allInstances.instance(i));
                        //}
                        //else
                        //{
                        //    DateTime hpDate = WekaUtils.GetDateTimeValueFromInstances(allInstances, 1, i);
                        //    nextHpDate = hpDate;
                        //}
                        newAllInstances.add(allInstances.instance(i));
                    }
                    else
                    {
                        //deleteList.Add(allInstances.instance(i));
                    }
                }
                //allInstances.removeAll(deleteList);
                allInstances = newAllInstances;
                WekaUtils.SaveInstances(allInstances, arffFileName);
            }
            else
            {
                allInstances = WekaUtils.LoadInstances(arffFileName);
            }
            //TestParameters.ClassifierType = typeof(weka.classifiers.lazy.IBk);
            //var cls = WekaUtils.CreateClassifier(0, 0);
            //TestParameters.ClassifierType = typeof(weka.classifiers.functions.LibSVM);

            //cls = WekaUtils.CreateClassifier(typeof(ProbClassifier));

            //GenerateHpDateSpan(allInstances);
            //return;

            int n = (int)(24 / TestParameters2.MainPeriodOfHour);
            n = TestParameters2.nPeriod;
            if (!withPrice)
            {
                return TestManager.IncrementTest(allInstances, () =>
                {
                    return WekaUtils.CreateClassifier(typeof(MyLibLinear), 0, 0, "-S 1 -C 1.0 -E 0.01 -B 1.0");
                    //return WekaUtils.CreateClassifier(typeof(weka.classifiers.lazy.IBk));
                    //return WekaUtils.CreateClassifier(typeof(ProbClassifier));
                    //return WekaUtils.CreateClassifier(typeof(InstancesProb));
                },
                "1,2,3,4,5,6,7,8", resultFile, n);
            }
            else
            {
                return TestManager.IncrementTest(allInstances, () =>
                {
                    return WekaUtils.CreateClassifier(typeof(MyLibLinear), 0, 0, "-S 1 -C 1.0 -E 0.01 -B 1.0");
                },
                "1,2,3,5,6,7,8", resultFile, n);
            }
        }
コード例 #3
0
ファイル: TestManager.cs プロジェクト: wushian/MLEA
 public void BatchGenerateData()
 {
     WekaData data = new WekaData('B', 20, 20, null);
     BatchAction(() =>
     {
         data.GenerateData();
     });
 }