public static RocCurve GetROC(GetRocParams pars, Region[] rgPeaks, Region[] rgNoises, IMotiff motiff) { var chrDic = new Dictionary<ChromosomeEnum, Chromosome>(); // подготовим данные для пиков var vsPeak = new double[rgPeaks.Length]; for (int i = 0; i < rgPeaks.Length; i++) { var rgPeak = rgPeaks[i]; Chromosome c; if (!chrDic.TryGetValue(rgPeak.Chr, out c)) chrDic.Add(rgPeak.Chr, c = ChrManager.GetChromosome(rgPeak.Chr)); var pack = c.GetPack(rgPeak.Start, rgPeak.Size); vsPeak[i] = motiff.CalcMaxScore(pack); } Array.Sort(vsPeak); int vsPeakId = 0; // подготовим данные для шума var vsNoise = new double[rgNoises.Length]; for (int i = 0; i < rgNoises.Length; i++) { var rgNoise = rgNoises[i]; Chromosome c; if (!chrDic.TryGetValue(rgNoise.Chr, out c)) chrDic.Add(rgNoise.Chr, c = ChrManager.GetChromosome(rgNoise.Chr)); var pack = c.GetPack(rgNoise.Start, rgNoise.Size); vsNoise[i] = motiff.CalcMaxScore(pack); } Array.Sort(vsNoise); int vsNoiseId = 0; // начинаем строить график var x = new List<double>(); var y = new List<double>(); x.Add(100); y.Add(100); for (double thr = 0.0; thr <= 1.0; thr += 1.0/pars.DeltaCounts) { while (vsPeakId < vsPeak.Length && vsPeak[vsPeakId] < thr) vsPeakId++; while (vsNoiseId < vsNoise.Length && vsNoise[vsNoiseId] < thr) vsNoiseId++; var sensitivity = 100.0*(vsPeak.Length - vsPeakId)/vsPeak.Length; var specifity = 100.0 * (vsNoise.Length - vsNoiseId) / vsNoise.Length; y.Add(sensitivity); x.Add(specifity); } x.Add(0); y.Add(0); return new RocCurve(motiff.ToString(), motiff.Count, x.ToArray(), y.ToArray(), motiff); }
public RocCurve(string name, int count, double[] x, double[] y, IMotiff mf) { Name = name; Count = count; X = x; Y = y; Area = CalcArea(x.Reverse().ToArray(), y.Reverse().ToArray()); Motiff = mf; }