You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('') and can be up to 35 characters long.
177 lines
5.9 KiB
177 lines
5.9 KiB
;;; orglearn.el  Implements SuperMemo's incremental learning algorithm




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




;; Author: John Wiegley <johnw at gnu dot org>


;; Keywords: outlines, hypermedia, calendar, wp


;; Homepage: http://orgmode.org


;; Version: 6.32trans


;;


;; This file is not 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)


(evalwhencompile


(require 'cl))




(defgroup orglearn nil


"Options concerning the learning code in Orgmode."


:tag "Org Learn"


:group 'orgprogress)




(defcustom orglearnalwaysreschedule nil


"If nonnil, always reschedule items, even if retention was \"perfect\"."


:type 'boolean


:group 'orglearn)




(defcustom orglearnfraction 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 'orglearn)




(defun initialoptimalfactor (n ef)


(if (= 1 n)


4


ef))




(defun getoptimalfactor (n ef ofmatrix)


(let ((factors (assoc n ofmatrix)))


(or (and factors


(let ((efof (assoc ef (cdr factors))))


(and efof (cdr efof))))


(initialoptimalfactor n ef))))




(defun setoptimalfactor (n ef ofmatrix of)


(let ((factors (assoc n ofmatrix)))


(if factors


(let ((efof (assoc ef (cdr factors))))


(if efof


(setcdr efof of)


(push (cons ef of) (cdr factors))))


(push (cons n (list (cons ef of))) ofmatrix)))


ofmatrix)




(defun interrepetitioninterval (n ef &optional ofmatrix)


(let ((of (getoptimalfactor n ef ofmatrix)))


(if (= 1 n)


of


(* of (interrepetitioninterval (1 n) ef ofmatrix)))))




(defun modifyefactor (ef quality)


(if (< ef 1.3)


1.3


(+ ef ( 0.1 (* ( 5 quality) (+ 0.08 (* ( 5 quality) 0.02)))))))




(defun modifyof (of q fraction)


(let ((temp (* of (+ 0.72 (* q 0.07)))))


(+ (* ( 1 fraction) of) (* fraction temp))))




(defun calculatenewoptimalfactor (intervalused quality usedof


oldof fraction)


"This implements the SM5 learning algorithm in Lisp.


INTERVALUSED is the last interval used for the item in question.


QUALITY is the quality of the repetition response.


USEDOF is the optimal factor used in calculation of the last


interval used for the item in question.


OLDOF is the previous value of the OF entry corresponding to the


relevant repetition number and the EFactor 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+ intervalused) intervalused))


;; the value proposed for the modifier in case of q=2


(mod2 (/ (1 intervalused) intervalused))


;; 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 newof (* usedof modifier))


(if (> quality 4)


(if (< newof oldof)


(setq newof oldof)))


(if (< quality 4)


(if (> newof oldof)


(setq newof oldof)))


(setq newof (+ (* newof fraction) (* oldof ( 1 fraction))))


(if (< newof 1.2)


(setq newof 1.2)


newof)))




(defvar initialrepetitionstate '(1 1 2.5 nil))




(defun determinenextinterval (n ef quality ofmatrix)


(assert (> n 0))


(assert (and (>= quality 0) (<= quality 5)))


(if (< quality 3)


(list (interrepetitioninterval n ef) (1+ n) ef nil)


(let ((nextef (modifyefactor ef quality)))


(setq ofmatrix


(setoptimalfactor n nextef ofmatrix


(modifyof (getoptimalfactor n ef ofmatrix)


quality orglearnfraction))


ef nextef)


;; For a zerobased quality of 4 or 5, don't repeat


(if (and (>= quality 4)


(not orglearnalwaysreschedule))


(list 0 (1+ n) ef ofmatrix)


(list (interrepetitioninterval n ef ofmatrix) (1+ n)


ef ofmatrix)))))




(defun orgsmartreschedule (quality)


(interactive "nHow well did you remember the information (on a scale of 05)? ")


(let* ((learnstr (orgentryget (point) "LEARN_DATA"))


(learndata (or (and learnstr


(read learnstr))


(copylist initialrepetitionstate)))


closeddates)


(setq learndata


(determinenextinterval (nth 1 learndata)


(nth 2 learndata)


quality


(nth 3 learndata)))


(orgentryput (point) "LEARN_DATA" (prin1tostring learndata))


(if (= 0 (nth 0 learndata))


(orgschedule t)


(orgschedule nil (timeadd (currenttime)


(daystotime (nth 0 learndata)))))))




(provide 'orglearn)




;;; orglearn.el ends here


