Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Calculating MTIE with racket

Name: Anonymous 2012-03-27 7:37

A simplified implementation of Extreme Fix algorithm for calculating MTIE.

My first functional programming excercise that does something useful. Comments, please.


(define (mtie-window data window-size current-mtie)
  (define-values (data-new peak-to-peak)
    (find-peaks data window-size))
  ; check if this iteration is the last one
  ; include less than because it can be reduced by 1 in
  (if (= (length data) window-size)
      (max current-mtie peak-to-peak)
      (mtie-window data-new window-size (max current-mtie peak-to-peak))))

; find peak-to-peak value of a window starting from the beginning of data
; return that and data cropped from left according to extreme fix logic
(define (find-peaks data window-size)
  (define window-data (take data window-size))
  (define xmin (argmin (lambda (x) x) window-data))
  (define xmax (argmax (lambda (x) x) window-data))
 
  ; crop data that has no use anymore from the beginning
  (define minlist (member xmin data))
  (define maxlist (member xmax data))
  ; return the larger dataset so that any points won't be missed
  (define retlist (if (> (length minlist) (length maxlist) )
                      minlist maxlist))
 
  (define ret-data
    (cond
      ; last iteration has to have window-size samples
      [(< (length retlist) window-size)
       (list-tail data (- (length data) window-size))]
      ; move forward by one if it would otherwise be the same
      ; i.e. if peak is was at the first point
      [(= (length retlist) (length data))
       (rest retlist)]
      [else retlist]))
 
  (values ret-data (- xmax xmin)))

(define tie-data '(-4 -2 0 4 6 3 2 5 6 3 2 1 4 6 7 2 3 4 5 4 7 10))
(define observation-window-sizes
  (append
   (build-list
    (inexact->exact (floor (/ (log (length tie-data)) (log 2))))
    (lambda (x) (expt 2 (+ x 1))))
   (list (length tie-data))))

(map (lambda (window-size)
       (list window-size (mtie-window tie-data window-size 0.0)))
     observation-window-sizes)

Name: Anonymous 2012-03-27 7:38

2get wwwwwwwwwwwwwwwwwwwwwwwwwwwww

Name: /prog/ awards 2012-03-27 11:10

The most LISP written this month that has balanced parenthesiseseses.

Name: Anonymous 2012-03-27 13:15

>>1
))))

Don't change these.
Name: Email:
Entire Thread Thread List