Esempio n. 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();
        }
Esempio n. 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;
        }
Esempio n. 3
0
        public static LinearModel[] GetAllExhaustiveModels(string distribution, string dimension,
            TrainingSet.Trajectory track, int iter, bool extended, PreferenceSet.Ranking rank, bool timedependent,
            DirectoryInfo dataDir, string stepwiseBias)
        {
            string pat = String.Format("exhaust.{0}.{1}.{2}.{3}.{4}.weights.{5}.csv",
                distribution, dimension, (char) rank, Trajectory2String(track, iter, extended),
                stepwiseBias, timedependent ? "timedependent" : "timeindependent");

            DirectoryInfo dir = new DirectoryInfo(String.Format(@"{0}\PREF\weights", dataDir.FullName));
            Regex reg = new Regex(pat);
            var files = dir.GetFiles("*.csv").Where(path => reg.IsMatch(path.ToString())).ToList();

            return files.Count < 1 ? null : ReadLoggedLinearWeights(files[0], distribution, dimension, Model.PREF);
        }
Esempio n. 4
0
        public static LinearModel[] GetAllVaryLmaxModels(string distribution, string dimension,
            TrainingSet.Trajectory track, int iter, bool extended, PreferenceSet.Ranking rank, bool timedependent,
            DirectoryInfo dataDir, string stepwiseBias)
        {
            string pat = String.Format("full.{0}.{1}.{2}.{3}.{4}.weights.{5}_lmax[0-9]+.csv",
                distribution, dimension, (char) rank, Trajectory2String(track, iter, extended),
                stepwiseBias, timedependent ? "timedependent" : "timeindependent");

            DirectoryInfo dir = new DirectoryInfo(String.Format(@"{0}\PREF\weights", dataDir.FullName));
            Regex reg = new Regex(pat);
            var files = dir.GetFiles("*.csv").Where(path => reg.IsMatch(path.ToString())).ToList();
            if (files.Count < 1) return null;

            LinearModel[] models = new LinearModel[0];
            foreach (
                var model in
                    files.Select(file => ReadLoggedLinearWeights(file, distribution, dimension, Model.PREF))
                        .Where(model => model != null))
            {
                Array.Resize(ref models, models.Length + model.Length);
                Array.Copy(model, 0, models, models.Length - model.Length, model.Length);
            }
            return models;
        }
Esempio n. 5
0
        public LinearModel(string distribution, string dimension, TrainingSet.Trajectory track, bool extended,
            PreferenceSet.Ranking rank, bool timedependent, DirectoryInfo dataDir,
            int numFeatures, int modelID, string stepwiseBias, int iter = -1, Features.Mode featMode = Features.Mode.Local)
            : this(null, featMode, numFeatures, modelID, !timedependent, distribution, dimension, Model.PREF)
        {
            switch (track)
            {
                case TrainingSet.Trajectory.ILFIXSUP:
                case TrainingSet.Trajectory.ILUNSUP:
                case TrainingSet.Trajectory.ILSUP:
                    LinearModel model;
                    Iteration = GetImitationLearningFile(out model, distribution, dimension, track, extended,
                        numFeatures, modelID, dataDir.FullName, stepwiseBias, timedependent, iter);
                    FileInfo = model.FileInfo;
                    LocalWeights = model.LocalWeights;
                    return;
                default:
                    string pat = String.Format("\\b(exhaust|full)\\.{0}.{1}.{2}.{3}{4}.{5}.{6}weights.{7}.csv",
                        distribution, dimension, (char) rank,
                        track, extended ? "EXT" : "", stepwiseBias,
                        FeatureMode == Features.Mode.Global ? "(Global|SDR)" : "",
                        timedependent ? "timedependent" : "timeindependent");

                    DirectoryInfo dir = new DirectoryInfo(String.Format(@"{0}\PREF\weights", dataDir.FullName));
                    Regex reg = new Regex(pat);
                    var files = dir.GetFiles("*.csv").Where(path => reg.IsMatch(path.ToString())).ToList();

                    if (files.Count <= 0)
                        throw new Exception(String.Format("Cannot find any weights belonging to {0}!", pat));

                    foreach (var file in files)
                    {
                        LinearModel[] logWeights = ReadLoggedLinearWeights(file, distribution, dimension, Model.PREF);
                        FileInfo = file;

                        foreach (
                            var w in logWeights.Where(w => w._numFeatures == _numFeatures && w._modelID == _modelID))
                        {
                            LocalWeights = w.LocalWeights;
                            GlobalWeights = w.GlobalWeights;
                            return;
                        }
                    }
                    throw new Exception(String.Format("Cannot find weights {0} to user requirements from {1}!", Name,
                        files[0].Name));
            }
        }