Ejemplo n.º 1
0
        /// <summary>
        /// Computes the influence of all configuration options and interactions based on the measurements of the given result db. It uses linear programming (simplex) and is an exact algorithm.
        /// </summary>
        /// <param name="nfp">The non-funcitonal property for which the influences of configuration options are to be computed. If null, we use the property of the global model.</param>
        /// <param name="infModel">The influence model containing the variability model, all configuration options and interactions.</param>
        /// <param name="db">The result database containing the measurements.</param>
        /// <param name="evaluateFeatureInteractionsOnly">Only interactions are learned.</param>
        /// <param name="withDeviation">(Not used) We can specifiy whether learned influences must be greater than a certain value (e.g., greater than measurement bias).</param>
        /// <param name="deviation">(Not used) We can specifiy whether learned influences must be greater than a certain value (e.g., greater than measurement bias).</param>
        /// <returns>Returns the learned infleunces of each option in a map whereas the String (Key) is the name of the option / interaction.</returns>
        public Dictionary <String, double> computeOptionInfluences(NFProperty nfp, InfluenceModel infModel, ResultDB db, bool evaluateFeatureInteractionsOnly, bool withDeviation, double deviation)
        {
            //Initialization
            List <List <BinaryOption> > configurations = new List <List <BinaryOption> >();

            this.evaluateInteractionsOnly = evaluateFeatureInteractionsOnly;
            this.withStandardDeviation    = withDeviation;
            this.standardDeviation        = deviation;
            List <double> results = new List <double>();

            foreach (Configuration c in db.Configurations)
            {
                configurations.Add(c.getBinaryOptions(BinaryOption.BinaryValue.Selected));
                if (nfp != null)
                {
                    results.Add(c.GetNFPValue(nfp));
                }
                else
                {
                    results.Add(c.GetNFPValue());
                }
            }

            List <BinaryOption>         variables     = new List <BinaryOption>();
            Dictionary <String, double> featureValues = new Dictionary <string, double>();
            Dictionary <String, double> faultRates    = new Dictionary <string, double>();
            List <int> indexOfErrorMeasurements       = new List <int>();

            if (configurations.Count == 0)
            {
                return(null);
            }

            //For the case there is an empty base
            if (configurations.Count != 0)
            {
                if (configurations[0].Count == 0)
                {//Should never occur that we get a configuration with no option selected... at least the root must be there
                    BinaryOption root = infModel.Vm.Root;
                    //Element baseElement = new Element("base_gen", infModel.getID(), infModel);
                    //variables.Add(baseElement);
                    //  featureValues.Add(baseElement.getName(), 0);
                    foreach (List <BinaryOption> config in configurations)
                    {
                        if (!config.Contains(root))
                        {
                            config.Insert(0, root);
                        }
                    }
                }
            }
            //Building the variable list
            foreach (var elem in infModel.Vm.BinaryOptions)
            {
                variables.Add(elem);
                featureValues.Add(elem.Name, 0);
            }

            featureValues = solve(variables, results, configurations, null);

            return(featureValues);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Computes the influence of all configuration options based on the measurements of the given result db. It uses linear programming (simplex) and is an exact algorithm.
        /// </summary>
        /// <param name="nfp">The non-funcitonal property for which the influences of configuration options are to be computed. If null, we use the property of the global model.</param>
        /// <param name="infModel">The influence model containing options and interactions. The state of the model will be changed by the result of the process</param>
        /// <param name="db">The result database containing the measurements.</param>
        /// <returns>A map of binary options to their computed influences.</returns>
        public Dictionary <BinaryOption, double> computeOptionInfluences(NFProperty nfp, InfluenceModel infModel, ResultDB db)
        {
            List <BinaryOption>         variables      = infModel.Vm.BinaryOptions;
            List <double>               results        = new List <double>();
            List <List <BinaryOption> > configurations = new List <List <BinaryOption> >();

            foreach (Configuration c in db.Configurations)
            {
                configurations.Add(c.getBinaryOptions(BinaryOption.BinaryValue.Selected));
                if (nfp != null)
                {
                    results.Add(c.GetNFPValue(nfp));
                }
                else
                {
                    results.Add(c.GetNFPValue());
                }
            }
            List <String> errorEqs = new List <string>();
            Dictionary <String, double> faultRates             = new Dictionary <string, double>();
            List <int> indexOfErrorMeasurements                = new List <int>();
            Dictionary <String, double> featureValuedAsStrings = solve(variables, results, configurations, infModel.InteractionInfluence.Keys.ToList());

            foreach (String current in featureValuedAsStrings.Keys)
            {
                BinaryOption temp = infModel.Vm.getBinaryOption(current);
                this.featureValues[temp] = featureValuedAsStrings[current];
                InfluenceFunction influence = new InfluenceFunction(temp.Name + " + " + featureValuedAsStrings[current].ToString(), infModel.Vm);
                if (infModel.BinaryOptionsInfluence.Keys.Contains(temp))
                {
                    infModel.BinaryOptionsInfluence[temp] = influence;
                }
                else
                {
                    infModel.BinaryOptionsInfluence.Add(temp, influence);
                }
            }
            return(this.featureValues);
        }
Ejemplo n.º 3
0
        public void learn(List <Feature> featureSet = null)
        {
            if (!hasNecessaryData())
            {
                return;
            }
            if (this.mlSettings.bagging)
            {
                //Get number of cores
                int coreCount = System.Environment.ProcessorCount;
                createThreadPool(coreCount);

                this.nbBaggings = this.mlSettings.baggingNumbers;
                iCount          = this.nbBaggings;
                Random rand        = new Random(0);
                int    nbOfConfigs = (testSet.Count * this.mlSettings.baggingTestDataFraction) / 100;
                for (int i = 0; i < nbBaggings; i++)
                {
                    InfluenceModel         infMod = new InfluenceModel(GlobalState.varModel, GlobalState.currentNFP);
                    FeatureSubsetSelection sel    = new FeatureSubsetSelection(infMod, this.mlSettings);
                    this.models.Add(sel);
                    List <int> selection = new List <int>();
                    for (int r = 0; r <= nbOfConfigs; r++)
                    {
                        selection.Add(rand.Next(nbOfConfigs));
                    }
                    List <Configuration> newTestSet       = new List <Configuration>();
                    List <Configuration> newValidationSet = new List <Configuration>();
                    for (int r = 0; r <= selection.Count; r++)
                    {
                        if (selection.Contains(r))
                        {
                            newTestSet.Add(testSet[r]);
                        }
                        else
                        {
                            newValidationSet.Add(testSet[r]);
                        }
                    }
                    sel.setLearningSet(newTestSet);
                    sel.setValidationSet(newValidationSet);
                    Task task = EnqueueTask(() => sel.learn());
                }
                eventX.WaitOne(Timeout.Infinite, true);
                averageModels();
            }
            else
            {
                GlobalState.logInfo.logLine("Learning progress:");
                InfluenceModel         infMod = new InfluenceModel(GlobalState.varModel, GlobalState.currentNFP);
                FeatureSubsetSelection sel    = new FeatureSubsetSelection(infMod, this.mlSettings);
                this.models.Add(sel);
                sel.setLearningSet(testSet);
                sel.setValidationSet(this.validationSet);
                Stopwatch sw = new Stopwatch();
                sw.Start();
                sel.learn(featureSet);
                sw.Stop();
                Console.WriteLine("Elapsed={0}", sw.Elapsed);
            }
        }
Ejemplo n.º 4
0
 public BettyFileParser()
 {
     _varModel  = new VariabilityModel("generated");
     _inflModel = new InfluenceModel(_varModel, new NFProperty("nfp"));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// This method searches for a corresponding methods in the dynamically loadeda assemblies and calls it if found. It prefers due to performance reasons the Microsoft Solver Foundation implementation.
        /// </summary>
        /// <param name="nfp">The non-funcitonal property for which the influences of configuration options are to be computed. If null, we use the property of the global model.</param>
        /// <param name="infModel">The influence model containing options and interactions. The state of the model will be changed by the result of the process</param>
        /// <param name="db">The result database containing the measurements.</param>
        /// <returns>A map of binary options to their computed influences.</returns>
        public Dictionary <BinaryOption, double> computeOptionInfluences(NFProperty nfp, InfluenceModel infModel, ResultDB db)
        {
            foreach (Lazy <ISolverLP, ISolverType> solver in solvers)
            {
                if (solver.Metadata.SolverType.Equals("MSSolverFoundation"))
                {
                    return(solver.Value.computeOptionInfluences(nfp, infModel, db));
                }
            }

            //If not MS Solver, take any solver. Should be changed when supporting more than 2 solvers here
            foreach (Lazy <ISolverLP, ISolverType> solver in solvers)
            {
                return(solver.Value.computeOptionInfluences(nfp, infModel, db));
            }

            return(null);
        }