Package fr.lip6.jkernelmachines.kernel.extra.bag

Examples of fr.lip6.jkernelmachines.kernel.extra.bag.UnormalizedListKernel


      printHelp();
      System.exit(-1);
    }
    // perform PCA
    if(hasPCA == 1) {
      DoublePCA pca = new DoublePCA();
      pca.train(list);
      list = pca.projectList(list);
    }
    else if(hasPCA == 2) {
      DoublePCA pca = new DoublePCA();
      pca.train(list);
      list = pca.projectList(list, true);
    }

    // initialize CV
    AccuracyEvaluator<double[]> ev = new AccuracyEvaluator<double[]>();
    RandomSplitCrossValidation<double[]> cv = new RandomSplitCrossValidation<double[]>(
View Full Code Here


    model.dim = train.get(0).sample.length;

    // perform preprocessing
    List<TrainingSample<double[]>> localTrain;
    if (pcaBox.isSelected()) {
      model.pca = new DoublePCA();
      model.pca.train(train);
      model.pcaEnable = true;
      model.whiteningEnable = whiteBox.isSelected();
      localTrain = model.pca.projectList(train, whiteBox.isSelected());
    } else {
View Full Code Here

    GaussianGenerator gen = new GaussianGenerator(dim);
    list = gen.generateList(nbSamples);
   
   
    pca = new DoublePCA();
    pca.train(list);
   
  }
View Full Code Here

      rmap.put(index, s);
      index++;
    }
   
    //computing matrix       
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for(int index = from ; index < to ; index++)
        {
          //reverse search through mapping S <-> index
          S s1 = rmap.get(index);
          //mapped signature
          T t1 = signatures.get(s1);

          //all mapping S <-> T
          for(Iterator<S> iter = map.keySet().iterator() ; iter.hasNext() ;)
          {
            S s2 = iter.next();
            //get index of s2
            int j = map.get(s2);
            //get signature of s2
            T t2 = signatures.get(s2);
            //add value of kernel
            matrix[index][j] = kernel.valueOf(t1, t2);
          }
        }
      };
    };


    /* do the actuel computing of the matrix */
    matrix = factory.getMatrix(matrix);
       
  }
View Full Code Here

    debug.println(4, "svmObj : alphas = " + Arrays.toString(alp));
    // debug.println(4, "svmObj : b="+svm.getB());

    // parallelized
    final double[] resLine = new double[kmatrix.length];
    ThreadedMatrixOperator objFactory = new ThreadedMatrixOperator() {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for (int index = from; index < to; index++) {
          if (abs(alp[index]) > 0) {
            double al1 = abs(alp[index]);
            for (int j = 0; j < matrix[index].length; j++) {
              if (abs(alp[j]) > 0)
                resLine[index] += al1 * abs(alp[j])
                    * matrix[index][j];
            }
          }
        }
      }
    };

    objFactory.getMatrix(kmatrix);
    double obj1 = 0;
    for (double d : resLine)
      obj1 += d;

    double obj2 = 0;
View Full Code Here

      Kernel<T> k = km.get(i);
      double kmatrix[][] = k.getKernelMatrix(list);

      // parallelized
      final double[] resLine = new double[kmatrix.length];
      ThreadedMatrixOperator gradFactory = new ThreadedMatrixOperator() {
        @Override
        public void doLines(double[][] matrix, int from, int to) {
          for (int index = from; index < to; index++) {
            if (alp[index] > 0) {
              double al1 = -0.5 * alp[index];
              for (int j = 0; j < matrix[index].length; j++) {
                resLine[index] += al1 * alp[j]
                    * matrix[index][j];
              }
            }
          }
        }
      };

      gradFactory.getMatrix(kmatrix);
      double g = 0;
      for (double d : resLine)
        g += d;
      grad.add(i, g);
    }
View Full Code Here

  public double[][] getKernelMatrix(final List<TrainingSample<T>> l)
  {
    double[][] matrix = new double[l.size()][l.size()];
   
    //computing matrix       
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for(int index = from ; index < to ; index++)
        {
          T s1 = l.get(index).sample;
          for(int j = 0 ; j < matrix.length ; j++)
            matrix[index][j] = valueOf(s1, l.get(j).sample);
        }
      }
    };
   
    factory.getMatrix(matrix)
   
    return matrix;
  }
View Full Code Here

  public double[][] getKernelMatrix(final List<TrainingSample<T>> l) {
   
    final List<TrainingSample<T>> e = l;
    double[][] matrix = new double[e.size()][e.size()];
       
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for(int index = from ; index < to ; index++)
        {
          T xi = l.get(index).sample;

          for(int j = 0 ; j < matrix[index].length ; j++)
          {
            matrix[index][j] = k.valueOf(xi, l.get(j).sample);
          }
        }
      };
    };

    /* do the actuel computing of the matrix */
    matrix = factory.getMatrix(matrix);
   
    return matrix;
  }
View Full Code Here

    final double [][] matrix = kernel.getKernelMatrix(listOfExamples);
    if(lambda_matrix == null)
      lambda_matrix = new double[matrix.length][matrix.length];
    debug.println(3, "+ update lambda matrix");
   
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] m , int from , int to) {
        for(int index = from ; index < to ; index++)
        {
          if(a[index] == 0) {
            m[index] = null;
            continue;
          }
         
          if(m[index] == null)
            m[index] = new double[matrix.length];
         
          int l1 = listOfExamples.get(index).label;
          double al1 = a[index]*l1;
          for(int j = 0 ; j < m[index].length ; j++)
          {
            int l2 = listOfExamples.get(j).label;
            m[index][j] = al1 * l2 * a[j] * matrix[index][j];
          }
        }
      }

     
    };
   
    lambda_matrix = factory.getMatrix(lambda_matrix);
  }
View Full Code Here

    mean = mul(mean, 1./list.size());
   
    // compute covariance matrix;
    double[][] cov = new double[dim][dim];
   
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator() {
     
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for(int i = from ; i < to ; i++) {
          for(int j = 0 ; j < matrix.length ; j++) {
            double sum = 0;
            for(TrainingSample<double[]> t : list) {
              sum += (t.sample[i]-mean[i]) * (t.sample[j]-mean[j]);
            }
            matrix[i][j] = sum/list.size();
          }
        }       
      }
    };
   
    cov = factory.getMatrix(cov);
   
    // eigen decomposition
    double[][][] eig = eig(cov);
   
    //projectors are eigenvectors transposed
View Full Code Here

TOP

Related Classes of fr.lip6.jkernelmachines.kernel.extra.bag.UnormalizedListKernel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.