示例#1
0
        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);
        }
示例#2
0
 public void Reset()
 {
     logger.LogDebug("Reset");
     negative.Clear();
     positive.Clear();
     duplicate.Clear();
     current = null;
 }
示例#3
0
        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);
        }