コード例 #1
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)
        {
            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));
         }
     }
 }
コード例 #4
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.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
 /// <summary>
 /// Button2_Click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button2_Click(object sender, RoutedEventArgs e)
 {
     SetB.Add(Input);
 }