Forward propagation
assumption: layer 0 has _a filled with (horizontalized categoricals) double values
@param seed
@param neurons
@param minfo
@param consensus_minfo
@param training
@param n Number of actually trained samples in this mini-batch
488365
public static void fpropMiniBatch(long seed, Neurons[] neurons, DeepLearningModelInfo minfo,
                                    DeepLearningModelInfo consensus_minfo, boolean training, double[] responses, double[] offset, int n) {
    // Forward propagation
    for (int i=1; i<neurons.length; ++i)
      neurons[i].fprop(seed, training, n);

    // Add offset (in link space) if applicable
    for (int mb=0;mb<n;++mb) {
      if (offset!=null && offset[mb] > 0) {
        assert (!minfo._classification); // Regression
        double[] m = minfo.data_info()._normRespMul;
        double[] s = minfo.data_info()._normRespSub;
        double mul = m == null ? 1 : m[0];
        double sub = s == null ? 0 : s[0];
        neurons[neurons.length - 1]._a[mb].add(0, ((offset[mb] - sub) * mul));
      }

      if (training) {
        // Compute the gradient at the output layer
        // auto-encoder: pass a dummy "response" (ignored)
        // otherwise: class label or regression target
        neurons[neurons.length - 1].setOutputLayerGradient(responses[mb], mb, n);

        // Elastic Averaging - set up helpers needed during back-propagation
        if (consensus_minfo != null) {
          for (int i = 1; i < neurons.length; i++) {
            neurons[i]._wEA = consensus_minfo.get_weights(i - 1);
            neurons[i]._bEA = consensus_minfo.get_biases(i - 1);
          }
        }
      }
    }
  }
1284310
def random_seed_np_tf(seed):
    
    if seed >= 0:
        np.random.seed(seed)
        tf.set_random_seed(seed)
        return True
    else:
        return False
785732
@Override
	public void propagate(int evtmask) throws ContradictionException {
		// reset
		int n = g.getNbMaxNodes();
		support.getNodes().clear();
		for (int i = 0; i < n; i++) {
			support.getNeighOf(i).clear();
		}
		ISet nodes = g.getMandatoryNodes();
		for (int i : nodes) {
			support.addNode(i);
		}
		for (int i : nodes) {
			ISet nei = g.getPotNeighOf(i);
			for (int j : nei) {
				if (i < j) {
					support.addEdge(i, j);
				}
			}
		}
		delta = n - g.getMandatoryNodes().size();
		// algorithm
		heur.prepare();
		do {
			heur.computeMIS();
			for (R rule : rules) {
				rule.filter(nb, support, heur, this);
			}
		} while (heur.hasNextMIS());
	}
810236
function (seed_x, seed_y, radius, layers_no) {
        // Layer 0 is the seed
        var layers = [[create_point(seed_x, seed_y)]];
        var layer, angle, point, p;
        for(layer = 0; layer < layers_no; layer++) {
            // Reserve space for next layer
            layers.push([]);
            for (point = 0; point < layers[layer].length; point++) {
                for (angle = 0; angle < angles.length; angle++) {
                    p = rotate_point(create_point(
                            layers[layer][point].x,
                            layers[layer][point].y - radius),
                            layers[layer][point], 
                            angles[angle]);

                    if (!point_exists(p, flatten(layers))) {
                        // Only new points continue generations
                        layers[layer + 1].push(p);
                    }
                }
            }
        }

        // Layers have been generated, return getters
        return {
            layers: function () {
                return layers;
            },

            points: function () {
                return flatten(layers);
            }
        }

    }
