Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Graphical Models in Experimental #3621

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
d9c0b58
Add fist files graphical models
Mar 15, 2024
fec1450
test commit
mariusneu Mar 19, 2024
3981379
added a greeting to readme
chgoergen Mar 19, 2024
2e1860d
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
chgoergen Mar 19, 2024
79840f0
TEST added a greeting to the phylomodels
chgoergen Mar 19, 2024
3dad960
reverted test commit
mariusneu Mar 19, 2024
7666f5f
Merge remote-tracking branch 'origin/HEAD'
mariusneu Mar 19, 2024
155465c
TEST from home
chgoergen Mar 20, 2024
f32aa1a
added phylomodels containing a few models, untested
chgoergen Mar 21, 2024
49758f8
first edits on specft
mariusneu Mar 25, 2024
11b5975
finished specialized fourier transform and its inverse
mariusneu Mar 25, 2024
e741e11
corrected a computational mistake in inverse spec_ft
mariusneu Mar 27, 2024
13c9dbd
Fourier Parametrization
Mar 27, 2024
f202d61
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Mar 27, 2024
9f3a1b8
deleted duplicate functionality
mariusneu Mar 27, 2024
5a65e5e
Merge branch 'spec_ft' into master ->
mariusneu Mar 27, 2024
097d13e
changed function names, minor changes in comments
mariusneu Mar 27, 2024
dff39b0
Split the code into totally three files according to the old structur…
mariusneu Mar 27, 2024
6d3146d
Deleted Christiane's phylomodels.jl as I integrated the contents into…
mariusneu Mar 27, 2024
e0498da
Edited Christiane's constructors to work with the new PhylogeneticMod…
mariusneu Mar 27, 2024
ad5178f
Added include-statements
mariusneu Mar 27, 2024
4bbbf03
corrected minor mistake in which_group_element, added correct include…
mariusneu Mar 27, 2024
753d03f
corrected minor spelling mistake
mariusneu Mar 28, 2024
5b2d869
corrected two minor mistakes in the building of the model
mariusneu Apr 2, 2024
e76cc40
Fixed typos K2 and K3 parameters
Apr 4, 2024
afe0dc6
added raw docs
chgoergen Apr 17, 2024
09ec8ac
cherries function
Apr 17, 2024
d4afa16
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Apr 17, 2024
9e53103
changed order in struct
chgoergen Apr 17, 2024
53b16dc
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Apr 17, 2024
c3f62b5
adding documentation
Apr 17, 2024
a1c9dfb
added runtests
Apr 17, 2024
c97be7d
Update README.md
marinagarrote Apr 17, 2024
26f37b2
export in GraphicalModels.jl
Apr 17, 2024
4913e39
started playing around with documentation as md document
chgoergen Apr 23, 2024
271993e
Added GroupBasedPhylogeneticModel and fixed the corresponding methods
Apr 23, 2024
b7ff69a
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Apr 23, 2024
4368373
Fixed equivalent classes functions
Apr 23, 2024
ca64a17
Using hadamard(R::ZZMatrixSpace) method
Apr 23, 2024
f6c6468
simplified code for specialized_fourier_transform and inverse
Apr 23, 2024
ff88321
update test files and exports
Apr 26, 2024
30024c3
added all exported functions to .md doc
chgoergen Apr 29, 2024
0c9b165
added raw doc to all models
chgoergen Apr 29, 2024
5f71a5e
started documenting parametrisation, nothing substantial yet
chgoergen Apr 29, 2024
9c50c7b
added possible documentation for parametrisations
chgoergen Apr 30, 2024
605d321
commit to pull
Apr 30, 2024
c24c85a
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Apr 30, 2024
2c57115
added doc for equivalent classes
chgoergen Apr 30, 2024
a664518
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
Apr 30, 2024
f34cc2a
changed access keys in parametrization map
Apr 30, 2024
f19f4e3
changed entries transition matrices in GMM
Apr 30, 2024
0fc1048
added root distribution in parametrization
Apr 30, 2024
ee1918d
Text to print in PhylogeneticModels and GroupBasedPM
May 1, 2024
1bbbcda
completed the docs for all models and exported functions, modified .m…
chgoergen May 2, 2024
c2f2f60
fixed equivalent classes
May 2, 2024
ce82e29
fixed sum_equivalent_classes
May 2, 2024
eff0b39
recent version with comments for everyone to work on
May 2, 2024
a6bf746
fixed indentation, blank lines, comments, and imperative form in docs
chgoergen May 3, 2024
6f744ba
fixed indentation in docs
chgoergen May 3, 2024
d7bc842
renamed file, fixed indentation in doc, put questions in slack
chgoergen May 3, 2024
b5c61c4
changed parametrisation to parametrization
chgoergen May 3, 2024
9b4bec0
updated testfile
May 3, 2024
bce8b98
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
May 3, 2024
8a7867c
updated todos
May 3, 2024
05e57b2
test for models including affine complete
May 7, 2024
ffdb839
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
May 8, 2024
007f0a9
tests for parametrizations
May 8, 2024
129e0b5
fixed tests and documentation
May 8, 2024
1447c50
Fixing documentation PhylogeneticModels.jl
May 17, 2024
ca373a2
Adding sections/comments
May 17, 2024
d610849
Fixing documentation PhyloParametrization.jl
May 17, 2024
4b0a352
changes order_eges for sort_edges
May 17, 2024
ebbb24e
fixing doctests
May 17, 2024
e46808d
fixing doctests
May 17, 2024
ca2ec0c
changed spaces and lenght output
May 17, 2024
c6416e6
fixing problems documentation
May 18, 2024
007b74c
ordering output trans_mat and fourier_param
May 20, 2024
cc79e5e
ordering output trans_mat and fourier_param 2
May 20, 2024
2352491
fix output groupBasedModel struct
May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions experimental/GraphicalModels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# An example template for the experimental section

