Megrez v1.1.3 // Nerf the additional weights to the balanced score.

This commit is contained in:
ShikiSuen 2022-05-22 08:37:22 +08:00
parent ba595c475e
commit 0bcaa61656
3 changed files with 22 additions and 15 deletions

View File

@ -193,8 +193,7 @@ extension Megrez {
//
//
if balanced {
let weightedScore: Double = (Double(n.spanningLength) - 1) * 2
n.accumulatedScore += weightedScore
n.accumulatedScore += n.additionalWeights
}
var path: [NodeAnchor] = reverseWalk(

View File

@ -204,33 +204,33 @@ extension Megrez {
extension Megrez.Grid {
public var dumpDOT: String {
var sst = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n"
var strOutput = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n"
for (p, span) in mutSpans.enumerated() {
for ni in 0...(span.maximumLength) {
guard let np: Megrez.Node = span.node(length: ni) else {
continue
}
if p == 0 {
sst += "BOS -> \(np.currentKeyValue.value);\n"
strOutput += "BOS -> \(np.currentKeyValue.value);\n"
}
sst += "\(np.currentKeyValue.value);\n"
strOutput += "\(np.currentKeyValue.value);\n"
if (p + ni) < mutSpans.count {
let dstSpan = mutSpans[p + ni]
for q in 0...(dstSpan.maximumLength) {
if let dn = dstSpan.node(length: q) {
sst += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n"
let destinatedSpan = mutSpans[p + ni]
for q in 0...(destinatedSpan.maximumLength) {
if let dn = destinatedSpan.node(length: q) {
strOutput += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n"
}
}
}
if (p + ni) == mutSpans.count {
sst += np.currentKeyValue.value + " -> EOS;\n"
strOutput += np.currentKeyValue.value + " -> EOS;\n"
}
}
}
sst += "EOS;\n}\n"
return sst
strOutput += "EOS;\n}\n"
return strOutput
}
}

View File

@ -52,11 +52,19 @@ extension Megrez {
return stream
}
///
public var additionalWeights: Double {
(Double(spanningLength) - 1) * 0.75
}
///
public var balancedScore: Double {
let weightedScore: Double = (Double(spanningLength) - 1) * 2
let nodeScore: Double = node?.score ?? 0
return weightedScore + nodeScore
(node?.score ?? 0) + additionalWeights
}
///
public var balancedAccumulatedScore: Double {
accumulatedScore + additionalWeights
}
}
}