public static double[] GetEntropy(MPPO.Protocol.Interface.IDataTable <DataRow> data, string[] sparams, Protocol.Structure.WaitObject wt) { if (data == null || sparams == null) { return(null); } int paraCount = sparams.Length; int dataCount = data.RowCount; if (paraCount == 0 || dataCount == 0) { return(null); } wt.Flags = new int[1]; wt.Max = paraCount * dataCount; double[] result = new double[paraCount]; List <double>[] distinct = new List <double> [paraCount]; List <int>[] distinctCount = new List <int> [paraCount]; for (int i = 0; i < paraCount; i++) { distinct[i] = new List <double>(); distinctCount[i] = new List <int>(); string sparam = sparams[i]; for (int j = 0; j < dataCount; j++) { var temp = data[j]; var value = data[j, sparam].ConvertToDouble(); var index = distinct[i].IndexOf(value); if (index == -1) { distinct[i].Add(value); distinctCount[i].Add(1); } else { distinctCount[i][index]++; } wt.Flags[0]++; } int disLength = distinctCount[i].Count; for (int k = 0; k < disLength; k++) { int c = distinctCount[i][k]; double p = (double)c / dataCount; result[i] += p * Math.Log(p, 2); } result[i] = -result[i]; } return(result); }
public static void ExportTableToExcel(MPPO.Protocol.Interface.IDataTable <DataRow> targettable, string filepath, Protocol.Structure.WaitObject wt) { try { MPPO.DataAccess.BasicExcelOperation.ExportToExcel(targettable, filepath, wt); } catch (Exception ex) { throw ex; } finally { GC.Collect(); } }
public static void Zscore(MPPO.Protocol.Interface.IDataTable <DataRow> data, string[] sparams, int datacount, int paracount, out double[,] result) { result = new double[datacount, paracount]; double[] sums = new double[paracount]; double[] avg = new double[paracount]; double[] sdv = new double[paracount]; int i, j; for (i = 0; i < paracount; i++) { string sparam = sparams[i]; for (j = 0; j < datacount; j++) { sums[i] += data[j, sparam].ConvertToDouble(); } avg[i] = sums[i] / datacount; } for (i = 0; i < paracount; i++) { string sparam = sparams[i]; for (j = 0; j < datacount; j++) { sdv[i] += Math.Pow((data[j, sparam].ConvertToDouble() - avg[i]), 2); } sdv[i] = Math.Pow(sdv[i] / datacount, 0.5); } for (i = 0; i < paracount; i++) { string sparam = sparams[i]; for (j = 0; j < datacount; j++) { if (sdv[i] != 0) { result[j, i] = (data[j, sparam].ConvertToDouble() - avg[i]) / sdv[i]; } else { result[j, i] = 0; } } } }
public static void CopyViewDataFromData(MPPO.Protocol.Interface.IMdiDataForm <DataRow> targetform, MPPO.Protocol.Interface.IDataTable <DataRow> data) { targetform.DataSource = data.Copy(); targetform.Caption = data.Name; }