Introducing Learning Mechanism for Class Responsibility Assignment ...

3 downloads 48808 Views 172KB Size Report
Jul 28, 2015 - Assigning responsibilities to classes is a vital task in object-oriented design, which has a great impact on the overall design of an application.
Introducing Learning Mechanism for Class Responsibility Assignment Problem Yongrui Xu1, Peng Liang1(&), and Muhammad Ali Babar2 1

2

State Key Lab of Software Engineering, Wuhan University, Wuhan, China {xuyongrui,liangp}@whu.edu.cn School of Computer Science, The University of Adelaide, Adelaide, Australia [email protected]

Abstract. Assigning responsibilities to classes is a vital task in object-oriented design, which has a great impact on the overall design of an application. However, this task is not easy for designers due to its complexity. Though many automated approaches have been developed to help designers to assign responsibilities to classes, none of them considers extracting the design knowledge (DK) about the relations between responsibilities in order to adapt designs better against design problems. To address the issue, we propose a novel Learning-based Genetic Algorithm (LGA) for the Class Responsibility Assignment (CRA) problem. In the proposed algorithm, a learning mechanism is introduced to extract DK about which responsibilities have a high probability to be assigned to the same class, and the extracted DK is employed to improve the design qualities of generated solutions. An experiment was conducted, which shows the effectiveness of the proposed approach. Keywords: CRA problem effect

 Data mining  Genetic algorithm  The Baldwin

1 Introduction In object-oriented design, assigning responsibilities to classes is a vital task, which has a great impact on the overall design of an application [1]. The main goal of Class Responsibility Assignment (CRA) is to find an optimal assignment of responsibilities (where responsibilities are presented in terms of methods and attributes) to classes and how objects should interact by using the methods [2]. Since the number of responsibilities can reach to hundreds and thousands in a normal industrial size system, and CRA depends heavily on human judgment and decision-making, it is challenging for designers to assign responsibilities to classes (especially for novice designers) [1]. Existing approaches on automated CRA can prevent novice designers from making improper software design [1–3]. In these automated approaches, quality metrics (e.g., structural metrics) are defined to evaluate the design qualities of generated solutions. However, several issues need to be considered for employing these automated CRA This work is partially sponsored by the NSFC under Grant No. 61170025 and No. 61472286. © Springer International Publishing Switzerland 2015 M. Barros and Y. Labiche (Eds.): SSBSE 2015, LNCS 9275, pp. 311–317, 2015. DOI: 10.1007/978-3-319-22183-0_28

312

Y. Xu et al.

approaches: (1) in [4], the authors argued that no magic metrics for the evaluation of design quality had been found; (2) structural metrics seem to be ‘cheating’ the software engineer: they are ‘improving the design’ from the structural metrics standpoint, but these changes do not correspond to the expectations of designers [5]. Considering these, a new trend for evaluating CRA results is to compare the similarity between generated solutions and expert designs [2]. The reason of this comparison is that the designs produced by experienced designers (experts) follow design principles as much as possible, and expert designs possess the desired design properties. As a reflection of this trend, we need to take a fresh look at the automated approach for CRA. The underlying reason of making generated solutions close to expert designs is that the designs produced by different experts are similar within the same context, and the best design practices (i.e., a type of implicit design knowledge (DK)) for the design problem may exist in these similar parts. If the implicit DK can be captured automatically and further used to generate software design solutions, it may adapt solutions better against design problems. To this end, a novel Learning-based Genetic Algorithm (LGA) is proposed in this paper, which introduces a learning mechanism for automated CRA. The contributions of this work are: (1) introduce learning mechanism for automated CRA, which adapts the generated solutions better against the design problems by considering the extracted DK; (2) propose a novel Genetic Algorithm (GA) based on the Baldwin effect, which considers relations between individuals to make better exploration and exploitation in the solution space. The proposed algorithm may also be applied to solve other software engineering (SE) problems with Search Based Software Engineering (SBSE) techniques.

2 Approach In this section, we introduce the proposed Learning-based Genetic Algorithm (LGA) and the theories behind it. We also describe the procedure of applying LGA for CRA.

2.1

Learning-Based Genetic Algorithm (LGA)

