/// <summary> /// 随机构建训练样本 /// </summary> /// <param name="oneDimensionCount">样本 features count</param> /// <param name="batchSize">样本数量</param> /// <returns></returns> public static List <float> CreateInputs(int oneDimensionCount = 64, int batchSize = 15) { var inputs = new List <List <float> >(); //构建指定feature数目的多样本集合 for (int i = 0; i < batchSize; i++) { var input = new List <float>(); for (int j = 0; j < oneDimensionCount; j++) { var num = NP.Random(10); input.Add(num); } inputs.Add(input); } //转换成一纬数组 var outputs = new List <float>(); inputs.ForEach(p => { outputs.AddRange(p); }); //返回一维数组,备用 return(outputs); }
/// <summary> /// create ont hot array stochastic /// </summary> /// <param name="length"></param> /// <returns></returns> public static double[] StochasticOnehot(int length) { double[] action = new double[length]; for (int i = 0; i < length; i++) { action[i] = NP.Random(2); } return(action); }
/// <summary> /// 构建10个长度的oneHot编码结果样本集 /// </summary> /// <param name="batchSzie">样本数量</param> /// <returns></returns> public static List <double> CreateLabels(int batchSzie = 15, int oneHot = 10) { var inputs = new List <double[]>(); //构建多样本的输出label for (int i = 0; i < batchSzie; i++) { var label = NP.Random(10); inputs.Add(ToOneHot(label, oneHot)); } var outputs = new List <double>(); inputs.ForEach(p => { outputs.AddRange(p); }); //返回一维数组,备用 return(outputs); }