last bit for incantation of adding something new. Should work now (I did test it).
[CommonLispStat.git] / model.lisp
blob8c69d1dacee8bdf0c7c4ab93d6370a51baf72421
1 ;;; -*- mode: lisp -*-
2 ;;; Copyright (c) 2005--2007, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
6 ;;; File: model.lisp
7 ;;; Author: AJ Rossini <blindglobe@gmail.com>
8 ;;; Copyright: (c)2007, AJ Rossini. BSD, LLGPL, or GPLv2, depending on how it arrives.
9 ;;; Purpose: models as a data summarization tools.
10 ;;; Time-stamp: <2006-05-19 12:33:41 rossini>
11 ;;; Creation: <2006-05-17 21:34:07 rossini>
13 ;;; What is this talk of 'release'? Klingons do not make software
14 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
15 ;;; designers and quality assurance people in its wake.
17 ;;; Work towards an object system with a comprehensive theory of data
18 ;;; summarization through models. The basic idea is that models are
19 ;;; used to summarize different aspects of a data generating process,
20 ;;; possibly realized by a dataset.
22 (in-package :cl-user)
24 (defpackage :lisp-stat-model
25 (:documentation "Model management and other mathematical technologies.")
26 (:nicknames :ls-data)
27 (:use :common-lisp
28 :lisp-stat-config
29 :lisp-stat-object-system
30 :lisp-stat-types
31 :lisp-stat-compound-data
32 :lisp-stat-matrix
33 :lisp-stat-linalg)
34 (:shadowing-import-from :lisp-stat-object-system
35 slot-value call-method call-next-method)
36 (:export model))
38 (in-package :lisp-stat-model)
40 (defclass model ()
41 ((name :initform nil
42 :initarg :name
43 :accessor name
44 :reader model-name)
45 (form :initform nil
46 :initarg :formula
47 :accessor form
48 :reader model-formula)
49 (parameter-vars :initform nil
50 :initarg :parameter-vars
51 :accessor param-vars
52 :reader model-formula)
53 (data-vars :initform nil
54 :initarg :data-vars
55 :accessor data-vars
56 :reader model-formula)
57 (fixed-vars :initform nil
58 :initarg :fixed-vars
59 :accessor fixed-vars
60 :reader model-formula)
61 (solution :initform nil
62 :initarg :criteriaFunction
63 :accessor critFcn-vars
64 :reader model-formula)
66 (done-solution? :initform nil :reader done-setup?)
67 (prototypes-initialized? :initform nil :reader prototypes-initialized?)
68 (current-values :initform nil :accessor current-values)
70 (log-file :initform nil :initarg :log-file :reader log-file)
71 (test-data :initform nil :accessor test-data)
72 (expected-failure-p :initform nil :initarg :expected-failure-p
73 :reader expected-failure-p)
74 (expected-error-p :initform nil :initarg :expected-error-p
75 :reader expected-error-p)
76 (expected-problem-p :initform nil :initarg :expected-problem-p
77 :reader expected-problem-p))
78 (:documentation "Mathematical Model"))
80 (defclass result (model)
81 ((param-values )
82 (param-uncertainity )
83 (param-characterization ))
85 ;; The following are types of models -- in particular, we can consider
86 ;; that these models
88 (defclass statistical-model (model) )
90 (defclass ode-model (model ))
92 (defclass linear-regression-model (statistical-mode))
94 (defclass generalized-linear-regression-model (statistical-model))
96 (defclass nonlinear-linear-regression-model (statistical-model))
99 ;;; garbage follows
102 ;; modelType
104 root
105 opt (min / max)
107 diffeqn
109 diffeqn + solve
111 ;; dataType
113 varExtract
114 tableExtract
115 relationExtract
118 ;; mappingType
120 (setf myFirstModel
121 (defineModel normalLikelihood '((* (/ 1 (sqrt (* 2 (pi) sigma)))
122 (exp (/ (- x mu)
123 sigma))))
124 :fixed '()
125 :param '(mu sigma)
126 :data '(x)
127 :critFcnSoln '(:max (one-of bfgs nelder-mead conjugate-gradient))))
129 (defclass model ()
130 ((name )
131 (vars-fixed :initarg nil :arg fixed)
132 (vars-param :initarg nil :arg param)
133 (vars-data :initarg nil :arg data)
134 (critFcn ))
141 (defclass meanModel (model) ... ) ;; a macro to map onto Model
142 (defclass meanVarModel (model) ... )
143 (defclass regressionModel (meanModel) )
144 (defclass mixedModel (regressionModel) ... )
145 (defclass bayesianModel (model) ... )
146 (defclass diffintgleqnModel (model) ) ;;(ODE, PDF, integral equations)
150 (setf modX
151 (solveModel :model myFirstModel
152 :data myVar
153 :mapping '((x . myVar))))
155 ;; result structure
157 (:solution
158 :params
159 :params-characterisation
160 :paradigm '(bayesian frequentist)
161 :dataname
162 :modelname )
165 (with-mapping map :model mymod :data mydata
166 (bootstrap mymod mydata))
169 ;; solution should inherit from model and data (and be recomputable)
170 ;; func args override embedded args
172 ;; (solveModel firstSoln) "=" firstSoln
174 ;; unless stoch approx used.
178 (defclass