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