Skip to content

Commit

Permalink
add edge noise
Browse files Browse the repository at this point in the history
  • Loading branch information
dbdimitrov committed Jan 17, 2024
1 parent 52c283c commit f45f911
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 9 additions & 4 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Release notes
=============

1.0.4 (02.01.2024)
1.0.4 (17.01.2024)
-------------------------------------------------

- Moved the Global score summaries of ``SpatialBivariate`` from .uns to .var

Expand All @@ -15,9 +16,9 @@ Release notes

- Global results of ``SpatialBivariate`` will now be saved to ``.var``

- LIANA's spatial methods will now work with non-aligned AnnData objects, i.e. when observations across modalities are not aligned.
= Added ``li.ut.interpolate_adata`` utility function to interpolate the data to a common space.
= MISTy will also work with directly non-aligned data with spatial connectivities from one modality to the other being passed via ``obsm`` rather than ``obsp``. Making use of ``li.ut.spatial_neighbors`` by passing reference coordinates.
- Added ``li.ut.interpolate_adata`` utility function to interpolate the data to a common space.

- MISTy will also work with directly non-aligned data with spatial connectivities from one modality to the other being passed via ``obsm`` rather than ``obsp``. Making use of ``li.ut.spatial_neighbors`` by passing reference coordinates.

- Fixed a bug where ``li.ut.obsm_to_adata`` would assign var as a method rather than DataFrame

Expand All @@ -33,8 +34,12 @@ Release notes

- ``li.rs.explode_complexes`` is now consistently exported to ``li.rs`` (as previous versions)

- ``li.mt.find_causalnet``: changed the noise assigned to nodes to be proportional to the minimum penalty of the model. Also, added noise to the edges to avoid multiple solutions to the same problem.


1.0.3 (06.11.2023)
-------------------------------------------------

- Added ``filterby`` and ``filter_lambda`` parameters to ``li.pl.interactions`` and ``li.pl.target_metrics`` to allow filtering of interactions and metrics, respectively.

- Removed unnecessary ``stat`` parameter from ``li.pl.contributions``
Expand Down
8 changes: 7 additions & 1 deletion liana/method/fun/_causalnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def find_causalnet(
# assign 0 penalties to input/output nodes, missing_penalty to missing nodes
# add a small amount of noise to the penalties to ensure reproducible solutions
rng = np.random.default_rng(seed=seed)
c_node_penalties = {k: node_penalties.get(k, missing_penalty) + rng.uniform(0, 0.00001)
c_node_penalties = {k: node_penalties.get(k, missing_penalty) + rng.uniform(min_penalty/100, min_penalty/10)
if k not in measured_nodes else 0.0 for k in prior_graph.vertices}

_logg("Building CORNETO problem...", verbose=verbose)
Expand All @@ -184,6 +184,11 @@ def find_causalnet(
edge_penalty=edge_penalty
)

# E is the variable with 1 if edge activates or inhibits, 0 otherwise
E = P.symbols['reaction_sends_activation_c0'] + P.symbols['reaction_sends_inhibition_c0']
W = rng.uniform(edge_penalty/100, edge_penalty/10, size=E.shape)
P.add_objectives(W.T @ E)

_logg(f"Solving with {solver}...", verbose=verbose)
if (solver=='scipy') and verbose:
kwargs.update(scipy_options=dict(disp='true'))
Expand All @@ -201,6 +206,7 @@ def find_causalnet(
_logg(f" - {s}: {o.value}", verbose=verbose)
rows, cols = cn.methods.carnival.export_results(P, G, input_node_scores, output_node_scores)
df = pd.DataFrame(rows, columns=cols)

return df, P


Expand Down
5 changes: 3 additions & 2 deletions liana/tests/test_causalnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def test_caulsalnet():
output_scores,
node_weights=node_weights,
verbose=False,
solver='scipy'
solver='scipy',
seed=1337
)

assert problem.weights == [1.0, 0.01, 1.0]
assert problem.weights == [1.0, 0.01, 1.0, 1.0]
assert df_res['source_pred_val'].values.sum() == 5
assert df_res['target_pred_val'].values.sum() == 8
assert df_res[df_res['source_type']=='input']['source'].values[0] == 'I2'
Expand Down

0 comments on commit f45f911

Please sign in to comment.