fix: temporary memoryの更新ロジックのバグを修正 (#81)

* fix: temporary memoryの更新ロジックのバグを修正

* unnecessary diff
This commit is contained in:
Miwa / Ensan
2024-04-22 00:30:51 +09:00
committed by GitHub
parent a5e794d858
commit b5f634f45e

View File

@@ -524,14 +524,16 @@ struct TemporalLearningMemoryTrie {
if let dataIndex = nodes[index].dataIndices.first(where: {Self.sameDicdataIfRubyIsEqual(left: self.dicdata[$0], right: dicdataElement)}) {
withMutableValue(&self.metadata[dataIndex]) {
$0.count += min(.max - $0.count, 1)
// 200
$0.lastUsedDay = day
}
// adjust
self.dicdata[dataIndex].adjust = LongTermLearningMemory.valueForData(metadata: self.metadata[dataIndex], dicdata: dicdataElement) - dicdataElement.baseValue
} else {
let dataIndex = self.dicdata.endIndex
var dicdataElement = dicdataElement
let metadataElement = MetadataElement(day: day, count: 1)
dicdataElement.baseValue = LongTermLearningMemory.valueForData(metadata: metadataElement, dicdata: dicdataElement)
// adjust
dicdataElement.adjust = LongTermLearningMemory.valueForData(metadata: metadataElement, dicdata: dicdataElement) - dicdataElement.baseValue
self.dicdata.append(dicdataElement)
self.metadata.append(metadataElement)
nodes[index].dataIndices.append(dataIndex)
@@ -723,6 +725,10 @@ final class LearningManager {
if var newFirstClause = firstClause {
if var newSecondClause = secondClause {
if DicdataStore.isClause(newFirstClause.rcid, datum.lcid) {
// indexcontinue
guard data.endIndex <= index else {
continue
}
// firstClausesecondClause, bigram
let element = DicdataElement(
word: newFirstClause.word + newSecondClause.word,
@@ -735,10 +741,6 @@ final class LearningManager {
// firstClause
firstClause = secondClause
secondClause = datum
// indexcontinue
guard data.endIndex <= index else {
continue
}
guard let chars = Self.keyToChars(element.ruby, char2UInt8: char2UInt8) else {
continue
}