[Gsll-devel] Thanks Liam!
Mirko Vukovic
mirko.vukovic at gmail.com
Tue Sep 2 13:33:25 UTC 2008
Liam,
I am afraid the usage is maybe too compact. I am simulating the
propagation of a 1D pulse. I use gsl::weighted-mean and
gsl::weighted-varience-nom to calculate the pulse centroid and width.
I *think* my approach is mathematically correct, but I am not sure of
its numerical soundness. To calculate the centroid of f(x) which is
defined as \frac{\int x f(x) dx}{\int f(x) dx}, I use the weighed mean
function, calculating the mean of x, which I weigh by the pulse
amplitude (phi, in the code below).
Likewise to calculate the width (defined as \frac{\int x^2 f(x)
dx}{\int f(x) dx}), I use the square root of the weighted variance
function, again applying it to x, weighted by the pulse height phi.
The calls to the two gsll function is in the body of this progn (which
in turn is part of a loop that propagates the pulse)
(progn
(format t "Step: ~A~%" it)
(format t "Expected/actual amplitude: ~a ~a ~%"
(* A (sqrt (/ t0 time))) (reduce #'max (coerce phi 'list)))
(format t "Expected/actual centroid: ~a ~a ~%"
(+ x0 (* F (- time t0)))
(letm ((gsl-phi (vector-double-float phi))
(gsl-x (vector-double-float grid-coords)))
(gsl::weighted-mean gsl-x gsl-phi))) ;; <================
(format t "Ideal/actual sigma: ~a ~a ~a ~%"
(sqrt (* 2 D time))
(letm ((gsl-phi (vector-double-float phi))
(gsl-x (vector-double-float grid-coords)))
(setf variance (gsl::weighted-variance-nom gsl-x gsl-phi))
;; <=============
(sqrt variance))))
I apologize for the flakiness of my arguments, but I needed something
quick and dirty, and my quick checks seemed ok.
Mirko
On Sat, Aug 23, 2008 at 1:35 PM, Liam Healy <lhealy at common-lisp.net> wrote:
> You're welcome.
>
> If your usage is reasonably compact, do you mind posting it? I would
> like to have as many examples as possible both for new users and for
> me to create tests and examples.
>
>
> On Fri, Aug 22, 2008 at 9:43 AM, Mirko Vukovic <mirko.vukovic at gmail.com> wrote:
>> Used the mean&variance stuff yesterday. Thanks (again)!
>>
>> Mirko
>
More information about the gsll-devel
mailing list