Given a set of already adapted rules, and a dictionary of
        patterns and alpha_nodes, wire up the beta part of the RETE
        network.
421805
def build_beta_part(ruleset, alpha_terminals):
        
        for rule in ruleset:
            if isinstance(rule[0], OR):
                for subrule in rule[0]:
                    wire_rule(rule, alpha_terminals, lhs=subrule)
            else:
                wire_rule(rule, alpha_terminals, lhs=rule)
94000
def _prepare_patterns(self, pattern_dict):
        """"""
        dict_compiled = {}
        dict_text = {}
        dict_dscr = {}
        for platform, patterns in pattern_dict.items():
            dict_text[platform] = {}
            dict_compiled[platform] = {}
            dict_dscr[platform] = {}

            for key, pattern in patterns.items():
                try:
                    text_pattern = None
                    compiled_pattern = None
                    description_pattern = None

                    if isinstance(pattern, str):
                        text_pattern = pattern
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = key

                    elif isinstance(pattern, dict):
                        text_pattern = pattern['pattern']
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = pattern['description']

                    elif isinstance(pattern, list):
                        text_pattern = self._concatenate_patterns(key, pattern)
                        compiled_pattern = re.compile(text_pattern, re.MULTILINE)
                        description_pattern = key

                    dict_text[platform][key] = text_pattern
                    dict_compiled[platform][key] = compiled_pattern
                    dict_dscr[platform][key] = description_pattern

                except re.error as e:
                    raise RuntimeError("Pattern compile error: {} ({}:{})".format(e.message, platform, key))

        return dict_compiled, dict_text, dict_dscr
734628
def update_terminal_regions(self, tree, X, y, residual, y_pred,
                                sample_weight, sample_mask,
                                learning_rate=1.0, k=0):
        
        # update predictions
        y_pred[:, k] += learning_rate * tree.predict(X).ravel()
1234732
def parse_rules(data, chain):
    
    rules = []
    for line in data.splitlines(True):
        m = re_rule.match(line)
        if m and m.group(3) == chain:
            rule = parse_rule(m.group(4))
            rule.packets = int(m.group(1))
            rule.bytes = int(m.group(2))
            rules.append(rule)
    return rules
684696
def _build_rules(specs):
    
    for spec in specs:
        if "context" in spec:
            yield Context(spec["context"], list(_build_rules(spec.get("routes", []))))
        else:
            rulespec = spec.copy()
            match = rulespec.pop("match")
            name = rulespec.pop("name")
            yield Rule(match, endpoint=name, **rulespec)
1012954
function(rules) {
      var normalizedRules = {};
      _.each(rules, function(rule) {
        _.each(rule.apiGroups, function(apiGroup) {
          if (!normalizedRules[apiGroup]) {
            normalizedRules[apiGroup] = {};
          }
          _.each(rule.resources, function(resource) {
            normalizedRules[apiGroup][resource] = rule.verbs;
          });
        });
      });
      return normalizedRules;
    }
1175426
function altersingle(alpha, i, b, g, r) {

    /* alter hit neuron */
    var n = network[i];
    n[0] -= (alpha * (n[0] - b)) / initalpha;
    n[1] -= (alpha * (n[1] - g)) / initalpha;
    n[2] -= (alpha * (n[2] - r)) / initalpha;
  }
986982
def altersingle(self, alpha, i, b, g, r):
        """"""
        n = self.network[i]  # Alter hit neuron
        n[0] -= (alpha * (n[0] - b))
        n[1] -= (alpha * (n[1] - g))
        n[2] -= (alpha * (n[2] - r))
