
(******************************************************************************
 * ORandForest
 * A pure OCaml implementation of a random forest classifier based on OC4.5.
 *
 * By Théophile Bastian <contact@tobast.fr>
 * and Noémie Fong (aka. Minithorynque), 2016.
 ******************************************************************************
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************)

module type S = sig

  type c45_data
  (** {!Oc45.S.data} *)

  type c45_category
  (** {!Oc45.S.category *)

  type c45_trainSet
  (** {!Oc45.S.trainSet} *)

  type randomForest
  (** Stores a random forest generated by {!genRandomForest} *)

  val genRandomForest: ?ncores:int -> int -> c45_trainSet -> randomForest
  (** [genRandomForest nbTrees trainSet] generates a random forest of
      [nbTrees] trees, based on [trainSet]. If [ncores] > 1 is given, the
      random forest will be built in parallel *)

  val classify: randomForest -> c45_data -> c45_category
  (** Classifies a new data vector, relying on the informations from the
      given random forest (generated by {!genRandomForest}), yielding a
      category. *)

  val classify_raw: randomForest -> c45_data -> (c45_category * float) list
  (** Like [classify] but gives access to the percentage of votes for
      each category.
      After calibration of your classifier (e.g. using Platt/sigmoid scaling
      or isotonic regression), those percentages can be converted to
      probabilities. No calibration method is included in the library
      currently. *)

  val save_to_file: string -> randomForest -> unit
  (** [save_to_file output model] saves the random forest [model]
      into the file [output]. *)

  val restore_from_file: string -> randomForest
  (** [restore_from_file input] restores the random forest that
      was previously saved in file [input]. *)
end

module Make(X: Oc45.S) : S with type c45_data = X.data
	                    and type c45_category = X.category
	                    and type c45_trainSet = X.trainSet

module IntRandForest : S with type c45_data = Oc45.IntOc45.data
	                  and type c45_category = Oc45.IntOc45.category
	                  and type c45_trainSet = Oc45.IntOc45.trainSet

module FloatRandForest : S with type c45_data = Oc45.FloatOc45.data
	                    and type c45_category = Oc45.FloatOc45.category
	                    and type c45_trainSet = Oc45.FloatOc45.trainSet
