/// <summary> /// Adds the given label to the <see cref="SampleList"/> dictionary if it is not present. /// </summary> /// <param name="label">The label to be added.</param> public virtual void UpdateSampleDictionaries(string label) { lock (SampleLocks) { if (ContainsSample(label)) { return; } SampleList.Add(label, new UdpSample()); SampleLocks.Add(label, new object()); } }
public void IRID119_PolynomialExtrapolatePositiveDirection() { double[] x = new double[] { -6.060771484, -5.855378418, -1.794238281, -1.229428711, 0.89935791, 2.912121582, 4.699230957, 4.788347168, 7.728830566, 11.70989502 }; double[] y = new double[] { 0.959422052, 0.959447861, 0.959958017, 0.960028946, 0.960323274, 0.960636258, 0.960914195, 0.960928023, 0.96138531, 0.962004483 }; PolynomialInterpolationAlgorithm pia = new PolynomialInterpolationAlgorithm(10); SampleList sl = new SampleList(10); for (int i = 0; i < 10; i++) { sl.Add(x[i], y[i]); } pia.Prepare(sl); Assert.That(pia.Extrapolate(12), NumericIs.AlmostEqualTo(0.9622, 1e-3), "extrapolate(12)"); }
public void AddSample(Sample sample) { if (!HasGender && sample.Gender != Sample.Genders.NEUTRAL) { throw new Exception("Cannot add sample with gender to non-gendered samples"); } if (HasGender) { if (sample.Gender == Sample.Genders.MALE || sample.Gender == Sample.Genders.NEUTRAL) { SampleList.Add(sample); } if (sample.Gender == Sample.Genders.FEMALE || sample.Gender == Sample.Genders.NEUTRAL) { FemaleSampleList.Add(sample); } } else { SampleList.Add(sample); } }
//到NetFlow存放區把指定使用者的NetFlow資訊整理後轉存到特徵庫 private void FlowArrange(int Day, int Hour, int Min, int Sec) { object FlowSampleListLock = new object(); DateTime StartTime = DateTime.Now .AddDays(-Day) .AddHours(-Hour) .AddMinutes(-Min) .AddSeconds(-Sec); NetFlow[] FlowDatas = db.NetFlows .Where(c => c.Source_Address == IPv4Address && c.Start_Time >= StartTime ).ToArray(); DateTime[] FlowTimes = FlowDatas.Select(c => c.Start_Time).Distinct().ToArray(); List <FlowSampleStatistics> FlowSampleList = new List <FlowSampleStatistics>(); DateTime NowTime = DateTime.Now; Parallel.For <List <FlowSampleStatistics> >(0, FlowTimes.Length, () => { return(new List <FlowSampleStatistics>()); }, (Index, State, SampleList) => { int?[] Protocols = FlowDatas.Where(c => c.Start_Time == FlowTimes[Index]) .Select(c => c.Protocol).Distinct().ToArray(); foreach (int Protocol in Protocols) { if (Protocol is 6 || Protocol is 17) { int?[] Ports = FlowDatas .Where(c => c.Start_Time == FlowTimes[Index] && c.Protocol == Protocol) .Select(c => c.Destination_Port).Distinct().ToArray(); foreach (int Port in Ports) { int ByteTotal = 0; foreach (int Bytes in FlowDatas .Where(c => c.Start_Time == FlowTimes[Index] && c.Protocol == Protocol && c.Destination_Port == Port) .Select(c => c.Bytes).ToList()) { ByteTotal += Bytes; } SampleList.Add( new FlowSampleStatistics { Id = Guid.NewGuid(), BehaviorNumber = BehaviorNumber, CreateTime = NowTime, StartTime = FlowTimes[Index], Source_Address = IPv4Address, Protocal = (int)Protocol, Port = Port, ByteTotal = ByteTotal, Count = FlowDatas .Where(c => c.Start_Time == FlowTimes[Index] && c.Protocol == Protocol && c.Destination_Port == Port).Count() }); } }
private void AddSample() { SampleList.Add(new SampleVM()); }