truelearn.models.HistoryAwareKnowledgeComponent#

class truelearn.models.HistoryAwareKnowledgeComponent(*args, **kwds)[source]#

Bases: KnowledgeComponent

A knowledge component that keeps a history about how it was updated.

Examples

>>> from truelearn.models import HistoryAwareKnowledgeComponent
>>> hkc = HistoryAwareKnowledgeComponent(mean=0.0, variance=1.0)
>>> hkc
HistoryAwareKnowledgeComponent(mean=0.0, variance=1.0, timestamp=None, title=None, description=None, url=None, history=deque([], maxlen=None))
>>> # update the mean and variance of the hkc
>>> hkc.update(mean=1.0, variance=2.0)
>>> hkc
HistoryAwareKnowledgeComponent(mean=1.0, variance=2.0, timestamp=None, title=None, description=None, url=None, history=deque([(0.0, 1.0, None)], maxlen=None))
>>> # clone the history aware knowledge component with given mean and variance
>>> hkc.clone(mean=2.0, variance=3.0)
HistoryAwareKnowledgeComponent(mean=2.0, variance=3.0, timestamp=None, title=None, description=None, url=None, history=deque([(0.0, 1.0, None)], maxlen=None))

Attributes

description#

The description of the knowledge component.

Type:

Optional[str]

history#

The update history of the current knowledge component.

Type:

Deque[Tuple[float, float, Optional[float]]]

mean#

The mean of the knowledge component.

Type:

float

timestamp#

The POSIX timestamp of when the knowledge component was last updated.

Type:

Optional[float]

title#

The title of the knowledge component.

Type:

Optional[str]

url#

The url of the knowledge component.

Type:

Optional[str]

variance#

The variance of the knowledge component.

Type:

float

Methods

__init__(*, mean, variance[, timestamp, ...])

Init the KnowledgeComponent object.

clone(*, mean, variance[, timestamp])

Generate a copy of the current knowledge component with given mean, variance and timestamp.

export_as_dict()

Export the knowledge component into a dictionary.

update(*[, mean, variance, timestamp])

Update the mean, variance, and timestamp of the current knowledge component.

__init__(*, mean: float, variance: float, timestamp: Optional[float] = None, title: Optional[str] = None, description: Optional[str] = None, url: Optional[str] = None, history_limit: Optional[int] = None, history: Optional[Deque[Tuple[float, float, Optional[float]]]] = None) None[source]#

Init the KnowledgeComponent object.

Parameters:
  • mean – A float indicating the mean of the knowledge component.

  • variance – A float indicating the variance of the knowledge component.

  • timestamp – A float indicating the POSIX timestamp of the last update of the knowledge component.

  • title – An optional string storing the title of the knowledge component.

  • description – An optional string that describes the knowledge component.

  • url – An optional string storing the url of the knowledge component.

  • history_limit – A positive int that specifies the number of entries stored in the history. If the limit is None, it means there is no limit.

  • history – A queue that stores the update history of the knowledge component. Each entry in the queue is a tuple (mean, variance, timestamp) which records the mean and variance of this knowledge component at the given timestamp.

Returns:

None.

clone(*, mean: float, variance: float, timestamp: Optional[float] = None) Self[source]#

Generate a copy of the current knowledge component with given mean, variance and timestamp.

Parameters:
  • * – Use to reject positional arguments.

  • mean – The new mean of the KnowledgeComponent.

  • variance – The new variance of the KnowledgeComponent.

  • timestamp – An optional new POSIX timestamp of the KnowledgeComponent. If None is given, the timestamp of the cloned knowledge component is assigned to None.

Returns:

A cloned knowledge component with given mean, variance and timestamp.

export_as_dict() Dict[str, Any][source]#

Export the knowledge component into a dictionary.

Returns:

A dictionary mapping the name of the variables to their value.

update(*, mean: Optional[float] = None, variance: Optional[float] = None, timestamp: Optional[float] = None) None[source]#

Update the mean, variance, and timestamp of the current knowledge component.

If the given parameters are None, the corresponding attributes of the current knowledge component will not be updated.

Parameters:
  • * – Use to reject positional arguments.

  • mean – The new mean of the knowledge component.

  • variance – The new variance of the knowledge component.

  • timestamp – The new POSIX timestamp that indicates the update time of the knowledge component.

Returns:

None.