Search in sources :

Example 6 with APredictionResult

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;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Example 7 with APredictionResult

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);
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Example 8 with APredictionResult

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;
}
Also used : TimePredictionResult(edu.cmu.cs.hcii.cogtool.model.TimePredictionResult) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult)

Example 9 with APredictionResult

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));
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 10 with APredictionResult

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;
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Aggregations

APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)11 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)8 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)7 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)6 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)5 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 ArrayList (java.util.ArrayList)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)2 TimePredictionResult (edu.cmu.cs.hcii.cogtool.model.TimePredictionResult)2 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)1 HumanCSVParser (edu.cmu.cs.hcii.cogtool.model.HumanCSVParser)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)1