Package com.clearnlp.classification.model

Examples of com.clearnlp.classification.model.AbstractModel


   
    IntArrayList        ys = space.getYs();
    ArrayList<int[]>    xs = space.getXs();
    ArrayList<double[]> vs = space.getVs();
   
    AbstractModel model = space.getModel();
    double[] cWeights = new double[WS];
    double[] aWeights = average ? new double[WS] : null;
    double[] gs       = new double[WS];
   
    double stdev, prevScore, currScore = 0;
    int[] indices = UTArray.range(N);
    int i, j, correct, count = 1;
   
    int      yi;
    int[]    xi;
    double[] vi = null;
   
    for (i=0; i<MAX_ITER; i++)
    {
      UTArray.shuffle(new Random(5), indices, N);
      prevScore = currScore;
      Arrays.fill(gs, 0);
      correct = 0;
     
      for (j=0; j<N; j++)
      {
        yi = ys.get(indices[j]);
        xi = xs.get(indices[j]);
        if (space.hasWeight())  vi = vs.get(indices[j]);
       
        if (average)
        {
          if (!update(L, yi, xi, vi, gs, cWeights, aWeights, count))
            correct++;
         
          count++;
        }
        else if (!update(L, yi, xi, vi, gs, cWeights))
          correct++;
      }
     
      currScore = 100d * correct / N;
      stdev = UTMath.stdev(prevScore, currScore);
      LOG.info(String.format("%4d: acc = %5.2f, stdev = %7.4f\n", i+1, currScore, stdev));
      if (stdev < d_eps) break;
    }
   
    if (averagemodel.setWeights(getWeights(cWeights, aWeights, count));
    else      model.setWeights(UTArray.toFloatArray(cWeights));
  }
View Full Code Here


    }
   
    space.readInstances(UTInput.createBufferedFileReader(trainFile));
    space.build();
   
    AbstractModel model = getModel(space, numThreads, solver, cost, eps, bias);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(modelFile)));
   
    out.writeObject(model);
    out.close();
  }
View Full Code Here

    }
   
    space.readInstances(UTInput.createBufferedFileReader(trainFile));
    space.build();
   
    AbstractModel model = getModel(space, solver, alpha, rho, eps, average);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(modelFile)));
   
    out.writeObject(model);
    out.close();
  }
View Full Code Here

    }
   
    space.readInstances(UTInput.createBufferedFileReader(trainFile));
    space.build();
   
    AbstractModel model = getModel(space, solver, alpha, rho, eps);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(modelFile)));
   
    out.writeObject(model);
    out.close();
  }
View Full Code Here

      algorithm = new AdaGradHinge(alpha, rho, eps); break;
    case AbstractAlgorithm.SOLVER_ADAGRAD_LR:
      algorithm = new AdaGradLR(alpha, rho, eps); break;
    }
   
    AbstractModel model = space.getModel();
   
    model.initWeightVector();
    algorithm.train(space);

    return model;
  }
View Full Code Here

    }
   
    space.readInstances(UTInput.createBufferedFileReader(trainFile));
    space.build();
   
    AbstractModel model = getModel(space, numThreads, solver, cost, eps, bias);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(modelFile)));
   
    out.writeObject(model);
    out.close();
  }
View Full Code Here

    }
   
    space.readInstances(UTInput.createBufferedFileReader(trainFile));
    space.build();
   
    AbstractModel model = getModel(space, solver, alpha, rho, eps);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(modelFile)));
   
    out.writeObject(model);
    out.close();
  }
View Full Code Here

   * Trains all instances in the training space.
   * @param space the training space.
   */
  public void train(AbstractTrainSpace space)
  {
    AbstractModel model = space.getModel();
   
    if (model.getWeights() == null)
      model.initWeightVector();
   
    updateWeights(space);
  }
View Full Code Here

   
    IntArrayList        ys = space.getYs();
    ArrayList<int[]>    xs = space.getXs();
    ArrayList<double[]> vs = space.getVs();
   
    AbstractModel model = space.getModel();
    double[] cWeights = UTArray.toDoubleArray(model.getWeights());
    double[] gs = new double[WS];
   
    double stdev, prevScore, currScore = 0;
    int[] indices = UTArray.range(N);
    int i, j, correct;
   
    int      yi;
    int[]    xi;
    double[] vi = null;
   
    for (i=0; i<MAX_ITER; i++)
    {
      UTArray.shuffle(new Random(5), indices, N);
      prevScore = currScore;
      Arrays.fill(gs, 0);
      correct = 0;
     
      for (j=0; j<N; j++)
      {
        yi = ys.get(indices[j]);
        xi = xs.get(indices[j]);
        if (space.hasWeight())  vi = vs.get(indices[j]);
       
        if (!update(L, yi, xi, vi, gs, cWeights))
          correct++;
      }
     
      currScore = 100d * correct / N;
      stdev = UTMath.stdev(prevScore, currScore);
      LOG.info(String.format("%4d: acc = %5.2f, stdev = %7.4f\n", i+1, currScore, stdev));
      if (stdev < d_eps) break;
    }
   
    model.setWeights(UTArray.toFloatArray(cWeights));
  }
View Full Code Here

TOP

Related Classes of com.clearnlp.classification.model.AbstractModel

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.