当前位置: 首页>>代码示例>>C#>>正文


C# IGenerator.Generate方法代码示例

本文整理汇总了C#中IGenerator.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# IGenerator.Generate方法的具体用法?C# IGenerator.Generate怎么用?C# IGenerator.Generate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGenerator的用法示例。


在下文中一共展示了IGenerator.Generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Field

 public Field(IGenerator generator)
 {
     _generator = generator;
     _generator.Generate(this);
     if (_tiles == null || _types == null)
         throw new Exception("Generator failed. Tiles or TileTypes missing!");
 }
开发者ID:cry-inc,项目名称:mahjong,代码行数:7,代码来源:Field.cs

示例2: GenerateWithWatch

        private static void GenerateWithWatch(IGenerator g)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("\r\n{0}: ", g);
            Console.ResetColor();
            Console.Write("Working...\r\n");

            List<string> result = null;
            var sw = new Stopwatch();
            var total = 0L;
            for (int i = 0;i < _loop;i++)
            {
                sw.Reset();
                sw.Start();
                result = g.Generate(DIC, _len);
                sw.Stop();
                total += sw.ElapsedMilliseconds;
                if (i <= 10)
                {
                    Console.WriteLine("\tGot {0} items in {1,7}ms", result.Count, sw.ElapsedMilliseconds);
                    if (i == 10 && _loop > 10)
                    {
                        Console.WriteLine("\t......");
                    }
                }
            }
            Console.WriteLine("\tGenerate finished for {2} times in {0,7}ms, {1,7}ms for each time.", total, total / _loop, _loop);
            if (result != null)
            {
                PrintTheResult(result);
            }
        }
开发者ID:uonun,项目名称:Whois,代码行数:32,代码来源:Program.cs

示例3: GenerateModel

        private static LearningModel GenerateModel(IGenerator generator, Matrix x, Vector y, IEnumerable<object> examples, double trainingPct)
        {
            var descriptor = generator.Descriptor;
            var total = examples.Count();
            var trainingCount = (int)System.Math.Floor(total * trainingPct);

            // 100 - trainingPercentage for testing
            var testingSlice = GetTestPoints(total - trainingCount, total).ToArray();

            // trainingPercentage for training
            var trainingSlice = GetTrainingPoints(testingSlice, total).ToArray();

            // training
            var x_t = x.Slice(trainingSlice);
            var y_t = y.Slice(trainingSlice);

            // generate model
            var model = generator.Generate(x_t, y_t);
            model.Descriptor = descriptor;

            // testing
            object[] test = GetTestExamples(testingSlice, examples);
            double accuracy = 0;

            for (int j = 0; j < test.Length; j++)
            {
                // items under test
                object o = test[j];

                // get truth
                var truth = Ject.Get(o, descriptor.Label.Name);

                // if truth is a string, sanitize
                if (descriptor.Label.Type == typeof(string))
                    truth = StringHelpers.Sanitize(truth.ToString());

                // make prediction
                var features = descriptor.Convert(o, false).ToVector();

                var p = model.Predict(features);
                var pred = descriptor.Label.Convert(p);

                // assess accuracy
                if (truth.Equals(pred))
                    accuracy += 1;
            }

            // get percentage correct
            accuracy /= test.Length;

            return new LearningModel { Generator = generator, Model = model, Accuracy = accuracy };
        }
开发者ID:vladtepes1473,项目名称:numl,代码行数:52,代码来源:Learner.cs

