/// <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
        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]));
                }
            }
        }
Пример #3
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));
         }
     }
 }
 /// <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.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));
         }
     }
 }
Пример #5
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);
         }
     });
 }
Пример #6
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);
        }