Exemplo n.º 1
0
Arquivo: Verify.cs Projeto: azret/ml
    public static bool Run(
        App app,
        string dir,
        Func <bool> IsTerminated)
    {
        const int CAPACITY = 1048576,
       DIMS = 3;
        string outputFileName = Path.GetTempFileName();
        var    expected       = new System.Ai.Model(CAPACITY, DIMS);
        var    a = expected.Push("a");

        a.SetScore(+0.5f);
        a.SetVector(
            new Complex[] { new Complex(0, 1), new Complex(2, 3), new Complex(4, 5) });
        var b = expected.Push("z");

        b.SetScore(-0.5f);
        b.SetVector(
            new Complex[] { new Complex(-6, -7), new Complex(-8, -9), new Complex(-10, -11) });
        var sort = expected.Sort();

        Model.Dump(sort, expected.Dims, Path.ChangeExtension(outputFileName, ".md"));
        Model.Write(Path.ChangeExtension(outputFileName, ".model"),
                    sort,
                    expected.Dims);
        var loaded = Model.Read(Path.ChangeExtension(outputFileName, ".model")).ToArray();

        return(false);
    }
Exemplo n.º 2
0
        public void SaveLoad()
        {
            var file = Path.Combine(TestContext.CurrentContext.TestDirectory, "model.dat");

            model.Parameter.Performance = 12;
            model.Write(file);
            var result = Model.Read(file);

            Assert.NotNull(result);
            Assert.AreEqual(12, result.Parameter.Performance);
        }
        public void ReadModel()
        {
            Problem        train     = SVMUtilities.CreateTwoClassProblem(100);
            Parameter      param     = new Parameter();
            RangeTransform transform = RangeTransform.Compute(train);
            Problem        scaled    = transform.Scale(train);

            param.KernelType = KernelType.LINEAR;

            Training.SetRandomSeed(SVMUtilities.TRAINING_SEED);
            Model expected = Training.Train(scaled, param);
            Model actual   = Model.Read("svm0.model");

            Assert.AreEqual(expected, actual);
        }
        public void Classify(string arff, string modelName, object result)
        {
            var file    = Path.Combine(TestContext.CurrentContext.TestDirectory, "data", arff);
            var dataSet = result.GetType() == typeof(PositivityType)
                              ? ArffDataSet.Load <PositivityType>(file)
                              : ArffDataSet.LoadSimple(file);

            file = Path.Combine(TestContext.CurrentContext.TestDirectory, "data", modelName);
            var model = Model.Read(file);

            IProblemFactory factory = new ProblemFactory(dataSet);
            var             client  = new SvmTesting(model, factory);

            var dataHolder = dataSet.CreateDataSet("Test");
            var review     = dataHolder.AddDocument();

            review.AddRecord("Good").Value = 2;
            review.AddRecord("Bad").Value  = 1;
            client.Classify(dataHolder);
            Assert.AreEqual(result, review.Class.Value);
        }
Exemplo n.º 5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        void InitModelSVM()
        {
            g_modelNum     = Model.Read("svmNum.model");
            g_modelCharNum = Model.Read("svmCharNum.model");
        }
Exemplo n.º 6
0
 /// <summary>
 /// Executes the <see cref="PwmTestUIModel.Read"/> action when the related button is clicked.
 /// </summary>
 private void OnReadButtonClick(object sender, RoutedEventArgs arguments)
 {
     Model.Read();
 }