Darwinism states that all species of organisms arise and develop through the natural selection of small, inherited variations that increase the individual’s ability to compete, survive, and reproduce. However, Darwinism has been questioned that whether it is suitable for the phenomenon of microevolution [6]. Microevolution means changes can occur within existing species or gene pools without natural selection. To support microevolution, the Baldwin effect was proposed as a post-Darwinian mechanism of evolution [7]. The core mechanism of the Baldwin effect is the learning mechanism for individuals in response to changes in their environment. Traditional GAs inspired by Darwinism are widely used in the field of SBSE, but they do not support microevolution well. Consequently, traditional GAs lead to isolations between candidate solutions, and cannot fully exploit the relations between candidate solutions to improve design qualities of final solutions. For instance, in a CRA problem, the relations between responsibilities in candidate solutions should be

Introducing Learning Mechanism for Class Responsibility

313

extracted as DK and be fully exploited to improve design qualities of individuals (i.e., candidate solutions) in the population. In addition, preferable individuals, which have better design qualities than others in a population, should evangelize their responsibility assignment as DK to other individuals, which leads to an adaptive change taking place simultaneously for most of the individuals of the population. To support microevolution of individuals with SBSE techniques, a Learning-based Genetic Algorithm (LGA) based on the Baldwin effect is proposed and shown in Fig. 1, which introduces a novel learning operator to support the learning mechanism for individuals.

1. Initial Population

2. Calculate the Fitness

3. Selection Operator

4. Crossover Operator

5. Mutation Operator

(a) Genetic Algorithm (Darwinism )

1. Initial Population

2. Calculate the Fitness

3. Selection Operator

4. Crossover Operator

5. Mutation Operator

6. Learning Operator

(b) Learning-based Genetic Algorithm (the Baldwin effect )

Fig. 1. Traditional Genetic Algorithm and Learning-based Genetic Algorithm

2.2

Solving CRA with LGA

In this section, we mainly show how to use the universal learning operator in LGA to extract implicit DK to improve design qualities for the CRA problem. Step 1 to Step 5 in Fig. 1 are omitted, which are detailed in [1, 2]. When Step 5 in Fig. 1 is completed, a new generation is produced in both GAs. In LGA, according to the fitness of each individual, the individuals of this generation are further classified into three groups: preferable individuals group (PG), ordinary individuals group (OG), and inferior individuals group (IG). If the fitness of an individual is in the top 20 % of the generation, the individual may have good design qualities, and it belongs to PG. If the fitness is in the bottom 30 %, the individual may have poor design qualities, and it belongs to IG. The remaining individuals with moderate design qualities belong to OG. For CRA, individuals of IG should learn the DK extracted from individuals of PG to evolve these IG individuals, which is defined as “learning mechanism” in this paper. Figure 2 shows the four sub-steps about how to extract the DK according to the relations between responsibilities from individuals in PG, and how to apply the extracted DK for individuals in IG in order to make adaptive changes for these IG individuals.

Start

6.1 Construct dataset from PG

6.2 Generate frequent itemsets Process

6.3 Generate rule set

6.4 Learn adaptively for IG

Sequence

Fig. 2. The procedure of learning in the learning operator

End

314

Y. Xu et al.

