using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BCMToolbox.Statistics { [Serializable] public class BasicStats { public readonly double AverageWeight = 0.0; public readonly double AveragePotential = 0.0; public readonly double MinWeight = double.MaxValue; public readonly double MaxWeight = double.MinValue; public readonly double Weight2Norm = 0.0; public readonly double StddevWeight = 0.0; public readonly double StddevPotential = 0.0; public BasicStats(INetwork net) { int validWeights = 0; for (int i = 0; i < net.Count; i++) { AveragePotential += net[i]; for (int j = 0; j < net.Count; j++) if (!double.IsNaN(net[i, j])) { AverageWeight += net[i, j]; Weight2Norm += net[i, j] * net[i, j]; if (net[i, j] < MinWeight) MinWeight = net[i, j]; if (net[i, j] > MaxWeight) MaxWeight = net[i, j]; validWeights++; } } AveragePotential /= net.Count; AverageWeight /= validWeights; for (int i = 0; i < net.Count; i++) { double p = net[i] - AveragePotential; p *= p; StddevPotential += p; for (int j = 0; j < net.Count; j++) if(!double.IsNaN(net[i,j])) { p = net[i, j] - AverageWeight; p *= p; StddevWeight += p; } } Weight2Norm = Math.Sqrt(Weight2Norm); StddevPotential = Math.Sqrt(StddevPotential); StddevPotential /= net.Count; StddevWeight = Math.Sqrt(StddevWeight); StddevWeight /= validWeights; } public override string ToString() { return String.Format("ave wt: {0} | stddev wt: {2} | wt range: {4} | wt norm2: {5} | ave out: {1} | stddev out: {3}", AverageWeight.ToString("#0.0000"), AveragePotential.ToString("#0.0000"), StddevWeight.ToString("#0.0000"), StddevPotential.ToString("#0.0000"), (MaxWeight - MinWeight).ToString("#0.0000"), Weight2Norm.ToString("#0.0000")); } } }