public IAnomalyDetector Load(string path) { logger.LogInformation("Loading <{0}>...", path); (string postiveFile, string negativeFile, string modelFile)files = GetFiles(path); if (File.Exists(files.postiveFile)) { logger.LogDebug("Loading <{0}> positive documents", files.postiveFile); Document[] positiveDocs = JsonConvert.DeserializeObject <Document[]>(File.ReadAllText(files.postiveFile)); positive = GetDocuments(positiveDocs); } if (File.Exists(files.negativeFile)) { logger.LogDebug("Loading <{0}> negative documents", files.negativeFile); Document[] negativeDocs = JsonConvert.DeserializeObject <Document[]>(File.ReadAllText(files.negativeFile)); negative = GetDocuments(negativeDocs); } SupportVectorMachine <Linear> model = null; if (File.Exists(files.modelFile)) { logger.LogDebug("Loading <{0}> model", files.modelFile); model = Serializer.Load <SupportVectorMachine <Linear> >(files.modelFile); } logger.LogDebug("Loaded <{0}> positive and <{1}> negative", positive.Count, negative.Count); current = new SvmAnomalyDetector(vectorSource, factory, model); return(Current); }
public void Reset() { logger.LogDebug("Reset"); negative.Clear(); positive.Clear(); duplicate.Clear(); current = null; }
public async Task <SvmAnomalyDetector> Train(CancellationToken token) { logger.LogDebug("Train"); if (positive.Count < 5 || negative.Count < 5) { throw new InvalidOperationException("Not enough training samples"); } SvmAnomalyDetector detector = new SvmAnomalyDetector(vectorSource, factory, null); DataSet dataset = new DataSet { Positive = positive.Select(item => new ProcessingTextBlock(item.Sentences.ToArray())).ToArray(), Negative = negative.Select(item => new ProcessingTextBlock(item.Sentences.ToArray())).ToArray() }; await detector.Train(dataset, token).ConfigureAwait(false); current = detector; return(detector); }