use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.
the class ResultDisplayPolicy method computeGroup.
// getTaskApplicationCell
/**
* Recursively computes value of script results on a particular design
* for tasks within a group.
*
* @param group the group whose resVal to calculate
* @param d the design whose script results should be used here
* @return the recursive value of script results on design d
* for tasks in the given TaskGroup; -1.0 if the group is empty
*/
public static double computeGroup(Project project, TaskGroup group, Design d) {
List<AUndertaking> children = group.getUndertakings();
if (children.size() == 0) {
// trivial case
return TimePredictionResult.UNSET_TIME;
}
GroupNature nature = group.getNature();
boolean validReturnValue = false;
double returnValue = 0.0d;
double meanDivisor = 0.0d;
for (AUndertaking child : children) {
double stepValue = TimePredictionResult.UNSET_TIME;
if (child.isTaskGroup()) {
// recursive (TaskGroup) case
stepValue = computeGroup(project, (TaskGroup) child, d);
} else {
// terminal case
TaskApplication ta = project.getTaskApplication(child, d);
if (ta != null) {
APredictionResult result = ta.getResult(ta.getFirstModelGenerator(), ta.determineActiveAlgorithm(project));
stepValue = getComputationResult(result);
}
}
if ((nature == GroupNature.SUM) || (nature == GroupNature.MEAN)) {
if (stepValue != TimePredictionResult.UNSET_TIME) {
returnValue += stepValue;
meanDivisor += 1.0d;
validReturnValue = true;
}
} else if (nature == GroupNature.MIN) {
if ((stepValue != TimePredictionResult.UNSET_TIME) && ((stepValue < returnValue) || (!validReturnValue))) {
returnValue = stepValue;
validReturnValue = true;
}
} else if (nature == GroupNature.MAX) {
if (stepValue > returnValue) {
returnValue = stepValue;
validReturnValue = true;
}
}
}
if (validReturnValue) {
if ((nature == GroupNature.MEAN) && (meanDivisor != 0.0d)) {
returnValue /= meanDivisor;
}
return returnValue;
}
return TimePredictionResult.UNSET_TIME;
}
use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.
the class ResultDisplayPolicy method getTaskApplicationCell.
public static String getTaskApplicationCell(Project project, TaskApplication taskApp, CognitiveModelGenerator gen, boolean forCell, String withSecs) {
if ((gen == null) || (taskApp == null) || ((!taskApp.hasComputedResult()) && (!taskApp.hasComputableScript())) || (taskApp.getScript(gen) == null)) {
// has a TaskApp, but no Script for the current algorithm
return "";
}
Demonstration demo = taskApp.getDemonstration();
IPredictionAlgo alg = taskApp.determineActiveAlgorithm(project);
APredictionResult r = taskApp.getResult(gen, alg);
int resultState = (r == null) ? APredictionResult.NOT_COMPUTED : r.getResultState();
// ?? means the demonstration is invalid or script needs regeneration
if (forCell) {
if (demo.isInvalid() || demo.isObsolete()) {
return "?? ";
}
if ((resultState == APredictionResult.NOT_COMPUTED) || (alg.requiresDemonstration() && !demo.isStartFrameChosen())) {
// No result yet computed for the associated script
return "-- ";
}
if (resultState == APredictionResult.COMPUTATION_IN_PROGRESS) {
// Result is being computed
return "(><) ";
}
if (resultState == APredictionResult.COMPUTE_FAILED) {
// Has a result for this algorithm, but it failed
return "XX ";
}
double timing = getComputationResult(r);
if (timing < 0.0) {
return "~~";
}
updateDigits();
String result = cellNumberFormat.format(timing);
if (CogToolPref.KLM_RESULT_RANGE.getBoolean() && withSecs != null && withSecs.length() > 0) {
result += " (" + cellNumberFormat.format(0.9 * timing);
result += ", " + cellNumberFormat.format(1.1 * timing);
result += ")";
}
result += withSecs;
return result;
// return (timing >= 0.0)
//// ? (cellNumberFormat.format(timing) + withSecs)
// ? (cellNumberFormat.format(timing) + withSecs + " ±10%")
// : "~~";
}
// Long form task application state descriptions, used for tooltips
// "" means no task application or no computable script for alg
// -- / "" means computable, not computed, and demo is valid
// -- / X means not computed and demo is invalid
// -- / ? means not computed and script needs regeneration
// NN / "" means computed and demo is valid
// NN / X means computed and demo is invalid
// NN / ? means computed and script needs regeneration
// ## / "" means computation failed and demo is valid
// ## / X means computation failed and demo is invalid
// ## / ? means computation failed, script needs regeneration
// (><) / ... means result is being computed
// ~~ / ... means result resulted in a negative number (??)
String demoState;
if (demo.isInvalid()) {
// " / X ";
demoState = " / INVALID";
} else if (demo.isObsolete()) {
// " / ? ";
demoState = " / OBSOLETE";
} else {
// " / ";
demoState = "";
}
if ((resultState == APredictionResult.NOT_COMPUTED) || !demo.isStartFrameChosen()) {
// No result yet computed for the associated script
return "NOT COMPUTED" + /* "--" */
demoState;
}
if (resultState == APredictionResult.COMPUTE_FAILED) {
// Has a result for this algo, but it failed
return "COMPUTE FAILED" + /* "##" */
demoState;
}
if (resultState == APredictionResult.COMPUTATION_IN_PROGRESS) {
// Result is being computed
return "BEING COMPUTED" + /* "(><)" */
demoState;
}
double timing = getComputationResult(r);
updateDigits();
return (timing >= 0.0) ? (cellNumberFormat.format(timing) + withSecs + demoState) : ("~~" + demoState);
}
use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.
the class PERTChartController method openController.
/**
* Creates a new PERTChartController for manipulating a PERTChart
* @return the Controller instance for manipulating the PERTChart
* @author jbc
*/
public static PERTChartController openController(TaskApplication ta, CognitiveModelGenerator modelGen, IPredictionAlgo computeAlg, Project project, int strategy, Interaction interaction) {
APredictionResult result = ta.getResult(modelGen, computeAlg);
int ver = ACTRPredictionAlgo.getTraceVersion(result);
if (ver != 0) {
if (ver < ACTRPredictionAlgo.TRACE_VERSION) {
interaction.protestTraceVersion(true);
return null;
} else if (ver > ACTRPredictionAlgo.TRACE_VERSION) {
interaction.protestTraceVersion(false);
return null;
}
} else if (result instanceof TimePredictionResult) {
String name = ((TimePredictionResult) result).getName();
if (name.startsWith("ACT-R") || name.equals("Untitled Result")) {
// a sufficiently old result that it has no trace version, even
// though it is an ACT-R result
interaction.protestTraceVersion(true);
return null;
}
}
// Check whether this project is already open based on the result object
PERTChartController controller = (PERTChartController) ControllerRegistry.ONLY.findOpenController(result);
// If already open, just bring it to front
if (controller != null) {
// TODO figure out how to make an already open PERT chart show the
// desired strategy, if one is supplied
controller.takeFocus();
} else {
// if this project isn't open, create a new controller
controller = new PERTChartController(ta, modelGen, computeAlg, project, strategy);
ControllerRegistry.ONLY.addOpenController(controller);
}
return controller;
}
use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.
the class HCIPACmd method initHCIPATaskDesign.
// For each design
protected static void initHCIPATaskDesign(Project project, String taskName, AUndertaking[] subtasks, Design design, CognitiveModelGenerator modelGen) {
Frame f = getStartFrame(design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, subtasks[0], design, modelGen, demoMgr);
Script script = ta.getScript(modelGen);
Demonstration demo = script.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
IPredictionAlgo computeAlg = ta.determineActiveAlgorithm(project);
ThinkScriptStep thinkStep = new ThinkScriptStep(f, RECOGNIZE_NEED + taskName);
demo.appendStep(thinkStep);
List<String> warnings = new ArrayList<String>();
List<DefaultModelGeneratorState> states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
APredictionResult result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
ta = DemoStateManager.ensureTaskApplication(project, subtasks[1], design, modelGen, demoMgr);
script = ta.getScript(modelGen);
demo = ta.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
thinkStep = new ThinkScriptStep(f, "Select Function Step");
demo.appendStep(thinkStep);
states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
}
use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.
the class ProjectController method openProjectOnCompute.
/**
* editSeq will be null if no regeneration occurred; otherwise,
* the edit sequence will contain the undoable edit for the regeneration.
*/
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
boolean notModified;
try {
notModified = UndoManager.isAtSavePoint(project);
} catch (IllegalStateException ex) {
System.err.println("Ignoring that isAtSavePoint failed.");
notModified = false;
}
ProjectController c = ProjectController.openController(project, false, notModified);
final CognitiveModelGenerator modelGen = script.getModelGenerator();
final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {
protected APredictionResult redoResult = newResult;
protected APredictionResult undoResult = oldResult;
@Override
public String getPresentationName() {
return COMPUTE_SCRIPT;
}
@Override
public void redo() {
super.redo();
redoResult = PredictionResultProxy.getLatestResult(redoResult);
taskApp.setResult(modelGen, computeAlg, redoResult);
}
@Override
public void undo() {
super.undo();
undoResult = PredictionResultProxy.getLatestResult(undoResult);
taskApp.setResult(modelGen, computeAlg, undoResult);
}
};
if (editSeq != null) {
editSeq.addEdit(edit);
editSeq.end();
edit = editSeq;
}
// Add to script's undo mgr first to set owner properly
scriptUndoMgr.addEdit(edit);
c.undoMgr.addEdit(edit);
c.takeFocus();
return true;
}
Aggregations