/** * Set target distributions using estimates from data. * * @param list InstanceList used to estimate targets. * @param features List of features for constraints. * @param normalize Whether to normalize by feature counts * @return Constraints (map of feature index to target), with targets * set using estimates from supplied data. */ public static HashMap<Integer,double[]> setTargetsUsingData(InstanceList list, ArrayList<Integer> features, boolean useValues, boolean normalize) { HashMap<Integer,double[]> constraints = new HashMap<Integer,double[]>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,useValues); for (int i = 0; i < features.size(); i++) { int fi = features.get(i); if (fi != list.getDataAlphabet().size()) { double[] prob = featureLabelCounts[fi]; if (normalize) { // Smooth probability distributions by adding a (very) // small count. We just need to make sure they aren't // zero in which case the KL-divergence is infinite. MatrixOps.plusEquals(prob, 1e-8); MatrixOps.timesEquals(prob, 1./MatrixOps.sum(prob)); } constraints.put(fi, prob); } } return constraints; }
/** * Set target distributions using estimates from data. * * @param list InstanceList used to estimate targets. * @param features List of features for constraints. * @param normalize Whether to normalize by feature counts * @return Constraints (map of feature index to target), with targets * set using estimates from supplied data. */ public static HashMap<Integer,double[]> setTargetsUsingData(InstanceList list, ArrayList<Integer> features, boolean useValues, boolean normalize) { HashMap<Integer,double[]> constraints = new HashMap<Integer,double[]>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,useValues); for (int i = 0; i < features.size(); i++) { int fi = features.get(i); if (fi != list.getDataAlphabet().size()) { double[] prob = featureLabelCounts[fi]; if (normalize) { // Smooth probability distributions by adding a (very) // small count. We just need to make sure they aren't // zero in which case the KL-divergence is infinite. MatrixOps.plusEquals(prob, 1e-8); MatrixOps.timesEquals(prob, 1./MatrixOps.sum(prob)); } constraints.put(fi, prob); } } return constraints; }
/** * Set target distributions using estimates from data. * * @param list InstanceList used to estimate targets. * @param features List of features for constraints. * @param normalize Whether to normalize by feature counts * @return Constraints (map of feature index to target), with targets * set using estimates from supplied data. */ public static HashMap<Integer,double[]> setTargetsUsingData(InstanceList list, ArrayList<Integer> features, boolean useValues, boolean normalize) { HashMap<Integer,double[]> constraints = new HashMap<Integer,double[]>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,useValues); for (int i = 0; i < features.size(); i++) { int fi = features.get(i); if (fi != list.getDataAlphabet().size()) { double[] prob = featureLabelCounts[fi]; if (normalize) { // Smooth probability distributions by adding a (very) // small count. We just need to make sure they aren't // zero in which case the KL-divergence is infinite. MatrixOps.plusEquals(prob, 1e-8); MatrixOps.timesEquals(prob, 1./MatrixOps.sum(prob)); } constraints.put(fi, prob); } } return constraints; }
HashMap<Integer,ArrayList<Integer>> labeledFeatures = new HashMap<Integer,ArrayList<Integer>>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,true);
HashMap<Integer,ArrayList<Integer>> labeledFeatures = new HashMap<Integer,ArrayList<Integer>>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,true);
HashMap<Integer,ArrayList<Integer>> labeledFeatures = new HashMap<Integer,ArrayList<Integer>>(); double[][] featureLabelCounts = getFeatureLabelCounts(list,true);