## Aims

This is an example for a file structure to set up a new package
in the experimental section. All files you find here are part of the
minimum requirements. See also the official Oscar documentation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust the content of this file


## Status

We plan to also provide a function to automatically copy this template
for you to start your own package.

5 changes: 5 additions & 0 deletions experimental/GraphicalModels/docs/doc.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"GraphicalModels" => [
"graphicalmodels.md",
]
]
67 changes: 67 additions & 0 deletions experimental/GraphicalModels/docs/src/graphicalmodels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
```@meta
CurrentModule = Oscar
DocTestSetup = quote
using Oscar
end
```
# Algebraic Phylogenetics

The Algebraic Phylogenetics part of OSCAR provides functionality for
- specifying phylogenetic models
- parametrizing such models
- calculating their algebraic invariants

## Models

The five most common models in algebraic phylogenetics can automatically be specified by calling the below functions, each taking a tree as input and attaching transition matrices to its edges as defined by Jukes Cantor, Kimura, etc., respectively, returning a structure `PhylogeneticModel` or `GroupBasedPhylogeneticModel`.

```@docs
cavender_farris_neyman_model(graph::Graph{Directed})
jukes_cantor_model(graph::Graph{Directed})
kimura2_model(graph::Graph{Directed})
kimura3_model(graph::Graph{Directed})
general_markov_model(graph::Graph{Directed})
```

The models are by default in projective space. For their affine versions, call

```@docs
affine_phylogenetic_model!(pm::PhylogeneticModel)
```

## Components of a model

`PhylogeneticModel` specifies any phylogenetic tree model in probability coordinates and `GroupBasedPhylogeneticModel` can specify group-based, e.g. Fourier, coordinates. For any model, we can call its graph, transition matrices attached to the graph's edges, the number of states of each vertex random variable, and the corresponding polynomial rings. For instance for Jukes Cantor on the star with three leaves:

```@docs
graph(pm::PhylogeneticModel)
transition_matrices(pm::PhylogeneticModel)
number_states(pm::PhylogeneticModel)
probability_ring(pm::PhylogeneticModel)
fourier_ring(pm::GroupBasedPhylogeneticModel)
fourier_parameters(pm::GroupBasedPhylogeneticModel)
group_of_model(pm::GroupBasedPhylogeneticModel)
```


## Parametrization

For each phylogenetic model, we can calculate the parametrization, a map from transition matrices to probabilities, parametrized in probability or Fourier coordinates. For group-based models, we can reparametrize between these and return the transformation matrix, and we can calculate equivalence classes of probabilities with the same parametrization.

```@docs
probability_map(pm::PhylogeneticModel)
fourier_map(pm::GroupBasedPhylogeneticModel)
compute_equivalent_classes(parametrization::Dict{Tuple{Vararg{Int64}}, QQMPolyRingElem})
sum_equivalent_classes(equivalent_classes::Dict{Vector{Tuple{Vararg{Int64}}}, QQMPolyRingElem})
specialized_fourier_transform(pm::GroupBasedPhylogeneticModel, p_equivclasses::Dict{Vector{Tuple{Vararg{Int64}}}, QQMPolyRingElem}, f_equivclasses::Dict{Vector{Tuple{Vararg{Int64}}}, QQMPolyRingElem})
inverse_specialized_fourier_transform(pm::GroupBasedPhylogeneticModel, p_equivclasses::Dict{Vector{Tuple{Vararg{Int64}}}, QQMPolyRingElem}, f_equivclasses::Dict{Vector{Tuple{Vararg{Int64}}}, QQMPolyRingElem})
```

