Mines the association rules. The discovered rules will be printed out
to the provided stream.
@param confidence the confidence threshold for association rules.
@return the number of discovered association rules.
964167
public long learn(double confidence, PrintStream out) {
        long n = 0;
        ttree = fim.buildTotalSupportTree();
        for (int i = 0; i < ttree.root.children.length; i++) {
            if (ttree.root.children[i] != null) {
                int[] itemset = {ttree.root.children[i].id};
                n += learn(out, null, itemset, i, ttree.root.children[i], confidence);
            }
        }
        return n;
    }
1238595
public void mTokens() throws RecognitionException {
        // InternalSimpleAntlr.g:1:8: ( T__13 | T__14 | T__15 | T__16 | T__17 | T__18 | T__19 | T__20 | T__21 | T__22 | T__23 | T__24 | T__25 | T__26 | T__27 | T__28 | T__29 | T__30 | T__31 | T__32 | T__33 | T__34 | T__35 | T__36 | RULE_EMPTY_PAREN | RULE_OPEN | RULE_ID | RULE_INT | RULE_STRING | RULE_ML_COMMENT | RULE_SL_COMMENT | RULE_WS | RULE_ANY_OTHER )
        int alt13=33;
        alt13 = dfa13.predict(input);
        switch (alt13) {
            case 1 :
                // InternalSimpleAntlr.g:1:10: T__13
                {
                mT__13(); 

                }
                break;
            case 2 :
                // InternalSimpleAntlr.g:1:16: T__14
                {
                mT__14(); 

                }
                break;
            case 3 :
                // InternalSimpleAntlr.g:1:22: T__15
                {
                mT__15(); 

                }
                break;
            case 4 :
                // InternalSimpleAntlr.g:1:28: T__16
                {
                mT__16(); 

                }
                break;
            case 5 :
                // InternalSimpleAntlr.g:1:34: T__17
                {
                mT__17(); 

                }
                break;
            case 6 :
                // InternalSimpleAntlr.g:1:40: T__18
                {
                mT__18(); 

                }
                break;
            case 7 :
                // InternalSimpleAntlr.g:1:46: T__19
                {
                mT__19(); 

                }
                break;
            case 8 :
                // InternalSimpleAntlr.g:1:52: T__20
                {
                mT__20(); 

                }
                break;
            case 9 :
                // InternalSimpleAntlr.g:1:58: T__21
                {
                mT__21(); 

                }
                break;
            case 10 :
                // InternalSimpleAntlr.g:1:64: T__22
                {
                mT__22(); 

                }
                break;
            case 11 :
                // InternalSimpleAntlr.g:1:70: T__23
                {
                mT__23(); 

                }
                break;
            case 12 :
                // InternalSimpleAntlr.g:1:76: T__24
                {
                mT__24(); 

                }
                break;
            case 13 :
                // InternalSimpleAntlr.g:1:82: T__25
                {
                mT__25(); 

                }
                break;
            case 14 :
                // InternalSimpleAntlr.g:1:88: T__26
                {
                mT__26(); 

                }
                break;
            case 15 :
                // InternalSimpleAntlr.g:1:94: T__27
                {
                mT__27(); 

                }
                break;
            case 16 :
                // InternalSimpleAntlr.g:1:100: T__28
                {
                mT__28(); 

                }
                break;
            case 17 :
                // InternalSimpleAntlr.g:1:106: T__29
                {
                mT__29(); 

                }
                break;
            case 18 :
                // InternalSimpleAntlr.g:1:112: T__30
                {
                mT__30(); 

                }
                break;
            case 19 :
                // InternalSimpleAntlr.g:1:118: T__31
                {
                mT__31(); 

                }
                break;
            case 20 :
                // InternalSimpleAntlr.g:1:124: T__32
                {
                mT__32(); 

                }
                break;
            case 21 :
                // InternalSimpleAntlr.g:1:130: T__33
                {
                mT__33(); 

                }
                break;
            case 22 :
                // InternalSimpleAntlr.g:1:136: T__34
                {
                mT__34(); 

                }
                break;
            case 23 :
                // InternalSimpleAntlr.g:1:142: T__35
                {
                mT__35(); 

                }
                break;
            case 24 :
                // InternalSimpleAntlr.g:1:148: T__36
                {
                mT__36(); 

                }
                break;
            case 25 :
                // InternalSimpleAntlr.g:1:154: RULE_EMPTY_PAREN
                {
                mRULE_EMPTY_PAREN(); 

                }
                break;
            case 26 :
                // InternalSimpleAntlr.g:1:171: RULE_OPEN
                {
                mRULE_OPEN(); 

                }
                break;
            case 27 :
                // InternalSimpleAntlr.g:1:181: RULE_ID
                {
                mRULE_ID(); 

                }
                break;
            case 28 :
                // InternalSimpleAntlr.g:1:189: RULE_INT
                {
                mRULE_INT(); 

                }
                break;
            case 29 :
                // InternalSimpleAntlr.g:1:198: RULE_STRING
                {
                mRULE_STRING(); 

                }
                break;
            case 30 :
                // InternalSimpleAntlr.g:1:210: RULE_ML_COMMENT
                {
                mRULE_ML_COMMENT(); 

                }
                break;
            case 31 :
                // InternalSimpleAntlr.g:1:226: RULE_SL_COMMENT
                {
                mRULE_SL_COMMENT(); 

                }
                break;
            case 32 :
                // InternalSimpleAntlr.g:1:242: RULE_WS
                {
                mRULE_WS(); 

                }
                break;
            case 33 :
                // InternalSimpleAntlr.g:1:250: RULE_ANY_OTHER
                {
                mRULE_ANY_OTHER(); 

                }
                break;

        }

    }
