本文整理汇总了C#中SortedDictionary.Average方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Average方法的具体用法?C# SortedDictionary.Average怎么用?C# SortedDictionary.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Average方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: startGlobal_Click
private void startGlobal_Click(object sender, EventArgs e)
{
Int16 p = Int16.Parse(this.branchIndexCmb.Text);
Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
int realizationCount = (Int32)this.realizationCountNum.Value;
double muLow = Double.Parse(this.muRangeLowExtendedTxt.Text);
double muHigh = Double.Parse(this.muRangeHighExtendedTxt.Text);
double muDelta = Double.Parse(this.deltaExtendedTxt.Text);
ResultResearch result = new ResultResearch();
result.Name = this.jobName;
result.ModelType = typeof(HierarchicModel);
result.Delta = muDelta;
result.RealizationCount = realizationCount;
result.Function = this.probabilityFunctionCmb.Text;
result.GenerationParams[GenerationParam.BranchIndex] = p;
result.GenerationParams[GenerationParam.Level] = maxLevel;
result.Size = (int)Math.Pow(p, maxLevel);
result.Result.Add(maxLevel, new SortedDictionary<double, SubGraphsInfo>());
Dictionary<GenerationParam, object> genParameters = new Dictionary<GenerationParam, object>();
genParameters.Add(GenerationParam.BranchIndex, p);
genParameters.Add(GenerationParam.Level, maxLevel);
HierarchicGenerator hGenerator = new HierarchicGenerator();
HierarchicAnalyzer hAnalyzer;
double muTemp = muLow;
SortedDictionary<int, int> subGraphInfo = new SortedDictionary<int,int>();
while (muTemp <= muHigh)
{
SubGraphsInfo tempInfo = new SubGraphsInfo();
for (int r = 0; r < realizationCount; ++r)
{
genParameters[GenerationParam.Mu] = muTemp;
hGenerator.Generation(genParameters);
hAnalyzer = new HierarchicAnalyzer((HierarchicContainer)hGenerator.Container);
subGraphInfo = hAnalyzer.GetConnSubGraph();
tempInfo.avgOrder += subGraphInfo.Last().Key;
tempInfo.avgOrderCount += subGraphInfo.Last().Value;
if (subGraphInfo.Count > 1)
{
subGraphInfo.Remove(subGraphInfo.Last().Key);
tempInfo.secondMax += subGraphInfo.Last().Key;
tempInfo.secondMaxCount += subGraphInfo.Last().Value;
}
if (subGraphInfo.Count > 2)
{
subGraphInfo.Remove(subGraphInfo.Last().Key);
tempInfo.avgOrderRest += subGraphInfo.Average(x => x.Key);
}
}
tempInfo.avgOrder /= (double)realizationCount;
tempInfo.avgOrder /= result.Size;
tempInfo.avgOrderCount /= (double)realizationCount;
tempInfo.secondMax /= (double)realizationCount;
tempInfo.secondMax /= result.Size;
tempInfo.secondMaxCount /= (double)realizationCount;
tempInfo.avgOrderRest /= (double)realizationCount;
tempInfo.avgOrderRest /= result.Size;
result.Result[maxLevel].Add(muTemp, tempInfo);
muTemp += muDelta;
}
XMLResultStorage storage = new XMLResultStorage(Options.StorageDirectory);
storage.SaveResearch(result);
MessageBox.Show("Results are saved succesfully!");
}
示例2: ResultResearch
/*private void startExtended_Click(object sender, EventArgs e)
{
ResultResearch result = new ResultResearch();
result.Name = this.jobName;
result.ModelType = typeof(HierarchicModel);
result.Delta = Double.Parse(this.deltaExtendedTxt.Text);
result.RealizationCount = (Int32)this.realizationCountNum.Value;
result.Function = this.probabilityFunctionCmb.Text;
result.GenerationParams[GenerationParam.BranchIndex] = Int16.Parse(this.branchIndexCmb.Text);
result.GenerationParams[GenerationParam.Level] = Int16.Parse(this.maxLevelCmb.Text);
result.Size = (int)Math.Pow(Int16.Parse(this.branchIndexCmb.Text), Int16.Parse(this.maxLevelCmb.Text));
Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
for (Int16 g = 1; g <= maxLevel; ++g)
{
result.Result.Add(g, AnalyzeExtendedHierarchic(g));
}
XMLResultStorage storage = new XMLResultStorage(Options.StorageDirectory);
storage.SaveResearch(result);
MessageBox.Show("Results are saved succesfully!");
}*/
private void startER_Click(object sender, EventArgs e)
{
ResultResearch result = new ResultResearch();
result.Name = this.jobName;
result.ModelType = typeof(ERModel);
// TODO remove hardcoded data
result.Delta = 0.00001;
result.RealizationCount = 100;
result.GenerationParams[GenerationParam.Vertices] = 65536;
SortedDictionary<double, SubGraphsInfo> pInfo =
new SortedDictionary<double, SubGraphsInfo>();
this.folderBrowserDialog1.ShowDialog();
string dirName = this.folderBrowserDialog1.SelectedPath;
DirectoryInfo parentDir = new DirectoryInfo(dirName);
foreach (FileInfo f in parentDir.GetFiles())
{
double p = Double.Parse(f.Name.Remove(f.Name.Length - 4));
SubGraphsInfo value = new SubGraphsInfo();
SortedDictionary<int, double> r = new SortedDictionary<int, double>();
using (StreamReader streamReader = new StreamReader(f.FullName, System.Text.Encoding.Default))
{
string contents;
while ((contents = streamReader.ReadLine()) != null)
{
string first = "", second = "";
int j = 0;
while (contents[j] != ' ')
{
first += contents[j];
++j;
}
second = contents.Substring(j);
r.Add(int.Parse(first), double.Parse(second));
}
}
value.avgOrder = r.First().Value;
value.avgOrderCount = r.First().Key;
if (r.Count > 1)
{
r.Remove(r.First().Key);
value.secondMax = r.First().Value;
value.secondMaxCount = r.First().Key;
}
if (r.Count > 2)
{
r.Remove(r.First().Key);
value.avgOrderRest = r.Average(x => x.Value);
}
pInfo.Add(p, value);
}
result.Result.Add(1, pInfo);
XMLResultStorage storage = new XMLResultStorage(Options.StorageDirectory);
storage.SaveResearch(result);
MessageBox.Show("Results are saved succesfully!");
}