annotate src/scheme/modelbase.scm @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 ;;; these functions handle the model hierarchy: it is notionally
samer@0 2 ;;; a multidimensional array. A particular model is a member of
samer@0 3 ;;; the product space:
samer@0 4 ;;; { sampling-rate x {mono, stereo} x frame-size x ensemble x model-class }
samer@0 5 ;;; sampling-rate in { 11kHz, 22kHz, 44kHz }
samer@0 6 ;;; frame-size is an integer
samer@0 7 ;;; ensemble denotes the set of audio files used to train the model
samer@0 8 ;;; model-class is eg, ICA, Gaussian, etc.
samer@0 9 ;;; The model classes may have a taxonomic hierarchy, eg,
samer@0 10 ;;; Gaussian: full covariance, spherical, diagonal, PCA
samer@0 11 ;;; and may have finer refinements, eg
samer@0 12 ;;; ICA with exponential prior, cauchy prior, generalised exponential
samer@0 13 ;;; In addition, there may be different instances of each model,
samer@0 14 ;;; trained at different times using a different realisation of the
samer@0 15 ;;; ensemble.
samer@0 16 ;;;
samer@0 17 ;;; Of-course, the file system doesn't support multidimensional arrays or
samer@0 18 ;;; product spaces: only strict hierarchies, so there needs to be a mapping
samer@0 19 ;;; between the two. The order in which the dimensions are arranged is somewhat
samer@0 20 ;;; arbitrary and invovles replication of directory names. Hence, these
samer@0 21 ;;; functions to automate the whole thing.
samer@0 22
samer@0 23 (define root "models") ; root defaults to "models" in current directory
samer@0 24 (define (_rate rate) ; return path component for rate
samer@0 25 (string-append (.toString rate) "kmono"))
samer@0 26
samer@0 27 (define (_frame fr)
samer@0 28 (string-append "x" (.toString fr)))
samer@0 29
samer@0 30
samer@0 31 (define (model-path rate frame data class)
samer@0 32 (define / "/") ; path separator
samer@0 33 (string-append
samer@0 34 root /
samer@0 35 (_rate rate) /
samer@0 36 data /
samer@0 37 (_frame frame) /
samer@0 38 class /
samer@0 39 )
samer@0 40 )
samer@0 41
samer@0 42 ;; set up environment for running given model
samer@0 43 (define (push-model rate x class data)
samer@0 44
samer@0 45 ; compose path for properties file
samer@0 46 (define model-props (cat (model-path rate (.size x) data class) "args"))
samer@0 47
samer@0 48 ; create new properties object for persistent properties
samer@0 49 ;(define model-env (samer.core.util.Properties. (env) (Node. class (.getNode x))))
samer@0 50 (define model-env (samer.core.util.Properties. (env) (.getNode x)))
samer@0 51
samer@0 52 ; load any previously saved properties
samer@0 53 (.load model-env (java.io.FileInputStream. model-props))
samer@0 54
samer@0 55 ; push an environment for non-persistent objects, with the properties as parent
samer@0 56 (Shell.push (samer.core.util.HashMap. model-env))
samer@0 57 (put "props-file" model-props) ; save the properties file name for later
samer@0 58
samer@0 59 ;; should we load a model script here?
samer@0 60 )
samer@0 61
samer@0 62 (define (pop-model)
samer@0 63 ; current environment should be a HashMap containing "props-file"
samer@0 64 ; it's parent should be a Properties environment
samer@0 65 ; so we save the parent environment to the recovered file
samer@0 66 (.save (.parent (env)) (java.io.FileOutputStream. (get "props-file")))
samer@0 67 (Shell.pop) ; this will unlink and discard both environments
samer@0 68 )
samer@0 69
samer@0 70
samer@0 71
samer@0 72