1180306
private long learn(PrintStream out, List<AssociationRule> list, int[] itemset, int support, double confidence) {
        long n = 0;
        // Determine combinations
        int[][] combinations = getPowerSet(itemset);

        // Loop through combinations
        for (int i = 0; i < combinations.length; i++) {
            // Find complement of combination in given itemSet
            int[] complement = getComplement(combinations[i], itemset);
            // If complement is not empty generate rule
            if (complement != null) {
                double arc = getConfidence(combinations[i], support);
                if (arc >= confidence) {
                    double supp = (double) support / fim.size();
                    AssociationRule ar = new AssociationRule(combinations[i], complement, supp, arc);
                    n++;

                    if (out != null) {
                        out.println(ar);
                    }

                    if (list != null) {
                        list.add(ar);
                    }
                }
            }
        }
        
        return n;
    }
1308431
def beta_code(self, text):
        
        text = text.upper().replace('-', '')
        for (pattern, repl) in self.pattern1:
            text = pattern.subn(repl, text)[0]
        for (pattern, repl) in self.pattern2:
            text = pattern.subn(repl, text)[0]
        # remove third run, if punct list not used
        for (pattern, repl) in self.pattern3:
            text = pattern.subn(repl, text)[0]
        return text
543040
def relevant_rules_for_match(self, action, subject):
        """"""
        matches = []
        for rule in self.rules:
            rule.expanded_actions = self.expand_actions(rule.actions)
            if rule.is_relevant(action, subject):
                matches.append(rule)

        return self.optimize(matches[::-1])
266175
def pattern_logic_aeidon():
    """"""

    if Config.options.pattern_files:
        return prep_patterns(Config.options.pattern_files)
    elif Config.options.regex:
        return Config.REGEX
    else:
        return Config.TERMS
247237
private void updateRuleSplitNode(PredicateContentEvent pce) {
		int ruleID = pce.getRuleNumberID();
		for (PassiveRule rule:ruleSet) {
			if (rule.getRuleNumberID() == ruleID) {
				if (pce.getRuleSplitNode() != null)
					rule.nodeListAdd(pce.getRuleSplitNode());
				if (pce.getLearningNode() != null)
					rule.setLearningNode(pce.getLearningNode());
			}
		}
	}
1318467
private void adaptHistories(int numberOfDeletions){
		for (int i = 0; i < numberOfDeletions; i++){
			SortedSet<Integer> keys = new TreeSet<>(this.predictionHistories.keySet());
			this.predictionHistories.remove(keys.first());
			keys = new TreeSet<>(this.predictionHistories.keySet());
			for (Integer key : keys){
				List<Integer> predHistory = this.predictionHistories.remove(key);
				this.predictionHistories.put(key-keys.first(), predHistory);
			}
		}
	}
