source: proiecte/ParallelANN/BCMToolbox/Statistics/BasicStats.cs @ 171

Last change on this file since 171 was 171, checked in by (none), 14 years ago
File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace BCMToolbox.Statistics
7{
8    [Serializable]
9    public class BasicStats
10    {
11        public readonly double AverageWeight = 0.0;
12        public readonly double AveragePotential = 0.0;
13
14        public readonly double MinWeight = double.MaxValue;
15        public readonly double MaxWeight = double.MinValue;
16        public readonly double Weight2Norm = 0.0;
17
18        public readonly double StddevWeight = 0.0;
19        public readonly double StddevPotential = 0.0;
20
21
22        public BasicStats(INetwork net)
23        {
24            int validWeights = 0;
25            for (int i = 0; i < net.Count; i++)
26            {
27                AveragePotential += net[i];
28                for (int j = 0; j < net.Count; j++)
29                    if (!double.IsNaN(net[i, j]))
30                    {
31                        AverageWeight += net[i, j];
32                        Weight2Norm += net[i, j] * net[i, j];
33                        if (net[i, j] < MinWeight)
34                            MinWeight = net[i, j];
35                        if (net[i, j] > MaxWeight)
36                            MaxWeight = net[i, j];
37                        validWeights++;
38                    }
39            }
40
41            AveragePotential /= net.Count;
42            AverageWeight /= validWeights;
43
44            for (int i = 0; i < net.Count; i++)
45            {
46                double p = net[i] - AveragePotential;
47                p *= p;
48                StddevPotential += p;
49
50                for (int j = 0; j < net.Count; j++)
51                    if(!double.IsNaN(net[i,j]))
52                    {
53                        p = net[i, j] - AverageWeight;
54                        p *= p;
55                        StddevWeight += p;
56                    }
57            }
58
59            Weight2Norm = Math.Sqrt(Weight2Norm);
60
61            StddevPotential = Math.Sqrt(StddevPotential);
62            StddevPotential /= net.Count;
63
64            StddevWeight = Math.Sqrt(StddevWeight);
65            StddevWeight /= validWeights;
66        }
67
68        public override string ToString()
69        {
70            return String.Format("ave wt: {0} | stddev wt: {2} | wt range: {4} | wt norm2: {5} | ave out: {1} | stddev out: {3}",
71                AverageWeight.ToString("#0.0000"),
72                AveragePotential.ToString("#0.0000"),
73                StddevWeight.ToString("#0.0000"),
74                StddevPotential.ToString("#0.0000"),
75                (MaxWeight - MinWeight).ToString("#0.0000"),
76                Weight2Norm.ToString("#0.0000"));
77        }
78    }
79}
Note: See TracBrowser for help on using the repository browser.