The |Transition| for the prevention example from Actual Causation
    Figure 5D.
554360
def prevention():
    
    tpm = np.array([
        [0.5, 0.5, 1],
        [0.5, 0.5, 0],
        [0.5, 0.5, 1],
        [0.5, 0.5, 1],
        [0.5, 0.5, 1],
        [0.5, 0.5, 0],
        [0.5, 0.5, 1],
        [0.5, 0.5, 1]
    ])
    cm = np.array([
        [0, 0, 1],
        [0, 0, 1],
        [0, 0, 0]
    ])
    network = Network(tpm, cm, node_labels=['A', 'B', 'F'])
    x_state = (1, 1, 1)
    y_state = (1, 1, 1)

    return Transition(network, x_state, y_state, (0, 1), (2,))
472896
def scenario(args):
    
    p = OptionParser(__doc__)
    opts, args = p.parse_args()

    fig = plt.figure(1, (5, 5))
    root = fig.add_axes([0, 0, 1, 1])

    root.set_xlim(0, 1)
    root.set_ylim(0, 1)
    root.set_axis_off()

    # Layout format: (x, y, label, (chr lengths))
    anc = (.5, .9, "Ancestor", (1,))
    s1 = (.2, .6, "Genome I", (1,))
    s2 = (.5, .6, "Genome II", (1,))
    s3 = (.8, .6, "Genome III", (1,))
    tetra = (.35, .4, "Tetraploid I / II", (.5, .9))
    hexa = (.5, .1, "Hexaploid I / II / III", (.36, .46, .9))
    labels = (anc, s1, s2, s3, tetra, hexa)
    connections = ((anc, s1), (anc, s2), (anc, s3),\
            (s1, tetra), (s2, tetra),
            (tetra, hexa), (s3, hexa))

    xinterval = .02
    yratio = .05
    for xx, yy, label, chrl in labels:
        #RoundLabel(root, xx, yy, label)
        root.text(xx, yy, label, ha="center", va="center")
        offset = len(label) * .012
        for i, c in enumerate(chrl):
            ya = yy + yratio * c
            yb = yy - yratio * c
            Chromosome(root, xx - offset + i * xinterval, ya, yb, width=.01)

    # Comments
    comments = ((.15, .33, "II dominant"),
                (.25, .03, "III dominant"))

    for xx, yy, c in comments:
        root.text(xx, yy, c, size=9, ha="center", va="center")

    # Branches
    tip = .04
    for a, b in connections:
        xa, ya, la, chra = a
        xb, yb, lb, chrb = b
        plt.plot((xa, xb), (ya - tip, yb + 2 * tip), 'k-', lw=2, alpha=.5)

    figname = fname() + ".pdf"
    savefig(figname, dpi=300)