64613
def get_config(network, data_shape, **kwargs):
    
    if network == 'vgg16_reduced':
        if data_shape >= 448:
            from_layers = ['relu4_3', 'relu7', '', '', '', '', '']
            num_filters = [512, -1, 512, 256, 256, 256, 256]
            strides = [-1, -1, 2, 2, 2, 2, 1]
            pads = [-1, -1, 1, 1, 1, 1, 1]
            sizes = [[.07, .1025], [.15,.2121], [.3, .3674], [.45, .5196], [.6, .6708], \
                [.75, .8216], [.9, .9721]]
            ratios = [[1,2,.5], [1,2,.5,3,1./3], [1,2,.5,3,1./3], [1,2,.5,3,1./3], \
                [1,2,.5,3,1./3], [1,2,.5], [1,2,.5]]
            normalizations = [20, -1, -1, -1, -1, -1, -1]
            steps = [] if data_shape != 512 else [x / 512.0 for x in
                [8, 16, 32, 64, 128, 256, 512]]
        else:
            from_layers = ['relu4_3', 'relu7', '', '', '', '']
            num_filters = [512, -1, 512, 256, 256, 256]
            strides = [-1, -1, 2, 2, 1, 1]
            pads = [-1, -1, 1, 1, 0, 0]
            sizes = [[.1, .141], [.2,.272], [.37, .447], [.54, .619], [.71, .79], [.88, .961]]
            ratios = [[1,2,.5], [1,2,.5,3,1./3], [1,2,.5,3,1./3], [1,2,.5,3,1./3], \
                [1,2,.5], [1,2,.5]]
            normalizations = [20, -1, -1, -1, -1, -1]
            steps = [] if data_shape != 300 else [x / 300.0 for x in [8, 16, 32, 64, 100, 300]]
        if not (data_shape == 300 or data_shape == 512):
            logging.warn('data_shape %d was not tested, use with caucious.' % data_shape)
        return locals()
    elif network == 'inceptionv3':
        from_layers = ['ch_concat_mixed_7_chconcat', 'ch_concat_mixed_10_chconcat', '', '', '', '']
        num_filters = [-1, -1, 512, 256, 256, 128]
        strides = [-1, -1, 2, 2, 2, 2]
        pads = [-1, -1, 1, 1, 1, 1]
        sizes = [[.1, .141], [.2,.272], [.37, .447], [.54, .619], [.71, .79], [.88, .961]]
        ratios = [[1,2,.5], [1,2,.5,3,1./3], [1,2,.5,3,1./3], [1,2,.5,3,1./3], \
            [1,2,.5], [1,2,.5]]
        normalizations = -1
        steps = []
        return locals()
    elif network == 'resnet50':
        num_layers = 50
        image_shape = '3,224,224'  # resnet require it as shape check
        network = 'resnet'
        from_layers = ['_plus12', '_plus15', '', '', '', '']
        num_filters = [-1, -1, 512, 256, 256, 128]
        strides = [-1, -1, 2, 2, 2, 2]
        pads = [-1, -1, 1, 1, 1, 1]
        sizes = [[.1, .141], [.2,.272], [.37, .447], [.54, .619], [.71, .79], [.88, .961]]
        ratios = [[1,2,.5], [1,2,.5,3,1./3], [1,2,.5,3,1./3], [1,2,.5,3,1./3], \
            [1,2,.5], [1,2,.5]]
        normalizations = -1
        steps = []
        return locals()
    elif network == 'resnet101':
        num_layers = 101
        image_shape = '3,224,224'
        network = 'resnet'
        from_layers = ['_plus29', '_plus32', '', '', '', '']
        num_filters = [-1, -1, 512, 256, 256, 128]
        strides = [-1, -1, 2, 2, 2, 2]
        pads = [-1, -1, 1, 1, 1, 1]
        sizes = [[.1, .141], [.2,.272], [.37, .447], [.54, .619], [.71, .79], [.88, .961]]
        ratios = [[1,2,.5], [1,2,.5,3,1./3], [1,2,.5,3,1./3], [1,2,.5,3,1./3], \
            [1,2,.5], [1,2,.5]]
        normalizations = -1
        steps = []
        return locals()
    else:
        msg = 'No configuration found for %s with data_shape %d' % (network, data_shape)
        raise NotImplementedError(msg)
1312678
def get_symbol_train(network, data_shape, **kwargs):
    
    if network.startswith('legacy'):
        logging.warn('Using legacy model.')
        return symbol_builder.import_module(network).get_symbol_train(**kwargs)
    config = get_config(network, data_shape, **kwargs).copy()
    config.update(kwargs)
    return symbol_builder.get_symbol_train(**config)
635184
function alterneigh(radius, i, b, g, r) {
    var lo = Math.abs(i - radius);
    var hi = Math.min(i + radius, netsize);

    var j = i + 1;
    var k = i - 1;
    var m = 1;

    var p, a;
    while ((j < hi) || (k > lo)) {
      a = radpower[m++];

      if (j < hi) {
        p = network[j++];
        p[0] -= (a * (p[0] - b)) / alpharadbias;
        p[1] -= (a * (p[1] - g)) / alpharadbias;
        p[2] -= (a * (p[2] - r)) / alpharadbias;
      }

      if (k > lo) {
        p = network[k--];
        p[0] -= (a * (p[0] - b)) / alpharadbias;
        p[1] -= (a * (p[1] - g)) / alpharadbias;
        p[2] -= (a * (p[2] - r)) / alpharadbias;
      }
    }
  }