emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Wiegley <jwiegley@gmail.com>
To: Richard Riley <rileyrgdev@googlemail.com>
Cc: Org-mode Mode <emacs-orgmode@gnu.org>
Subject: Re: New module: org-learn, incremental reading
Date: Sun, 25 Oct 2009 17:49:08 -0400	[thread overview]
Message-ID: <EA94433A-5CA6-4975-9C37-39A4E075FD23@gmail.com> (raw)
In-Reply-To: <4ae4c751.1438560a.579a.ffffea34@mx.google.com>

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

On Oct 25, 2009, at 5:46 PM, Richard Riley wrote:

> Just trying this and got
>
> org-smart-reschedule: Symbol's value as variable is void:
> learning-fraction
>
> when I enter 0-3. It worked with 5.

Attached is an updated version.

John


[-- Attachment #2: org-learn.el --]
[-- Type: application/octet-stream, Size: 6088 bytes --]

;;; org-learn.el --- Implements SuperMemo's incremental learning algorithm

;; Copyright (C) 2009
;;   Free Software Foundation, Inc.

;; Author: John Wiegley <johnw at gnu dot org>
;; 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 <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; 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-learn-always-reschedule nil
  "If non-nil, always reschedule items, even if retention was \"perfect\"."
  :type 'boolean
  :group 'org-learn)

(defcustom org-learn-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)

(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 1 2.5 nil))

(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) (1+ n) 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 org-learn-fraction))
	    ef next-ef)
      ;; For a zero-based quality of 4 or 5, don't repeat
      (if (and (>= quality 4)
	       (not org-learn-always-reschedule))
	  (list 0 (1+ n) ef of-matrix)
	(list (inter-repetition-interval n ef of-matrix) (1+ n)
	      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)
    (setq learn-data
	  (determine-next-interval (nth 1 learn-data)
				   (nth 2 learn-data)
				   quality
				   (nth 3 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)))))))

(provide 'org-learn)

;; arch-tag: 

;;; org-learn.el ends here

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




[-- Attachment #4: Type: text/plain, Size: 204 bytes --]

_______________________________________________
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

  parent reply	other threads:[~2009-10-25 21:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21  8:53 New module: org-learn, incremental reading John Wiegley
2009-10-21 12:23 ` Russell Adams
2009-10-21 13:58 ` Bill Powell
2009-10-21 22:44   ` John Wiegley
2009-10-24 14:36   ` Richard KLINDA
2009-10-21 20:26 ` Quintana Seguí, Pere
2009-10-24 14:32 ` Richard KLINDA
2009-10-25 16:04 ` Huang Tao
2009-10-25 20:51   ` John Wiegley
     [not found]     ` <4ae4c751.1438560a.579a.ffffea34@mx.google.com>
2009-10-25 21:49       ` John Wiegley [this message]
2009-10-27 15:47         ` Jonathan Arkell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EA94433A-5CA6-4975-9C37-39A4E075FD23@gmail.com \
    --to=jwiegley@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=rileyrgdev@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).