Examples of ThreadedMatrixOperator


Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

  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

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

  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

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    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

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    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

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    double[][] matrix = new double[l.size()][l.size()];
   
//    if(gammas[x] == 0)
//      return matrix;
    //computing matrix       
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        double tmp = 0;
        for(int index = from ; index < to ; index++)
        {
          double s1 = l.get(index).sample[x];
          for(int j = 0 ; j < matrix.length ; j++){
            tmp = s1 - l.get(j).sample[x];
//            matrix[index][j] = gammas[x]*tmp*tmp;
            matrix[index][j] = tmp*tmp;
          }
           
        }
      }
    };
   
    factory.getMatrix(matrix);
   
    return matrix;
  }
View Full Code Here

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

  public double[][] getDistanceMatrix(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] = distanceValueOf(s1, l.get(j).sample);
        }
      }
    };
   
    factory.getMatrix(matrix);
   
    return matrix;
  }
View Full Code Here

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    double[][] matrix = new double[l.size()][l.size()];
   
//    if(gammas[x] == 0)
//      return matrix;
    //computing matrix       
    ThreadedMatrixOperator factory = new ThreadedMatrixOperator()
    {
      @Override
      public void doLines(double[][] matrix, int from, int to) {
        double tmp = 0;
        for(int index = from ; index < to ; index++)
        {
          double s1 = l.get(index).sample[x];
          for(int j = 0 ; j < matrix.length ; j++){
            tmp = s1 - l.get(j).sample[x];
//            matrix[index][j] = gammas[x]*tmp*tmp;
            matrix[index][j] = tmp*tmp;
          }
           
        }
      }
    };
   
    factory.getMatrix(matrix);
   
    return matrix;
  }
View Full Code Here

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    //rebuild matrix
    kmatrix = kernel.getKernelMatrix(tlist);
   
    //rebuild gradient
    final double[] tmp = new double[g.length];
    (new ThreadedMatrixOperator(){

      @Override
      public void doLines(double[][] matrix, int from, int to) {
        for(int index = from ; index < to ; index++)
        {
View Full Code Here

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

    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++)
        {
          resLine[index] = 0;
          if(abs(alp[index]) > 0)
          {
            double al1 = abs(alp[index]) * l.get(index).label;
            for(int j = 0 ; j < matrix[index].length ; j++)
            {
              if(abs(alp[j]) > 0)
                resLine[index] += al1 * abs(alp[j]) * l.get(j).label * matrix[index][j];
            }
          }
        }
      } 
    };
   
    objFactory.getMatrix(kmatrix);
    double obj1 = 0;
    for(double d : resLine)
      obj1 += d;
   
    double obj2 = 0;
View Full Code Here

Examples of fr.lip6.jkernelmachines.threading.ThreadedMatrixOperator

      Kernel<T> k = km.get(i);
      double kmatrix[][] = k.getKernelMatrix(l);
           
      //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++)
          {
            resLine[index] = 0;
            if(alp[index] > 0)
            {
              double al1 = -0.5 * alp[index] * l.get(index).label;
              for(int j = 0 ; j < matrix[index].length ; j++)
              {
                resLine[index] += al1 * alp[j] * l.get(j).label * matrix[index][j];
              }
            }
          }
        } 
      };
     
      gradFactory.getMatrix(kmatrix);
      double g = 0;
      for(double d : resLine)
        g += d;
      grad.add(i, g);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.