1354339
public TransactionConfidence getOrCreate(Sha256Hash hash) {
        checkNotNull(hash);
        lock.lock();
        try {
            WeakConfidenceReference reference = table.get(hash);
            if (reference != null) {
                TransactionConfidence confidence = reference.get();
                if (confidence != null)
                    return confidence;
            }
            TransactionConfidence newConfidence = confidenceFactory.createConfidence(hash);
            table.put(hash, new WeakConfidenceReference(newConfidence, referenceQueue));
            return newConfidence;
        } finally {
            lock.unlock();
        }
    }
502729
public static List<List<List<Writable>>> sampleSequence(int count, JavaRDD<List<List<Writable>>> data) {
        return data.takeSample(false, count);
    }
932527
def generate_association_rules(patterns, confidence_threshold):
    
    rules = {}
    for itemset in patterns.keys():
        upper_support = patterns[itemset]

        for i in range(1, len(itemset)):
            for antecedent in itertools.combinations(itemset, i):
                antecedent = tuple(sorted(antecedent))
                consequent = tuple(sorted(set(itemset) - set(antecedent)))

                if antecedent in patterns:
                    lower_support = patterns[antecedent]
                    confidence = float(upper_support) / lower_support

                    if confidence >= confidence_threshold:
                        rules[antecedent] = (consequent, confidence)

    return rules
478205
public AssociativeArray2D getWordProbabilitiesPerTopic() {
        AssociativeArray2D ptw = new AssociativeArray2D();
        
        ModelParameters modelParameters = knowledgeBase.getModelParameters();
        TrainingParameters trainingParameters = knowledgeBase.getTrainingParameters();
        
        //initialize a probability list for every topic
        int k = trainingParameters.getK();
        for(int topicId=0;topicId<k;++topicId) {
            ptw.put(topicId, new AssociativeArray());
        }
        
        int d = modelParameters.getD();
        double beta = trainingParameters.getBeta();
        
        Map<List<Object>, Integer> topicWordCounts = modelParameters.getTopicWordCounts();
        Map<Integer, Integer> topicCounts = modelParameters.getTopicCounts();
        for(Map.Entry<List<Object>, Integer> entry : topicWordCounts.entrySet()) {
            List<Object> tpk = entry.getKey();
            Integer topicId = (Integer)tpk.get(0);
            Object word = tpk.get(1);
            Integer njw = entry.getValue();
            
            Integer nj = topicCounts.get(topicId);
            
            double probability = (njw+beta)/(nj+beta*d);
            
            ptw.get(topicId).put(word, probability);
        }
        
        for(int topicId=0;topicId<k;++topicId) {
            ptw.put(topicId, MapMethods.sortAssociativeArrayByValueDescending(ptw.get(topicId)));
        }
        
        return ptw;
    }
