public ClassifierModel TrainModel() { var attributes = Attributes.Where(x => !x.IsClass); //[ClassValue][Attribute][AttributeValue] int[][][] countMatrix = new int[ClassInfo.NominalOptionCount][][]; decimal[][][] modelMatrix = new decimal[countMatrix.Length][][]; for (int i = 0; i < countMatrix.Length; i++) { countMatrix[i] = new int[attributes.Count()][]; modelMatrix[i] = new decimal[countMatrix[i].Length][]; int j = 0; foreach (var attr in attributes) { countMatrix[i][j] = new int[attr.NominalOptionCount]; modelMatrix[i][j] = new decimal[attr.NominalOptionCount]; j++; } } foreach (var row in Data) { var data = GetRowData(row, Attributes); var classValue = data.ElementAt(ClassIndex); int i = 0, j = 0; foreach (var o in data) { if (i != ClassIndex) { countMatrix[classValue][j][o]++; j++; } i++; } } for (int i = 0; i < countMatrix.Length; i++) { var countBase = (decimal)countMatrix[i][0].Sum(); if (countBase != 0) { for (int j = 0; j < countMatrix[i].Length; j++) { for (int k = 0; k < countMatrix[i][j].Length; k++) { modelMatrix[i][j][k] = countMatrix[i][j][k] / countBase; } } } } _TrainedModel = new ClassifierModel(ClassInfo, attributes, modelMatrix); return(_TrainedModel); }
public DamerauLevensteinClassifier(ClassifierModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } MAX = model.MaxChanges; SHORTSYNNONYMACCEPTANCETHRESHOLD = model.ShortSynnonymAcceptanceThreshold; STRINGLENGTHTHRESHOLD = model.StringLengthThreshold; BREAKONCOMPLETEMATCH = model.BreakOnCompleteMatch; FULLSTRINGMATCHPROPORTION = model.FullStringMatchProportion; EACHWORDMATCHPROPORTION = model.EachWordMatchProportion; MAXITERATIVEGROUPVALUE = model.MaxIterativeWordGroupValue; dLmetric = new DamerauLevensteinMetric(new DamerauLevensteinMetricModel { MaxLength = MAX }); }
private void InitialiseClassifiers() { if (!IsSupported) { return; } var modelDir = MLUtils.ModelFolder; if (modelDir != null) { var haarcascades = modelDir.GetFiles("haarcascade*.xml", SearchOption.AllDirectories).ToList(); foreach (var modelFile in haarcascades) { try { var tag = modelFile.Directory?.Name.Transform(To.SentenceCase); if (string.IsNullOrEmpty(tag)) { tag = "Object"; } var classifier = new CascadeClassifier(modelFile.FullName); var model = new ClassifierModel(modelFile.Name, tag, classifier); Logging.Log($"Initialised EMGU classifier with {model.ClassifierFile} for tag '{tag}'"); classifiers.Add(model); } catch (Exception ex) { Logging.LogError($"Unable to initialize Emgu face detection: {ex}"); } } } }