示例4: GenerateModel

        /// <summary>
        /// Generates and returns a new Tuple of objects: IClassifier, Score and object state
        /// </summary>
        /// <param name="generator">Generator to use for the model.</param>
        /// <param name="truthExamples">True examples.</param>
        /// <param name="falseExamples">False examples.</param>
        /// <param name="truthLabel">Truth label object.</param>
        /// <param name="trainingPct">Training percentage.</param>
        /// <param name="state">Object state</param>
        /// <returns></returns>
        private static Tuple<IClassifier, Score, object> GenerateModel(IGenerator generator, object[] truthExamples, object[] falseExamples, 
                                                                                object truthLabel, double trainingPct, object state = null)
        {
            Descriptor descriptor = generator.Descriptor;

            object[] examples = truthExamples.Union(falseExamples).Shuffle().ToArray(); // changed from .Shuffle()

            int total = examples.Count();

            int trainingCount = (int)System.Math.Floor((double)total * trainingPct);

            //// 100 - trainingPercentage for testing
            int[] testingSlice = Learner.GetTestPoints(total - trainingCount, total).ToArray();
            int[] trainingSlice = Learner.GetTrainingPoints(testingSlice, total).ToArray();

            var training = generator.Descriptor.Convert(examples.Slice(trainingSlice).ToArray(), true).ToExamples();

            // convert label to 1's and 0's
            Vector y = MultiClassLearner.ChangeClassLabels(examples.ToArray(), descriptor, truthLabel);

            IModel model = generator.Generate(training.Item1, y.Slice(trainingSlice));

            Score score = new Score();

            if (testingSlice.Count() > 0)
            {
                object[] testExamples = examples.Slice(testingSlice).ToArray();
                var testing = generator.Descriptor.Convert(testExamples, true).ToExamples();

                Vector y_pred = new Vector(testExamples.Length);

                // make sure labels are 1 / 0 based
                Vector y_test = MultiClassLearner.ChangeClassLabels(testExamples.ToArray(), descriptor, truthLabel);

                for (int i = 0; i < testExamples.Length; i++)
                {
                    double result = model.Predict(testing.Item1[i, VectorType.Row]);

                    y_pred[i] = result;
                }

                score = Score.ScorePredictions(y_pred, y_test);
            }
            return new Tuple<IClassifier, Score, object>((IClassifier)model, score, state);
        }
开发者ID:sethjuarez,项目名称:numl,代码行数:55,代码来源:MultiClassLearner.cs

示例5: GenerateModel

        /// <summary>Generates a model.</summary>
        /// <param name="generator">Model generator used.</param>
        /// <param name="x">The Matrix to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <param name="examples">Source data.</param>
        /// <param name="trainingPct">The training pct.</param>
        /// <param name="total">Number of Examples</param>
        /// <returns>The model.</returns>
        private static LearningModel GenerateModel(IGenerator generator, Matrix x, Vector y, IEnumerable<object> examples, double trainingPct, int total)
        {
            var descriptor = generator.Descriptor;
            //var total = examples.Count();
            var trainingCount = (int)System.Math.Floor(total * trainingPct);

            // 100 - trainingPercentage for testing
            var testingSlice = GetTestPoints(total - trainingCount, total).ToArray();

            // trainingPercentage for training
            var trainingSlice = GetTrainingPoints(testingSlice, total).ToArray();

            // training
            var x_t = x.Slice(trainingSlice);
            var y_t = y.Slice(trainingSlice);

            // generate model
            var model = generator.Generate(x_t, y_t);
            model.Descriptor = descriptor;

            Score score = new Score();

            if (testingSlice.Count() > 0)
            {
                // testing
                object[] test = GetTestExamples(testingSlice, examples);
                Vector y_pred = new Vector(test.Length);
                Vector y_test = descriptor.ToExamples(test).Item2;

                bool isBinary = y_test.IsBinary();
                if (isBinary)
                    y_test = y_test.ToBinary(f => f == 1d, 1.0, 0.0);

                for (int j = 0; j < test.Length; j++)
                {
                    // items under test
                    object o = test[j];

                    // make prediction
                    var features = descriptor.Convert(o, false).ToVector();
                    // --- temp changes ---
                    double val = model.Predict(features);
                    var pred = descriptor.Label.Convert(val);

                    var truth = Ject.Get(o, descriptor.Label.Name);

                    if (truth.Equals(pred))
                        y_pred[j] = y_test[j];
                    else
                        y_pred[j] = (isBinary ? (y_test[j] >= 1d ? 0d : 1d) : val);
                }

                // score predictions
                score = Score.ScorePredictions(y_pred, y_test);
            }

            return new LearningModel { Generator = generator, Model = model, Score = score };
        }
开发者ID:sethjuarez,项目名称:numl,代码行数:66,代码来源:Learner.cs


注:本文中的IGenerator.Generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。