Example #1
0
        public static double resultPrepareWithCrossFold(string classifierFileName, int baseClasses, string clasifier)
        {
            double performance = 0.0;

            if (clasifier == "svm")
            {
                weka.classifiers.Classifier svm = new SMO();

                performance = Weka.classifyCrossFold_Train_Test(classifierFileName, baseClasses, svm);
            }
            else if (clasifier == "nb")
            {
                weka.classifiers.Classifier nb = new NaiveBayes();
                performance = Weka.classifyCrossFold_Train_Test(classifierFileName, baseClasses, nb);
            }
            else if (clasifier == "rf")
            {
                weka.classifiers.Classifier rf = new RandomForest();
                performance = Weka.classifyCrossFold_Train_Test(classifierFileName, baseClasses, rf);
            }
            else if (clasifier == "j48")
            {
                weka.classifiers.Classifier j48 = new J48();
                performance = Weka.classifyCrossFold_Train_Test(classifierFileName, baseClasses, j48);
            }
            return(performance);
        }
Example #2
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         SMO.publicationDatabase = TextBox5.Text;
         SMO s = new SMO();
         if (s.IsDBExsit())
         {
             Label1.ForeColor = Color.Green;
             Label1.Text      = "数据库已存在";
             TextBox3.Text   += "数据库已存在 \r\n";
         }
         else
         {
             Label1.ForeColor = Color.Brown;
             Label1.Text      = "数据库不存在";
             TextBox3.Text   += "数据库不存在 \r\n";
         }
     }
     catch (Exception ex)
     {
         Label1.ForeColor = Color.Brown;
         Label1.Text      = "操作异常: " + ex.Message;
         TextBox3.Text   += "操作异常: " + ex.Message + " \r\n";
     }
 }
Example #3
0
        public static int work(int kassaCount, int clients, int servTime, int totalTime)
        {
            int timeUnit    = 1000;
            int currentTime = 0;

            SMO smo = new SMO(kassaCount);

            while (currentTime <= totalTime)
            {
                Console.WriteLine("тик " + currentTime / 1000);

                if (currentTime > 0)
                {
                    smo.clientComming(clients);
                }
                Console.WriteLine(smo.getSMO());

                if (currentTime % servTime == 0 && currentTime != 0)
                {
                    smo.doneSevice();
                    Console.WriteLine("Обслужено");
                    Console.WriteLine(smo.getSMO());
                }

                currentTime += timeUnit;
                System.Threading.Thread.Sleep(timeUnit);
            }
            Console.WriteLine("end");
            return(smo.doneClients);
        }