## Contact

Please direct questions about this part of OSCAR to the following people:
* [Marina Garrote López](https://sites.google.com/view/marinagarrotelopez),
* possibly others.

You can ask questions in the [OSCAR Slack](https://www.oscar-system.org/community/#slack).
Alternatively, you can [raise an issue on github](https://www.oscar-system.org/community/#how-to-report-issues).
38 changes: 38 additions & 0 deletions experimental/GraphicalModels/src/GraphicalModels.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include("PhylogeneticModels.jl")
include("PhylogeneticAuxiliary.jl")
include("PhylogeneticParametrization.jl")

#export models
export cavender_farris_neyman_model
export jukes_cantor_model
export kimura2_model
export kimura3_model
export general_markov_model
export affine_phylogenetic_model!

#export phylogenetic models attributes
export phylogenetic_model
export graph
export number_states
export transition_matrices
export probability_ring
export root_distribution
export fourier_parameters
export fourier_ring
export group_of_model

#export probability and fourier map
export probability_map
export fourier_map

# export functions to calculate equivalent classes
export compute_equivalent_classes
export sum_equivalent_classes

# export transformation matrices
export specialized_fourier_transform
export inverse_specialized_fourier_transform

# export structs for GroupBasedPhylogeneticModel,PhylogeneticModel
export PhylogeneticModel
export GroupBasedPhylogeneticModel
89 changes: 89 additions & 0 deletions experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
##########################
#### GROUP OPERATIONS ####
##########################
# This function implements the group operation on Z2 x Z2 and is subsequently
# used to check the condition given in the computation of the Fourier
# coordinates and to calculate the sum of the leaves beneath a given edge.

function group_sum(pm::GroupBasedPhylogeneticModel, states::Vector{Int})
group = group_of_model(pm)
return sum(group[states]).%2
end

function is_zero_group_sum(pm::GroupBasedPhylogeneticModel, states::Vector{Int})
ng = length(states)
return group_sum(pm, [states[1]]) == group_sum(pm, states[2:ng])
end

function which_group_element(pm::GroupBasedPhylogeneticModel, elem::Vector{Int64})
group = group_of_model(pm)
return findall([all(group[i].==elem) for i in 1:length(group)])[1]
end


########################################
#### AUXILIARY FUNCTIONS FOR GRAPHS ####
########################################

function interior_nodes(graph::Graph)
big_graph = Polymake.graph.Graph(ADJACENCY = pm_object(graph))
degrees = big_graph.NODE_DEGREES
return findall(x -> x > 1, degrees)
end

function leaves(graph::Graph)
big_graph = Polymake.graph.Graph(ADJACENCY = pm_object(graph))
degrees = big_graph.NODE_DEGREES
return findall(x -> x == 1, degrees)
end

function vertex_descendants(v::Int, gr::Graph, desc::Vector{Any})
lvs = leaves(gr)
outn = outneighbors(gr, v)

if v in lvs
return [v]
end

innodes = setdiff(outn, lvs)
d = unique(append!(desc, intersect(outn, lvs)))

Check warning on line 49 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L48-L49

Added lines #L48 - L49 were not covered by tests

if length(innodes) > 0
for i in innodes
d = vertex_descendants(i, gr, d)
end
return d

Check warning on line 55 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L51-L55

Added lines #L51 - L55 were not covered by tests
end

return d

Check warning on line 58 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L58

Added line #L58 was not covered by tests
end

function cherries(graph::Graph)
lvs = leaves(graph)
cherry = []
for l in lvs
in_node = inneighbors(graph,l)[1]
lvs_cherr = outneighbors(graph, inneighbors(graph,l)[1])
if issubset(lvs_cherr, lvs) == 2
cherry = append!(cherry, [[Edge(in_node, lvs_cherr[1]), Edge(in_node, lvs_cherr[2])]])

Check warning on line 68 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L61-L68

Added lines #L61 - L68 were not covered by tests
end
end

Check warning on line 70 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L70

Added line #L70 was not covered by tests

return unique(cherry)

Check warning on line 72 in experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/GraphicalModels/src/PhylogeneticAuxiliary.jl#L72

Added line #L72 was not covered by tests
end

function root(graph::Graph)
n_parents = [length(inneighbors(graph, v)) for v in 1:n_vertices(graph)]
return findall(x -> x == 0, n_parents)[1]
end


########################
#### SORT FUNCTIONS ####
########################

function sort_edges(graph::Graph)
edgs = collect(edges(graph))
leaves_idx = findall(edge -> dst(edge) in Oscar.leaves(graph), edgs)
return edgs[vcat(leaves_idx, setdiff(1:length(edgs), leaves_idx))]
end
Loading
Loading