Ejemplo n.º 1
0
Archivo: SVM.cs Proyecto: nes1983/cc
 /** Subtracts a vector from this vector. Assumes equal dimensions. */
 public void Subtract(RealVector other)
 {
     double[] u = other.GetFeatures();
     for (int i = 0; i < u.Length; ++i) {
     w[i] -= u[i];
     }
 }
Ejemplo n.º 2
0
Archivo: SVM.cs Proyecto: nes1983/cc
            private static RealVector BatchGradient(double[] logloss, TrainingInstance[] batch)
            {
                int dimensions = batch[0].GetFeatureCount();
                int batchSize = batch.Length;

                RealVector toReplicate =  new RealVector(logloss);

                RealVector labels = new RealVector(batchSize);

                for (int i = 0 ; i < batchSize; i++)
                {
                labels.GetFeatures()[i] = batch[i].GetLabel();
                }

                labels.Add(1).ScaleThis(0.5);
                toReplicate.Subtract(labels);

                RealVector[] repmat = new RealVector[dimensions];
                for (int i = 0; i < dimensions; i++) {
                repmat[i] = new RealVector(toReplicate);
                }

                for (int i = 0; i < dimensions; i++) {
                for(int j = 0; j < batchSize; j++) {
                    repmat[i].w[j] *= batch[j].GetFeatures().w[i];
                }
                }

                RealVector result = new RealVector(dimensions);

                for (int i = 0; i < dimensions;i++) {
                result.w[i] = repmat[i].Average();
                }
                return result;
            }
Ejemplo n.º 3
0
Archivo: SVM.cs Proyecto: nes1983/cc
 /** Dot-product between two vectors. Assumes equal dimensions. */
 public double DotProduct(RealVector other)
 {
     double result = 0.0;
     double[] u = other.GetFeatures();
     for (int i = 0; i < u.Length; ++i) {
     result += u[i] * this.w[i];
     }
     return result;
 }