Ignore:
Timestamp:
09/24/15 10:59:05 (9 years ago)
Author:
sherbold
Message:
  • formatted code and added copyrights
Location:
trunk/CrossPare/src/de/ugoe/cs/cpdp/versions
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/AbstractVersionFilter.java

    r2 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
     
    620/** 
    721 * Implements a skeletal {@link IVersionFilter}. 
     22 *  
    823 * @author Steffen Herbold 
    924 */ 
    1025public abstract class AbstractVersionFilter implements IVersionFilter { 
    1126 
    12         /** 
    13         * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(java.util.List) 
    14         */ 
    15         @Override 
    16         public int apply(List<SoftwareVersion> versions) { 
    17                 int removed = 0; 
    18                 for( final Iterator<SoftwareVersion> iter=versions.iterator() ; iter.hasNext() ; ) { 
    19                         SoftwareVersion version = iter.next(); 
    20                          
    21                         if( apply(version) ) { 
    22                                 iter.remove(); 
    23                                 removed++; 
    24                         } 
    25                 } 
    26                 return removed; 
    27         } 
     27    /** 
     28    * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(java.util.List) 
     29    */ 
     30    @Override 
     31    public int apply(List<SoftwareVersion> versions) { 
     32        int removed = 0; 
     33        for (final Iterator<SoftwareVersion> iter = versions.iterator(); iter.hasNext();) { 
     34            SoftwareVersion version = iter.next(); 
     35 
     36            if (apply(version)) { 
     37                iter.remove(); 
     38                removed++; 
     39            } 
     40        } 
     41        return removed; 
     42    } 
    2843} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/IVersionFilter.java

    r2 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
     
    620 
    721/** 
    8  * Implements the interface for a {@link SoftwareVersion} filter.  
     22 * Implements the interface for a {@link SoftwareVersion} filter. 
     23 *  
    924 * @author Steffen Herbold 
    1025 */ 
    1126public interface IVersionFilter extends IParameterizable { 
    1227 
    13         /** 
    14          * Applies the filter to a single version.  
    15          * @param version the version 
    16          * @return true if filter applies to version, false otherwise 
    17          */ 
    18         boolean apply(SoftwareVersion version); 
    19          
    20         /** 
    21          * Applies the filter a a list of versions. Versions were the filter applies are automatically removed from the list.  
    22          * @param versions list of versions 
    23          * @return number of removed versions 
    24          */ 
    25         int apply(List<SoftwareVersion> versions); 
     28    /** 
     29     * Applies the filter to a single version. 
     30     *  
     31     * @param version 
     32     *            the version 
     33     * @return true if filter applies to version, false otherwise 
     34     */ 
     35    boolean apply(SoftwareVersion version); 
     36 
     37    /** 
     38     * Applies the filter a a list of versions. Versions were the filter applies are automatically 
     39     * removed from the list. 
     40     *  
     41     * @param versions 
     42     *            list of versions 
     43     * @return number of removed versions 
     44     */ 
     45    int apply(List<SoftwareVersion> versions); 
    2646} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/MaxInstanceNumberFilter.java

    r2 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
    317/** 
    4  * Applies to large data sets. All data sets that have more than the required maximum number of instances are removed.  
     18 * Applies to large data sets. All data sets that have more than the required maximum number of 
     19 * instances are removed. 
     20 *  
    521 * @author Steffen Herbold 
    622 */ 
    723public class MaxInstanceNumberFilter extends AbstractVersionFilter { 
    824 
    9         /** 
    10          * maximum number of instances required 
    11          */ 
    12         private int maxInstances = 0; 
    13          
    14         /** 
    15          * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
    16          */ 
    17         @Override 
    18         public boolean apply(SoftwareVersion version) { 
    19                 return version.getInstances().numInstances()>maxInstances; 
    20         } 
     25    /** 
     26     * maximum number of instances required 
     27     */ 
     28    private int maxInstances = 0; 
    2129 
    22         /** 
    23          * Sets the minimal number of instances. 
    24          * @param parameters number of instances 
    25          */ 
    26         @Override 
    27         public void setParameter(String parameters) { 
    28                 maxInstances = Integer.parseInt(parameters); 
    29         } 
     30    /** 
     31     * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
     32     */ 
     33    @Override 
     34    public boolean apply(SoftwareVersion version) { 
     35        return version.getInstances().numInstances() > maxInstances; 
     36    } 
     37 
     38    /** 
     39     * Sets the minimal number of instances. 
     40     *  
     41     * @param parameters 
     42     *            number of instances 
     43     */ 
     44    @Override 
     45    public void setParameter(String parameters) { 
     46        maxInstances = Integer.parseInt(parameters); 
     47    } 
    3048 
    3149} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/MinClassNumberFilter.java

    r26 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
     
    418 
    519/** 
    6  * Applies to small data sets. All data sets that do not have the required minimal number of instances in each class (i.e., positive, negative) are removed.  
     20 * Applies to small data sets. All data sets that do not have the required minimal number of 
     21 * instances in each class (i.e., positive, negative) are removed. 
     22 *  
    723 * @author Steffen Herbold 
    824 */ 
    925public class MinClassNumberFilter extends AbstractVersionFilter { 
    1026 
    11         /** 
    12          * minimal number of instances required 
    13          */ 
    14         private int minInstances = 0; 
    15          
    16         /** 
    17          * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
    18          */ 
    19         @Override 
    20         public boolean apply(SoftwareVersion version) { 
    21                 Instances instances = version.getInstances(); 
    22                 int[] counts = instances.attributeStats(instances.classIndex()).nominalCounts; 
    23                 boolean toSmall = false; 
    24                 for( int count : counts ) { 
    25                         toSmall |= count<minInstances; 
    26                 } 
    27                 return toSmall; 
    28         } 
     27    /** 
     28     * minimal number of instances required 
     29     */ 
     30    private int minInstances = 0; 
    2931 
    30         /** 
    31          * Sets the minimal number of instances for each class. 
    32          * @param parameters number of instances 
    33          */ 
    34         @Override 
    35         public void setParameter(String parameters) { 
    36                 minInstances = Integer.parseInt(parameters); 
    37         } 
     32    /** 
     33     * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
     34     */ 
     35    @Override 
     36    public boolean apply(SoftwareVersion version) { 
     37        Instances instances = version.getInstances(); 
     38        int[] counts = instances.attributeStats(instances.classIndex()).nominalCounts; 
     39        boolean toSmall = false; 
     40        for (int count : counts) { 
     41            toSmall |= count < minInstances; 
     42        } 
     43        return toSmall; 
     44    } 
     45 
     46    /** 
     47     * Sets the minimal number of instances for each class. 
     48     *  
     49     * @param parameters 
     50     *            number of instances 
     51     */ 
     52    @Override 
     53    public void setParameter(String parameters) { 
     54        minInstances = Integer.parseInt(parameters); 
     55    } 
    3856 
    3957} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/MinInstanceNumberFilter.java

    r2 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
    317/** 
    4  * Applies to small data sets. All data sets that do not have the required minimal number of instances are removed.  
     18 * Applies to small data sets. All data sets that do not have the required minimal number of 
     19 * instances are removed. 
     20 *  
    521 * @author Steffen Herbold 
    622 */ 
    723public class MinInstanceNumberFilter extends AbstractVersionFilter { 
    824 
    9         /** 
    10          * minimal number of instances required 
    11          */ 
    12         private int minInstances = 0; 
    13          
    14         /** 
    15          * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
    16          */ 
    17         @Override 
    18         public boolean apply(SoftwareVersion version) { 
    19                 return version.getInstances().numInstances()<minInstances; 
    20         } 
     25    /** 
     26     * minimal number of instances required 
     27     */ 
     28    private int minInstances = 0; 
    2129 
    22         /** 
    23          * Sets the minimal number of instances. 
    24          * @param parameters number of instances 
    25          */ 
    26         @Override 
    27         public void setParameter(String parameters) { 
    28                 minInstances = Integer.parseInt(parameters); 
    29         } 
     30    /** 
     31     * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
     32     */ 
     33    @Override 
     34    public boolean apply(SoftwareVersion version) { 
     35        return version.getInstances().numInstances() < minInstances; 
     36    } 
     37 
     38    /** 
     39     * Sets the minimal number of instances. 
     40     *  
     41     * @param parameters 
     42     *            number of instances 
     43     */ 
     44    @Override 
     45    public void setParameter(String parameters) { 
     46        minInstances = Integer.parseInt(parameters); 
     47    } 
    3048 
    3149} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/SoftwareVersion.java

    r27 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
     
    418 
    519/** 
    6  * Data class for software versions.  
     20 * Data class for software versions. 
     21 *  
    722 * @author Steffen Herbold 
    823 */ 
    924public class SoftwareVersion implements Comparable<SoftwareVersion> { 
    1025 
    11         /** 
    12          * name of the project 
    13          */ 
    14         private final String project; 
    15          
    16         /** 
    17          * version of the project 
    18          */ 
    19         private final String version; 
     26    /** 
     27     * name of the project 
     28     */ 
     29    private final String project; 
    2030 
    21         /** 
    22          * data of the version 
    23          */ 
    24         private final Instances instances; 
    25          
    26         /** 
    27          * Constructor. Creates a new version.  
    28          * @param project name of the project 
    29          * @param version name of the version 
    30          * @param instances data of the version 
    31          */ 
    32         public SoftwareVersion(String project, String version, Instances instances) { 
    33                 this.project = project; 
    34                 this.version = version; 
    35                 this.instances = instances; 
    36         } 
    37          
    38         /** 
    39          * returns the project name 
    40          * @return project name 
    41          */ 
    42         public String getProject() { 
    43                 return project; 
    44         } 
    45          
    46         /** 
    47          * returns the name of the version 
    48          * @return name of the version 
    49          */ 
    50         public String getVersion() { 
    51                 return version; 
    52         } 
    53          
    54         /** 
    55          * returns the data of the version 
    56          * @return data 
    57          */ 
    58         public Instances getInstances() { 
    59                 return new Instances(instances); 
    60         } 
     31    /** 
     32     * version of the project 
     33     */ 
     34    private final String version; 
    6135 
    62         /**  
    63          * Compares first based on project name and then based on version. Only string comparisons are performed.  
    64          * @see java.lang.Comparable#compareTo(java.lang.Object) 
    65          */ 
    66         @Override 
    67         public int compareTo(SoftwareVersion o) { 
    68                 int projectStrCmp = 0; 
    69                 if( project!=null ) { 
    70                         projectStrCmp = project.compareTo(o.project); 
    71                 }  
    72                 if( projectStrCmp==0 && version!=null ) { 
    73                         return version.compareTo(o.version);                     
    74                 } else { 
    75                         return projectStrCmp; 
    76                 } 
    77         } 
     36    /** 
     37     * data of the version 
     38     */ 
     39    private final Instances instances; 
     40 
     41    /** 
     42     * Constructor. Creates a new version. 
     43     *  
     44     * @param project 
     45     *            name of the project 
     46     * @param version 
     47     *            name of the version 
     48     * @param instances 
     49     *            data of the version 
     50     */ 
     51    public SoftwareVersion(String project, String version, Instances instances) { 
     52        this.project = project; 
     53        this.version = version; 
     54        this.instances = instances; 
     55    } 
     56 
     57    /** 
     58     * returns the project name 
     59     *  
     60     * @return project name 
     61     */ 
     62    public String getProject() { 
     63        return project; 
     64    } 
     65 
     66    /** 
     67     * returns the name of the version 
     68     *  
     69     * @return name of the version 
     70     */ 
     71    public String getVersion() { 
     72        return version; 
     73    } 
     74 
     75    /** 
     76     * returns the data of the version 
     77     *  
     78     * @return data 
     79     */ 
     80    public Instances getInstances() { 
     81        return new Instances(instances); 
     82    } 
     83 
     84    /** 
     85     * Compares first based on project name and then based on version. Only string comparisons are 
     86     * performed. 
     87     *  
     88     * @see java.lang.Comparable#compareTo(java.lang.Object) 
     89     */ 
     90    @Override 
     91    public int compareTo(SoftwareVersion o) { 
     92        int projectStrCmp = 0; 
     93        if (project != null) { 
     94            projectStrCmp = project.compareTo(o.project); 
     95        } 
     96        if (projectStrCmp == 0 && version != null) { 
     97            return version.compareTo(o.version); 
     98        } 
     99        else { 
     100            return projectStrCmp; 
     101        } 
     102    } 
    78103} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/UnbalancedFilter.java

    r2 r41  
     1// Copyright 2015 Georg-August-Universität Göttingen, Germany 
     2// 
     3//   Licensed under the Apache License, Version 2.0 (the "License"); 
     4//   you may not use this file except in compliance with the License. 
     5//   You may obtain a copy of the License at 
     6// 
     7//       http://www.apache.org/licenses/LICENSE-2.0 
     8// 
     9//   Unless required by applicable law or agreed to in writing, software 
     10//   distributed under the License is distributed on an "AS IS" BASIS, 
     11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     12//   See the License for the specific language governing permissions and 
     13//   limitations under the License. 
     14 
    115package de.ugoe.cs.cpdp.versions; 
    216 
     
    418 
    519/** 
    6  * Removes unbalanced data sets in terms of classification. All data sets that are outside of the quantil defined 
    7  * by setParameter (default=0.1) are removed.  
     20 * Removes unbalanced data sets in terms of classification. All data sets that are outside of the 
     21 * quantil defined by setParameter (default=0.1) are removed. 
     22 *  
    823 * @author Steffen Herbold 
    924 */ 
    1025public class UnbalancedFilter extends AbstractVersionFilter { 
    1126 
    12         /** 
    13          * quantil where outside lying versions are removed 
    14          */ 
    15         private double quantil = 0.1; 
    16          
    17         /** 
    18          * Sets the quantil. 
    19          * @param parameters the quantil as string 
    20          */ 
    21         @Override 
    22         public void setParameter(String parameters) { 
    23                 quantil = Double.parseDouble(parameters); 
    24         } 
     27    /** 
     28     * quantil where outside lying versions are removed 
     29     */ 
     30    private double quantil = 0.1; 
    2531 
    26         /** 
    27          * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
    28          */ 
    29         @Override 
    30         public boolean apply(SoftwareVersion version) { 
    31                 final Instances instances = version.getInstances(); 
    32                  
    33                 final int[] counts = instances.attributeStats(instances.classIndex()).nominalCounts; 
    34                 return ((double) counts[0])/instances.numInstances() >= (1-quantil) || 
    35                         ((double) counts[0])/instances.numInstances() <= (quantil); 
    36         } 
     32    /** 
     33     * Sets the quantil. 
     34     *  
     35     * @param parameters 
     36     *            the quantil as string 
     37     */ 
     38    @Override 
     39    public void setParameter(String parameters) { 
     40        quantil = Double.parseDouble(parameters); 
     41    } 
     42 
     43    /** 
     44     * @see de.ugoe.cs.cpdp.versions.IVersionFilter#apply(de.ugoe.cs.cpdp.versions.SoftwareVersion) 
     45     */ 
     46    @Override 
     47    public boolean apply(SoftwareVersion version) { 
     48        final Instances instances = version.getInstances(); 
     49 
     50        final int[] counts = instances.attributeStats(instances.classIndex()).nominalCounts; 
     51        return ((double) counts[0]) / instances.numInstances() >= (1 - quantil) || 
     52            ((double) counts[0]) / instances.numInstances() <= (quantil); 
     53    } 
    3754 
    3855} 
Note: See TracChangeset for help on using the changeset viewer.