Mercurial > hg > jslab
diff src/scheme/modelbase.scm @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/scheme/modelbase.scm Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,72 @@ +;;; these functions handle the model hierarchy: it is notionally +;;; a multidimensional array. A particular model is a member of +;;; the product space: +;;; { sampling-rate x {mono, stereo} x frame-size x ensemble x model-class } +;;; sampling-rate in { 11kHz, 22kHz, 44kHz } +;;; frame-size is an integer +;;; ensemble denotes the set of audio files used to train the model +;;; model-class is eg, ICA, Gaussian, etc. +;;; The model classes may have a taxonomic hierarchy, eg, +;;; Gaussian: full covariance, spherical, diagonal, PCA +;;; and may have finer refinements, eg +;;; ICA with exponential prior, cauchy prior, generalised exponential +;;; In addition, there may be different instances of each model, +;;; trained at different times using a different realisation of the +;;; ensemble. +;;; +;;; Of-course, the file system doesn't support multidimensional arrays or +;;; product spaces: only strict hierarchies, so there needs to be a mapping +;;; between the two. The order in which the dimensions are arranged is somewhat +;;; arbitrary and invovles replication of directory names. Hence, these +;;; functions to automate the whole thing. + +(define root "models") ; root defaults to "models" in current directory +(define (_rate rate) ; return path component for rate + (string-append (.toString rate) "kmono")) + +(define (_frame fr) + (string-append "x" (.toString fr))) + + +(define (model-path rate frame data class) + (define / "/") ; path separator + (string-append + root / + (_rate rate) / + data / + (_frame frame) / + class / + ) +) + +;; set up environment for running given model +(define (push-model rate x class data) + + ; compose path for properties file + (define model-props (cat (model-path rate (.size x) data class) "args")) + + ; create new properties object for persistent properties + ;(define model-env (samer.core.util.Properties. (env) (Node. class (.getNode x)))) + (define model-env (samer.core.util.Properties. (env) (.getNode x))) + + ; load any previously saved properties + (.load model-env (java.io.FileInputStream. model-props)) + + ; push an environment for non-persistent objects, with the properties as parent + (Shell.push (samer.core.util.HashMap. model-env)) + (put "props-file" model-props) ; save the properties file name for later + + ;; should we load a model script here? +) + +(define (pop-model) + ; current environment should be a HashMap containing "props-file" + ; it's parent should be a Properties environment + ; so we save the parent environment to the recovered file + (.save (.parent (env)) (java.io.FileOutputStream. (get "props-file"))) + (Shell.pop) ; this will unlink and discard both environments +) + + + +