/// <summary>
        /// Loads a set of tokens
        /// </summary>
        /// <param name="SetATokens">Set A</param>
        /// <param name="SetBTokens">Set B</param>
        public virtual void LoadTokens(System.Collections.Generic.List <T> SetATokens, System.Collections.Generic.List <T> SetBTokens)
        {
            if (SetATokens == null)
            {
                throw new ArgumentNullException("SetATokens");
            }
            if (SetBTokens == null)
            {
                throw new ArgumentNullException("SetBTokens");
            }
            if (SetA == null)
            {
                SetA = new Bag <T>();
            }
            if (SetB == null)
            {
                SetB = new Bag <T>();
            }

            foreach (T TokenA in SetATokens)
            {
                SetA.Add(TokenA);
            }
            foreach (T TokenB in SetBTokens)
            {
                SetB.Add(TokenB);
            }
            TotalA = 0;
            TotalB = 0;
            foreach (T Token in SetA)
            {
                TotalA += SetA[Token];
            }
            foreach (T Token in SetB)
            {
                TotalB += SetB[Token];
            }
            Total         = TotalA + TotalB;
            Probabilities = new Dictionary <T, double>();
            foreach (T Token in SetA)
            {
                Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
            }
            foreach (T Token in SetB)
            {
                if (!Probabilities.ContainsKey(Token))
                {
                    Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Calculates a single items probability of being in set A
        /// </summary>
        /// <param name="Item">Item to calculate</param>
        /// <returns>The probability that the token is from set A</returns>
        protected virtual double CalculateProbabilityOfToken(T Item)
        {
            Contract.Requires <ArgumentNullException>(SetA != null && SetB != null, "Probabilities have not been initialized");
            double Probability = 0;
            int    ACount      = SetA.Contains(Item) ? SetA[Item] * ATokenWeight : 0;
            int    BCount      = SetB.Contains(Item) ? SetB[Item] * BTokenWeight : 0;

            if (ACount + BCount >= MinCountForInclusion)
            {
                double AProbability = ((double)ACount / (double)TotalA).Min(1);
                double BProbability = ((double)BCount / (double)TotalB).Min(1);
                Probability = MinTokenProbability.Max(MaxTokenProbability.Min(AProbability / (AProbability + BProbability)));
            }
            return(Probability);
        }
Пример #3
0
        /// <summary>
        /// Button4_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            // check and indicate if T is subset of A
            SubsetIndicatorT = SetT.All(x => SetA.Contains(x)); if (SubsetIndicatorT)
            {
                Console.Beep();
            }
            else
            {
                Console.Beep(); Console.Beep();
            }

            // execute the LINQ commands
            IntersectionAB       = new ObservableCollection <string>(SetA.Intersect(SetB));
            UnionAB              = new ObservableCollection <string>(SetA.Union(SetB));
            RelativeComplementAB = new ObservableCollection <string>(SetA.Except(SetB));
        }
Пример #4
0
        /// <summary>
        /// Calculates a single items probability of being in set A
        /// </summary>
        /// <param name="Item">Item to calculate</param>
        /// <returns>The probability that the token is from set A</returns>
        protected virtual double CalculateProbabilityOfToken(T Item)
        {
            if (SetA == null || SetB == null)
            {
                throw new NullReferenceException("Probabilities have not been initialized");
            }
            double Probability = 0;
            int    ACount      = SetA.Contains(Item) ? SetA[Item] * ATokenWeight : 0;
            int    BCount      = SetB.Contains(Item) ? SetB[Item] * BTokenWeight : 0;

            if (ACount + BCount >= MinCountForInclusion)
            {
                double AProbability = ((double)ACount / (double)TotalA).Min(1);
                double BProbability = ((double)BCount / (double)TotalB).Min(1);
                Probability = MinTokenProbability.Max(MaxTokenProbability.Min(AProbability / (AProbability + BProbability)));
            }
            return(Probability);
        }
Пример #5
0
 private void ClearSets()
 {
     SetA.Clear();
     SetB.Clear();
     SetT.Clear();
     if (IntersectionAB != null)
     {
         IntersectionAB.Clear();
     }
     if (UnionAB != null)
     {
         UnionAB.Clear();
     }
     if (RelativeComplementAB != null)
     {
         RelativeComplementAB.Clear();
     }
 }
Пример #6
0
        public void Predict(IEnumerable <double[]> elems)
        {
            var roundWeights = Weights.RoundValues(2).ToArray();
            var roundBias = new [] { Bias }.RoundValues(2).ToArray();

            foreach (var e in elems)
            {
                var @class = Math.Sign(e.Dot(roundWeights) + ModelToUse * roundBias.First());
                if (@class >= 1)
                {
                    SetA.Add(new Tuple <double, double>(e[0], e[1]));
                }
                else if (@class <= -1)
                {
                    SetB.Add(new Tuple <double, double>(e[0], e[1]));
                }
                else
                {
                    Hyperplane.Add(new Tuple <double, double>(e[0], e[1]));
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Button4_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            // check and indicate if T is subset of A
            SubsetIndicatorT = SetT.All(x => SetA.Contains(x, new KeyAndTimeComparer())); if (SubsetIndicatorT)
            {
                Console.Beep();
            }
            else
            {
                Console.Beep(); Console.Beep();
            }

            // execute the LINQ commands
            var ResultSet = SetA.Intersect(SetB, new KeyAndTimeComparer());

            IntersectionAB = new ObservableCollection <KeyAndTime>(ResultSet.ToList <KeyAndTime>());

            ResultSet = SetA.Union(SetB, new KeyAndTimeComparer());
            UnionAB   = new ObservableCollection <KeyAndTime>(ResultSet.ToList <KeyAndTime>());

            ResultSet            = SetA.Except(SetB, new KeyAndTimeComparer());
            RelativeComplementAB = new ObservableCollection <KeyAndTime>(ResultSet.ToList <KeyAndTime>());
        }
Пример #8
0
 /// <summary>
 /// Loads a set of tokens
 /// </summary>
 /// <param name="SetATokens">Set A</param>
 /// <param name="SetBTokens">Set B</param>
 public virtual void LoadTokens(System.Collections.Generic.List <T> SetATokens, System.Collections.Generic.List <T> SetBTokens)
 {
     SetATokens.ThrowIfNull("SetATokens");
     SetBTokens.ThrowIfNull("SetBTokens");
     SetA = SetA.NullCheck(new Bag <T>());
     SetB = SetB.NullCheck(new Bag <T>());
     SetA.AddRange(SetATokens);
     SetB.AddRange(SetBTokens);
     TotalA        = SetA.Sum(x => SetA[x]);
     TotalB        = SetB.Sum(x => SetB[x]);
     Total         = TotalA + TotalB;
     Probabilities = new Dictionary <T, double>();
     foreach (T Token in SetA)
     {
         Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
     }
     foreach (T Token in SetB)
     {
         if (!Probabilities.ContainsKey(Token))
         {
             Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Loads a set of tokens
 /// </summary>
 /// <param name="SetATokens">Set A</param>
 /// <param name="SetBTokens">Set B</param>
 public virtual void LoadTokens(IEnumerable <T> SetATokens, IEnumerable <T> SetBTokens)
 {
     Contract.Requires <ArgumentNullException>(SetATokens != null, "SetATokens");
     Contract.Requires <ArgumentNullException>(SetBTokens != null, "SetBTokens");
     SetA = SetA.Check(() => new Bag <T>());
     SetB = SetB.Check(() => new Bag <T>());
     SetA.Add(SetATokens);
     SetB.Add(SetBTokens);
     TotalA        = SetA.Sum(x => SetA[x]);
     TotalB        = SetB.Sum(x => SetB[x]);
     Total         = TotalA + TotalB;
     Probabilities = new Dictionary <T, double>();
     foreach (T Token in SetA)
     {
         Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
     }
     foreach (T Token in SetB)
     {
         if (!Probabilities.ContainsKey(Token))
         {
             Probabilities.Add(Token, CalculateProbabilityOfToken(Token));
         }
     }
 }
Пример #10
0
 /// <summary>
 /// Loads a set of tokens
 /// </summary>
 /// <param name="SetATokens">Set A</param>
 /// <param name="SetBTokens">Set B</param>
 public virtual void LoadTokens(IEnumerable <T> SetATokens, IEnumerable <T> SetBTokens)
 {
     Contract.Requires <ArgumentNullException>(SetATokens != null, "SetATokens");
     Contract.Requires <ArgumentNullException>(SetBTokens != null, "SetBTokens");
     SetA = SetA.Check(() => new Bag <T>());
     SetB = SetB.Check(() => new Bag <T>());
     SetA.Add(SetATokens);
     SetB.Add(SetBTokens);
     TotalA        = SetA.Sum(x => SetA[x]);
     TotalB        = SetB.Sum(x => SetB[x]);
     Total         = TotalA + TotalB;
     Probabilities = new ConcurrentDictionary <T, double>();
     Parallel.ForEach(SetA, Token =>
     {
         Probabilities.AddOrUpdate(Token, x => CalculateProbabilityOfToken(x), (x, y) => CalculateProbabilityOfToken(x));
     });
     Parallel.ForEach(SetB, Token =>
     {
         if (!Probabilities.ContainsKey(Token))
         {
             Probabilities.AddOrUpdate(Token, x => CalculateProbabilityOfToken(x), (x, y) => y);
         }
     });
 }
Пример #11
0
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                aString = SetA.Text;
                bString = SetB.Text;
                rString = Relation.Text;

                Relation relation = new Relation(aString, bString, rString);

                CustomButton b1 = new CustomButton(aString, bString, rString);
                Label        l2 = new Label();
                Label        l3 = new Label();
                Label        l4 = new Label();
                Label        l5 = new Label();
                Label        l6 = new Label();
                Label        l7 = new Label();

                Label l8  = new Label();
                Label l9  = new Label();
                Label l10 = new Label();
                Label l11 = new Label();
                b1.Name    = "wholeRel" + counter;
                b1.Content = "Draw this relation";
                b1.Click  += DrawRelation_Click;
                b1.Height  = 23;

                l2.Name    = "lefttotal" + counter;
                l2.Content = "Lefttotal: " + relation.isLefttotal();
                l2.Height  = 23;
                l3.Name    = "righttotal";
                l3.Content = "Righttotal: " + relation.isRighttotal();
                l3.Height  = 23;
                l4.Name    = "bitotal";
                l4.Content = "Bitotal: " + relation.isBitotal();
                l4.Height  = 23;
                l5.Name    = "leftunique";
                l5.Content = "Leftunique: " + relation.isLeftunique();
                l5.Height  = 23;
                l6.Name    = "rightunique";
                l6.Content = "Rightunique: " + relation.isRightunique();
                l6.Height  = 23;
                l7.Name    = "onetoone";
                l7.Content = "One-to-one: " + relation.isOneunique();
                l7.Height  = 23;

                l8.Name     = "function";
                l8.Content  = "Function: " + relation.isFunction();
                l8.Height   = 23;
                l9.Name     = "surjective";
                l9.Content  = "Surjective: " + relation.isSurjective();
                l9.Height   = 23;
                l10.Name    = "injective";
                l10.Content = "Injective: " + relation.isInjective();
                l10.Height  = 23;
                l11.Name    = "bijective";
                l11.Content = "Bijective: " + relation.isBijective();
                l11.Height  = 23;


                CustomButton btn = new CustomButton(aString, bString, rString);
                btn.Name    = "RelBtn" + counter;
                btn.Content = ("R" + counter + " = ({" + aString + "} x {" + bString + "}, {" + rString + "})");
                btn.Click  += RelButton_Click;
                TopStackPanel.Children.Add(btn);

                StackPanel stack = new StackPanel();
                stack.Name                = "S" + counter;
                stack.Visibility          = Visibility.Collapsed;
                stack.HorizontalAlignment = HorizontalAlignment.Center;


                stack.Children.Add(b1);
                stack.Children.Add(l2);
                stack.Children.Add(l3);
                stack.Children.Add(l4);
                stack.Children.Add(l5);
                stack.Children.Add(l6);
                stack.Children.Add(l7);
                stack.Children.Add(l8);
                stack.Children.Add(l9);
                stack.Children.Add(l10);
                stack.Children.Add(l11);
                TopStackPanel.Children.Add(stack);

                counter++;

                SetA.Foreground = Brushes.LightGray;
                SetA.Text       = defaultTextA;

                SetB.Foreground = Brushes.LightGray;
                SetB.Text       = defaultTextB;

                Relation.Foreground = Brushes.LightGray;
                Relation.Text       = defaultTextR;

                SetA.Focus();
            }
            catch (InputNotIntException)
            {
                MessageBox.Show("You need to enter numbers only!");
            }
        }
Пример #12
0
        /******************************/
        /*       Button Events        */
        /******************************/
        #region Button Events

        /// <summary>
        /// Button1_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            SetA.Add(Input);
        }