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; }
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())); } }
public void setEmpiricalWeight(int sampleNumber) { for (FeatureValue featureValue : featureMap.values()) { featureValue.setEmpiricalWeight(1.0 * featureValue.getCount() / sampleNumber); } }
public void setLastWeight() { for (FeatureValue featureValue : featureMap.values()) { featureValue.setLastWeight(); } }