data-point.scm 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. ;; ======================
  2. ;; DATA POINT ABSTRACTION
  3. ;; ======================
  4. ;; These procedures serve as an abstraction layer over the underlying data
  5. ;; structures used to represent data points. Make sure to only ever use these
  6. ;; procedures, when dealing with data points.
  7. (define-module (data-point))
  8. (use-modules
  9. (utils vector))
  10. (define-public make-data-point
  11. (lambda (. elems)
  12. (list->vector elems)))
  13. (define-public data-point-length vector-length)
  14. (define-public data-point-get-col vector-ref)
  15. (define-public data-point-set-col! vector-set!)
  16. (define-public data-point-take
  17. (lambda (from-data-point num)
  18. "Get the first n feature values of the data point."
  19. (let ([to-new-vec (make-vector num)])
  20. (vector-move-left! from-data-point 0 num to-new-vec 0)
  21. to-new-vec)))
  22. (define-public data-point-take-features
  23. (lambda (data-point label-column-index)
  24. "Take all columns of a data point except for the label column."
  25. (vector-take-except-ref data-point label-column-index)))