2.2.1 Construct Dataset from PG A dataset which can be further used to extract DK is needed in our approach, and Step 6.1 constructs this dataset from individuals in PG. The dataset is composed of records, and each record contains responsibilities which are assigned to the same class in a PG individual. For example, suppose there are five responsibilities (i.e., R1 to R5) that need to be assigned to classes. An individual ind in PG may assign R1 and R2 to Class1, and assign other responsibilities to Class 2. In this situation, two records exist for ind: {R1, R2} and {R3, R4, R5}. Different with the genotype of ind, the two records are independent records in the constructed dataset. Hence, the dataset can be generated by combining records of all the individuals in PG. 2.2.2 Generate Frequent Itemsets and the Rule Set In Step 6.2, we use the Apriori algorithm, an association algorithm from data mining, to discover the frequent itemsets of responsibilities from the dataset generated in Step 6.1. In data mining, a frequent itemset contains the elements, which have a high probability to appear together in records. When Step 6.2 is completed, the DK about which responsibilities are always assigned to the same class in PG individuals can be discovered. For example, suppose {R1, R2} and {R3, R4, R5} are two frequent itemsets acquired by the Apriori algorithm in Step 6.2, we then know R1 and R2 are often assigned to the same class in different PG individuals (similar case for R3, R4, and R5). However, it is not enough that the proposed approach can only be aware of which responsibilities have a high probability to be assigned to the same class in PG individuals. We need to discover and understand which responsibilities make other responsibilities be assigned to the same class in the frequent itemsets before introducing learning for individuals in IG. For instance, if {R1, R2} is a frequent itemset acquired in Step 6.2, we need to know whether R1 leads to the assignment of R2 to the same class with R1 (i.e., R1 => R2), or vice versa (i.e., R2 => R1). Each situation above (e.g., R1 => R2) is called a rule, and a rule set is generated in Step 6.3. The generated rule set in Step 6.3 contains the DK about how to optimize responsibilities assignment for design problems. In Step 6.3, all possible rules for each frequent itemset are generated, and we use support, confidence, and lift measures which are widely used in data mining to filter out uninteresting and repeated rules [8]. Suppose a rule has the form X => Y, the support of the rule is the proportion of records that contain both X and Y in the constructed dataset, and the confidence of this rule is the proportion of records that contain Y among the records that contain X. In addition, the lift measure calculates the relevance between X and Y in a rule. When Step 6.3 is completed, the DK for design problems is automatically extracted with our approach, and individuals in IG can learn these DK from the rule set in Step 6.4. 2.2.3 Learn Adaptively for Individuals in IG According to the support and confidence measure of each rule calculated in Step 6.3, the concept of learning rate is introduced for each rule. More specifically, a rule with higher values of support and confidence measures will have a higher learning rate, resulting that this rule has a higher probability to be learned by individuals in IG. In Step 6.4, each individual in IG tries to learn each rule in the generated rule set with the learning rate of that rule, and adaptively changes the individual itself with the rules that

Introducing Learning Mechanism for Class Responsibility

315

the IG individual decides to learn. For instance, if an individual in IG decides to learn the rule “R1 => R2”, the individual will change itself, and assign R2 to the class which contains R1. However, each rule has its precondition, which should be satisfied before the rule is applied by individuals in IG. We define the precondition of a rule according to the left part of the rule. For example, in the rule “R1, R2 ⇒ R3”, the left part of the rule is {R1, R2}, and the precondition of the rule is that R1 and R2 should belong to the same class in an individual. If R1 and R2 are assigned in different classes in an individual in IG, this rule cannot be applied by this individual. In Step 6.4, individuals in IG apply the extracted DK from individuals in PG to make adaptive changes in order to better adapt against design problems. With the novel learning operator in LGA, our proposed approach for CRA can fully exploit the use information between responsibilities, and extract the DK from individuals which have better design qualities in the population. In addition, our approach supports the microevolution mechanisms for the population, and allows individuals to adaptively change themselves to better adapt against the design problems.

3 Experiment To evaluate the effectiveness of the proposed approach, we compare our approach with a GA based approach. The experiments were performed on a Dual [email protected] GHz with 10 GB of RAM. We use three software design problems (i.e., CBS, GDP, and SC) that are used in [3], which spans a range of size and complexity, to compare the similarity degree of the design solutions generated by the two approaches with the expert design. Expert designs can be found in [9]. F-Score is a cluster/classification evaluation measure that combines “precision” and “recall” from information retrieval, and existing CRA work [2] used it to calculate the similarity degree between two solutions, which is an appropriate measure for our purpose. The definition of the FScore measure for the CRA problem can be found in [2], and higher F-Score value means the generated solution is closer to the expert design. Given the probabilistic nature of the algorithms, multiple runs are mandatory. For each problem instance, we run the evaluation 30 times for each algorithm to calculate the mean F-Score values of all the individuals in the population, and the mean value of the 30 F-Score values is used to represent the final F-Score value for an instance with corresponding algorithms. To enable a fair comparison, we used the same settings in each evaluation. The population size is 100, and for traditional genetic operators used in both algorithms, binary tournament is used as the default selection operator, swap mutation as the default mutation operator with reciprocal of chromosome lengths mutation probability, and single point crossover as the default crossover operator with crossover rate 0.9. The FScore values of the three design problems with the two approaches are shown in Table 1. The results indicate that the proposed approach can generate solutions which are closer to expert design for all the three problems.

