Examples of HashSparseVector


Examples of org.fnlp.ml.types.sv.HashSparseVector

    }

    private void updateCenter(int classid, HashSparseVector vector) {
        int count = classCount.get(classid);
        classCount.set(classid, count+1);
        HashSparseVector vectorcenter = classCenter.get(classid);
        updateBaseDist(classid, vector);
        vectorcenter.plus(vector);
//        vectorcenter.scaleDivide((float)count / (float)(count+1));
    }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

            int[] fea = template.get(i);
            String eleFea = i + ":" + perFea(1, seqFea, fea);
            int id  = alphabet.lookupIndex(eleFea);
            feaId[i] = id;
        }
        HashSparseVector hsvector = new HashSparseVector();
        hsvector.put(feaId, 1.0f);
        return new TrainInstance(seqFea[1], hsvector);
    }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   */
  public boolean useInstWeight;

  public AbstractPAUpdate(Loss loss) {
    diffw = 0;
    diffv = new HashSparseVector();
    this.loss = loss;
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

      ParsingState state = new ParsingState(instance,factory);
      while (!state.isFinalState()) {
        // 左右焦点词在句子中的位置
        int[] lr = state.getFocusIndices();

        HashSparseVector features = state.getFeatures();
        ParsingState.Action action = getAction(lr[0], lr[1],
            heads);
        state.next(action);
        if (action == ParsingState.Action.LEFT)
          heads[lr[1]] = -1;
        if (action == ParsingState.Action.RIGHT)
          heads[lr[0]] = -1;

        // writer.write(String.valueOf(instance.postags[lr[0]]));
        String pos = instance.getTagAt(lr[0]);
        postagAlphabet.lookupIndex(pos);
        writer.write(pos);
        writer.write(" ");
        switch (action) {
        case LEFT:
          writer.write("L");
          break;
        case RIGHT:
          writer.write("R");
          break;
        default:
          writer.write("S");
        }
        writer.write(" ");
        int[] idx = features.indices();
        Arrays.sort(idx);
        for (int i = 0; i < idx.length; i++) {
          writer.write(String.valueOf(idx[i]));
          writer.write(" ");
        }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

  private HashSparseVector sv;

  @Before
  public void setUp() throws Exception {
    sv = new HashSparseVector();
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   
    for(int i=0;i<len;i++){
      w[i]=(float) i/100.0f;
    }
   
    HashSparseVector sv1 = new HashSparseVector();
    LinearSparseVector sv2 = new LinearSparseVector();
   
   
    long stime;
    long etime;
   
    stime = System.currentTimeMillis();
    for(int i=0;i<len;i++){
      sv1.put(i, w[i]);
    }
    etime = System.currentTimeMillis();   
    System.out.println("time:" + (etime-stime));
   
    stime = System.currentTimeMillis();
    for(int i=0;i<len;i++){
      sv2.put(i, w[i]);
    }
    etime = System.currentTimeMillis();   
    System.out.println("time:" + (etime-stime));
   
    stime = System.currentTimeMillis();
    for(int i=0;i<len;i++){
      sv1.get(i);
    }
    etime = System.currentTimeMillis();   
    System.out.println("time:" + (etime-stime));
   
    stime = System.currentTimeMillis();
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

  }

  @Test
  public void test() {
    float[] w = { 0.3f, 1.2f, 1.09f, -0.45f, -1.2f, 0, 0, 0, 0 };
    HashSparseVector sv = new HashSparseVector(w);
    int[][] idx = MyHashSparseArrays.getTop(sv.data, 0.99f);
    MyHashSparseArrays.setZero(sv.data, idx[1]);
    System.out.println(sv);
  }
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   
    IFeatureAlphabet features = factory.DefaultFeatureAlphabet();

    int rightFocus = leftFocus + 1;

    HashSparseVector vec = new HashSparseVector();

    // 设定上下文窗口大小
    int l = 2;
    int r = 2;
    for (int i = 0; i <= l; i++) {
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

    int numLabels = alphabet.size();
    HashSparseVector[] means = new  HashSparseVector[numLabels];
    int[] classNum = new int[numLabels];

    for(int i=0;i<numLabels;i++){
      means[i]=new HashSparseVector();
    }

    for (int ii = 0; ii < trainingList.size(); ii++){
      Instance inst = trainingList.getInstance(ii);
      ISparseVector fv = (ISparseVector) inst.getData ();
View Full Code Here

Examples of org.fnlp.ml.types.sv.HashSparseVector

   *         0->SHIFT
   * @throws UnsupportedDataTypeException
   */
  private float[][] estimateActions(ParsingState state) throws UnsupportedDataTypeException {
    // 当前状态的特征
    HashSparseVector features = state.getFeatures();
    Instance inst = new Instance(features.indices());

    String pos = state.getLeftPos();
    int lpos = postagAlphabet.lookupIndex(pos);
    if(lpos==-1)
      throw new UnsupportedDataTypeException("不支持词性:"+pos);
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.