1321963
@Override
    public synchronized double learnSequence(@NonNull Sequence<T> sequence, @NonNull AtomicLong nextRandom,
                    double learningRate) {
        /*
                GloVe learning algorithm is implemented like a hack over settled ElementsLearningAlgorithm mechanics. It's called in SequenceVectors context, but actually only for the first call.
                All subsequent calls will met early termination condition, and will be successfully ignored. But since elements vectors will be updated within first call,
                this will allow compatibility with everything beyond this implementaton
         */
        if (isTerminate.get())
            return 0;

        final AtomicLong pairsCount = new AtomicLong(0);
        final Counter<Integer> errorCounter = new Counter<>();

        //List<Pair<T, T>> coList = coOccurrences.coOccurrenceList();

        for (int i = 0; i < configuration.getEpochs(); i++) {

            // TODO: shuffle should be built in another way.
            //if (shuffle)
            //Collections.shuffle(coList);

            Iterator<Pair<Pair<T, T>, Double>> pairs = coOccurrences.iterator();

            List<GloveCalculationsThread> threads = new ArrayList<>();
            for (int x = 0; x < workers; x++) {
                threads.add(x, new GloveCalculationsThread(i, x, pairs, pairsCount, errorCounter));
                threads.get(x).start();
            }



            for (int x = 0; x < workers; x++) {
                try {
                    threads.get(x).join();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            log.info("Processed [" + pairsCount.get() + "] pairs, Error was [" + errorCounter.getCount(i) + "]");
        }

        isTerminate.set(true);
        return 0;
    }
636819
private void propagate(Layer lower, Layer upper) {
        for (int i = 0; i < upper.units; i++) {
            double sum = 0.0;
            for (int j = 0; j <= lower.units; j++) {
                sum += upper.weight[i][j] * lower.output[j];
            }

            if (upper == outputLayer) {
                upper.output[i] = sum;
            }

            else {
                if (activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                    upper.output[i] = Math.logistic(sum);
                }
                else if (activationFunction==ActivationFunction.TANH){
                    upper.output[i]=(2*Math.logistic(2*sum))-1;
                }
            }
        }
    }
383350
private void trainOnOneSample(Instance instance, int partialTreeIter, int i, int dataCount, CompletionService<ArrayList<BeamElement>> pool) throws InterruptedException, ExecutionException
    {
        boolean isPartial = instance.isPartial(options.rootFirst);

        if (partialTreeIter > i && isPartial)
            return;

        Configuration initialConfiguration = new Configuration(instance.getSentence(), options.rootFirst);
        Configuration firstOracle = initialConfiguration.clone();
        ArrayList<Configuration> beam = new ArrayList<Configuration>(options.beamWidth);
        beam.add(initialConfiguration);

        /**
         * The float is the oracle's cost
         * For more information see:
         * Yoav Goldberg and Joakim Nivre. "Training Deterministic Parsers with Non-Deterministic Oracles."
         * TACL 1 (2013): 403-414.
         * for the mean while we just use zero-cost oracles
         */
        Collection<Configuration> oracles = new HashSet<Configuration>();

        oracles.add(firstOracle);

        /**
         * For keeping track of the violations
         * For more information see:
         * Liang Huang, Suphan Fayong and Yang Guo. "Structured perceptron with inexact search."
         * In Proceedings of the 2012 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies,
         * pp. 142-151. Association for Computational Linguistics, 2012.
         */
        float maxViol = Float.NEGATIVE_INFINITY;
        Pair<Configuration, Configuration> maxViolPair = null;

        Configuration bestScoringOracle = null;
        boolean oracleInBeam = false;

        while (!ArcEager.isTerminal(beam) && beam.size() > 0)
        {
            /**
             *  generating new oracles
             *  it keeps the oracles which are in the terminal state
             */
            Collection<Configuration> newOracles = new HashSet<Configuration>();

            if (options.useDynamicOracle || isPartial)
            {
                bestScoringOracle = zeroCostDynamicOracle(instance, oracles, newOracles);
            }
            else
            {
                bestScoringOracle = staticOracle(instance, oracles, newOracles);
            }
            // try explore non-optimal transitions

            if (newOracles.size() == 0)
            {
//                System.err.println("...no oracle(" + dataCount + ")...");
                bestScoringOracle = staticOracle(instance, oracles, newOracles);
            }
            oracles = newOracles;

            TreeSet<BeamElement> beamPreserver = new TreeSet<BeamElement>();

            if (options.numOfThreads == 1 || beam.size() == 1)
            {
                beamSortOneThread(beam, beamPreserver);
            }
            else
            {
                for (int b = 0; b < beam.size(); b++)
                {
                    pool.submit(new BeamScorerThread(false, classifier, beam.get(b),
                                                     dependencyRelations, featureLength, b, options.rootFirst));
                }
                for (int b = 0; b < beam.size(); b++)
                {
                    for (BeamElement element : pool.take().get())
                    {
                        beamPreserver.add(element);
                        if (beamPreserver.size() > options.beamWidth)
                            beamPreserver.pollFirst();
                    }
                }
            }

            if (beamPreserver.size() == 0 || beam.size() == 0)
            {
                break;
            }
            else
            {
                oracleInBeam = false;

                ArrayList<Configuration> repBeam = new ArrayList<Configuration>(options.beamWidth);
                for (BeamElement beamElement : beamPreserver.descendingSet())
                {
//                    if (repBeam.size() >= options.beamWidth) // 只要beamWidth个configuration（这句是多余的）
//                        break;
                    int b = beamElement.index;
                    int action = beamElement.action;
                    int label = beamElement.label;
                    float score = beamElement.score;

                    Configuration newConfig = beam.get(b).clone();

                    ArcEager.commitAction(action, label, score, dependencyRelations, newConfig);
                    repBeam.add(newConfig);

                    if (!oracleInBeam && oracles.contains(newConfig))
                        oracleInBeam = true;
                }
                beam = repBeam;

                if (beam.size() > 0 && oracles.size() > 0)
                {
                    Configuration bestConfig = beam.get(0);
                    if (oracles.contains(bestConfig)) // 模型认为的最大分值configuration是zero cost
                    {
                        oracles = new HashSet<Configuration>();
                        oracles.add(bestConfig);
                    }
                    else // 否则
                    {
                        if (options.useRandomOracleSelection) // 随机选择一个 oracle
                        { // choosing randomly, otherwise using latent structured Perceptron
                            List<Configuration> keys = new ArrayList<Configuration>(oracles);
                            Configuration randomKey = keys.get(randGen.nextInt(keys.size()));
                            oracles = new HashSet<Configuration>();
                            oracles.add(randomKey);
                            bestScoringOracle = randomKey;
                        }
                        else // 选择 oracle中被模型认为分值最大的那个
                        {
                            oracles = new HashSet<Configuration>();
                            oracles.add(bestScoringOracle);
                        }
                    }

                    // do early update
                    if (!oracleInBeam && updateMode.equals("early"))
                        break;

                    // keep violations
                    if (!oracleInBeam && updateMode.equals("max_violation"))
                    {
                        float violation = bestConfig.getScore(true) - bestScoringOracle.getScore(true);//Math.abs(beam.get(0).getScore(true) - bestScoringOracle.getScore(true));
                        if (violation > maxViol)
                        {
                            maxViol = violation;
                            maxViolPair = new Pair<Configuration, Configuration>(bestConfig, bestScoringOracle);
                        }
                    }
                }
                else
                    break;
            }
        }

        // updating weights
        if (!oracleInBeam ||
                !bestScoringOracle.equals(beam.get(0)) // 虽然oracle在beam里面，但在最后时刻，它的得分不是最高
                )
        {
            updateWeights(initialConfiguration, maxViol, isPartial, bestScoringOracle, maxViolPair, beam);
        }
    }
601308
private static void updateSoftEvidenceAuxiliaryNodeCPT(
            ProbabilisticNetwork bn, String targetNodeName,
            HashMap<String, Double> softEvidence) throws ShanksException {

        ProbabilisticNode targetNode = (ProbabilisticNode) bn
                .getNode(targetNodeName);
        ProbabilisticNode auxNode = (ProbabilisticNode) bn
                .getNode(softEvidenceNodePrefix + targetNodeName);

        // Check if new beliefs join 1
        double total = 0;
        for (Entry<String, Double> entry : softEvidence.entrySet()) {
            total += entry.getValue();
        }
        double aux = 1 - total;
        if (aux < (-0.05) || aux > 0.05) {
            throw new ShanksException(
                    "Impossible to set soft-evidence in node: "
                            + targetNode.getName()
                            + " Target probabilistic distribution is not consistent. All states joint: "
                            + total);
        }

        // Check if believes are consistent
        if (targetNode.getStatesSize() != softEvidence.size()) {
            throw new ShanksException(
                    "Old belief and new belief are incompatible. Different number of states of hypothesis");
        }

        for (String status : softEvidence.keySet()) {
            boolean found = false;
            for (int i = 0; i < targetNode.getStatesSize(); i++) {
                if (targetNode.getStateAt(i).equals(status)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new ShanksException(
                        "Not valid Belief, exist unconsistent between current and old believes.");
            }
        }

        // Now, when the consistent has been checked
        // Update the belief

        // Reset evidence.
        ShanksAgentBayesianReasoningCapability.clearEvidence(bn, auxNode);

        // Obtain required data
        double[] currentProbabilities = new double[targetNode.getStatesSize()];
        double[] newProbabilities = new double[targetNode.getStatesSize()];
        for (int i = 0; i < targetNode.getStatesSize(); i++) {
            for (String status : softEvidence.keySet()) {
                if (targetNode.getStateAt(i).equals(status)) {
                    currentProbabilities[i] = targetNode.getMarginalAt(i);
                    newProbabilities[i] = softEvidence.get(status);
                }
            }
        }

        // Build the new CPT
        double auxNumber = new Float(0.1);
        double[] cptProbabilitiesPrime = new double[currentProbabilities.length];
        for (int i = 0; i < currentProbabilities.length; i++) {
            cptProbabilitiesPrime[i] = 0.5;
            if (currentProbabilities[i] != 0.0) {
                cptProbabilitiesPrime[i] = newProbabilities[i] * auxNumber
                        / currentProbabilities[i];
            } else if (newProbabilities[i] != 0.0) {
                // If there is a full confidence (i.e. 0.0 probability, you must
                // not request a belief
                // It is impossible that a change in a full confidence (100% or
                // 0%)
                // If this occurs, the BN is wrong fixed (CPT's are wrong)
                throw new ShanksException(
                        "Incoherence! Belief does not update. Probability for status: "
                                + targetNodeName + " is ficked as evidence!!");
            }
            if (cptProbabilitiesPrime[i] > 1) {
                // In this case, reduce auxNumber and rebuild CPT probabilities.
                auxNumber = auxNumber / 2;
                i = -1;
            }
        }

        // Update the CPT and the Inference Engine
        PotentialTable cpt = auxNode.getProbabilityFunction();
        for (int i = 0; i < cptProbabilitiesPrime.length; i++) {
            cpt.setValue(2 * i, (float) cptProbabilitiesPrime[i]);
            cpt.setValue(1 + (2 * i), (float) (1 - cptProbabilitiesPrime[i]));
        }

        // Compiling new network
        Map<String, String> currentEvidences = ShanksAgentBayesianReasoningCapability
                .getEvidences(bn);
        ShanksAgentBayesianReasoningCapability.clearEvidences(bn);
        ShanksAgentBayesianReasoningCapability.addEvidences(bn,
                currentEvidences);

        // Testing CPT

        ShanksAgentBayesianReasoningCapability.addEvidence(bn,
                softEvidenceNodePrefix + targetNodeName, triggerState);
        double conf = ShanksAgentBayesianReasoningCapability.getHypothesis(bn,
                softEvidenceNodePrefix + targetNodeName, triggerState);
        if (Math.abs(conf - 1) > 0.01) {
            throw new ShanksException(
                    "Error adding finding to soft-evidence node for node: "
                            + targetNodeName
                            + " It should be equals to 1, but it is: " + conf);
        }
        ShanksAgentBayesianReasoningCapability.clearEvidence(bn, auxNode);
    }
315222
function() {
      var input_depth = this.data[0].w.length;
      var num_classes = this.unique_labels.length;

      // sample network topology and hyperparameters
      var layer_defs = [];
      layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth: input_depth});
      var nl = weightedSample([0,1,2,3], [0.2, 0.3, 0.3, 0.2]); // prefer nets with 1,2 hidden layers
      for(var q=0;q<nl;q++) {
        var ni = randi(this.neurons_min, this.neurons_max);
        var act = ['tanh','maxout','relu'][randi(0,3)];
        if(randf(0,1)<0.5) {
          var dp = Math.random();
          layer_defs.push({type:'fc', num_neurons: ni, activation: act, drop_prob: dp});
        } else {
          layer_defs.push({type:'fc', num_neurons: ni, activation: act});
        }
      }
      layer_defs.push({type:'softmax', num_classes: num_classes});
      var net = new Net();
      net.makeLayers(layer_defs);

      // sample training hyperparameters
      var bs = randi(this.batch_size_min, this.batch_size_max); // batch size
      var l2 = Math.pow(10, randf(this.l2_decay_min, this.l2_decay_max)); // l2 weight decay
      var lr = Math.pow(10, randf(this.learning_rate_min, this.learning_rate_max)); // learning rate
      var mom = randf(this.momentum_min, this.momentum_max); // momentum. Lets just use 0.9, works okay usually ;p
      var tp = randf(0,1); // trainer type
      var trainer_def;
      if(tp<0.33) {
        trainer_def = {method:'adadelta', batch_size:bs, l2_decay:l2};
      } else if(tp<0.66) {
        trainer_def = {method:'adagrad', learning_rate: lr, batch_size:bs, l2_decay:l2};
      } else {
        trainer_def = {method:'sgd', learning_rate: lr, momentum: mom, batch_size:bs, l2_decay:l2};
      }
      
      var trainer = new Trainer(net, trainer_def);

      var cand = {};
      cand.acc = [];
      cand.accv = 0; // this will maintained as sum(acc) for convenience
      cand.layer_defs = layer_defs;
      cand.trainer_def = trainer_def;
      cand.net = net;
      cand.trainer = trainer;
      return cand;
    }
981932
def train(num_training_iterations, report_interval,
          reduce_learning_rate_interval):
  """"""

  # Build the computation graph.
  graph_tensors, dataset_train = build_graph(
      lstm_depth=FLAGS.lstm_depth, batch_size=FLAGS.batch_size,
      num_embedding=FLAGS.num_embedding, num_hidden=FLAGS.num_hidden,
      truncation_length=FLAGS.truncation_length,
      sample_length=FLAGS.sample_length, max_grad_norm=FLAGS.max_grad_norm,
      initial_learning_rate=FLAGS.learning_rate,
      reduce_learning_rate_multiplier=FLAGS.reduce_learning_rate_multiplier,
      optimizer_epsilon=FLAGS.optimizer_epsilon)

  # Configure a checkpoint saver.
  saver_hook = _configure_saver(FLAGS.checkpoint_dir,
                                FLAGS.checkpoint_interval)

  # Train the network.
  with tf.train.SingularMonitoredSession(
      hooks=[saver_hook], checkpoint_dir=FLAGS.checkpoint_dir) as sess:

    start_iteration = sess.run(graph_tensors["global_step"])

    for train_iteration in range(start_iteration, num_training_iterations):
      if (train_iteration + 1) % report_interval == 0:
        train_loss_v, valid_loss_v, _ = sess.run(
            (graph_tensors["train_loss"],
             graph_tensors["valid_loss"],
             graph_tensors["train_step"]))

        train_generated_string_v = sess.run(
            graph_tensors["train_generated_string"])

        train_generated_string_human = dataset_train.to_human_readable(
            (train_generated_string_v, 0), indices=[0])

        tf.logging.info("%d: Training loss %f. Validation loss %f. Sample = %s",
                        train_iteration,
                        train_loss_v,
                        valid_loss_v,
                        train_generated_string_human)
      else:
        train_loss_v, _ = sess.run((graph_tensors["train_loss"],
                                    graph_tensors["train_step"]))
        tf.logging.info("%d: Training loss %f.", train_iteration, train_loss_v)

      if (train_iteration + 1) % reduce_learning_rate_interval == 0:
        sess.run(graph_tensors["reduce_learning_rate"])
        tf.logging.info("Reducing learning rate.")

    test_loss = sess.run(graph_tensors["test_loss"])
    tf.logging.info("Test loss %f", test_loss)
816986
@Override
    public void trainOnInstanceImpl(Instance instance) {

        if (m_weights == null) {
            m_weights = new double[instance.numAttributes() + 1];
        }
        if (!instance.classIsMissing()) {

            double learningRate = 1.0 / (m_lambda * m_t);
            //double scale = 1.0 - learningRate * m_lambda;
            double scale = 1.0 - 1.0 / m_t;
            double y = (instance.classValue() == 0) ? -1 : 1;
            double wx = dotProd(instance, m_weights, instance.classIndex());
            double z = y * (wx + m_weights[m_weights.length - 1]);

            for (int j = 0; j < m_weights.length - 1; j++) {
                if (j != instance.classIndex()) {
                    m_weights[j] *= scale;
                }
            }

            if (m_loss == LOGLOSS || (z < 1)) {
                double loss = dloss(z);
                int n1 = instance.numValues();
                for (int p1 = 0; p1 < n1; p1++) {
                    int indS = instance.index(p1);
                    if (indS != instance.classIndex() && !instance.isMissingSparse(p1)) {
                        double m = learningRate * loss * (instance.valueSparse(p1) * y);
                        m_weights[indS] += m;
                    }
                }

                // update the bias
                m_weights[m_weights.length - 1] += learningRate * loss * y;
            }

            double norm = 0;
            for (int k = 0; k < m_weights.length - 1; k++) {
                if (k != instance.classIndex()) {
                    norm += (m_weights[k] * m_weights[k]);
                }
            }

            double scale2 = Math.min(1.0, (1.0 / (m_lambda * norm)));
            if (scale2 < 1.0) {
                scale2 = Math.sqrt(scale2);
                for (int j = 0; j < m_weights.length - 1; j++) {
                    if (j != instance.classIndex()) {
                        m_weights[j] *= scale2;
                    }
                }
            }
            m_t++;
        }
    }
862174
def initialize(
            self, M_c, M_r, T, seed, initialization=b'from_the_prior',
            row_initialization=-1, n_chains=1,
            ROW_CRP_ALPHA_GRID=(), COLUMN_CRP_ALPHA_GRID=(),
            S_GRID=(), MU_GRID=(), N_GRID=31,):
        
        # FIXME: why is M_r passed?
        arg_tuples = self.get_initialize_arg_tuples(
            M_c, M_r, T, initialization, row_initialization, n_chains,
            ROW_CRP_ALPHA_GRID, COLUMN_CRP_ALPHA_GRID, S_GRID, MU_GRID, N_GRID,
            make_get_next_seed(seed),)

        chain_tuples = self.mapper(self.do_initialize, arg_tuples)
        X_L_list, X_D_list = zip(*chain_tuples)
        if n_chains == 1:
            X_L_list, X_D_list = X_L_list[0], X_D_list[0]

        return X_L_list, X_D_list
397535
private void forwardSendMessage(int edge, int iter) {      
        // Update the residual
        double oldResidual = residuals[edge];
        residuals[edge] = smartResidual(msgs[edge], newMsgs[edge], edge);
        if (oldResidual > prm.convergenceThreshold && residuals[edge] <= prm.convergenceThreshold) {
            // This message has (newly) converged.
            numConverged ++;
        }
        if (oldResidual <= prm.convergenceThreshold && residuals[edge] > prm.convergenceThreshold) {
            // This message was marked as converged, but is no longer converged.
            numConverged--;
        }
        
        // Check for oscillation. Did the argmax change?
        if (log.isTraceEnabled() && iter > 0) {
            if (msgs[edge].getArgmaxConfigId() != newMsgs[edge].getArgmaxConfigId()) {    
                oscillationCount.incrementAndGet();
            }
            sendCount.incrementAndGet();
            log.trace("Residual: {} {}", fg.edgeToString(edge), residuals[edge]);
        }

        // Update the cached belief.
        int child = bg.childE(edge);
        if (!bg.isT1T2(edge) && bg.numNbsT1(child) >= prm.minVarNbsForCache) {
            varBeliefs[child].elemDivBP(msgs[edge]);
            varBeliefs[child].elemMultiply(newMsgs[edge]); 
            assert !varBeliefs[child].containsBadValues() : "varBeliefs[child] = " + varBeliefs[child];
        } else if (bg.isT1T2(edge) && bg.numNbsT2(child) >= prm.minFacNbsForCache){
            Factor f = bg.t2E(edge);
            if (! (f instanceof GlobalFactor)) {
                facBeliefs[child].divBP(msgs[edge]);
                facBeliefs[child].prod(newMsgs[edge]);
                assert !facBeliefs[child].containsBadValues() : "facBeliefs[child] = " + facBeliefs[child];
            }
        }
        
        // Send message: Just swap the pointers to the current message and the new message, so
        // that we don't have to create a new factor object.
        VarTensor oldMessage = msgs[edge];
        msgs[edge] = newMsgs[edge];
        newMsgs[edge] = oldMessage;
        assert !msgs[edge].containsBadValues() : "msgs[edge] = " + msgs[edge];
                
        if (log.isTraceEnabled()) {
            log.trace("Message sent: {} {}", fg.edgeToString(edge), msgs[edge]);
        }
    }
826036
@Override
	public void trainOnInstanceImpl(Instance inst)
	{
		//Initialize
		if(this.reset)
		{
			this.numAttributes = inst.numAttributes()-1;
			this.initializeNetwork();
		}
		
		this.backpropagation(inst);		
	}
141538
private void propagate(Layer lower, Layer upper) {
        for (int i = 0; i < upper.units; i++) {
            double sum = 0.0;
            for (int j = 0; j <= lower.units; j++) {
                sum += upper.weight[i][j] * lower.output[j];
            }

            if (upper != outputLayer || activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                upper.output[i] = Math.logistic(sum);
            } else {
                if (activationFunction == ActivationFunction.LINEAR || activationFunction == ActivationFunction.SOFTMAX) {
                    upper.output[i] = sum;
                } else {
                    throw new UnsupportedOperationException("Unsupported activation function.");
                }
            }
        }

        if (upper == outputLayer && activationFunction == ActivationFunction.SOFTMAX) {
            softmax();
        }
    }
694469
def forward(self, sequence):
        
        data = self.input_block(sequence)

        for idx in range(len(self.rnn_layers)):
            data, _ = self.rnn_layers[idx](data)

            if self.rnn_dropout_layers:
                data = self.rnn_dropout_layers[idx](data)

        # We are interested only in the last element of the sequence
        if self.bidirectional:
            last_hidden_size = self.rnn_layers_sizes[-1]
            data = torch.cat([data[:, -1, :last_hidden_size], data[:, 0, last_hidden_size:]], dim=1)
        else:
            data = data[:, -1]

        for idx in range(len(self.linear_layers_sizes)):
            data = F.relu(self.linear_layers[idx](data))

            if self.linear_dropout_layers:
                data = self.linear_dropout_layers[idx](data)

        data = self.output_layer(data)

        return self.output_activation(data)
471231
@Override
  public final double[] score0(double[] dataRow, double offset, double[] preds) {
    assert(dataRow != null) : "doubles are null"; // check to make sure data is not null
    double[] neuronsInput = new double[_units[0]]; // store inputs into the neural network
    double[] neuronsOutput;  // save output from a neural network layer

    // transform inputs: NAs in categoricals are always set to new extra level.
    setInput(dataRow, neuronsInput, _numsA, _catsA, _nums, _cats, _catoffsets, _normmul, _normsub, _use_all_factor_levels, true);

    // proprogate inputs through neural network
    for (int layer=0; layer < _numLayers; layer++) {
      NeuralNetwork oneLayer = new NeuralNetwork(_allActivations[layer], _all_drop_out_ratios[layer],
              _weightsAndBias[layer], neuronsInput, _units[layer + 1]);
      neuronsOutput = oneLayer.fprop1Layer();
      neuronsInput = neuronsOutput;
    }
    if (!this.isAutoEncoder())
      assert (_nclasses == neuronsInput.length) : "nclasses " + _nclasses + " neuronsOutput.length " + neuronsInput.length;
    // Correction for classification or standardize outputs
    return modifyOutputs(neuronsInput, preds, dataRow);
  }