-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignatures.ml
140 lines (96 loc) · 3.47 KB
/
signatures.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
open Core.Std
(* A module signature for comparing data types *)
module type COMPARABLE =
sig
(* Type *)
type t
(* zero of type, used for array creation (Invariant) *)
val zero : t
(* Comparison function *)
val compare : t -> t -> Ordering.t
(* Multiplication function*)
val multiply : t -> t -> t
(* Addition *)
val add : t -> t -> t
(* Prints specific types *)
val print : t -> unit
(*converts element to a float*)
val float_of_t : t -> float
(* inverse of above; converts flaot to t *)
val t_of_float : float -> t
end
module type MATRIX =
sig
(*type of the elements*)
type elt
(*implementation of the matrix itself*)
type t
exception Invalid_Dimensions
val zero : elt
(*creates a matrix out of list of lists*)
val of_list : elt list list -> t
(* creates a matrix with given dimensions. Initial values are
undefined behavior *)
val of_dimensions : (int * int) -> t
(*multiplies two matrices together*)
val multiply : t -> t -> t
(* map function over matrix *)
val map : t -> f:(elt -> elt) -> t
(*returns an element of the matrix *)
val get : (int * int) -> t -> elt
(* edits an element of the matrix and returns unit *)
val set : (int * int) -> t -> elt -> unit
(*returns the dimensions of an array*)
val dimensions : t -> (int * int)
(*returns the smallest non-zero element of a matrix*)
val maximum : t -> elt
(*since matrices are abstract, this function prints them out*)
val print : t -> unit
(* similarly to the above, we can use this for testing and printing *)
val print_elt : elt -> unit
(*returns all the elements of a given column *)
val get_column : t -> int -> elt array
(* returns all elements in a given row *)
val get_row : t -> int -> elt array
(*turns elements into floats for purposes of stats module*)
val float_of_elt : elt -> float
(* inverse of the above transformation *)
val elt_of_float : float -> elt
(* Compares two elts *)
val compare_elts : elt -> elt -> int
end
type cluster_args_t = | Kruskal of int
| Markov of int * float * bool
(*signature for graph clustering algorithms:
* Kruskal's Algorithm and Markov Process Clustering *)
module type CLUSTER =
functor (MatrixMod : MATRIX) ->
sig
(* The first argument is for the parameters of that
* specific algorithm.
* The second argument is the matrix, and the third argument
* is a verbose option. *)
val cluster: cluster_args_t -> MatrixMod.t -> int list list
end
module type STATS =
functor (Matrix : MATRIX) ->
sig
(* calculates the average distance between nodes in a cluster
* would ideally be small for good clustering algorithms
* returns none if there are no connections between the nodes *)
val avg_dist_single : Matrix.t -> int list -> float option
(* does the same thing as the above but for multiple clusters *)
val avg_dist_all : Matrix.t -> int list list -> float option list
(* calculates distances between clusters
* would ideally be large for good clustering algorithms
* returns None if the two clusters are not connected *)
val dist_between_two : Matrix.t -> int list -> int list -> float option
(* calculates the distance between all pairs of clusters *)
val dist_between_all : Matrix.t -> int list list -> float option list
end
module type TO_GRAPH =
functor (Matrix: MATRIX) ->
sig
(* takes in a list of points and outputs the transition matrix *)
val to_graph : float list list -> Matrix.t
end