/** * 训练 */ public override void Train(int IteratCnt) { if (FeatureSummary == null) { FeatureSummary = new MLFeatureFunctionsSummary <int, int>(); } for (int k = 0; k < (IteratCnt > 0? IteratCnt:ITERATIONS); k++) { int i = 0; //for (int i = 0; i < functions.Count; i++) //分组线程 List <Thread> thds = new List <Thread>(); foreach (string key in functions.Keys) { double delta = iis_solve_delta(empirical_expects[i], key); if (k == 0) { wNames[i] = key; } w[i] += delta; OnPeriodEvent(_GrpId, k, i, wNames, w); i++; } //if (DEBUG) System.out.println("ITERATIONS: " + k + " " + Arrays.toString(w)); } FeatureSummary.Keys.Add(w); if (_GrpId == 0) { FeatureSummary.FuncList.AddRange(functions.Values.ToArray()); } //FeatureSummary.Functions = functions; this.OnTrainFinished(); }
public void LoadSummary() { string txt = OnLoadLocalFile(); List <MLFeatureFunctionsSummary <LabelT, FeatureT> > ret = DetailStringClass.getObjectListByXml <MLFeatureFunctionsSummary <LabelT, FeatureT> >(txt); if (ret != null && ret.Count > 0) { FeatureSummary = ret[0]; } }
/** * 创建特征函数 * @param instances 实例 */ private void createFeatFunctions(InstanceList instances) { int maxLabel = 0; int minLabel = int.MaxValue; int[] maxFeatures = new int[instances[0].Feature.Count]; List <MLFeature <int> > featureSet = new List <MLFeature <int> >(); foreach (MLInstance <int, int> instance in instances) { if (instance.Label > maxLabel) { maxLabel = instance.Label; } if (instance.Label < minLabel) { minLabel = instance.Label; } for (int i = 0; i < instance.Feature.Count; i++) { if (instance.Feature[i] > maxFeatures[i]) { maxFeatures[i] = instance.Feature[i]; } } featureSet.Add(instance.Feature); } features = new List <MLFeature <int> >(); List <List <int> > flist = Feature.getNextFeature("1234567890", maxFeatures.Length); flist.ForEach(p => features.Add(new Feature(p))); //featureSet maxY = maxLabel; minY = minLabel; for (int i = 0; i < maxFeatures.Length; i++) { for (int x = 0; x <= maxFeatures[i]; x++) { for (int y = minY; y <= maxLabel; y++) { functions.Add(string.Format("{0}_{1}_{2}", i, x, y), new MLFeatureFunctionsClass <int, int>(i, x, y)); } } } if (_GrpId == 0) { if (FeatureSummary == null) { FeatureSummary = new MLFeatureFunctionsSummary <int, int>(); } FeatureSummary.TrainCnt = N; FeatureSummary.FeatureCnt = maxFeatures.Length; for (int i = 0; i < maxFeatures.Length; i++) { List <int> list = new List <int>(); for (int j = 0; j <= maxFeatures[i]; j++) { list.Add(j); } FeatureSummary.FeatureList.Add(list); } FeatureSummary.LabelCnt = maxY - minY + 1; for (int i = minY; i <= maxY; i++) { FeatureSummary.LabelList.Add(i); } } if (DEBUG) { //System.out.println("# features = " + features.size()); //System.out.println("# functions = " + functions.size()); } }