Ejemplo n.º 1
0
        public string[] Classify(Vector[] sample)
        {
            var result = new List <string>( );

            var classes = answers.Distinct( ).ToList( );

            var classDists = new Dictionary <string, double>( );

            foreach (var u in sample)
            {
                classDists.Clear( );

                foreach (var c in classes)
                {
                    classDists.Add(c, 0);
                }

                int i = 0;

                foreach (var v in GetSampleUnion( ).OrderBy(v => Euclid.Dist(u, v.Values)))
                {
                    classDists[v.Class] += CalcNeighbourWeight(u, v.Values, i++);
                }

                // To make class with max weight first
                result.Add(classDists.OrderByDescending(pair => pair.Value).First( ).Key);
            }

            return(result.ToArray( ));
        }
Ejemplo n.º 2
0
        protected override double CalcNeighbourWeight(Vector u, Vector neighbour, int neighbourIndex)
        {
            if (u != cachedU)
            {
                sourceVec = train.OrderBy(x => Euclid.Dist(u, x)).ElementAt(hSource);
                cachedU   = u;
            }

            double h = Euclid.Dist(u, sourceVec);

            return(kernelFunc(Euclid.Dist(u, neighbour) / h));
        }
Ejemplo n.º 3
0
        protected override double CalcNeighbourWeight(Vector u, Vector neighbour, int neighbourIndex)
        {
            if (u != cachedU)
            {
                indexOrder = (from quant in train.Select((x, i) => new { Values = x, Index = i })
                              orderby Euclid.Dist(u, quant.Values)
                              select quant.Index).ToArray( );
                cachedU = u;
            }

            var dist = Euclid.Dist(u, neighbour) / widths[indexOrder[neighbourIndex]];

            return(charges[indexOrder[neighbourIndex]] * PotentialFunction(dist));
        }
 protected override double CalcNeighbourWeight(Vector u, Vector neighbour, int neighbourIndex)
 {
     return(kernelFunc(Euclid.Dist(u, neighbour) / h));
 }
Ejemplo n.º 5
0
 public static Func <Vector, Vector, int, double> DistanceWeight( )
 {
     // Because we maximize weight of class, nearest object must have the biggest weight
     return((u, v, i) => 1.0 / Euclid.Dist(u, v));
 }