From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Wiegley Subject: New module: org-learn, incremental reading Date: Wed, 21 Oct 2009 04:53:39 -0400 Message-ID: <558B167B-65F3-4E3B-8696-1FF00243177E@gmail.com> Mime-Version: 1.0 (Apple Message framework v1075.2) Content-Type: multipart/mixed; boundary=Apple-Mail-6-782629411 Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0Wx3-0000kV-UM for emacs-orgmode@gnu.org; Wed, 21 Oct 2009 04:53:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0Wwz-0000jS-7W for emacs-orgmode@gnu.org; Wed, 21 Oct 2009 04:53:49 -0400 Received: from [199.232.76.173] (port=49912 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0Wwz-0000jP-2I for emacs-orgmode@gnu.org; Wed, 21 Oct 2009 04:53:45 -0400 Received: from mail-ew0-f206.google.com ([209.85.219.206]:50938) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0Wwy-0004n2-DZ for emacs-orgmode@gnu.org; Wed, 21 Oct 2009 04:53:44 -0400 Received: by ewy2 with SMTP id 2so7153297ewy.31 for ; Wed, 21 Oct 2009 01:53:43 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-mode Mode Cc: Carsten Dominik --Apple-Mail-6-782629411 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes The attached file, when loaded, provides two new commands: M-x org-smart-reschedule M-x org-agenda-smart-reschedule The latter being only for the *Org Agenda* buffer. You should use these commands on a scheduled entry, with state logging =20= enabled for the DONE state. It then reschedules the item to a future =20= date based on the "SM-5" algorithm and a quality factor you are =20 prompted for. To summarize the SM-5 algorithm: 1. After you read an item on the scheduled day, you hit M-x org-=20 smart-reschedule. 2. You are then asked how well you remember what you just read, =20 from 0-5: 5 - perfect response 4 - correct response after a hesitation 3 - correct response recalled with serious difficulty 2 - incorrect response; where the correct one seemed easy to =20 recall 1 - incorrect response; the correct one remembered 0 - complete blackout. 3. If your answer is 4 or 5, the item will not be repeated. If it =20= is anything else, the item is rescheduled, to be read again on a future date. 4. Based on the quality of your response, AND the number of times =20 you've read the item so far, the amount of time being reschedulings will =20 vary. If your retention is good, the gaps grow wider; if it is poor, they grow =20= shorter. 5. Your "learning data" is kept in a special property =20 called :LEARN_DATA:. Do not modify this, as it controls how the algorithm reschedules =20 after future repetitions, and based on past quality responses. More about this algorithm can be read here: = http://www.supermemo.com/english/ol/sm2.htm=20 . This contribution is made in honor of Russell Adams, who drove all the =20= way to New Jersey from Kennedy airport to visit me today, and who =20 brought up the idea of implementing it, based on an earlier proposal =20 by Pere Quintana Segu=ED = (http://article.gmane.org/gmane.emacs.orgmode/17781=20 ). John --Apple-Mail-6-782629411 Content-Disposition: attachment; filename=org-learn.el Content-Type: application/octet-stream; name="org-learn.el" Content-Transfer-Encoding: 7bit ;;; org-learn.el --- Implements SuperMemo's incremental learning algorithm ;; Copyright (C) 2009 ;; Free Software Foundation, Inc. ;; Author: John Wiegley ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org ;; Version: 6.31trans ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; The file implements the learning algorithm described at ;; http://supermemo.com/english/ol/sm5.htm, which is a system for reading ;; material according to "spaced repetition". See ;; http://en.wikipedia.org/wiki/Spaced_repetition for more details. ;; ;; To use, turn on state logging and schedule some piece of information you ;; want to read. Then in the agenda buffer type (require 'org) (eval-when-compile (require 'cl) (require 'calendar)) (defgroup org-learn nil "Options concerning the learning code in Org-mode." :tag "Org Learn" :group 'org-progress) (defcustom org-learning-fraction 0.5 "Controls the rate at which EF is increased or decreased. Must be a number between 0 and 1 (the greater it is the faster the changes of the OF matrix)." :type 'float :group 'org-learn) (defvar optimal-factors nil "A list of alists relating (N, EF) => OF. The format is: ((N . ((EF . OF) ...)) ...)") (defun initial-optimal-factor (n ef) (if (= 1 n) 4 ef)) (defun get-optimal-factor (n ef of-matrix) (let ((factors (assoc n of-matrix))) (or (and factors (let ((ef-of (assoc ef (cdr factors)))) (and ef-of (cdr ef-of)))) (initial-optimal-factor n ef)))) (defun set-optimal-factor (n ef of-matrix of) (let ((factors (assoc n of-matrix))) (if factors (let ((ef-of (assoc ef (cdr factors)))) (if ef-of (setcdr ef-of of) (push (cons ef of) (cdr factors)))) (push (cons n (list (cons ef of))) of-matrix))) of-matrix) (defun inter-repetition-interval (n ef &optional of-matrix) (let ((of (get-optimal-factor n ef of-matrix))) (if (= 1 n) of (* of (inter-repetition-interval (1- n) ef of-matrix))))) (defun modify-e-factor (ef quality) (if (< ef 1.3) 1.3 (+ ef (- 0.1 (* (- 5 quality) (+ 0.08 (* (- 5 quality) 0.02))))))) (defun modify-of (of q fraction) (let ((temp (* of (+ 0.72 (* q 0.07))))) (+ (* (- 1 fraction) of) (* fraction temp)))) (defun calculate-new-optimal-factor (interval-used quality used-of old-of fraction) "This implements the SM-5 learning algorithm in Lisp. INTERVAL-USED is the last interval used for the item in question. QUALITY is the quality of the repetition response. USED-OF is the optimal factor used in calculation of the last interval used for the item in question. OLD-OF is the previous value of the OF entry corresponding to the relevant repetition number and the E-Factor of the item. FRACTION is a number belonging to the range (0,1) determining the rate of modifications (the greater it is the faster the changes of the OF matrix). Returns the newly calculated value of the considered entry of the OF matrix." (let (;; the value proposed for the modifier in case of q=5 (mod5 (/ (1+ interval-used) interval-used)) ;; the value proposed for the modifier in case of q=2 (mod2 (/ (1- interval-used) interval-used)) ;; the number determining how many times the OF value will ;; increase or decrease modifier) (if (< mod5 1.05) (setq mod5 1.05)) (if (< mod2 0.75) (setq mod5 0.75)) (if (> quality 4) (setq modifier (1+ (* (- mod5 1) (- quality 4)))) (setq modifier (- 1 (* (/ (- 1 mod2) 2) (- 4 quality))))) (if (< modifier 0.05) (setq modifier 0.05)) (setq new-of (* used-of modifier)) (if (> quality 4) (if (< new-of old-of) (setq new-of old-of))) (if (< quality 4) (if (> new-of old-of) (setq new-of old-of))) (setq new-of (+ (* new-of fraction) (* old-of (- 1 fraction)))) (if (< new-of 1.2) (setq new-of 1.2) new-of))) (defvar initial-repetition-state '(-1 2.5 nil) "Here -1 = show now, 2.5 is the E-Factor, and nil is the OF-Matrix") (defun determine-next-interval (n ef quality of-matrix) (assert (> n 0)) (assert (and (>= quality 0) (<= quality 5))) (if (< quality 3) (list (inter-repetition-interval n ef) ef nil) (let ((next-ef (modify-e-factor ef quality))) (setq of-matrix (set-optimal-factor n next-ef of-matrix (modify-of (get-optimal-factor n ef of-matrix) quality learning-fraction)) ef next-ef) ;; For a zero-based quality of 4 or 5, don't repeat (if (>= quality 4) (list 0 ef of-matrix) (list (inter-repetition-interval n ef of-matrix) ef of-matrix))))) (defun org-smart-reschedule (quality) (interactive "nHow well did you remember the information (on a scale of 0-5)? ") (let* ((learn-str (org-entry-get (point) "LEARN_DATA")) (learn-data (or (and learn-str (read learn-str)) (copy-list initial-repetition-state))) closed-dates) (save-excursion (goto-char (org-entry-beginning-position)) (let ((end (org-entry-end-position))) (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\\]" end t) (push (org-time-string-to-time (match-string-no-properties 1)) closed-dates)))) (setq learn-data (determine-next-interval (1+ (length closed-dates)) (nth 1 learn-data) quality (nth 2 learn-data))) (org-entry-put (point) "LEARN_DATA" (prin1-to-string learn-data)) (if (= 0 (nth 0 learn-data)) (org-schedule t) (org-schedule nil (time-add (current-time) (days-to-time (nth 0 learn-data))))))) (defun org-agenda-smart-reschedule (&optional arg) "Add a time-stamped note to the entry at point." (interactive "P") (org-agenda-check-no-diary) (let* ((marker (or (org-get-at-bol 'org-marker) (org-agenda-error))) (buffer (marker-buffer marker)) (pos (marker-position marker)) (hdmarker (org-get-at-bol 'org-hd-marker)) (inhibit-read-only t) ts) (with-current-buffer buffer (widen) (goto-char pos) (org-show-context 'agenda) (save-excursion (and (outline-next-heading) (org-flag-heading nil))) ; show the next heading (setq ts (call-interactively 'org-smart-reschedule))) (org-agenda-show-new-time marker ts "S"))) (provide 'org-learn) ;; arch-tag: ;;; org-learn.el ends here --Apple-Mail-6-782629411 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Apple-Mail-6-782629411--