Skip to content

[2/6] Integrate adjust_influence into calculate_influence#6

Open
alexanderbates wants to merge 2 commits into
DrugowitschLab:mainfrom
alexanderbates:pr2-integrate-adjust-influence
Open

[2/6] Integrate adjust_influence into calculate_influence#6
alexanderbates wants to merge 2 commits into
DrugowitschLab:mainfrom
alexanderbates:pr2-integrate-adjust-influence

Conversation

@alexanderbates
Copy link
Copy Markdown

Integrate adjust_influence into calculate_influence

calculate_influence now returns both the raw influence column and the
three log-compressed adjusted_influence columns by default. Users can
compare adjusted vs unadjusted scores from a single call rather than
having to import adjust_influence and post-process the output
themselves; opt out with adjust=False.

The log compression is parameterised via two new kwargs on
calculate_influence: adjust_const (the exp(-c) junk-node floor /+c
shift, default 24) and adjust_signif (rounding, default 6).

adjust_influence is added as a module-level function so advanced
workflows can still post-process aggregated DataFrames (e.g. summing
per-(target_class, seed_class) across multiple seeds before log
compression in a worked example). Its output is three columns:

  • adjusted_influence = sign(x) * (log(max(|x|, exp(-const))) + const)
  • adjusted_influence_norm_by_targets (divides by n_targets per group)
  • adjusted_influence_norm_by_sources_and_targets (divides by
    n_sources * n_targets per group)

The function dispatches on the presence of 'target' and 'seed' columns:
when present it groups and sums per (target, seed); when absent it
treats each row as its own group, which is the case for the DataFrame
calculate_influence builds. Sign is preserved, so signed-mode input
yields signed-mode output.

…as kwargs

Replaces the hardcoded NEG_NEUROTRANSMITTERS module constant with two
explicit constructor arguments so that the library no longer pre-empts
the user's neurotransmitter sign assignment:

- inhibitory_nts: pre-neuron top_nt values to negate when signed=True
  (required when signed=True; raises ValueError otherwise).
- excluded_nts: pre-neuron top_nt values to drop entirely from W,
  independent of signed=True/False. Useful for transmitter classes
  whose net sign at a given target depends on the receptor mix and so
  cannot be assigned a single sign safely.

Adds lambda_max as a constructor argument (default 0.99 for backwards
compatibility). _normalize_W now always rescales to lambda_max exactly
rather than only capping when the natural eigenvalue exceeds it, so the
parameter is a true control knob over leading-mode amplification rather
than just a stability ceiling. The amplification of the leading mode in
(I - W_rescaled)^-1 is 1 / (1 - lambda_max), so 0.99 gives ~100x and
0.5 gives ~2x.

Surfaces syn_weight_measure ('count' or 'norm') as a constructor
argument and changes the default from 'norm' to 'count'. Fixes a
pre-existing bug in _create_sparse_W: the signed=True path negated the
'count' column unconditionally, but the matrix was populated from the
column named by syn_weight_measure (default 'norm'), so the signed flag
silently produced the same matrix as signed=False. The negation now
applies to the column actually consumed. An inline comment notes that
flipping signs on 'norm' breaks the column-sums-to-1 interpretation, so
'count' is the more natural choice in signed mode.

Sign preservation: _build_influence_dataframe now keeps the real part
of the steady-state vector in signed mode rather than always taking the
magnitude, so net-inhibited targets carry a negative score.

Validates lambda_max in (0, 1) and syn_weight_measure in {'count',
'norm'}. When signed=True or excluded_nts is set, the SQLite meta
table must include a 'top_nt' column or _create_sparse_W raises.
calculate_influence now returns both the raw influence column and the
three log-compressed adjusted_influence columns by default.  Users can
compare adjusted vs unadjusted scores from a single call rather than
having to import adjust_influence and post-process the output
themselves; opt out with adjust=False.

The log compression is parameterised via two new kwargs on
calculate_influence: adjust_const (the exp(-c) junk-node floor /+c
shift, default 24) and adjust_signif (rounding, default 6).

adjust_influence is added as a module-level function so advanced
workflows can still post-process aggregated DataFrames (e.g. summing
per-(target_class, seed_class) across multiple seeds before log
compression in a worked example).  Its output is three columns:

- adjusted_influence = sign(x) * (log(max(|x|, exp(-const))) + const)
- adjusted_influence_norm_by_targets (divides by n_targets per group)
- adjusted_influence_norm_by_sources_and_targets (divides by
  n_sources * n_targets per group)

The function dispatches on the presence of 'target' and 'seed' columns:
when present it groups and sums per (target, seed); when absent it
treats each row as its own group, which is the case for the DataFrame
calculate_influence builds.  Sign is preserved, so signed-mode input
yields signed-mode output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant