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 { if balanced {
let weightedScore: Double = (Double(n.spanningLength) - 1) * 2 n.accumulatedScore += n.additionalWeights
n.accumulatedScore += weightedScore
} }
var path: [NodeAnchor] = reverseWalk( var path: [NodeAnchor] = reverseWalk(

View File

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

View File

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