Examples of DoubleSGDQN


Examples of JKernelMachines.fr.lip6.classifier.DoubleSGDQN

  {
    eprintln(2, "training on "+train.size()+" train data and "+test.size()+" test data");
   
    //first training
    eprint(3, "first training ");
    svm = new DoubleSGDQN();
    DoubleSGDQN.VERBOSE = false;
    svm.train(train);
    eprintln(3, " done.");
   
    //affect numplus highest output to plus class
    eprintln(3, "affecting 1 to the "+numplus+" highest output");
    SortedSet<TrainingSample<double[]>> sorted = new TreeSet<TrainingSample<double[]>>(new Comparator<TrainingSample<double[]>>(){

      public int compare(TrainingSample<double[]> o1, TrainingSample<double[]> o2) {
        int ret = (new Double(svm.valueOf(o2.sample))).compareTo(svm.valueOf(o1.sample));
        if(ret == 0)
          ret = -1;
        return ret;
      }
     
    });
    sorted.addAll(test);
    eprintln(4, "sorted size : "+sorted.size()+" test size : "+test.size());
    int n = 0;
    for(TrainingSample<double[]> t : sorted)
    {
      if(n < numplus)
        t.label = 1;
      else
        t.label = -1;
      n++;
    }
   
    double Cminus = 1e-5;
    double Cplus = 1e-5 * numplus/(test.size() - numplus);
   
    while(Cminus < C || Cplus < C)
    {
      //solve full problem
      ArrayList<TrainingSample<double[]>> full = new ArrayList<TrainingSample<double[]>>();
      full.addAll(train);
      full.addAll(test);
     
      eprint(3, "full training ");
      svm = new DoubleSGDQN();
      svm.setC((Cminus+Cplus)/2.);
      svm.train(full);
      eprintln(3, "done.");
     
      boolean changed = false;
     
      do
      {
        changed = false;
        //0. computing error
        final Map<TrainingSample<double[]>, Double> errorCache = new HashMap<TrainingSample<double[]>, Double>();
        for(TrainingSample<double[]> t : test)
        {
          double err1 = 1. - t.label * svm.valueOf(t.sample);
          errorCache.put(t, err1);
        }
        eprintln(3, "Error cache done.");
       
        // 1 . sort by descending error
        sorted = new TreeSet<TrainingSample<double[]>>(new Comparator<TrainingSample<double[]>>(){

          public int compare(TrainingSample<double[]> o1,
              TrainingSample<double[]> o2) {
            int ret = errorCache.get(o2).compareTo(errorCache.get(o1));
            if(ret == 0)
              ret = -1;
            return ret;
          }
        });
        sorted.addAll(test);
        List<TrainingSample<double[]>> sortedList = new ArrayList<TrainingSample<double[]>>();
        sortedList.addAll(sorted);
       
       
        eprintln(3, "sorting done, checking couple");
       
        // 2 . test all couple by decreasing error order
//        for(TrainingSample<T> i1 : sorted)
        for(int i = 0 ; i < sortedList.size(); i++)
        {
          TrainingSample<double[]> i1 = sortedList.get(i);
//          for(TrainingSample<T> i2 : sorted)
          for(int j = i+1; j < sortedList.size(); j++)
          {
            TrainingSample<double[]> i2 = sortedList.get(j);
            if(examine(i1, i2, errorCache))
            {
              eprintln(3, "couple found !");
              changed = true;
              break;
            }
          }
          if(changed)
            break;
        }

        if(changed)
        {
          eprintln(3, "re-training");
          svm = new DoubleSGDQN();
          svm.setC((Cminus+Cplus)/2.);
          svm.train(full);
        }
      }
      while(changed);
View Full Code Here

Examples of fr.lip6.jkernelmachines.classifier.DoubleSGDQN

  {
    debug.println(2, "training on "+train.size()+" train data and "+test.size()+" test data");
   
    //first training
    debug.print(3, "first training ");
    svm = new DoubleSGDQN();
    DoubleSGDQN.VERBOSE = false;
    svm.train(train);
    debug.println(3, " done.");
   
    //affect numplus highest output to plus class
    debug.println(3, "affecting 1 to the "+numplus+" highest output");
    SortedSet<TrainingSample<double[]>> sorted = new TreeSet<TrainingSample<double[]>>(new Comparator<TrainingSample<double[]>>(){

      @Override
      public int compare(TrainingSample<double[]> o1, TrainingSample<double[]> o2) {
        int ret = (new Double(svm.valueOf(o2.sample))).compareTo(svm.valueOf(o1.sample));
        if(ret == 0)
          ret = -1;
        return ret;
      }
     
    });
    sorted.addAll(test);
    debug.println(4, "sorted size : "+sorted.size()+" test size : "+test.size());
    int n = 0;
    for(TrainingSample<double[]> t : sorted)
    {
      if(n <= numplus)
        t.label = 1;
      else
        t.label = -1;
      n++;
    }
   
    double Cminus = 1e-5;
    double Cplus = 1e-5 * numplus/(test.size() - numplus);
   
    while(Cminus < C || Cplus < C)
    {
      //solve full problem
      ArrayList<TrainingSample<double[]>> full = new ArrayList<TrainingSample<double[]>>();
      full.addAll(train);
      full.addAll(test);
     
      debug.print(3, "full training ");
      svm = new DoubleSGDQN();
      svm.setC((Cminus+Cplus)/2.);
      svm.train(full);
      debug.println(3, "done.");
     
      boolean changed = false;
     
      do
      {
        changed = false;
        //0. computing error
        final Map<TrainingSample<double[]>, Double> errorCache = new HashMap<TrainingSample<double[]>, Double>();
        for(TrainingSample<double[]> t : test)
        {
          double err1 = 1. - t.label * svm.valueOf(t.sample);
          errorCache.put(t, err1);
        }
        debug.println(3, "Error cache done.");
       
        // 1 . sort by descending error
        sorted = new TreeSet<TrainingSample<double[]>>(new Comparator<TrainingSample<double[]>>(){

          @Override
          public int compare(TrainingSample<double[]> o1,
              TrainingSample<double[]> o2) {
            int ret = errorCache.get(o2).compareTo(errorCache.get(o1));
            if(ret == 0)
              ret = -1;
            return ret;
          }
        });
        sorted.addAll(test);
        List<TrainingSample<double[]>> sortedList = new ArrayList<TrainingSample<double[]>>();
        sortedList.addAll(sorted);
       
       
        debug.println(3, "sorting done, checking couple");
       
        // 2 . test all couple by decreasing error order
//        for(TrainingSample<T> i1 : sorted)
        for(int i = 0 ; i < sortedList.size(); i++)
        {
          TrainingSample<double[]> i1 = sortedList.get(i);
//          for(TrainingSample<T> i2 : sorted)
          for(int j = i+1; j < sortedList.size(); j++)
          {
            TrainingSample<double[]> i2 = sortedList.get(j);
            if(examine(i1, i2, errorCache))
            {
              debug.println(3, "couple found !");
              changed = true;
              break;
            }
          }
          if(changed)
            break;
        }

        if(changed)
        {
          debug.println(3, "re-training");
          svm = new DoubleSGDQN();
          svm.setC((Cminus+Cplus)/2.);
          svm.train(full);
        }
      }
      while(changed);
View Full Code Here

Examples of fr.lip6.jkernelmachines.classifier.DoubleSGDQN

  @Before
  public void setUp() throws Exception {
    GaussianGenerator g = new GaussianGenerator(10, 5.0f, 1.0);
    train = g.generateList(10);
   
    svm = new DoubleSGDQN();
  }
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.