Exemple #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()));
      }
    }
Exemple #2
0
 public boolean isConvergence(double threshold) {
   double sum = 0;
   for (FeatureValue featureValue : featureMap.values()) {
     sum +=
         (featureValue.getLastWeight() - featureValue.getModelWeight())
             * (featureValue.getLastWeight() - featureValue.getModelWeight());
   }
   return Math.sqrt(sum) <= threshold ? true : false;
 }
Exemple #3
0
 public void setEmpiricalWeight(int sampleNumber) {
   for (FeatureValue featureValue : featureMap.values()) {
     featureValue.setEmpiricalWeight(1.0 * featureValue.getCount() / sampleNumber);
   }
 }
Exemple #4
0
 public void setLastWeight() {
   for (FeatureValue featureValue : featureMap.values()) {
     featureValue.setLastWeight();
   }
 }