885499
def demo(args):
    
    p = OptionParser(demo.__doc__)
    opts, args = p.parse_args(args)

    fig = plt.figure(1, (8, 5))
    root = fig.add_axes([0, 0, 1, 1])

    panel_space = .23
    dup_space = .025
    # Draw a gene and two regulatory elements at these arbitrary locations
    locs = [(.5, .9), # ancestral gene
            (.5, .9 - panel_space + dup_space), # identical copies
            (.5, .9 - panel_space - dup_space),
            (.5, .9 - 2 * panel_space + dup_space), # degenerate copies
            (.5, .9 - 2 * panel_space - dup_space),
            (.2, .9 - 3 * panel_space + dup_space), # sub-functionalization
            (.2, .9 - 3 * panel_space - dup_space),
            (.5, .9 - 3 * panel_space + dup_space), # neo-functionalization
            (.5, .9 - 3 * panel_space - dup_space),
            (.8, .9 - 3 * panel_space + dup_space), # non-functionalization
            (.8, .9 - 3 * panel_space - dup_space),
            ]

    default_regulator = "gm"
    regulators = [default_regulator,
            default_regulator, default_regulator,
            "wm", default_regulator,
            "wm", "gw",
            "wb", default_regulator,
            "ww", default_regulator,
            ]

    width = .24
    for i, (xx, yy) in enumerate(locs):
        regulator = regulators[i]
        x1, x2 = xx - .5 * width, xx + .5 * width
        Glyph(root, x1, x2, yy)
        if i == 9:  # upper copy for non-functionalization
            continue

        # coding region
        x1, x2 = xx - .16 * width, xx + .45 * width
        Glyph(root, x1, x2, yy, fc="k")

        # two regulatory elements
        x1, x2 = xx - .4 * width, xx - .28 * width
        for xx, fc in zip((x1, x2), regulator):
            if fc == 'w':
                continue

            DoubleCircle(root, xx, yy, fc=fc)

        rotation = 30
        tip = .02
        if i == 0:
            ya = yy + tip
            root.text(x1, ya, "Flower", rotation=rotation, va="bottom")
            root.text(x2, ya, "Root", rotation=rotation, va="bottom")
        elif i == 7:
            ya = yy + tip
            root.text(x2, ya, "Leaf", rotation=rotation, va="bottom")

    # Draw arrows between panels (center)
    arrow_dist = .08
    ar_xpos = .5
    for ar_ypos in (.3, .53, .76):
        root.annotate(" ", (ar_xpos, ar_ypos),
                (ar_xpos, ar_ypos + arrow_dist),
                arrowprops=arrowprops)

    ar_ypos = .3
    for ar_xpos in (.2, .8):
        root.annotate(" ", (ar_xpos, ar_ypos),
                (.5, ar_ypos + arrow_dist),
                arrowprops=arrowprops)

    # Duplication, Degeneration
    xx = .6
    ys = (.76, .53)
    processes = ("Duplication", "Degeneration")
    for yy, process in zip(ys, processes):
        root.text(xx, yy + .02, process, fontweight="bold")

    # Label of fates
    xs = (.2, .5, .8)
    fates = ("Subfunctionalization", "Neofunctionalization",
            "Nonfunctionalization")
    yy = .05
    for xx, fate in zip(xs, fates):
        RoundLabel(root, xx, yy, fate)

    root.set_xlim(0, 1)
    root.set_ylim(0, 1)
    root.set_axis_off()

    figname = "demo.pdf"
    savefig(figname, dpi=300)
281221
def add_transition(self, output,
                       probability_func=lambda index: np.ones(len(index), dtype=float),
                       triggered=Trigger.NOT_TRIGGERED):
        
        t = Transition(self, output, probability_func=probability_func, triggered=triggered)
        self.transition_set.append(t)
        return t
454582
private List<Transition> getIncomingTransitions(Process procdef, Long activityId,
            Map<String,String> idToEscapedName) {
        List<Transition> incomingTransitions = new ArrayList<Transition>();
        for (Transition trans : procdef.getTransitions()) {
            if (trans.getToId().equals(activityId)) {
                Transition sync = new Transition();
                sync.setId(trans.getId());
                Activity act = procdef.getActivityVO(trans.getFromId());
                String logicalId = act.getLogicalId();
                // id to escaped name map is for backward compatibility
                idToEscapedName.put(logicalId, escape(act.getName()));
                sync.setCompletionCode(logicalId);
                incomingTransitions.add(sync);
            }
        }
        return incomingTransitions;
    }
88154
protected void createAcceptableUsagePolicyView(final Flow flow) {
        val viewState = createViewState(flow, VIEW_ID_ACCEPTABLE_USAGE_POLICY_VIEW, "casAcceptableUsagePolicyView");
        createTransitionForState(viewState, CasWebflowConstants.TRANSITION_ID_SUBMIT, AUP_ACCEPTED_ACTION);
    }
145326
function Diagram() {
        ExtensibleModel.apply(this, arguments);

        /** @member {boolean} */
        this.visible = true;

        /** @member {boolean} */
        this.defaultDiagram = false;

        /** @member {Array.<View>} */
        this.ownedViews = [];

        /** @member {Array.<View>} */
        this.selectedViews = [];
    }
1186218
function(mapping, notYetSubstitutedFact, causedBy, graphs) {
        var subject, predicate, object, substitutedFact;
        if (mapping == {}) {
            return notYetSubstitutedFact;
        }
        subject = this.substituteElementVariablesWithMapping(notYetSubstitutedFact.subject, mapping);
        predicate = this.substituteElementVariablesWithMapping(notYetSubstitutedFact.predicate, mapping);
        object = this.substituteElementVariablesWithMapping(notYetSubstitutedFact.object, mapping);        

        substitutedFact = new Fact(predicate, subject, object, [], false);

        if (causedBy) {
            substitutedFact.causedBy = causedBy;
            substitutedFact.explicit = false;
        }

        if (graphs) {
            substitutedFact.graphs = graphs;
        }

        return substitutedFact;
    }
