Search in sources :

Example 11 with IPredictionAlgo

use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo 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 12 with IPredictionAlgo

use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.

the class ComputePredictionCmd method computeInBackground.

/**
     * Perform the analysis in the background.  Set the result when done.
     */
public static APredictionResult computeInBackground(IPredictionAlgo computeAlg, Script s, Interaction interact) {
    try {
        DefaultAnalysisWorkThread workThread = new DefaultAnalysisWorkThread(computeAlg, s, null, interact);
        ITraceWindow traceWin = interact.createTraceWindow("Computation trace", workThread, "Trace output: stdout (top) and stderr (bottom)");
        workThread.setTraceWindow(traceWin);
        ThreadManager.startNewThread(workThread);
        return workThread.getResultProxy();
    } catch (IPredictionAlgo.ComputationException ex) {
        throw new RcvrComputationException(ex);
    } catch (IllegalStateException ex) {
        throw new RcvrIllegalStateException(ex);
    } catch (UnsupportedOperationException ex) {
        throw new RcvrUnimplementedFnException(ex);
    } catch (Exception ex) {
        throw new RcvrComputationException(ex);
    }
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ITraceWindow(edu.cmu.cs.hcii.cogtool.ui.Interaction.ITraceWindow) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) RcvrComputationException(edu.cmu.cs.hcii.cogtool.util.RcvrComputationException) RcvrComputationException(edu.cmu.cs.hcii.cogtool.util.RcvrComputationException) RcvrParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrParsingException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)

Example 13 with IPredictionAlgo

use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.

the class ProjectController method createExportActrModelFile.

// Action for ExportDesignFiles
// XXX: does this really belong in ProjectController? It seems like
//      something that's tied to whichever backend we're really using,
//      and so should be somewhere else
protected IListenerAction createExportActrModelFile() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object actionParms) {
            ProjectSelectionState sel = (ProjectSelectionState) actionParms;
            // Must have selected tasks and design
            Design design = sel.getSelectedDesign();
            AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            // Ask user for location of saved file.
            File exportFile = interaction.selectExportLocation("Exported ACT-R Model", CogToolFileTypes.LISP_FILE_EXT);
            // User canceled
            if (exportFile == null) {
                return false;
            }
            for (AUndertaking task : tasks) {
                // If no script set exists for this cell, create
                TaskApplication ta = project.getTaskApplication(task, design);
                if (ta != null) {
                    if (ta.getDesign() != design) {
                        throw new RcvrIllegalStateException("Unexpected Design mis-match (" + ta.getDesign() + ", " + design + ")");
                    }
                    // If no script exists for this cell, create one
                    Script script = DemoStateManager.ensureScript(ta, MODELGEN_ALG);
                    try {
                        IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
                        if (!(taAlg instanceof ACTRPredictionAlgo)) {
                            throw new RcvrIllegalStateException("Can't export ACT-R Model from a non ACT-R task.");
                        }
                        if (script.getAssociatedPath() != null) {
                            File f = new File(script.getAssociatedPath());
                            // The following will throw an IOException if
                            // the input file doesn't exist; this is exactly
                            // the same behaviour as if we're trying to do
                            // a recompute, and is better than silently
                            // substituting a generated model file
                            FileUtil.copyTextFileToFile(f, exportFile);
                            return true;
                        }
                        ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
                        algo.outputModel(design, task, ta.getDemonstration().getStartFrame(), script, exportFile, null);
                    } catch (UnsupportedOperationException ex) {
                        throw new RcvrUnimplementedFnException(ex);
                    } catch (IOException ex) {
                        throw new RcvrIOException(("IOException exporting model file for task " + task.getName() + " in design " + design.getName()), ex);
                    }
                }
            }
            return true;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)

Example 14 with IPredictionAlgo

use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo 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 15 with IPredictionAlgo

use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.

the class ProjectController method createGenerateACTRModelAction.

// createImportHumanCSVFileAction
protected IListenerAction createGenerateACTRModelAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            for (AUndertaking task : tasks) {
                TaskApplication ta = project.getTaskApplication(task, design);
                Script s = DemoStateManager.ensureScript(ta, KLMCognitiveGenerator.ONLY);
                // TODO There's too much algorithm specific code
                //      in here; but for now it seems the expedient
                //      thing to do -- all this needs to be thought
                //      through for all back ends, and restructured
                String path = s.getAssociatedPath();
                String filename = null;
                if (path == null) {
                    filename = design.getName() + "-" + task.getName();
                } else {
                    filename = (new File(path)).getName();
                    if ((filename != null) && filename.endsWith(CogToolFileTypes.LISP_FILE_EXT)) {
                        filename = filename.substring(0, filename.length() - CogToolFileTypes.LISP_FILE_EXT.length());
                    }
                }
                File file = interaction.selectExportLocation(filename, CogToolFileTypes.LISP_FILE_EXT);
                if (file == null) {
                    return false;
                }
                s.setAssociatedPath(file.getAbsolutePath());
                // so we have to delete it.
                if (file.length() == 0) {
                    file.delete();
                }
                try {
                    IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
                    if (!(taAlg instanceof ACTRPredictionAlgo)) {
                        throw new RcvrIllegalStateException("Can't generate ACT-R Model from a non ACT-R task.");
                    }
                    ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
                    algo.outputModel(design, task, s.getDemonstration().getStartFrame(), s, file, null);
                } catch (UnsupportedOperationException ex) {
                    throw new RcvrUnimplementedFnException(ex);
                } catch (IOException ex) {
                    throw new RcvrIOException(("IOException generating model file for task " + task.getName() + " in design " + design.getName()), ex);
                }
            }
            return false;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)

Aggregations

IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)15 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)7 Script (edu.cmu.cs.hcii.cogtool.model.Script)7 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)7 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)7 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)5 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)5 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)4 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)4 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)4 File (java.io.File)4 IOException (java.io.IOException)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3