本文整理汇总了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!");
}
示例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);
}
}
示例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 };
}
示例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);
}
示例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 };
}