> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# extract_node_degree

> Calculate network node degrees. 

Calculates the [degree centrality](https://en.wikipedia.org/wiki/Degree_\(graph_theory\))
of each node in the network, i.e. the number of each node's incoming and/or outgoing connections.

## Usage

The following example shows how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      E.g. in a network of twitter accounts, where a directed link between nodes A and B indicates the number of times A has retweeted B, the following calculates the total number of retweets each account has received: Since in the example network links A→B and B→A can be different, we indicate that we want to interpret the network as *directed*. And since each link's weight is the number of retweets, we pass the retweets weight as the weights column. Keep in mind that both columns contain lists of numbers for each row.

      ```stan theme={null}
      extract_node_degree(ds.targets, ds.retweets, {
        "mode": "in",
        "loops": false,
        "directed": true
      }) -> (ds.keywords)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      extract_node_degree(targets: list[number], *weights: list[number], {
          "param": value,
          ...
      }) -> (degree: number)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="targets" type="column[list[number]]" required>
    A column containing link targets. Source is implied in the index.
  </ParamField>

  <ParamField path="*weights" type="column[list[number]]">
    An optional column containing link weights.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="degree" type="column[number]" required>
    Column containing the number of incoming, outgoing or all connections for each row/node in the dataset.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="mode" type="string" default="all">
    Which node connections to count.
    Whether to

    * `in`: count only a node's incoming links
    * `out`: count only a node's outgoing links
    * `all`/`both` count both incoming and outgoing links.

    Values must be one of the following:

    * `all`
    * `out`
    * `in`
    * `both`
  </ParamField>

  <ParamField path="directed" type="boolean" default="false">
    Whether the links are directed or not.
  </ParamField>

  <ParamField path="loops" type="boolean">
    Whether loops will be counted.
    Loops are links of nodes to themselves.
  </ParamField>
</Accordion>
