-
Notifications
You must be signed in to change notification settings - Fork 134
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
Closed
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
fec1450
test commit
mariusneu 3981379
added a greeting to readme
chgoergen 2e1860d
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
chgoergen 79840f0
TEST added a greeting to the phylomodels
chgoergen 3dad960
reverted test commit
mariusneu 7666f5f
Merge remote-tracking branch 'origin/HEAD'
mariusneu 155465c
TEST from home
chgoergen f32aa1a
added phylomodels containing a few models, untested
chgoergen 49758f8
first edits on specft
mariusneu 11b5975
finished specialized fourier transform and its inverse
mariusneu e741e11
corrected a computational mistake in inverse spec_ft
mariusneu 13c9dbd
Fourier Parametrization
f202d61
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
9f3a1b8
deleted duplicate functionality
mariusneu 5a65e5e
Merge branch 'spec_ft' into master ->
mariusneu 097d13e
changed function names, minor changes in comments
mariusneu dff39b0
Split the code into totally three files according to the old structur…
mariusneu 6d3146d
Deleted Christiane's phylomodels.jl as I integrated the contents into…
mariusneu e0498da
Edited Christiane's constructors to work with the new PhylogeneticMod…
mariusneu ad5178f
Added include-statements
mariusneu 4bbbf03
corrected minor mistake in which_group_element, added correct include…
mariusneu 753d03f
corrected minor spelling mistake
mariusneu 5b2d869
corrected two minor mistakes in the building of the model
mariusneu e76cc40
Fixed typos K2 and K3 parameters
afe0dc6
added raw docs
chgoergen 09ec8ac
cherries function
d4afa16
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
9e53103
changed order in struct
chgoergen 53b16dc
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
c3f62b5
adding documentation
a1c9dfb
added runtests
c97be7d
Update README.md
marinagarrote 26f37b2
export in GraphicalModels.jl
4913e39
started playing around with documentation as md document
chgoergen 271993e
Added GroupBasedPhylogeneticModel and fixed the corresponding methods
b7ff69a
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
4368373
Fixed equivalent classes functions
ca64a17
Using hadamard(R::ZZMatrixSpace) method
f6c6468
simplified code for specialized_fourier_transform and inverse
ff88321
update test files and exports
30024c3
added all exported functions to .md doc
chgoergen 0c9b165
added raw doc to all models
chgoergen 5f71a5e
started documenting parametrisation, nothing substantial yet
chgoergen 9c50c7b
added possible documentation for parametrisations
chgoergen 605d321
commit to pull
c24c85a
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
2c57115
added doc for equivalent classes
chgoergen a664518
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
f34cc2a
changed access keys in parametrization map
f19f4e3
changed entries transition matrices in GMM
0fc1048
added root distribution in parametrization
ee1918d
Text to print in PhylogeneticModels and GroupBasedPM
1bbbcda
completed the docs for all models and exported functions, modified .m…
chgoergen c2f2f60
fixed equivalent classes
ce82e29
fixed sum_equivalent_classes
eff0b39
recent version with comments for everyone to work on
a6bf746
fixed indentation, blank lines, comments, and imperative form in docs
chgoergen 6f744ba
fixed indentation in docs
chgoergen d7bc842
renamed file, fixed indentation in doc, put questions in slack
chgoergen b5c61c4
changed parametrisation to parametrization
chgoergen 9b4bec0
updated testfile
bce8b98
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
8a7867c
updated todos
05e57b2
test for models including affine complete
ffdb839
Merge branch 'master' of github.com:marinagarrote/Oscar.jl
007f0a9
tests for parametrizations
129e0b5
fixed tests and documentation
1447c50
Fixing documentation PhylogeneticModels.jl
ca373a2
Adding sections/comments
d610849
Fixing documentation PhyloParametrization.jl
4b0a352
changes order_eges for sort_edges
ebbb24e
fixing doctests
e46808d
fixing doctests
ca2ec0c
changed spaces and lenght output
c6416e6
fixing problems documentation
007b74c
ordering output trans_mat and fourier_param
cc79e5e
ordering output trans_mat and fourier_param 2
2352491
fix output groupBasedModel struct
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
## Status | ||
|
||
We plan to also provide a function to automatically copy this template | ||
for you to start your own package. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
"GraphicalModels" => [ | ||
"graphicalmodels.md", | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|
||
if length(innodes) > 0 | ||
for i in innodes | ||
d = vertex_descendants(i, gr, d) | ||
end | ||
return d | ||
end | ||
|
||
return d | ||
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])]]) | ||
end | ||
end | ||
|
||
return unique(cherry) | ||
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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