Example #4
0
        public static void TrainSMO(Instances data)
        {
            //grab SMO, config
            weka.classifiers.functions.SMO smo = new SMO();
            smo.setOptions(weka.core.Utils.splitOptions(" -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));

            //train
            smo.buildClassifier(data);

            //test on self should get 100%
            weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));

            //save model serialize model
            weka.core.SerializationHelper.write(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.model", smo);

            //load model deserialize model
            smo = (weka.classifiers.functions.SMO)weka.core.SerializationHelper.read(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG.model");

            //test loaded model
            eval = new weka.classifiers.Evaluation(data);
            eval.evaluateModel(smo, data);
            Training_Output.printWekaResults(eval.toSummaryString("\nResults\n======\n", false));
        }
Example #5
0
    public Boolean CreateSubscriptionRequest(SubscriptionInfo info)
    {
        SMO smo = new SMO();

        return(smo.RegisterSubscriptionOnPublisher(info.subscriberName, info.subscriptionDbName));

        return(true);
    }
Example #6
0
        public smo2(int _k, int _q)
        {
            kanal_quality = _k;
            query_quality = _q * _k;


            for (int i = 0; i < kanal_quality; i++)
            {
                SMO.Add(new Chanel(_q));
            }
        }
Example #7
0
        public static void classifierOne(string classifierFileName, string predictionModel)
        {
            FileReader javaFileReader = new FileReader(classifierFileName);

            weka.core.Instances wekaInsts = new weka.core.Instances(javaFileReader);
            javaFileReader.close();

            wekaInsts.setClassIndex(wekaInsts.numAttributes() - 1);
            Classifier cl = new SMO();

            //Classifier cl = new NaiveBayes();
            java.util.Random random     = new java.util.Random(1);
            Evaluation       evaluation = new Evaluation(wekaInsts);

            evaluation.crossValidateModel(cl, wekaInsts, 10, random);

            foreach (object o in evaluation.getMetricsToDisplay().toArray())
            {
            }
            int           count = 0;
            StringBuilder sb    = new StringBuilder();

            foreach (object o in evaluation.predictions().toArray())
            {
                NominalPrediction prediction = o as NominalPrediction;
                if (prediction != null)
                {
                    double[] distribution = prediction.distribution();
                    double   predicted    = prediction.predicted();
                    double   actual       = prediction.actual();
                    string   revision     = prediction.getRevision();
                    double   weight       = prediction.weight();
                    double   margine      = prediction.margin();
                    //bool equals = prediction.@equals();

                    string distributions = String.Empty;
                    for (int i = 0; i < distribution.Length; i++)
                    {
                        //System.Console.WriteLine(distribution[i]);
                        distributions += distribution[i];
                    }
                    var predictionLine = String.Format("{0} - {1} - {2} - {3} - {4} - {5}\n", actual, predicted, revision, weight, margine, distributions);
                    sb.Append(predictionLine);
                    //System.Console.WriteLine(predicted);
                }
                count++;
            }
            File_Helper.WriteToFile(sb, predictionModel + "NbCl.txt");
            System.Console.WriteLine(count);
            System.Console.ReadKey();
        }
Example #8
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     try
     {
         SMO.publicationDatabase = TextBox5.Text;
         SMO s = new SMO();
         s.DeleteDB();
         Label1.ForeColor = Color.Green;
         Label1.Text      = "操作成功";
         TextBox3.Text   += "操作成功  \r\n";
     }
     catch (Exception ex)
     {
         Label1.ForeColor = Color.Brown;
         TextBox3.Text   += "操作异常: " + ex.Message + " \r\n";
     }
 }
Example #9
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     try
     {
         SMO.publicationDatabase = TextBox5.Text;
         SMO s = new SMO();
         s.CreatDB(Server.MapPath("~/App_Data"));
         Label1.ForeColor = Color.Green;
         Label1.Text      = "操作成功";
         TextBox3.Text   += "操作成功  \r\n";
     }
     catch (Exception ex)
     {
         Label1.ForeColor = Color.Brown;
         Label1.Text      = "操作异常: " + ex.Message;
         TextBox3.Text   += "操作异常: " + ex.Message + " \r\n";
     }
 }
Example #10
0
 public Boolean CreateSubscriptionRequest(SubscriptionInfo info)
 {
     SMO smo = new SMO();
     return smo.RegisterSubscriptionOnPublisher(info.subscriberName,info.subscriptionDbName);
     return true;
 }
Example #11
0
    protected void Button13_Click(object sender, EventArgs e)
    {
        SMO smo = new SMO();

        smo.RegisterSubscriptionOnPublisher(TextBox9.Text, TextBox10.Text);
    }
Example #12
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     try
     {
         SMO.publicationDatabase = TextBox5.Text;
         SMO s = new SMO();
         s.DeleteDB();
         Label1.ForeColor = Color.Green;
         Label1.Text = "操作成功";
         TextBox3.Text += "操作成功  \r\n";
     }
     catch (Exception ex)
     {
         Label1.ForeColor = Color.Brown;
         TextBox3.Text += "操作异常: " + ex.Message +" \r\n";
     }
 }
