Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dissiml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guyslain Naves
Dissiml
Commits
0b846295
Commit
0b846295
authored
1 year ago
by
Guyslain Naves
Browse files
Options
Downloads
Patches
Plain Diff
add sampler for compatible orders of a pqtree
parent
ce33d89b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pqtrees/pqTree.ml
+57
-0
57 additions, 0 deletions
lib/pqtrees/pqTree.ml
lib/pqtrees/pqTree.mli
+14
-2
14 additions, 2 deletions
lib/pqtrees/pqTree.mli
with
71 additions
and
2 deletions
lib/pqtrees/pqTree.ml
+
57
−
0
View file @
0b846295
...
@@ -126,6 +126,7 @@ sig
...
@@ -126,6 +126,7 @@ sig
type
elt
type
elt
include
FeatCore
.
EnumSig
.
ENUM
include
FeatCore
.
EnumSig
.
ENUM
val
enumeration
:
elt
t
enum
val
enumeration
:
elt
t
enum
val
compatible_orders
:
'
elt
t
->
'
elt
list
IFSeq
.
seq
end
end
module
MakeEnumerate
=
module
MakeEnumerate
=
...
@@ -190,6 +191,54 @@ module MakeEnumerate =
...
@@ -190,6 +191,54 @@ module MakeEnumerate =
let
enumeration
=
let
enumeration
=
PQTEnum
.
map
to_pqtree
enum_skeleton
PQTEnum
.
map
to_pqtree
enum_skeleton
let
extensions
list
=
let
rec
go
previous
=
function
|
[]
->
[]
|
this
::
next
->
(
this
,
List
.
rev_append
previous
next
)
::
go
(
this
::
previous
)
next
in
go
[]
list
let
rec
enum_permutations
=
let
open
PQTIFSeq
in
function
|
[]
->
singleton
[]
|
elements
->
exists
(
extensions
elements
)
(
fun
(
head
,
tail
)
->
map
(
List
.
cons
head
)
(
enum_permutations
tail
))
let
rec
big_product
=
let
open
PQTIFSeq
in
function
|
[]
->
singleton
[]
|
head
::
tail
->
product
head
(
big_product
tail
)
|>
map
(
fun
(
sample_head
,
samples_tail
)
->
sample_head
::
samples_tail
)
let
apply_permutation
(
sigma
:
int
list
)
(
elements
:
'
a
list
)
:
'
a
list
=
List
.
map
(
List
.
nth
elements
)
sigma
let
rec
compatible_orders
pqtree
=
let
open
PQTIFSeq
in
match
pqtree
with
|
Leaf
x
->
singleton
[
x
]
|
P
children
->
let
permutations
=
enum_permutations
(
List
.
mapi
(
fun
i
_
->
i
)
children
)
in
let
orders
=
big_product
(
List
.
map
compatible_orders
children
)
in
product
permutations
orders
|>
map
(
fun
(
permutation
,
orders
)
->
apply_permutation
permutation
orders
|>
List
.
concat
)
|
Q
children
->
let
left_to_right_seq
=
children
|>
List
.
map
compatible_orders
|>
big_product
|>
map
List
.
concat
in
sum
(
left_to_right_seq
)
(
left_to_right_seq
|>
map
List
.
rev
)
end
end
...
@@ -201,6 +250,14 @@ let sample size =
...
@@ -201,6 +250,14 @@ let sample size =
|
_
->
invalid_arg
(
Format
.
sprintf
"PqTree.sample %d"
size
)
|
_
->
invalid_arg
(
Format
.
sprintf
"PqTree.sample %d"
size
)
let
sample_compatible_order
pqtree
=
let
sequence
=
Enum
.
compatible_orders
pqtree
in
match
Seq
.
uncons
(
Enum
.
PQTIFSeq
.
sample
1
sequence
Seq
.
empty
)
with
|
Some
(
sample
,_
)
->
sample
|
None
->
assert
false
let
rec
shrink_a_child
children
=
let
rec
shrink_a_child
children
=
MoreList
.
extend
children
MoreList
.
extend
children
|>
List
.
to_seq
|>
List
.
to_seq
...
...
This diff is collapsed.
Click to expand it.
lib/pqtrees/pqTree.mli
+
14
−
2
View file @
0b846295
...
@@ -61,7 +61,8 @@ val count_permutations : 'elt t -> Big_int_Z.big_int
...
@@ -61,7 +61,8 @@ val count_permutations : 'elt t -> Big_int_Z.big_int
(** A random permutation among those encoded by a given PQ-tree.
(** A random permutation among those encoded by a given PQ-tree.
@param tree a PQ-tree
@param tree a PQ-tree
@return a random permutation, as a list of elements, chosen uniformly randomly among all permutations encoded by [tree]
@return a random permutation, as a list of elements, chosen
uniformly randomly among all permutations encoded by [tree]
*)
*)
val
sample_permutation
:
'
elt
t
->
'
elt
list
val
sample_permutation
:
'
elt
t
->
'
elt
list
...
@@ -71,7 +72,7 @@ val sample_permutation : 'elt t -> 'elt list
...
@@ -71,7 +72,7 @@ val sample_permutation : 'elt t -> 'elt list
consecutively in any permutation in the set {%$\mathcal{P}$%}. The
consecutively in any permutation in the set {%$\mathcal{P}$%}. The
interval is sampled by first sampling a uniformly chosen
interval is sampled by first sampling a uniformly chosen
permutation, then sampling in this permutation a random
permutation, then sampling in this permutation a random
subsequence of elemnts. This sampling is not uniform in general.
subsequence of elem
e
nts. This sampling is not uniform in general.
@param tree a PQ-tree
@param tree a PQ-tree
@return a random interval for the set of permutations encoded by [tree]
@return a random interval for the set of permutations encoded by [tree]
...
@@ -161,6 +162,9 @@ sig
...
@@ -161,6 +162,9 @@ sig
(** An enumeration of all PQ-trees over some type of elements *)
(** An enumeration of all PQ-trees over some type of elements *)
val
enumeration
:
elt
t
enum
val
enumeration
:
elt
t
enum
(** A sequence of all compatible orders of a PQ-tree. *)
val
compatible_orders
:
'
elt
t
->
'
elt
list
IFSeq
.
seq
end
end
(** A functor to build a function to enumerate over PQ-trees. *)
(** A functor to build a function to enumerate over PQ-trees. *)
...
@@ -183,6 +187,14 @@ module Enum : EnumerateSig with type elt = int
...
@@ -183,6 +187,14 @@ module Enum : EnumerateSig with type elt = int
val
sample
:
int
->
int
t
val
sample
:
int
->
int
t
(** Sample a uniformly random compatible order from a PQ-tree.
@param pqtree the pqtree from which a compatible order must be sampled.
@return A uniformly random compatible order of [pqtree].
*)
val
sample_compatible_order
:
'
elt
t
->
'
elt
list
(** A type for modules providing functions to define a canonical
(** A type for modules providing functions to define a canonical
representation of equivalent PQ-trees, where two PQ-trees are
representation of equivalent PQ-trees, where two PQ-trees are
equivalent when they encode the same set of permutations.
equivalent when they encode the same set of permutations.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment