Example #1
0
    public void updateModelWeight(List<Sample> sampleList) {
      for (FeatureValue featureValue : featureMap.values()) {
        featureValue.setTempWeight(0);
      }

      for (Sample sample : sampleList) {
        Map<String, Double> probMap = predict(sample.getFeatures());
        for (String feature : sample.getFeatures()) {
          for (String label : labelSet) {
            this.setTempWeight(
                label,
                feature,
                this.getTempWeight(label, feature)
                    + probMap.get(label) * (1.0 / sampleList.size()));
          }
        }
      }

      // GIS;
      features.setLastWeight();
      for (FeatureValue featureValue : featureMap.values()) {
        featureValue.setModelWeight(
            featureValue.getModelWeight()
                + 1.0
                    / maxFeaturePerSample
                    * Math.log(featureValue.getEmpiricalWeight() / featureValue.getTempWeight()));
      }
    }