427607
def sample_forward_transitions(self, batch_size, batch_info,
                                   forward_steps: int, discount_factor: float) -> Transitions:
        
        probs, indexes, tree_idxs = self.backend.sample_batch_transitions(batch_size, forward_steps)

        return self._get_transitions(
            probs, indexes, tree_idxs, batch_info
        )
1111363
def _significant_pathways_dataframe(pvalue_information,
                                    side_information,
                                    alpha):
    
    significant_pathways = pd.concat(
        [pvalue_information, side_information], axis=1)
    # fdr_bh: false discovery rate, Benjamini & Hochberg (1995, 2000)
    below_alpha, qvalues, _, _ = multipletests(
        significant_pathways["p-value"], alpha=alpha, method="fdr_bh")
    below_alpha = pd.Series(
        below_alpha, index=pvalue_information.index, name="pass")
    qvalues = pd.Series(
        qvalues, index=pvalue_information.index, name="q-value")
    significant_pathways = pd.concat(
        [significant_pathways, below_alpha, qvalues], axis=1)
    significant_pathways = significant_pathways[significant_pathways["pass"]]
    significant_pathways.drop("pass", axis=1, inplace=True)
    significant_pathways.loc[:, "pathway"] = significant_pathways.index
    return significant_pathways
944542
def transition(self, duration, brightness=None, temperature=None):
        
        # Transition immediately if duration is zero.
        if duration == 0:
            if brightness is not None:
                self.brightness = brightness
            if temperature is not None:
                self.temperature = temperature
            return
        if brightness != self.brightness or temperature != self.temperature:
            self._transition(duration, brightness, temperature)
1025593
def transitions_for(self, roles=None, actor=None, anchors=[]):
        
        proxy = self.obj.access_for(roles, actor, anchors)
        return {name: transition for name, transition in self.transitions(current=False).items()
            if name in proxy}
174907
def transition_state(state)
      authorize @contribution
      @initiative = @contribution.initiative
      @user = @contribution.user
      state = state.to_sym
      transition = @contribution.transition_by_state(state)
      initial_state = @contribution.state_name
      resource_name = @contribution.class.model_name.human
      if @contribution.send("can_#{transition}?")
        begin
          if @contribution.state_on_gateway != state
            if @contribution.update_state_on_gateway!(state)
              @contribution.send("#{transition}!")
            else
              flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
            end
          else
            @contribution.send("#{transition}!")
          end
        rescue
          flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
        end
      else
        flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
      end
      if flash[:alert].present?
        render 'initiatives/contributions/show'
      else
        if initial_state == :pending
          flash[:notice] = t('flash.actions.create.notice', resource_name: resource_name)
        else
          flash[:notice] = t('flash.actions.update.notice', resource_name: resource_name)
        end
        redirect_to initiative_contribution_path(@contribution.initiative.id, @contribution)
      end
    end
259080
def find_actual_effect(self, mechanism, purviews=False):
        """"""
        return self.find_causal_link(Direction.EFFECT, mechanism, purviews)
100695
def dotransition(accountable, transition_id):
    
    t = accountable.issue_do_transition(transition_id)
    if t.status_code == 204:
        click.secho(
            'Successfully transitioned {}'.format(accountable.issue_key),
            fg='green'
        )
1324873
def sample_batch_transitions(self, batch_size, forward_steps=1):
        
        batches = [
            self._sample_batch_prioritized(
                segment_tree, batch_size, self.deque.frame_history, forward_steps=forward_steps
            )
            for segment_tree in self.segment_trees
        ]

        probs, idxs, tree_idxs = zip(*batches)

        return np.stack(probs, axis=1).astype(float), np.stack(idxs, axis=1), np.stack(tree_idxs, axis=1)
1256655
def _transition(self, nxt, cur=None, since=None):
        '''
        
        '''
        self.transition_intervals[(cur, nxt)].tick()
        if since:
            self.state_durations[cur].end(since)