271701
private static void checkAndCorrect(final double[] probabilities) {
		boolean ok = true;
		for (int i = probabilities.length; --i >= 0 && ok;) {
			ok = Double.isFinite(probabilities[i]);
		}

		if (!ok) {
			final double value = 1.0/probabilities.length;
			for (int i = probabilities.length; --i >= 0;) {
				probabilities[i] = value;
			}
		}
	}
79171
public void mTokens() throws RecognitionException {
        // InternalXtype.g:1:8: ( T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 | T__17 | T__18 | T__19 | T__20 | T__21 | T__22 | T__23 | T__24 | T__25 | T__26 | T__27 | RULE_ID | RULE_STRING | RULE_ML_COMMENT | RULE_SL_COMMENT | RULE_WS | RULE_ANY_OTHER )
        int alt13=24;
        alt13 = dfa13.predict(input);
        switch (alt13) {
            case 1 :
                // InternalXtype.g:1:10: T__10
                {
                mT__10(); 

                }
                break;
            case 2 :
                // InternalXtype.g:1:16: T__11
                {
                mT__11(); 

                }
                break;
            case 3 :
                // InternalXtype.g:1:22: T__12
                {
                mT__12(); 

                }
                break;
            case 4 :
                // InternalXtype.g:1:28: T__13
                {
                mT__13(); 

                }
                break;
            case 5 :
                // InternalXtype.g:1:34: T__14
                {
                mT__14(); 

                }
                break;
            case 6 :
                // InternalXtype.g:1:40: T__15
                {
                mT__15(); 

                }
                break;
            case 7 :
                // InternalXtype.g:1:46: T__16
                {
                mT__16(); 

                }
                break;
            case 8 :
                // InternalXtype.g:1:52: T__17
                {
                mT__17(); 

                }
                break;
            case 9 :
                // InternalXtype.g:1:58: T__18
                {
                mT__18(); 

                }
                break;
            case 10 :
                // InternalXtype.g:1:64: T__19
                {
                mT__19(); 

                }
                break;
            case 11 :
                // InternalXtype.g:1:70: T__20
                {
                mT__20(); 

                }
                break;
            case 12 :
                // InternalXtype.g:1:76: T__21
                {
                mT__21(); 

                }
                break;
            case 13 :
                // InternalXtype.g:1:82: T__22
                {
                mT__22(); 

                }
                break;
            case 14 :
                // InternalXtype.g:1:88: T__23
                {
                mT__23(); 

                }
                break;
            case 15 :
                // InternalXtype.g:1:94: T__24
                {
                mT__24(); 

                }
                break;
            case 16 :
                // InternalXtype.g:1:100: T__25
                {
                mT__25(); 

                }
                break;
            case 17 :
                // InternalXtype.g:1:106: T__26
                {
                mT__26(); 

                }
                break;
            case 18 :
                // InternalXtype.g:1:112: T__27
                {
                mT__27(); 

                }
                break;
            case 19 :
                // InternalXtype.g:1:118: RULE_ID
                {
                mRULE_ID(); 

                }
                break;
            case 20 :
                // InternalXtype.g:1:126: RULE_STRING
                {
                mRULE_STRING(); 

                }
                break;
            case 21 :
                // InternalXtype.g:1:138: RULE_ML_COMMENT
                {
                mRULE_ML_COMMENT(); 

                }
                break;
            case 22 :
                // InternalXtype.g:1:154: RULE_SL_COMMENT
                {
                mRULE_SL_COMMENT(); 

                }
                break;
            case 23 :
                // InternalXtype.g:1:170: RULE_WS
                {
                mRULE_WS(); 

                }
                break;
            case 24 :
                // InternalXtype.g:1:178: RULE_ANY_OTHER
                {
                mRULE_ANY_OTHER(); 

                }
                break;

        }

    }
291147
private boolean rule4(Double sample) {
        if (null == rule4PreviousSample || sample.doubleValue() == rule4PreviousSample.doubleValue()) {
            rule4PreviousSample = sample;
            rule4PreviousDirection = "=";
            rule4Count = 0;
            return false;
        }

        String sampleDirection = (sample > rule4PreviousSample) ? ">" : "<";

        if (sampleDirection.equals(rule4PreviousDirection)) {
            rule4Count = 0;
        } else {
            ++rule4Count;
        }

        rule4PreviousSample = sample;
        rule4PreviousDirection = sampleDirection;

        return Math.abs(rule4Count) >= 14;
    }
