⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assocrulemining.java

📁 多关联分类算法
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	// No old item set		if (oldItemSet == null) {	    short[] newItemSet = {newElement};	    return(newItemSet);	    }		// Otherwise create new item set with length one greater than old	// item set		int oldItemSetLength = oldItemSet.length;	short[] newItemSet = new short[oldItemSetLength+1];		// Loop		int index1;		for (index1=0;index1 < oldItemSetLength;index1++) {	    if (newElement < oldItemSet[index1]) {		newItemSet[index1] = newElement;			// Add rest			for(int index2 = index1+1;index2<newItemSet.length;index2++)				newItemSet[index2] = oldItemSet[index2-1];		return(newItemSet);		}	    else newItemSet[index1] = oldItemSet[index1];	    }		// Add to end		newItemSet[newItemSet.length-1] = newElement;		// Return new item set		return(newItemSet);	}	    /* REALLOC 1 */    /** Resizes given item set so that its length is increased by one    and appends new element (identical to append method)    @param oldItemSet the original item set    @param newElement the new element/attribute to be appended    @return the combined item set */    protected short[] realloc1(short[] oldItemSet, short newElement) {	// No old item set		if (oldItemSet == null) {	    short[] newItemSet = {newElement};	    return(newItemSet);	    }		// Otherwise create new item set with length one greater than old	// item set		int oldItemSetLength = oldItemSet.length;	short[] newItemSet = new short[oldItemSetLength+1];		// Loop		int index;	for (index=0;index < oldItemSetLength;index++)		newItemSet[index] = oldItemSet[index];	newItemSet[index] = newElement;		// Return new item set		return(newItemSet);	}    /* REALLOC 2 */    /** Resizes given array so that its length is increased by one element    and new element added to front    @param oldItemSet the original item set    @param newElement the new element/attribute to be appended    @return the combined item set */    protected short[] realloc2(short[] oldItemSet, short newElement) {	// No old array		if (oldItemSet == null) {	    short[] newItemSet = {newElement};	    return(newItemSet);	    }		// Otherwise create new array with length one greater than old array		int oldItemSetLength = oldItemSet.length;	short[] newItemSet = new short[oldItemSetLength+1];		// Loop		newItemSet[0] = newElement;	for (int index=0;index < oldItemSetLength;index++)		newItemSet[index+1] = oldItemSet[index];		// Return new array		return(newItemSet);	}	    /* REALLOC 3 */    /** Resizes given array so that its length is decreased by one element    and first element removed    @param oldItemSet the original item set    @return the shortened item set */    protected short[] realloc3(short[] oldItemSet) {        		// If old item set comprises one element return null		if (oldItemSet.length == 1) return null;		// Create new array with length one greater than old array		int newItemSetLength = oldItemSet.length-1;	short[] newItemSet = new short[newItemSetLength];		// Loop		for (int index=0;index < newItemSetLength;index++)		newItemSet[index] = oldItemSet[index+1];		// Return new array		return(newItemSet);	}	    /* REALLOC 4 */    /** Resize given array so that its length is decreased by size of    second array (which is expected to be a leading subset of the first)    and remove second array.    @param oldItemSet The first item set.    @param array2 The leading subset of the <TT>oldItemSet</TT>.    @return Revised item set with leading subset removed. */    protected short[] realloc4(short[] oldItemSet, short[] array2) {        int array2length   = array2.length;	int newItemSetLength = oldItemSet.length-array2length;		// Create new array		short[] newItemSet = new short[newItemSetLength];		// Loop		for (int index=0;index < newItemSetLength;index++)		newItemSet[index] = oldItemSet[index+array2length];		// Return new array		return(newItemSet);	}	    /* --------------------------------------------- */    /*                                               */    /*            ITEM SET DELETE METHODS            */    /*                                               */    /* --------------------------------------------- */    /* REMOVE FIRST N ELEMENTS */    /** Removes the first n elements/attributes from the given item set.    @param oldItemSet the given item set.    @param n the number of leading elements to be removed.    @return Revised item set with first n elements removed. */    protected short[] removeFirstNelements(short[] oldItemSet, int n) {        if (oldItemSet.length == n) return(null);    	else {	    short[] newItemSet = new short[oldItemSet.length-n];	    for (int index=0;index<newItemSet.length;index++) {	        newItemSet[index] = oldItemSet[index+n];	        }	    return(newItemSet);	    }	}	    /* ---------------------------------------------------------------- */    /*                                                                  */    /*              METHODS TO RETURN SUBSETS OF ITEMSETS               */    /*                                                                  */    /* ---------------------------------------------------------------- */    /* GET LAST ELEMENT */          /** Gets the last element in the given item set, or '0' if the itemset is     empty.     @param itemSet the given item set.      @return the last element. */           protected short getLastElement(short[] itemSet) {         // Check for empty item set 	if (itemSet == null) return(0); 	// Otherwise return last element         return(itemSet[itemSet.length-1]); 	} 	     /* COMPLEMENT */    /** Returns complement of first itemset with respect to second itemset.    @param itemSet1 the first given item set.    @param itemSet1 the second given item set.    @return complement if <TT>itemSet1</TT> in <TT>itemSet2</TT>. */    protected short[] complement(short[] itemSet1, short[] itemSet2) {        int lengthOfComp = itemSet2.length-itemSet1.length;		// Return null if no complement	if (lengthOfComp<1) return(null);		// Otherwsiose define combination array and determine complement	short[] complement  = new short[lengthOfComp];	int complementIndex = 0;	for(int index=0;index<itemSet2.length;index++) {	    // Add to comination if not in first itemset	    if (notMemberOf(itemSet2[index],itemSet1)) {	    	complement[complementIndex] = itemSet2[index];		complementIndex++;		}		    }		// Return	return(complement);	}			    	    /* --------------------------------------- */    /*                                         */    /*             SORT ITEM SET               */    /*                                         */    /* --------------------------------------- */    		    /* SORT ITEM SET: Given an unordered itemSet, sort the set */    /** Sorts an unordered item set.    @param itemSet the given item set. */    protected void sortItemSet(short[] itemSet) {        short temp;	        boolean isOrdered;        int index;        do {	    isOrdered = true;            index     = 0;            while (index < (itemSet.length-1)) {                if (itemSet[index] <= itemSet[index+1]) index++;	        else {	            isOrdered=false;                    // Swap		    temp = itemSet[index];	            itemSet[index] = itemSet[index+1];                    itemSet[index+1] = temp;	            // Increment index		    index++;	            }	  	}	    } while (isOrdered==false);    	}	    /* ----------------------------------------------------- */    /*                                                       */    /*             BOOLEAN ITEM SET METHODS ETC.             */    /*                                                       */    /* ----------------------------------------------------- */	    		  	    /* CHECK ITEM SET: */    /** Determines relationship between two item sets (same, parent,    before, child or after).    @param itemSet1 the first item set.    @param itemSet2 the second item set to be compared with first.    @return 1 = same, 2 = itemSet2 is parent of itemSet1, 3 = itemSet2    lexicographically before itemSet1, 4 = itemSet2 is child of itemSet1,    and 5 = itemSet2 lexicographically after itemSet1. */    protected int checkItemSets(short[] itemSet1, short[] itemSet2) {        // Check if the same	if (isEqual(itemSet1,itemSet2)) return(1);	// Check whether before or after and subset/superset.	if (isBefore(itemSet1,itemSet2)) {	    if (isSubset(itemSet1,itemSet2)) return(2);	    else return(3);	    }        if (isSubset(itemSet2,itemSet1)) return(4);        return(5);        }	    /* EQUALITY CHECK */    /** Checks whether two item sets are the same.    @param itemSet1 the first item set.    @param itemSet2 the second item set to be compared with first.    @return true if itemSet1 is equal to itemSet2, and false otherwise. */    protected boolean isEqual(short[] itemSet1, short[] itemSet2) {		// If no itemSet2 (i.e. itemSet2 is null return false)		if (itemSet2 == null) return(false);		// Compare sizes, if not same length they cannot be equal.		int length1 = itemSet1.length;	int length2 = itemSet2.length;	if (length1 != length2) return(false);        // Same size compare elements        for (int index=0;index < length1;index++) {	    if (itemSet1[index] != itemSet2[index]) return(false);	    }        // itemSet the same.        return(true);        }	    /* BEFORE CHECK */    /** Checks whether one item set is lexicographically before a second    item set.    @param itemSet1 the first item set.    @param itemSet2 the second item set to be compared with first.    @return true if itemSet1 is less than or equal (before) itemSet2 and    false otherwise. Note that before here is not numerical but lexical,    i.e. {1,2} is before {2} */    public static boolean isBefore(short[] itemSet1, short[] itemSet2) {        int length2 = itemSet2.length;		// Compare elements	for(int index1=0;index1<itemSet1.length;index1++) {	    if (index1 == length2) return(false); // itemSet2 is a proper subset of itemSet1	    	    if (itemSet1[index1] < itemSet2[index1]) return(true);	    if (itemSet1[index1] > itemSet2[index1]) return(false);	    }		// Return true	return(true);	}		    /* SUBSET CHECK */    /** Checks whether one item set is subset of a second item set.    @param itemSet1 the first item set.    @param itemSet2 the second item set to be compared with first.    @return true if itemSet1 is a subset of itemSet2, and false otherwise.    */    protected boolean isSubset(short[] itemSet1, short[] itemSet2) {	// Check for empty itemsets	if (itemSet1==null) return(true);	if (itemSet2==null) return(false);		// Loop through itemSet1	for(int index1=0;index1<itemSet1.length;index1++) {	    if (notMemberOf(itemSet1[index1],itemSet2)) return(false);	    }		// itemSet1 is a subset of itemSet2	return(true);	}		    /* NOT MEMBER OF */    /** Checks whether a particular element/attribute identified by a    column number is not a member of the given item set.    @param number the attribute identifier (column number).    @param itemSet the given item set.    @return true if first argument is not a member of itemSet, and false    otherwise */    protected boolean notMemberOf(short number, short[] itemSet) {	// Loop through itemSet		for(int index=0;index<itemSet.length;index++) {	    if (number < itemSet[index]) return(true);	    if (number == itemSet[index]) return(false);	    }		// Got to the end of itemSet and found nothing, return false		return(true);	}	    /* CHECK FOR LEADING SUB STRING */    /** Checks whether two itemSets share a leading substring.    @param itemSet1 the first item set.    @param itemSet2 the second item set to be compared with first.    @return the substring if a shared leading substring exists, and null    otherwise. */		    protected short[] checkForLeadingSubString(short[] itemSet1,    							short[] itemSet2) {        //int index3=0;	short[] itemSet3 = null;		// Loop through itemSets		for(int index=0;index<itemSet1.length;index++) {	    if (index == itemSet2.length) break;	    if (itemSet1[index] == itemSet2[index])	    			itemSet3 = realloc1(itemSet3,itemSet1[index]);	    else break;	    }	 			// Return		return(itemSet3);	}		    /* -------------------------------------------------- */    /*                                                    */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -