我正在生成一个模型列表,模拟每分钟收集的一天数据。我想创建一些其他模型,随机删除一些数据点。有没有办法实现这种行为?下面是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics;
using MathNet.Numerics.Statistics;
public void dataGenerator()
{
int hrs = 24;
int minutes = 60;
int samplesize = hrs * minutes; // this is one day worth of data, with data created every minute
double mean = 50;
double stdev = 1;
int maxmodel = 10;
List<double[]> models = new List<double[]>();
List<double> modelaverage = new List<double>();
List<double> modelvariance = new List<double>();
// generating normal models with different mean / deviations
for (int i = 1; i <= maxmodel; i++)
{
//deviations are incremented by i, to create modles of different deviations, with every model having a different center by 2*i
double[] model = Generate.Normal(samplesize, mean + 2*i, stdev * i);
models.Add(model);
modelaverage.Add(model.Average());
modelvariance.Add(model.Variance());
}
}
答案 0 :(得分:0)
只需添加以下代码(我认为它已经不言自明了):
Random rnd = new Random();
int RandomRemoveCount = 10;
for (int i = 0; i < Math.Min(models.Count, RandomRemoveCount); i++)
{
models.RemoveAt(rnd.Next(models.Count));
}
并将RandomRemoveCount
更改为您要删除的值。 Math.Min
是为了确保您不会尝试删除超过的内容。