1152256
public int getLearnerToUse(Instance instance, int predMode) {
		int predictionMode = predMode;
		if (predictionMode == 0) {
			double 	perceptronError= this.perceptron.getCurrentError();
			double meanTargetError =this.targetMean.getCurrentError();
			debug("\n Check P:" + perceptronError + " M:" + meanTargetError,5);
			debug("Rule" + this.owner.ruleNumberID + " P:" + this.perceptron.getVotesForInstance(instance)[0] + " (" + perceptronError + ")" + " M:" + this.targetMean.getVotesForInstance(instance)[0]+ " (" + meanTargetError + ")",3) ; //Commented by JD
			debug("Observed Value: " + instance.classValue(),5);
			if (perceptronError < meanTargetError) {
				predictionMode = 1; //PERCEPTRON
			} else {
				predictionMode = 2; //TARGET MEAN
			}
		}
		return predictionMode;
	}
373277
boolean rule6(final IFactory factory, final Inclusion[] gcis) {
        boolean result = false;

        if (rhs instanceof Existential) {
            Existential existential = (Existential) rhs;
            final AbstractConcept cHat = existential.getConcept();
            if (!(cHat instanceof Concept)) {
                result = true;
                Concept a = getA(factory, cHat);
                gcis[0] = new GCI(lhs,
                        new Existential(existential.getRole(), a));
                gcis[1] = new GCI(a, cHat);
            }
        }

        return result;
    }
1018362
public final void ruleValidID() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:1879:2: ( ( RULE_ID ) )
            // InternalXbase.g:1880:2: ( RULE_ID )
            {
            // InternalXbase.g:1880:2: ( RULE_ID )
            // InternalXbase.g:1881:3: RULE_ID
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getValidIDAccess().getIDTerminalRuleCall()); 
            }
            match(input,RULE_ID,FOLLOW_2); if (state.failed) return ;
            if ( state.backtracking==0 ) {
               after(grammarAccess.getValidIDAccess().getIDTerminalRuleCall()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
369497
public ArrayList<Integer> getOccurrences() {
    ArrayList<Integer> res = new ArrayList<Integer>(this.occurrences.size());
    for (Integer e : this.occurrences) {
      res.add(e);
    }
    return res;
  }
821251
public int getErrorCount() {
    int count = 0;
    for (AggregatedTestResultEvent t : getTests()) {
      if (t.getStatus() == TestStatus.ERROR)
        count++;
    }
    
    for (FailureMirror m : getFailures()) {
      if (m.isErrorViolation())
        count++;
    }
    return count;
  }
1110320
public double accuracy(int outputNum) {
        assertIndex(outputNum);
        return (countTruePositive[outputNum] + countTrueNegative[outputNum]) / (double) totalCount(outputNum);
    }
452819
public void mapColumns() {
            //System.err.print("Patterns found: ");
            //System.err.println(pattern_list.size());
        
            int index = 0;
            //NOTE: occurrences can be used as Sigma X<k,j> when calculating Entropy
            for (InterveningWordsPattern a_pattern : pattern_list.keySet()) {
                //int val = a_pattern.getOccurrences();
                //System.err.println(a_pattern.getPattern() + " " + val);
                matrix_column_map.put(new Integer(index), a_pattern);
                index++;
                InterveningWordsPattern b_pattern = new InterveningWordsPattern(a_pattern.getPattern());
                b_pattern.setOccurrences(a_pattern.getOccurrences());
                b_pattern.setReverse(true);
                matrix_column_map.put(new Integer(index), b_pattern);
                index++;
            }
    }
165704
def get_confidence(self):
        """"""
        # if we didn't receive any character in our consideration range,
        # return negative answer
        if self._total_chars <= 0 or self._freq_chars <= self.MINIMUM_DATA_THRESHOLD:
            return self.SURE_NO

        if self._total_chars != self._freq_chars:
            r = (self._freq_chars / ((self._total_chars - self._freq_chars)
                 * self.typical_distribution_ratio))
            if r < self.SURE_YES:
                return r

        # normalize confidence (we don't want to be 100% sure)
        return self.SURE_YES