Documentation
¶
Overview ¶
Package learnermodel is NovaTrail's learner model: it estimates how well a learner has mastered each skill of a module from the evidence of finished attempts, and computes each skill's state.
It is a library with no input or output of its own. The api service hands it the evidence and the module's skill graph, keeps the evidence log and the state the library computes from it, and passes the time in as a number; the engine reads that state to pick what comes next. The library picks no lesson or task, gives no verdict, calls no AI model and reads no module package or database.
The state is a fold of the evidence log, so appending a record gives, bit for bit, the state recomputed from the whole log, on any build of one version of this module, WebAssembly included. The code imports nothing but Go's standard library, and only the packages its rules allow.
What the library computes and why is in this repository's docs/architecture.md and docs/decisions.md.
Index ¶
- Constants
- Variables
- func Append(s State, e Evidence, g Graphs) (State, Evidence, error)
- func EncodeEvidence(e Evidence) ([]byte, error)
- func EncodeState(s State) ([]byte, error)
- type AnchorReadout
- type AnchorReason
- type AnchorStatus
- type Assessability
- type Band
- type BandRef
- type CheckKind
- type Evidence
- type FoundTrap
- type Grade
- type Graph
- type Graphs
- type ItemAnswer
- type ItemProbability
- type ModuleGraph
- type ModuleReadout
- type ModuleState
- type Outcome
- type OutcomeKind
- type Provenance
- type Readout
- type RetiredSkill
- type ReviewDate
- type Skill
- type SkillReadout
- type SkillState
- type Slot
- type State
- type Task
- type TaskItem
- type TaskReadout
- type TeacherReadout
- type TrapCount
- type TrialAnswer
- type UnverdictedReason
- type Verdict
Constants ¶
const EvidenceKind = 3
EvidenceKind is the kind of evidence this version writes. It reads every kind up to it, and a later one too, skipping what it does not know. Kind 2 adds LeadingQuestionOnRequest, which kind 1 does not record, and kind 3 LevelSetByAdult, which kinds 1 and 2 do not.
const StateKind = 2
StateKind is the kind of state this version writes. It reads every kind up to it. Kind 2 adds a module's FailuresInARow and TrialEndedByAdult, the state of the guard and of the adult's correction, which kind 1 does not record.
Variables ¶
var ( // ErrInvalid is an input that breaks a rule the library relies on: a duplicate ID, a place // outside the bands, a skill the graph does not know. ErrInvalid = errors.New("learnermodel: invalid input") // ErrCorrupt is bytes that are no encoding of evidence or a state. ErrCorrupt = errors.New("learnermodel: corrupt bytes") // ErrNotFinite is a NaN or an infinity, which the encoding refuses both ways. ErrNotFinite = errors.New("learnermodel: a number that is not finite") )
The kinds of error the library returns, as values and never by panicking. errors.Is tells them apart; the message says where.
Functions ¶
func Append ¶
Append appends a piece of evidence to a state — the cache api keeps — against the graphs of the current versions of the modules, and gives the new state and the evidence with the start band the step took: the module's, when it has a state, and the evidence's own otherwise. api writes both in one transaction. The zero State is the empty one; the state Append gives is of StateKind and shares no memory with s, while the evidence it gives shares e's lists.
The step reads only the graph of the evidence's module, and gives the evidence of a skill that graph retired to each skill that replaced it, in full. A module whose entry says it has no current version moves nothing: its evidence waits in the log. Evidence with no answer moves nothing either, and gives a module no state; nor does evidence whose key or skill tags came from AI, or whose provenance is not given or one this version does not know.
It refuses, with ErrInvalid:
- a state of a kind outside 1 to StateKind, unless it is the zero State, one not in its canonical order, one with a skill of a stability below τ₀, and one EncodeState would refuse;
- evidence of a kind below 1, evidence EncodeEvidence would refuse but for a later kind, and evidence whose task ID names no module, whose task is not of a difficulty from 1 to 5, or whose task band or start band is at a place below 1;
- a choice without its number of options or with fewer than two, an item with reasons of submissions that was never submitted, and an item with an answer, in evidence that weighs, and no slot;
- a module with no entry in g, and a graph whose module is not its entry's, whose lists — its skills, the bands each is taught at, its retired skills and the replacements of each — are not in the order NewGraph gives, or with a retired skill that is still a skill or a replacement that is not one.
func EncodeEvidence ¶
EncodeEvidence gives the bytes of e. It refuses, with ErrInvalid: a kind outside 1 to EvidenceKind; a string that is no UTF-8; a duplicate place, skill or trap; items of the task and answers whose places do not match one for one; a value set without its flag of presence — a rung without HasRung, say; a leading question on request in evidence of kind 1, and a correction in kinds 1 and 2, which do not record them; and a correction with skills, items, traps or the other facts of an attempt, or whose task is not that of LevelCorrection.
func EncodeState ¶
EncodeState gives the bytes of s. It refuses, with ErrNotFinite, a NaN or an infinity, and, with ErrInvalid, a kind outside 1 to StateKind, a string that is no UTF-8, a duplicate module, skill or trap, a mastery band without Mastered, a count of the guard below 0, and, in a state of kind 1, which does not record them, a count of the guard or a trial series ended by an adult.
Types ¶
type AnchorReadout ¶
type AnchorReadout struct {
Anchor string
Status AnchorStatus
Reason AnchorReason
Teachers []TeacherReadout // ordered by skill ID byte by byte
}
AnchorReadout is the status of an anchor skill, with its reason and the skills that teach it.
type AnchorReason ¶
type AnchorReason int32
AnchorReason is why an anchor skill has its status: for AnchorHasNot, not mastered or no evidence; for AnchorUnknown, no one teaches it or only skills that may not be mastered do — without a verdict, or with no band they are taught at, as in a module with no tasks —, which AnchorReasonNoVerdictTeacher names.
const ( AnchorReasonNone AnchorReason = iota AnchorReasonNotMastered AnchorReasonNoEvidence AnchorReasonNoTeacher AnchorReasonNoVerdictTeacher )
type AnchorStatus ¶
type AnchorStatus int32
AnchorStatus is whether a learner has an anchor skill.
const ( AnchorUnspecified AnchorStatus = iota AnchorHas AnchorHasNot AnchorUnknown )
type Assessability ¶
type Assessability int32
Assessability is how the platform can know a learner's command of a skill. Only a skill with AssessabilityVerdict has a state.
const ( AssessabilityUnspecified Assessability = iota AssessabilityVerdict AssessabilityRubric AssessabilityNone )
type Band ¶
type Band struct {
Place int32
ID string
Grades []int32 // the grades the band names, ascending; empty in a module without grades
}
Band is a band of a module's difficulty scale, in the order of the manifest's `bands`.
type BandRef ¶
BandRef names a band of a module's difficulty scale by its place in the `bands` of the module version, from 1, and by its ID in the manifest. The model reads the place; the ID is kept.
func BandByGrade ¶
BandByGrade gives the start band of a module for a learner's grade, from the bands of the version the attempt ran on, in their order: the band whose grades name the grade; for a grade no band names, the band nearest by the distance to its nearest grade, and the lower of two as near; without a grade, or in a module without grades, the first band. api puts it in the evidence it builds, and Append keeps it only for a module with no state yet.
It refuses, with ErrInvalid, no bands, bands out of their places 1, 2, … and a band ID twice, as NewGraph does.
type CheckKind ¶
type CheckKind int32
CheckKind is how the answer in a slot is checked: the kinds that give a verdict. A value this version does not know is kept as its number, and its item reads as one with no answer.
type Evidence ¶
type Evidence struct {
Kind int32
Task Task
StartBand BandRef
Outcome Outcome
// PracticeTime is the time of the attempt's last action, in whole seconds of Unix time, UTC.
PracticeTime int64
TechniqueOnStep bool
TechniqueOnRequest bool
// LeadingQuestionOnRequest is whether a hint the learner asked for gave the task's leading
// question, which a hint gives only before the first wrong answer. Kind 1 does not record it, and
// it is false there.
LeadingQuestionOnRequest bool
ExplainAgainCount int32
SolutionSeenBefore bool
HasSolutionSeenFact bool // false for a template, whose instances differ
// Items holds what happened to each item; the slots and the item's own skills are in Task.
Items []ItemAnswer
Traps []FoundTrap // ordered by ID byte by byte
// LevelSetByAdult tells that the evidence is no attempt but an adult's correction of the
// module's level, as LevelCorrection gives it. Kinds 1 and 2 do not record it, and it is
// false there.
LevelSetByAdult bool
}
Evidence is the evidence of one finished attempt: its observations, not the model's conclusions, so that a later version recomputes the state from it.
func DecodeEvidence ¶
DecodeEvidence reads evidence from b, of any kind from 1: a later kind too.
func LevelCorrection ¶ added in v0.1.13
LevelCorrection gives the evidence of an adult's correction of the level of a module, by its full ID: the band the adult set, by its place and ID in the module's current version, at a time in whole seconds of Unix time, UTC, with the start band api gives any evidence of the module, by BandByGrade. Append sets the module's level in that band in one step, or keeps it when it stands there already, ends the trial series and starts the guard's count anew, so that a repeat changes nothing; a band above the version's highest is the highest. Its task is no task: its ID is `<module>/level/<band ID>`, its band the band set and its difficulty 3, the band's middle, where the level goes, and the adult its provenance; it has no skills and no items, so that a version before kind 3, which does not know LevelSetByAdult, reads it as evidence with no answer, which moves nothing.
type FoundTrap ¶
type FoundTrap struct {
ID string
Skills []string // its skills in the trap catalog of the attempt's version, by full ID
ItemPlaces []int32 // where it was found, ascending
}
FoundTrap is a trap the program found in the attempt by a wrong value.
type Grade ¶
Grade is a learner's school grade, or no grade: Known is false for a learner without one, and Value is then 0. "No grade" is a case of its own, not grade 0.
type Graph ¶
type Graph struct {
Module string
Bands []Band // by place, from 1
Skills []Skill // ordered by ID byte by byte
Retired []RetiredSkill // ordered by ID byte by byte
}
Graph is the graph of one version of a module, as the model and the engine read it.
func NewGraph ¶
func NewGraph(module string, bands []Band, skills []Skill, retired []RetiredSkill, tasks []Task) (Graph, error)
NewGraph builds the graph of a module version from its bands, its skills, its retired skills and the descriptions of its tasks, so that api and sim build one graph of one module alike. It derives each skill's BandsTaught — the BandsTaught given is ignored — and orders every list canonically. It copies what it is given: the graph shares nothing with its input.
A skill is taught at the band of a task where it is a primary skill of an item: of the item's own skills, or of the task's for an item without its own, or for a task without items.
It refuses, with ErrInvalid: bands out of their places 1, 2, …; a duplicate band, skill or retired ID, and an ID or grade twice in one list; a retired ID that is a skill; a replacement or a primary skill of a task or an item the module does not have; a task band outside the bands or whose ID is not the ID of the band at its place; and a difficulty outside 1 to 5.
type Graphs ¶
type Graphs map[string]ModuleGraph
Graphs gives each module the graph of its current version, by the module's full ID. The model looks modules up in it and never ranges over it, so its order cannot matter.
type ItemAnswer ¶
type ItemAnswer struct {
Place int32
Submitted bool
// Unverdicted is why each submission before the first verdict gave none, in their order.
Unverdicted []UnverdictedReason
// FirstVerdict is the item's first verdict, when HasFirstVerdict, and WrongBeforeFirst the
// number of wrong answers in the attempt before the submission that gave it.
FirstVerdict Verdict
HasFirstVerdict bool
WrongBeforeFirst int32
// FinalVerdict is the item's verdict at the end, when HasFinalVerdict.
FinalVerdict Verdict
HasFinalVerdict bool
// WrongBeforeFirstCorrect is the number of wrong answers in the attempt before the item's
// first correct verdict, when HasFirstCorrect.
WrongBeforeFirstCorrect int32
HasFirstCorrect bool
}
ItemAnswer is what happened to one item in the attempt, by its place.
type ItemProbability ¶
ItemProbability is the probability of a right answer to an item of a candidate task at t₀: Probability, when HasVerdict; an item without a verdict has none.
type ModuleGraph ¶
ModuleGraph is the entry of a module in Graphs: the graph of its current version, or no current version, when Current is false and Graph is empty.
type ModuleReadout ¶
type ModuleReadout struct {
Module string
// HasEvidence is false for a module of the engine with no evidence yet, whose StartBand is
// then the band of the learner's grade, BandByGrade, the starting point a band below it, or the
// zero BandRef when the module's current version has no bands.
HasEvidence bool
StartBand BandRef
// LevelBand is the band the module's level stands in, by the bands of its current version — of
// the starting point for a module with no evidence —: the band whose middle task is nearest the
// level, the highest band when the level is above it. HasLevelBand is false, and LevelBand
// the zero BandRef, when the level is more than half a band below the lowest band, as it starts
// for a learner of that band's grades, and when the module has no current version or one with no
// bands. An adult's correction sets the level in the band it names, where the next evidence
// moves it on; that the band is next to this one is for api to check.
LevelBand BandRef
HasLevelBand bool
// TrialOver tells whether the module's trial series is over, and LastInTrial whether the last
// evidence that moved the module was still in it, the evidence that ended it too.
// Both are false before the module's first evidence.
TrialOver bool
LastInTrial bool
// Traps are the traps the program found that have no skill with a state, counted
// at the module.
Traps []TrapCount
Skills []SkillReadout // ordered by skill ID byte by byte
}
ModuleReadout is what reading gives of a module.
type ModuleState ¶
type ModuleState struct {
Module string
Level float64 // θ
AnswerWeight float64 // n
StartBand BandRef
Trial []TrialAnswer // in the order of the log, while the trial series lasts
Traps []TrapCount // the traps with no skill that has a state
Skills []SkillState // ordered by skill ID byte by byte
// LastInTrial tells whether the last piece of evidence that moved the module was still in the
// trial series, the one that ended it too: that one clears the series' answers, and the engine
// still needs to know. Evidence that moves nothing leaves it as it is.
LastInTrial bool
// FailuresInARow is the count of the guard: the pieces of evidence in a row, past the
// trial series, on which the model expected the learner to know at least half of the answers,
// above the guessing floor, and fewer than half of the items with an answer were solved at the
// end of the attempt. The third lowers the level by a band; the count goes on until a piece of
// evidence that is no such failure.
FailuresInARow int32
// TrialEndedByAdult tells whether an adult's correction of the level ended the trial series
// before its five answers: the series is then over whatever the weight of answers.
TrialEndedByAdult bool
}
ModuleState is the state of a learner in one module.
type Outcome ¶
type Outcome struct {
Kind OutcomeKind
Rung int32
HasRung bool
}
Outcome is the outcome of an attempt, with the rung of the hint after which it ended, when HasRung: from 1, for OutcomeAfterHint.
type OutcomeKind ¶
type OutcomeKind int32
OutcomeKind is how an attempt ended. A value this version does not know is kept as its number and weighs nothing.
const ( OutcomeUnspecified OutcomeKind = iota OutcomeFirstSubmission OutcomeAfterHint OutcomeWithSketch OutcomeSolutionShown OutcomeLeftUnfinished OutcomeUnchecked )
type Provenance ¶
type Provenance int32
Provenance is where a key or the skill tags of a task came from.
const ( ProvenanceUnspecified Provenance = iota ProvenanceAuthor ProvenanceSolver ProvenanceAdult ProvenanceAI )
type Readout ¶
type Readout struct {
Modules []ModuleReadout // ordered by module ID byte by byte
Anchors []AnchorReadout // ordered by anchor ID byte by byte
// contains filtered or unexported fields
}
Readout is what reading the state at t₀ gives. It keeps what Task needs: a copy of the state, the graphs, t₀ and the grade.
func Read ¶
Read reads a state — the cache api keeps — at the time at, in whole seconds of Unix time, UTC, for a learner of a grade, against the graphs of the current versions of the modules and the modules of the engine: those connected and fit for the learner, whose graphs the engine gets. g gives an entry to every module of the state and of the engine; the Readout keeps g for Task, and the caller changes neither while it reads.
Modules are the modules of the state and of the engine. A module with a state gives its start band, the two flags of the trial series and its skills; a module of the engine with no state and a current version gives the starting point by the grade, BandByGrade, or none when that version has no bands, as a module with no tasks may have none; one with neither is left out. Anchors are the anchor skills a graph of a module of the engine names as a prerequisite or a skill it teaches, each with its status: held, when a skill that teaches it is mastered in any of the modules with a current version; otherwise not held, when a skill of the engine's modules that may be mastered teaches it — a skill with a verdict and a band it is taught at —, not mastered when one of them has answers, no evidence otherwise; and unknown otherwise: no one teaches it, or only skills that may not be mastered do. A module with no current version gives no graph, so its mastery is not seen.
It refuses, with ErrInvalid, a state Append would refuse, a module of the engine twice or not named by the full ID of a module, a module with no entry in g, a graph Append would refuse, and bands, other than none, that BandByGrade would refuse.
func (Readout) Task ¶
func (r Readout) Task(t Task) (TaskReadout, error)
Task gives the probability of a right answer to each item of a candidate task at the time of reading, by place: the P the step would take of evidence at that time, by the same function — with the retention of the item's skills at t₀, and without it, R̄ = 1, while the module's trial series lasts. A module with no state starts at the starting point by the grade. An item with no slot, or with one of a kind of check this version does not know, has no verdict and so no P. The provenance of the task's key and skill tags does not change P: evidence that weighs nothing by it moves nothing, but the chance of a right answer is the same.
It refuses, with ErrInvalid, a task the codec would refuse, one whose ID names no module, one not of a difficulty from 1 to 5 or at a band place below 1, a choice without its number of options or with fewer than two, a module with no entry in the graphs or with no current version, a graph Append would refuse, bands BandByGrade would, and a module with no state whose current version has no bands: a task of it would have none to be in.
It copies nothing it need not: tags and items already in their order are read as they are, and R at t₀ and the start of a module Read has read come from Read.
type RetiredSkill ¶
RetiredSkill is an entry of `retired_skills`: a skill of an earlier version of the module and the skills of this one that replaced it. An empty ReplacedBy is `[]`: no skill took over.
type ReviewDate ¶
ReviewDate is when a mastered skill is due for review: At, in whole seconds of Unix time, UTC, or Already, when it is due whatever the time.
type Skill ¶
type Skill struct {
ID string
Assessability Assessability
Teaches []string // the anchor skills it teaches, `core.<name>`, ordered byte by byte
// BandsTaught is the places of the bands where the skill is taught: the bands of the tasks
// where it is a primary skill of the task or of an item, ascending. NewGraph derives it.
BandsTaught []int32
Prerequisites []string // skills of the module by full ID and anchor skills; the engine reads them
Tier int32 // the skill's tier, `skill_tiers` of the server part; the engine reads it
}
Skill is a skill of a module's graph, by its full ID.
type SkillReadout ¶
type SkillReadout struct {
Skill string
EvidenceCount int64
LastPractice int64
Estimate float64 // θ + δ
Uncertainty float64 // v
Retention float64 // R at t₀
Traps []TrapCount
// For a mastered skill: its mastery band — the ID from the graph of the module's current
// version, empty without one —, the cautious probability with retention at t₀, R · q, and
// the review date. Zero while the skill is not mastered.
Mastered bool
MasteryBand BandRef
CautiousProbability float64
Review ReviewDate
}
SkillReadout is what reading gives of a skill with practice.
type SkillState ¶
type SkillState struct {
Skill string
Correction float64 // δ
AnswerWeight float64 // m
EvidenceCount int64
LastPractice int64 // whole seconds of Unix time, UTC
Stability float64 // τ, in days
Traps []TrapCount
// MasteryBand is the place of the mastery band, when Mastered.
MasteryBand int32
Mastered bool
FailuresInARow int32
}
SkillState is the state of one skill of the module whose assessability is verdict.
type Slot ¶
type Slot struct {
Check CheckKind
// Options is the number of options of a choice, and is meaningful only when HasOptions.
Options int32
HasOptions bool
}
Slot is an answer slot of an item, as the model needs it for the guessing of the item.
type State ¶
type State struct {
Kind int32
Modules []ModuleState // ordered by module ID byte by byte
}
State is the state of one learner: the fold of the evidence log.
func Recompute ¶
Recompute folds the evidence log, in the order of its numbers, from the empty state, against the graphs of the current versions of the modules: Append of each piece of evidence in turn. Its errors are Append's, with the index of the evidence in log, from 0. It checks the graph of each module once.
type Task ¶
type Task struct {
ID string // the full ID of the task; of a template, of the template
Template bool
Band BandRef
Difficulty int32 // from 1 to 5
Primary []string
Supporting []string // full IDs or anchor skills, `core.<name>`
// KeyProvenance and SkillTagsProvenance are where the key and the skill tags came from.
KeyProvenance Provenance
SkillTagsProvenance Provenance
Items []TaskItem // by place
}
Task describes a task, the same for evidence and for a candidate task of the engine.
type TaskItem ¶
type TaskItem struct {
Place int32
// OwnSkills tells whether the item names skills of its own, Primary and Supporting, which take
// the place of the task's for it.
OwnSkills bool
Primary []string
Supporting []string
Slots []Slot // in their order
}
TaskItem is an item of a task, by its place, from 1.
type TaskReadout ¶
type TaskReadout struct {
Items []ItemProbability
}
TaskReadout is what Readout.Task gives of a candidate task: the P of each item, by place.
type TeacherReadout ¶
type TeacherReadout struct {
Skill string
HighestBand BandRef
Practised bool
Estimate float64
Mastered bool
MasteryBand BandRef
Retention float64
Review ReviewDate
}
TeacherReadout is a skill that teaches an anchor skill, as reading gives it with the anchor: the highest band it is taught at — Place 0 when there is none —, and, when Practised, its estimate, mastery, retention at t₀ and review date, as its SkillReadout has them.
type TrapCount ¶
TrapCount is a trap the program found, with the number of pieces of evidence it was found in and the practice time of the latest.
type TrialAnswer ¶
type TrialAnswer struct {
BandPlace int32
Difficulty int32
Slots []Slot
Verdict Verdict
Weight float64 // u, the answer's weight in its series
}
TrialAnswer is one answer of the trial series, as its likelihood needs it.
type UnverdictedReason ¶
type UnverdictedReason int32
UnverdictedReason is why a submission gave no verdict.
const ( UnverdictedUnspecified UnverdictedReason = iota UnverdictedUnreadableBlank UnverdictedUnreadableOther UnverdictedUnchecked )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package detmath is the arithmetic of the learner model that package math would give differently on different builds: exp, log, the logistic function σ, a power and the retention of a skill.
|
Package detmath is the arithmetic of the learner model that package math would give differently on different builds: exp, log, the logistic function σ, a power and the retention of a skill. |
|
internal
|
|
|
wire
Package wire writes and reads the binary form of protobuf, the part of it the schema of learner-model uses, on Go's standard library alone: varints, 64-bit fixed numbers in little-endian, and length-delimited strings, messages and packed lists.
|
Package wire writes and reads the binary form of protobuf, the part of it the schema of learner-model uses, on Go's standard library alone: varints, 64-bit fixed numbers in little-endian, and length-delimited strings, messages and packed lists. |