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