/// <summary> /// /// </summary> public static VectorIntDataset CsvToVid(string path, int leng, char separator = ',') { string[] content = File.ReadAllLines(path); VectorClass[] vC = new VectorClass[leng]; string[] vectorData, data; Vector vect; for (int i = 0; i < leng; i++) { data = content[i].Split(separator); vectorData = new string[data.Length - 1]; Array.Copy(data, vectorData, data.Length - 1); vect = new Vector(vectorData); vect[29] = 1; vect = vect.TransformVector(d => (double.IsNaN(d) ? 0 : d)); vC[i] = new VectorClass( vect, Convert.ToInt32(data[data.Length - 1]) - 1); } VectorIntDataset vid = new VectorIntDataset(); vid.AddRange(vC); return(vid); }
/// <summary> /// Нормализация датасета /// </summary> /// <returns>Датасет</returns> public VectorIntDataset Normalise() { DispMeanResult(); disp = disp.TransformVector(d => (d == 0) ? 1e-109 : d); VectorIntDataset vid = new VectorIntDataset(); Vector std = MathFunc.sqrt(disp); for (int i = 0; i < Count; i++) { vid.Add(new VectorClass ( (this[i].InpVector - mean) / std, this[i].ClassMark ) ); } return(vid); }
/// <summary> /// Удаление похожих векторов из разных классов /// </summary> /// <param name="simCoef">Коэффициент схожести</param> public VectorIntDataset GetDatasetDelSim(double simCoef = 0.9) { VectorIntDataset vid = new VectorIntDataset(); List <int> simIndex = new List <int>(); VectorClass[] vc; for (int i = 0; i < Count - 1; i++) { for (int j = i + 1; j < Count; j++) { if (this[i].ClassMark != this[j].ClassMark) { if (Statistic.CorrelationCoefficient(this[i].InpVector, this[j].InpVector) > simCoef) { if (IsNotSerch(simIndex, j)) { simIndex.Add(j); } } } } } vc = new VectorClass[Count - simIndex.Count]; for (int i = 0, k = 0; i < Count; i++) { if (IsNotSerch(simIndex, i)) { vc[k++] = this[i]; } } vid.AddRange(vc); return(vid); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="separator"></param> /// <returns></returns> public static VectorIntDataset CsvToVid(string path, char separator = ',') { string[] content = File.ReadAllLines(path); VectorClass[] vC = new VectorClass[content.Length]; string[] vectorData = new string[1], data; for (int i = 0; i < content.Length; i++) { data = content[i].Split(separator); Array.Copy(data, vectorData, data.Length - 1); vC[i] = new VectorClass( new Vector(vectorData), Convert.ToInt32(data[data.Length - 1])); } VectorIntDataset vid = new VectorIntDataset(); vid.AddRange(vC); return(vid); }