316

Y. Xu et al. Table 1. F-Score values of design problems with different approaches CBS GDP SC LGA for CRA 0.8347 0.7891 0.7019 GA for CRA 0.8289 0.7434 0.6583

4 Related Work Traditional GAs inspired by Darwinism do not support learning during the evolutionary process. To tackle this problem, the authors in [10] introduced macroevolutionary algorithm (MA) for optimization problems. Similar to our proposed LGA, MA can also exploit the presence of links between “species” that represent candidate solutions to the optimization problem. However, the two approaches have essential difference on the evolutionary model: LGA is based on the Baldwin effect, while MA is inspired by macroevolution. In addition, many existing work also introduced machine learning (ML) techniques in evolutionary algorithms to generate better solutions for their problems [11–14], while our approach used an association algorithm in the search process. To our knowledge, it is the first time that a ML technique is employed for the CRA problem, which shows that introducing ML techniques in GAs can facilitate generating solutions closer to expert design.

5 Conclusions In this paper, we propose a novel Learning-based Genetic Algorithm (LGA) for the CRA problem, which is based on the Baldwin effect. In LGA, an association algorithm is used to extract the implicit DK about which responsibilities have a high probability to be assigned to the same class, and the extracted DK is further employed to improve the design qualities of the individuals with poor design qualities in the population. An experiment was conducted to evaluate the effectiveness of our approach, and the results show that the approach can generate solutions closer to expert design. In the next step, a tool that supports LGA for CRA problem will be developed and LGA will be evaluated against the GA approach for CRA problem.

References 1. Bowman, M., Briand, L.C., Labiche, Y.: Solving the class responsibility assignment problem in object-oriented analysis with multi-objective genetic algorithms. IEEE Trans. Softw. Eng. 36(6), 817–837 (2010) 2. Masoud, H., Jalili, S.: A clustering-based model for class responsibility assignment problem in object-oriented analysis. J. Syst. Softw. 93(7), 110–131 (2014) 3. Smith, J.E., Simons, C.L.: The influence of search components and problem characteristics in early life cycle class modelling. J. Syst. Softw. 103(5), 440–451 (2015)

Introducing Learning Mechanism for Class Responsibility

317

4. Lanza, M., Marinescu, R.: Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems, 1st edn. Springer, Heidelberg (2006) 5. de Oliveira, M., de Almeida, F., Horta, G.: Learning from optimization: a case study with apache ant. Inf. Softw. Technol. 57(1), 684–704 (2015) 6. Kelly, K.: Out of Control: The New Biology of Machines, Social Systems and the Economic World, 1st edn. Basic Books, New York (1995) 7. Baldwin, J.M.: A new factor in evolution. Am. Nat. 30(354), 441–451 (1896) 8. Merceron, A., Yacef, K.: Interestingness measures for association rules in educational data. In: Educational Data Mining, pp. 57–66 (2008) 9. Manual Designs. http://www.cems.uwe.ac.uk/*clsimons/CaseStudies/ManualDesigns.pdf. Accessed on 01 July 2014 10. Marín, J., Solé, R.V.: Macroevolutionary algorithms: a new optimization method on fitness landscapes. IEEE Trans. Evol. Comput. 3(4), 272–286 (1999) 11. Corazza, A., Di Martino, S., Ferrucci, F., Gravino, C., Sarro, F., Mendes, E.: Using tabu search to configure support vector regression for effort estimation. Empir. Softw. Eng. 18(3), 506–546 (2013) 12. Amal, B., Kessentini, M., Bechikh, S., Dea, J., Said, L.B.: On the use of machine learning and search-based software engineering for Ill-defined fitness function: a case study on software refactoring. In: Le Goues, C., Yoo, S. (eds.) SSBSE 2014. LNCS, vol. 8636, pp. 31–45. Springer, Heidelberg (2014) 13. Minku, L., Yao, X.: An analysis of multi-objective evolutionary algorithms for training ensemble models based on different performance measures in software effort estimation. In: PROMISE 2013, Article No. 8 (2013) 14. Sarro, F., Di Martino, S., Ferrucci, F., Gravino, C.: A further analysis on the use of genetic algorithm to configure support vector machines for inter-release fault prediction. In: ACM SAC 2012, pp. 1215–1220 (2012)