Example #13
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     try
     {
         SMO.publicationDatabase = TextBox5.Text;
         SMO s = new SMO();
         s.CreatDB(Server.MapPath("~/App_Data"));
         Label1.ForeColor = Color.Green;
         Label1.Text = "操作成功";
         TextBox3.Text += "操作成功  \r\n";
     }
     catch (Exception ex)
     {
         Label1.ForeColor = Color.Brown;
         Label1.Text = "操作异常: " + ex.Message;
         TextBox3.Text += "操作异常: " + ex.Message +" \r\n";
     }
 }
Example #14
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SMO.publicationDatabase = TextBox5.Text;
            SMO s = new SMO();
            if (s.IsDBExsit())
            {
                Label1.ForeColor = Color.Green;
                Label1.Text = "数据库已存在";
                TextBox3.Text += "数据库已存在 \r\n";
            }
            else
            {
                Label1.ForeColor = Color.Brown;
                Label1.Text = "数据库不存在";
                TextBox3.Text += "数据库不存在 \r\n";
            }

        }
        catch (Exception ex)
        {
            Label1.ForeColor = Color.Brown;
            Label1.Text = "操作异常: " + ex.Message;
            TextBox3.Text += "操作异常: " + ex.Message + " \r\n";
        }
    }
Example #15
0
 protected void Button13_Click(object sender, EventArgs e)
 {
     SMO smo = new SMO();
     smo.RegisterSubscriptionOnPublisher(TextBox9.Text,TextBox10.Text);
 }
Example #16
0
        public void LearnModel()
        {
            Init();
            foreach (Feature currFeature in DomPool.SelectorFeatures)
            {
                String             featureString = currFeature.ToString();
                HashSet <HtmlNode> resNodes      = DomPool.RunXpathQuery(featureString);
                foreach (HtmlNode nd in resNodes)
                {
                    if (!allNodes.Contains(nd))
                    {
                        continue;
                    }
                    nodeFeatures[nd].Add(featureString);
                }
            }
            FastVector fvWekaAttributes = GetDataSetAtts();
            Instances  trainingSet      = new Instances("TS", fvWekaAttributes, 10);

            trainingSet.setClassIndex(fvWekaAttributes.size() - 1);

            foreach (HtmlNode currNode in allNodes)
            {
                Instance item = new SparseInstance(fvWekaAttributes.size());

                for (int i = 0; i < fvWekaAttributes.size() - 1; i++)
                {
                    weka.core.Attribute currFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(i);
                    if (nodeFeatures[currNode].Contains(currFeature.name()))
                    {
                        item.setValue(currFeature, 1);
                    }
                    else
                    {
                        item.setValue(currFeature, 0);
                    }
                }

                //set the class
                weka.core.Attribute classFeature = (weka.core.Attribute)fvWekaAttributes.elementAt(fvWekaAttributes.size() - 1);
                item.setValue(classFeature, (DomPool.TargetNodes.Contains(currNode)?"yes":"no"));
                item.setDataset(trainingSet);
                if (DomPool.TargetNodes.Contains(currNode))
                {
                    for (int t = 0; t < (DomPool.NonTargetNodes.Count() / DomPool.TargetNodes.Count()); t++)
                    {
                        trainingSet.add(new SparseInstance(item));
                    }
                }
                else
                {
                    trainingSet.add(item);
                }
            }

            //String[] options = new String[2];
            //options = new string[] { "-C", "0.05" };            // unpruned tree
            SMO cls = new SMO();        // new instance of tree

            cls.setOptions(weka.core.Utils.splitOptions("-C 1.0 -L 0.0010 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
            // cls.setOptions(options);     // set the options
            cls.buildClassifier(trainingSet);  // build classifier
            //save the resulting classifier
            classifier = cls;

            //  Reader treeDot = new StringReader(tree.graph());
            //  TreeBuild treeBuild = new TreeBuild();
            //  Node treeRoot = treeBuild.create(treeDot);
            FeaturesUsed = new HashSet <string>();

            foreach (Feature f in DomPool.SelectorFeatures)
            {
                FeaturesUsed.Add(f.ToString());
            }
        }