Skip to content

Commit

Permalink
CMTutor - limit path finding algorithm search depth
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRibakov committed Jun 7, 2018
1 parent 3132966 commit 0298727
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public PathFinder(StudentActionsModel model)
/// List of PathInfo objects that contain info about destination nodes that paths could be found to and
/// maximum possible path confidence.
/// </returns>
public List<PathInfo> Find(string fromNodeKey, HashSet<string> targetNodeKeys)
public List<PathInfo> Find(string fromNodeKey, HashSet<string> targetNodeKeys, int searchDepth)
{
// Init the finder
PathInfo p = new PathInfo(fromNodeKey, fromNodeKey, 0, 1);
Queue<PathInfo> toExplore = new Queue<PathInfo>();
toExplore.Enqueue(p);

List<PathInfo> pathsToTargets = ExplorePaths(toExplore, targetNodeKeys);
List<PathInfo> pathsToTargets = ExplorePaths(toExplore, targetNodeKeys, searchDepth);

return pathsToTargets;
}
Expand All @@ -49,7 +49,7 @@ public List<PathInfo> Find(string fromNodeKey, HashSet<string> targetNodeKeys)
/// <param name="targetNodeKeys"></param>
/// <param name="pathConfThreshold"></param>
/// <returns></returns>
private List<PathInfo> ExplorePaths(Queue<PathInfo> toExplore, HashSet<string> targetNodeKeys)
private List<PathInfo> ExplorePaths(Queue<PathInfo> toExplore, HashSet<string> targetNodeKeys, int searchDepth)
{
double allPathConfidenceSum = 1;
List<PathInfo> pathsToTargets = new List<PathInfo>();
Expand All @@ -69,15 +69,23 @@ private List<PathInfo> ExplorePaths(Queue<PathInfo> toExplore, HashSet<string> t
// Create + enqueue PathInfo for all transitions
foreach (Arc<State, Event> transition in node.OutArcs.Values)
{
if (pathInfo.Visited(transition.Key.ToString()))
{
continue;
}
else
if (!pathInfo.Visited(transition.Key.ToString()))
{
string nextNodeKey = model.GetInStateKey(transition);
Node<State, Event> nextNode = model.GetState(nextNodeKey);
int length = pathInfo.PathLength + 1;
int length = pathInfo.PathLength;

// Only count correct states to determine search depth (prevents depth inflation by multiple errors states attached to a single action)
if (nextNode.Specification.GetType() == typeof(CorrectState))
{
length += 1;
}

if (length > searchDepth)
{
continue;
}

double newPathConfidence = pathInfo.PathConfidence * model.GetEventConfidence(transition);

// Replace old path condifence with the sum of confidences of all child paths
Expand Down Expand Up @@ -119,11 +127,10 @@ public Dictionary<string, double> AddPathConfidenceByTarget(List<PathInfo> paths
}

public Dictionary<string, double> FindPathsAboveThreshold(string fromNodeKey, HashSet<string> targetNodeKeys,
double pathConfThreshold)
double pathConfThreshold, int searchDepth)
{
Dictionary<string, double> results = new Dictionary<string, double>();
// List<PathInfo> allPathsToTargets = Find(fromNodeKey, targetNodeKeys, pathConfThreshold);
List<PathInfo> allPathsToTargets = Find(fromNodeKey, targetNodeKeys);
List<PathInfo> allPathsToTargets = Find(fromNodeKey, targetNodeKeys, searchDepth);
Dictionary<string, double> totalPathConfidencesByTarget = AddPathConfidenceByTarget(allPathsToTargets);

foreach (string key in totalPathConfidencesByTarget.Keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void GetRelevantErrorPreventionMessages(string actionName, string domain

PathFinder pf = new PathFinder(sbpControl.GetStudentActionsModel(domainName, CLUSTER_METHOD, studentKey));
Dictionary<string, double> reStatePathConfidences =
pf.FindPathsAboveThreshold(lastState.Key, reStateKeys, _config.NoErrorPreventionConfidenceThreshold);
pf.FindPathsAboveThreshold(lastState.Key, reStateKeys, _config.NoErrorPreventionConfidenceThreshold, _config.ErrorPreventionSearchDepthLimit);

// Add messages of the right level of detail to the output container
foreach (string targetStateKey in reStatePathConfidences.Keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void TestDomain1Graph1PathFinding()
// Check probable errors from Initial State
PathFinder pf = new PathFinder(sam);
Dictionary<string, double> reStatePathConfidences =
pf.FindPathsAboveThreshold(initState.Key, reStateKeys, noErrorPreventionConfidenceThreshold);
pf.FindPathsAboveThreshold(initState.Key, reStateKeys, noErrorPreventionConfidenceThreshold, 10);

Assert.AreEqual(2, reStatePathConfidences.Count);
Assert.That(reStatePathConfidences["f0t4_f0t3_RelevantErrors"], Is.EqualTo(0.6).Within(Util.DOUBLE_PRECISION));
Expand Down Expand Up @@ -511,13 +511,13 @@ public void TestDomain1Graph2PathFinding()
// Check probable errors from Initial State
PathFinder pf = new PathFinder(sam);
Dictionary<string, double> reStatePathConfidences =
pf.FindPathsAboveThreshold(initState.Key, reStateKeys, noErrorPreventionConfidenceThreshold);
pf.FindPathsAboveThreshold(initState.Key, reStateKeys, noErrorPreventionConfidenceThreshold, 10);

Assert.AreEqual(1, reStatePathConfidences.Count);
Assert.That(reStatePathConfidences["f0t4_f0t3_RelevantErrors"], Is.EqualTo(0.6).Within(Util.DOUBLE_PRECISION));

// Check probable errors from f0t4_CorrectFlow
reStatePathConfidences = pf.FindPathsAboveThreshold("f0t4_CorrectFlow", reStateKeys, noErrorPreventionConfidenceThreshold);
reStatePathConfidences = pf.FindPathsAboveThreshold("f0t4_CorrectFlow", reStateKeys, noErrorPreventionConfidenceThreshold, 10);

Assert.AreEqual(2, reStatePathConfidences.Count);
Assert.That(reStatePathConfidences["f0t4_f0t3_RelevantErrors"], Is.EqualTo(1).Within(Util.DOUBLE_PRECISION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<add key="MediumDetailErrorPreventionConfidenceThreshold" value="0.5"/>
<add key="NoErrorPreventionIEConfidenceThreshold" value="0.5"/>
<add key="NoErrorPreventionIERepetitionThreshold" value="0.5"/>
<add key="ErrorPreventionSearchDepthLimit" value="10"/>
</appSettings>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
<add key="MediumDetailErrorPreventionConfidenceThreshold" value="0.5"/>
<add key="NoErrorPreventionIEConfidenceThreshold" value="0.5"/>
<add key="NoErrorPreventionIERepetitionThreshold" value="0.5"/>
<add key="ErrorPreventionSearchDepthLimit" value="10"/>
</appSettings>
</configuration>
14 changes: 14 additions & 0 deletions Utils/Its.Utils.Config/DefaultTutorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class DefaultTutorConfig : ITutorConfig
private double mediumDetailErrorPreventionConfidenceThreshold;
private double noErrorPreventionIEConfidenceThreshold;
private double noErrorPreventionIERepetitionThreshold;
private int errorPreventionSearchDepthLimit;

public int InitialColumn
{
Expand Down Expand Up @@ -138,6 +139,11 @@ public double NoErrorPreventionIERepetitionThreshold
get { return noErrorPreventionIERepetitionThreshold; }
}

public int ErrorPreventionSearchDepthLimit
{
get { return errorPreventionSearchDepthLimit; }
}

public DefaultTutorConfig()
{
InitFromSystemConfig();
Expand Down Expand Up @@ -178,6 +184,7 @@ private void InitFromSystemConfig()
mediumDetailErrorPreventionConfidenceThreshold = double.Parse(ConfigurationManager.AppSettings["MediumDetailErrorPreventionConfidenceThreshold"]);
noErrorPreventionIEConfidenceThreshold = double.Parse(ConfigurationManager.AppSettings["NoErrorPreventionIEConfidenceThreshold"]);
noErrorPreventionIERepetitionThreshold = double.Parse(ConfigurationManager.AppSettings["NoErrorPreventionIERepetitionThreshold"]);
errorPreventionSearchDepthLimit = int.Parse(ConfigurationManager.AppSettings["ErrorPreventionSearchDepthLimit"]);
}

private void InitFromTutorConfig(ITutorConfig config)
Expand All @@ -204,6 +211,7 @@ private void InitFromTutorConfig(ITutorConfig config)
mediumDetailErrorPreventionConfidenceThreshold = config.MediumDetailErrorPreventionConfidenceThreshold;
noErrorPreventionIEConfidenceThreshold = config.NoErrorPreventionIEConfidenceThreshold;
noErrorPreventionIERepetitionThreshold = config.NoErrorPreventionIERepetitionThreshold;
errorPreventionSearchDepthLimit = config.ErrorPreventionSearchDepthLimit;
}

private void InitFromDictionary(Dictionary<string, string> values)
Expand All @@ -230,6 +238,7 @@ private void InitFromDictionary(Dictionary<string, string> values)
string mediumDetailErrorPreventionConfidenceThreshold;
string noErrorPreventionIEConfidenceThreshold;
string noErrorPreventionIERepetitionThreshold;
string errorPreventionSearchDepthLimit;

if (values.TryGetValue("InitialColumn", out initialColumn))
{
Expand Down Expand Up @@ -341,6 +350,11 @@ private void InitFromDictionary(Dictionary<string, string> values)
{
this.noErrorPreventionIERepetitionThreshold = double.Parse(noErrorPreventionIERepetitionThreshold);
}

if (values.TryGetValue("ErrorPreventionSearchDepthLimit", out errorPreventionSearchDepthLimit))
{
this.errorPreventionSearchDepthLimit = int.Parse(errorPreventionSearchDepthLimit);
}
}
}
}
1 change: 1 addition & 0 deletions Utils/Its.Utils.Config/ITutorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public interface ITutorConfig
double HighDetailErrorPreventionConfidenceThreshold { get; }
double NoErrorPreventionIEConfidenceThreshold { get; }
double NoErrorPreventionIERepetitionThreshold { get; }
int ErrorPreventionSearchDepthLimit { get; }
}
}

0 comments on commit 0298727

Please sign in to comment.