Exemplo n.º 7
0
        /// <summary>
        /// 初始化函数
        /// </summary>
        /// <param name="MediaType"></param>
        /// <param name="Language"></param>
        /// <param name="modelpath_title"></param>
        /// <param name="modelpath_rel"></param>
        /// <param name="stencilfeature"></param>
        public SoftStrategy(Enums.MediaType MediaType, Enums.Language Language)
        {
            this.MediaType = MediaType;
            this.Language  = Language;

            this.model_title = Model.Read("SVMmodel/model_title_WebNews");
            this.model_rel   = Model.Read("SVMmodel/model_rel_WebNews");
            //目前在用比较笨的方法来赋值,以后将直接调用文件资源对这些评分标准进行赋值

            this.Threshold = new HardThreshold(MediaType, Language);

            #region stencil定义部分

            string FileAdd = Path.Combine("Stencil");
            if (File.Exists(FileAdd + "/Stencil_ListTitle"))
            {
                this.Stencil_ListTitle = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ListTitle"), typeof(Feature));
            }
            else
            {
                #region listTitle模版定义部分
                this.Stencil_ListTitle = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "DateParseCount" || key == "AvgNumber" || key == "AvgDateDistance" || key == "DigitCountRate" || key == "DateCountRate")
                    {
                        this.Stencil_ListTitle.FigureFeatures[key] = 0;
                    }
                }

                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ListTitle.CharRecordf[key] = 0;
                }

                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ListTitle.CharRecords[key] = 0;
                }

                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ListTitle.BoolFeatures[key] = 0;
                }
                #endregion listtitle模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ListRel"))
            {
                this.Stencil_ListRel = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ListRel"), typeof(Feature));
            }
            else
            {
                #region listRel模版定义部分
                this.Stencil_ListRel = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "DateParseCount" || key == "AvgNumber" || key == "AvgDateDistance" || key == "ItemCount" || key == "AvgDateDistance")
                    {
                        this.Stencil_ListRel.FigureFeatures[key] = 0;
                    }
                }

                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ListRel.BoolFeatures[key] = 0;
                }

                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ListRel.IdClassnameRecord[key] = 0;
                }
                #endregion listRel模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ItemContent"))
            {
                this.Stencil_ItemContent = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ItemContent"), typeof(Feature));
            }
            else
            {
                #region itemcontent模版定义部分
                this.Stencil_ItemContent = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "AllTextLen")
                    {
                        this.Stencil_ItemContent.FigureFeatures[key] = 1;
                    }
                    else
                    {
                        this.Stencil_ItemContent.FigureFeatures[key] = 0;
                    }
                }
                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ItemContent.CharRecordf[key] = 1;
                }
                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ItemContent.CharRecords[key] = 1;
                }
                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ItemContent.IdClassnameRecord[key] = 1;
                }
                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ItemContent.BoolFeatures[key] = 0;
                }
                #endregion itemcontent模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ItemOthers"))
            {
                this.Stencil_ItemOthers = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ItemOthers"), typeof(Feature));
            }
            else
            {
                #region itemcontent模版定义部分
                this.Stencil_ItemOthers = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "AllTextLen" || key == "DateParseCount")
                    {
                        this.Stencil_ItemOthers.FigureFeatures[key] = 1;
                    }
                    else
                    {
                        this.Stencil_ItemOthers.FigureFeatures[key] = 0;
                    }
                }
                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ItemOthers.CharRecordf[key] = 1;
                }
                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ItemOthers.CharRecords[key] = 1;
                }
                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ItemOthers.IdClassnameRecord[key] = 1;
                }
                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ItemOthers.BoolFeatures[key] = 0;
                }
                #endregion itemcontent模版定义部分
            }

            #endregion stencil定义部分
        }
Exemplo n.º 8
0
        private void UpdateMode(Model.BoatCatalog boatCatalog)
        {
            if (Cin.boolResponseOfQuestion(View.ConsoleIn.FAQProceedUnlock, "yY"))
            {
                while (true)
                {
                    try
                    {
                        Cout.Print(View.ConsoleIn.FAQBoatWhichtoEdit);
                        int clientsChoice = -1 + Cin.readKeyToInt();

                        boat = boatCatalog.Read(clientsChoice);

                        if (Cin.boolResponseOfQuestion(string.Format(View.ConsoleIn.FAQPreviousValue, boat.Type), "yY"))
                        {
                            Cout.Print(View.ConsoleIn.FAQBoatType);
                            boat.Type = (Model.Boat.TypeBoat)Cin.readKeyToInt();
                        }

                        if (Cin.boolResponseOfQuestion(string.Format(View.ConsoleIn.FAQPreviousValue, boat.Length), "yY"))
                        {
                            boat.Length = int.Parse(Cin.ResponseToAskedQustion(View.ConsoleIn.FAQBoatLength));
                        }

                    }
                    catch (Exception e)
                    {
                        new View.Error(e);
                        Cin.boolResponseOfQuestion(View.ConsoleIn.FAQContinueWithY, "yY");
                        break;
                    }
                    break;
                }
            }
        }
Exemplo n.º 9
0
        private void DeleteMode(Model.BoatCatalog boatCatalog)
        {
            if (Cin.boolResponseOfQuestion(View.ConsoleIn.FAQProceedUnlock, "yY"))
            {
                while (true)
                {
                    try
                    {
                        Cout.Print(View.ConsoleIn.FAQBoatWhichtoDelete);
                        int clientsChoice = -1 + Cin.readKeyToInt();

                        boat = boatCatalog.Read(clientsChoice);

                        boatCatalog.delete(boat);

                    }
                    catch (Exception e)
                    {
                        new View.Error(e);
                        Cin.boolResponseOfQuestion(View.ConsoleIn.FAQContinueWithY, "yY");
                        break;
                    }
                    break;
                }
            }
        }
Exemplo n.º 10
0
 public Brisque(string model)
 {
     _extractor    = new BrisqueFeatureExtractor();
     _trainingData = new List <string>();
     _model        = Model.Read(ToStream(model));
 }