dataframe issues added to ditz
[CommonLispStat.git] / src / stat-models / model.lisp
blobdf52c40012edd84245e10a0362c7b97ee5038e97
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
9 ;;; on how it arrives.
10 ;;; Purpose: models as a data summarization tools.
11 ;;; Time-stamp: <2006-05-19 12:33:41 rossini>
12 ;;; Creation: <2006-05-17 21:34:07 rossini>
14 ;;; What is this talk of 'release'? Klingons do not make software
15 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
16 ;;; designers and quality assurance people in its wake.
18 ;;; Work towards an object system with a comprehensive theory of data
19 ;;; summarization through models. The basic idea is that models are
20 ;;; used to summarize different aspects of a data generating process,
21 ;;; possibly realized by a dataset.
23 (in-package :cl-user)
25 (defpackage :lisp-stat-model
26 (:documentation "Model management and other mathematical technologies.")
27 (:nicknames :ls-data)
28 (:use :common-lisp
29 :lisp-stat-config
30 :lisp-stat-object-system
31 :lisp-stat-types
32 :lisp-stat-compound-data
33 #|
34 :lisp-stat-matrix
35 :lisp-stat-linalg
38 (:shadowing-import-from :lisp-stat-object-system
39 slot-value call-method call-next-method)
40 (:export model))
42 (in-package :lisp-stat-model)
44 (defclass model ()
45 ((name :initform nil
46 :initarg :name
47 :accessor name
48 :reader model-name)
49 (form :initform nil
50 :initarg :formula
51 :accessor form
52 :reader model-formula)
53 (parameter-vars :initform nil
54 :initarg :parameter-vars
55 :accessor param-vars
56 :reader model-formula)
57 (data-vars :initform nil
58 :initarg :data-vars
59 :accessor data-vars
60 :reader model-formula)
61 (fixed-vars :initform nil
62 :initarg :fixed-vars
63 :accessor fixed-vars
64 :reader model-formula)
65 (solution :initform nil
66 :initarg :criteriaFunction
67 :accessor critFcn-vars
68 :reader model-formula)
70 (done-solution? :initform nil :reader done-setup?)
71 (prototypes-initialized? :initform nil :reader prototypes-initialized?)
72 (current-values :initform nil :accessor current-values)
74 (log-file :initform nil :initarg :log-file :reader log-file)
75 (test-data :initform nil :accessor test-data)
76 (expected-failure-p :initform nil :initarg :expected-failure-p
77 :reader expected-failure-p)
78 (expected-error-p :initform nil :initarg :expected-error-p
79 :reader expected-error-p)
80 (expected-problem-p :initform nil :initarg :expected-problem-p
81 :reader expected-problem-p))
82 (:documentation "Mathematical Model"))
84 (defclass result (model)
85 ((param-values )
86 (param-uncertainity )
87 (param-characterization ))
89 ;; The following are types of models -- in particular, we can consider
90 ;; that these models
92 (defclass statistical-model (model) )
94 (defclass ode-model (model ))
96 (defclass linear-regression-model (statistical-mode))
98 (defclass generalized-linear-regression-model (statistical-model))
100 (defclass nonlinear-linear-regression-model (statistical-model))
105 ;;; garbage follows
108 ;; modelType
110 root
111 opt (min / max)
113 diffeqn
115 diffeqn + solve
117 ;; dataType
119 varExtract
120 tableExtract
121 relationExtract
124 ;; mappingType
126 (setf myFirstModel
127 (defineModel normalLikelihood '((* (/ 1 (sqrt (* 2 (pi) sigma)))
128 (exp (/ (- x mu)
129 sigma))))
130 :fixed '()
131 :param '(mu sigma)
132 :data '(x)
133 :critFcnSoln '(:max (one-of bfgs nelder-mead conjugate-gradient))))
135 (defclass model ()
136 ((name )
137 (vars-fixed :initarg nil :arg fixed)
138 (vars-param :initarg nil :arg param)
139 (vars-data :initarg nil :arg data)
140 (critFcn ))
147 (defclass meanModel (model) ... ) ;; a macro to map onto Model
148 (defclass meanVarModel (model) ... )
149 (defclass regressionModel (meanModel) )
150 (defclass mixedModel (regressionModel) ... )
151 (defclass bayesianModel (model) ... )
152 (defclass diffintgleqnModel (model) ) ;;(ODE, PDF, integral equations)
156 (setf modX
157 (solveModel :model myFirstModel
158 :data myVar
159 :mapping '((x . myVar))))
161 ;; result structure
163 (:solution
164 :params
165 :params-characterisation
166 :paradigm '(bayesian frequentist)
167 :dataname
168 :modelname )
171 (with-mapping map :model mymod :data mydata
172 (bootstrap mymod mydata))
175 ;; solution should inherit from model and data (and be recomputable)
176 ;; func args override embedded args
178 ;; (solveModel firstSoln) "=" firstSoln
180 ;; unless stoch approx used.
184 (defclass