Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace NullWeight
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<Tuple<string, int>>> dict = new Dictionary<string, List<Tuple<string, int>>>();
- Random rnd = new Random();
- List<Tuple<string, int>> testList = new List<Tuple<string, int>>();
- for(int i = 0; i<6; i++) testList.Add(Tuple.Create<string, int>("*", rnd.Next(500)));
- for (int i = 0; i < 4; i++) testList.Add(Tuple.Create<string, int>("*", 0));
- dict.Add("test", testList);
- foreach (Tuple<string, int> t in testList) Console.Write(t.Item2.ToString() + ",");
- Console.WriteLine();
- foreach (KeyValuePair<string, List<Tuple<string, int>>> d in dict)
- {
- int tWeight = 0; int nullCount = 0; int propValue = 0;
- foreach(Tuple<string, int> t in d.Value)
- {
- tWeight += t.Item2;
- if (t.Item2 == 0) nullCount++;
- }
- Console.WriteLine("origTotal: " + tWeight);
- propValue = (tWeight / d.Value.Count);
- float proptWeight = (float)tWeight * (1f+ (float)nullCount / (float)d.Value.Count);
- Console.WriteLine("propTotal: " + proptWeight);
- Console.WriteLine("Ratio: " + nullCount + "/" + d.Value.Count);
- Console.WriteLine("PropValue: " + propValue);
- Console.WriteLine("Orig+prop: " + (tWeight + propValue * nullCount));
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement