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

📄 rulelist.java

📁 多关联分类算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         private short selectBestWCS(double[] wcsValues) {         double bestValue = wcsValues[0]; 	int bestIndex    = 0; 	 	for (int index=1;index<wcsValues.length;index++) { 	    if (wcsValues[index]>bestValue) { 	        bestValue=wcsValues[index]; 		bestIndex=index; 		} 	    } 	 	// Return 	return((short) (numOneItemSets-bestIndex)); 	} 	     /* CALCULATE CHI SQUARED VALUE UPPER BOUND */          /** Claculates the upper bound for the Chi-Squared value of a rule.      @param suppAnte the support for the antecedent of a rule.     @param suppCons the support for the consequent of a rule.     @return the Chi-Squared upper bound. */          private double calcChiSquaredUpperBound(double suppAnte, double suppCons) {         double term; 	 	// Test support for antecedent and confidence and choose minimum 	if (suppAnte<suppCons) term =  		      Math.pow(suppAnte-((suppAnte*suppCons)/numRecords),2.0); 		      	else term = Math.pow(suppCons-((suppAnte*suppCons)/numRecords),2.0); 		       	// Determine e 	double eVlaue = calcWCSeValue(suppAnte,suppCons); 	 	// Rerturn upper bound 	return(term*eVlaue*numRecords); 	} 	     /* CALCULATE WCS e VALUE. */          /** Calculates and returns the e value for calculating Weighted Chi-Squared     (WCS) values.     @param suppAnte the support for the antecedent of a rule.     @param suppCons the support for the consequent of a rule.     @return the ECS e value. */          private double calcWCSeValue(double suppAnte, double suppCons) {         double term1 = 1/(suppAnte*suppCons); 	double term2 = 1/(suppAnte*(numRecords-suppCons));         double term3 = 1/(suppCons*(numRecords-suppAnte)); 	double term4 = 1/((numRecords-suppAnte)*(numRecords-suppCons)); 	 	// Return sum 	return(term1+term2+term3+term4);  	}          /* ------------------------------------------------------------- */     /*                 CLASSIFIER  (UTILITY METHODS)                 */     /* ------------------------------------------------------------- */          /** Places all rules that satisfy the given record in a CMAR rule linked      list pointed at by startCMARrulelist field, in the order that rules are      presented. <P> Used in Weighted Chi-Squared classification (CMAR) algorithm.     @param linkref The reference to the start of the existing list of rules.     @param itemset the record to be classified.	*/      private void obtainallRulesForRecord(RuleNodeCMAR linkRef, short[] itemSet) { 	RuleNodeCMAR newStartRef = null; 	RuleNodeCMAR markerRef   = null; 	 	// Loop through linked list of existing rules 	while (linkRef!=null) { 	    // If rule satisfies record add to new rule list 	    if (isSubset(linkRef.antecedent,itemSet)) { 	        RuleNodeCMAR newNode = new RuleNodeCMAR(linkRef.antecedent, 				linkRef.consequent,linkRef.supportForRule, 				linkRef.suppAntecedent,linkRef.suppConsequent, 				linkRef.confidenceForRule); 	   	if (newStartRef==null) newStartRef=newNode; 		else markerRef.next=newNode; 		markerRef=newNode;  		/*if (newStartRef==null) newStartRef=linkRef; 		else markerRef.next=linkRef; 		markerRef=linkRef; */ 		} 	    linkRef=linkRef.next; 	    } 	 	// Set rule list  	startCMARrulelist = newStartRef; 	}	  	         /* ----------------------------------- */    /*                                     */    /*              GET METHODS            */    /*                                     */    /* ----------------------------------- */	    /* GET NUMBER OF RULES */    /**  Returns the number of generated rules (usually used in    conjunction with classification rule mining algorithms rather than ARM    algorithms).    @return the number of CRs. */    public int getNumCRs() {        int number = 0;        RuleNode linkRuleNode = startRulelist;		// Loop through linked list	while (linkRuleNode != null) {	    number++;	    linkRuleNode = linkRuleNode.next;	    }		// Return	return(number);	}          /* GET NUMBER OF CMAR CLASSIFICATION RULES */      /**  Returns the number of generated CMAR classification rules.     @return the number of CRs. */      public int getNumCMAR_CRs() {         int number = 0;         RuleNodeCMAR linkRuleNode = startCMARrulelist; 	 	// Loop through linked list 	while (linkRuleNode != null) { 	    number++; 	    linkRuleNode = linkRuleNode.next; 	    } 	 	// Return 	return(number); 	} 	    /* ----------------------------------- */    /*                                     */    /*              SET METHODS            */    /*                                     */    /* ----------------------------------- */        /* SET NUMBER OF ROWS */        /** Sets number of rows field. */        protected void setNumRows(int numR) {        numRows=numR;	}  	    /* SET NUMBER OF CLASSES */        /** Sets number of rows field. */        protected void setNumClasses(int numC) {        numClasses=numC;	}    		    /* SET NUMBER OF ONE ITEM SETS */        /** Sets number of one item sets field. */        protected void setNumOneItemSets(int nois) {        numOneItemSets=nois;	}  	        /* SET DATA ARRAT */        /** Set 2-D "short" data array reference. */        /*protected void setDataArray(short[][] dArray) {        dataArray=dArray;	}    */    /* SET RECONVERSION ARRAYS */    /** Sets the reconversion array reference values.    @param conversionArrayRef the reference to the 2-D array used to renumber    coulmns for input data in terms of frequency of single attributes    (reordering will enhance performance for some ARM and CARM algorithms).    @param reconversionArrayRef the reference to the 1-D array used to reconvert    input data column numbers to their original numbering where the input data    has been ordered to enhance computational efficienvy. */    protected void setReconversionArrayRefs(int[][] conversionArrayRef,    					short[] reconversionArrayRef) {        conversionArray   = conversionArrayRef;        reconversionArray = reconversionArrayRef;        }        	    /* ------------------------------ */    /*                                */    /*              OUTPUT            */    /*                                */    /* ------------------------------ */    /* OUTPUT CMAR RULE LINKED LIST */     /** Outputs contents of CMAR rule linked list (if any) */          public void outputCMARrules() {         outputRules(startCMARrulelist); 	}      /** Outputs given CMAR rule list.     @param ruleList the given rule list. */          public void outputRules(RuleNodeCMAR ruleList) { 	 	// Check for empty rule list 	if (ruleList==null) System.out.println("No rules generated!"); 	 	// Loop through rule list 	int number = 1;         RuleNodeCMAR linkRuleNode = ruleList; 	while (linkRuleNode != null) { 	    System.out.print("(" + number + ") "); 	    outputRule(linkRuleNode);             System.out.println(" " +  	        twoDecPlaces(linkRuleNode.confidenceForRule) + "%, (" + 	        linkRuleNode.supportForRule + ", " +  		linkRuleNode.suppAntecedent + ", " +   		linkRuleNode.suppConsequent + ")"); 	    number++; 	    linkRuleNode = linkRuleNode.next; 	    } 	} 	     /** Outputs a CMAR rule.     @param rule the rule to be output. */          private void outputRule(RuleNodeCMAR rule) {         outputItemSet(rule.antecedent); 	System.out.print(" -> ");         outputItemSet(rule.consequent); 	}         /* OUTPUT RULE LINKED LIST WITH RECONVERSION */       /** Outputs contents of rule linked list (if any) with reconversion. */        public void outputRulesWithReconversion() {	// Check for empty rule list	if (startRulelist==null) System.out.println("No rules generated!");		// Loop through rule list        int number = 1;        RuleNode linkRuleNode = startRulelist;	while (linkRuleNode != null) {	    System.out.print("(" + number + ") ");	    outputItemSetWithReconversion(linkRuleNode.antecedent);	    System.out.print(" -> ");            outputItemSetWithReconversion(linkRuleNode.consequent);            System.out.println(" " + linkRuleNode.confidenceForRule + "%");	    number++;	    linkRuleNode = linkRuleNode.next;	    }	}		    /* OUTPUT RULE LINKED LIST WITH DEFAULT */       /** Outputs contents of rule linked list (if any), with reconversion, such     that last rule is the defualt rule. */        /*public void outputRulesWithDefault() {        int number = 1;        RuleNode linkRuleNode = startRulelist;		while (linkRuleNode != null) {	    // Output rule number	    System.out.print("(" + number + ") ");	    // Output antecedent	    if (linkRuleNode.next==null) System.out.print("Default -> ");	    else {	        outputItemSet(linkRuleNode.antecedent);	        System.out.print(" -> ");		}	    // Output concequent            outputItemSet(linkRuleNode.consequent);            System.out.println(" " + linkRuleNode.confidenceForRule + "%");	    // Increment parameters	    number++;	    linkRuleNode = linkRuleNode.next;	    }	}   */		    /* OUTPUT RULE LINKED LIST WITH DEFAULT AND RECONVERSION */       /** Outputs contents of rule linked list (if any), with reconversion, such     that last rule is the defualt rule. */        /*public void outputRulesWithDefaultRecon() {        int number = 1;        RuleNode linkRuleNode = startRulelist;		while (true) {	    // Output rule number	    System.out.print("(" + number + ") ");	    // Output antecedent	    if (linkRuleNode.next==null) {	        System.out.print("Default -> ");		break;		}	    else {	        outputItemSetWithReconversion(linkRuleNode.antecedent);	        System.out.print(" -> ");		}	    // Output concequent            outputItemSetWithReconversion(linkRuleNode.consequent);            System.out.println(" " + linkRuleNode.confidenceForRule + "%");	    // Increment parameters	    number++;	    linkRuleNode = linkRuleNode.next;	    }	}     */    /* OUTPUT NUMBER OF RULES */          /** Outputs number of generated rules (ARs or CARS). */          public void outputNumRules() {         System.out.println("Number of rules         = " + getNumCRs()); 	}      /* OUTPUT NUMBER OF CMAR RULES */          /** Outputs number of generated rules (ARs or CARS). */          public void outputNumCMARrules() {         System.out.println("Number of CMAR rules    = " + getNumCMAR_CRs()); 	}     }

⌨️ 快捷键说明

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