Beispiel #1
0
        private int GetImitationLearningFile(out LinearModel model, string distribution, string dimension,
            TrainingSet.Trajectory track, bool extended, int numFeatures, int modelID, string directoryName, string stepwiseBias,
            bool timedependent = false, int iter = -1)
        {
            DirectoryInfo dir = new DirectoryInfo(String.Format(@"{0}\PREF\weights", directoryName));

            string pat = String.Format("\\b(exhaust|full)\\.{0}.{1}.{2}.(OPT|IL([0-9]+){3}{4}{5}).{6}.weights.{7}",
                distribution, dimension,
                (char) PreferenceSet.Ranking.PartialPareto, track.ToString().Substring(2),
                numFeatures < Features.LocalCount ? String.Format("_F{0}M{1}", numFeatures, modelID) : "",
                extended ? "EXT" : "",
                stepwiseBias,
                timedependent ? "timedependent" : "timeindependent");

            Regex reg = new Regex(pat);

            var files = dir.GetFiles("*.csv").Where(path => reg.IsMatch(path.ToString())).ToList();

            if (files.Count <= (iter >= 0 ? iter : 0))
                throw new Exception(String.Format("Cannot find any weights belonging to {0}. Start with optimal!", track));

            int[] iters = new int[files.Count];
            for (int i = 0; i < iters.Length; i++)
            {
                Match m = reg.Match(files[i].Name);
                if (m.Groups[2].Value == "OPT")
                    iters[i] = 0;
                else
                    iters[i] = Convert.ToInt32(m.Groups[3].Value);
            }

            if (iter < 0) iter = iters.Max(); // then take the latest version

            FileInfo weightFile = files[Array.FindIndex(iters, x => x == iter)];
            model = new LinearModel(weightFile, numFeatures, modelID, Distribution, Dimension);

            return iters.Max();
        }
Beispiel #2
0
        private static string Trajectory2String(TrainingSet.Trajectory track, int iter, bool extended)
        {
            string str;
            switch (track)
            {
                case TrainingSet.Trajectory.ILSUP:
                case TrainingSet.Trajectory.ILUNSUP:
                case TrainingSet.Trajectory.ILFIXSUP:
                    str = iter > 0
                        ? String.Format("IL{0}{1}", iter, track.ToString().Substring(2))
                        : String.Format("{0}", TrainingSet.Trajectory.OPT);
                    break;
                default:
                    str = String.Format("{0}", track);
                    break;
            }

            if (extended)
                str += "EXT";

            return str;
        }