Search in sources :

Example 6 with SimpleReferenceData

use of cbit.vcell.opt.SimpleReferenceData in project vcell by virtualcell.

the class ReactionDominantTest method solve.

private OptimizationResultSet solve() throws ExpressionException, IOException {
    Expression Fbleached_bleachFastExp = new Expression(Fbleached_bleachFast);
    Expression OmegaExp = new Expression(strOmega);
    Expression Omega_cExp = new Expression(strOmega_c);
    Expression WExp = new Expression(strW);
    Fbleached_bleachFastExp.substituteInPlace(OmegaExp, new Expression(Omega));
    Fbleached_bleachFastExp.substituteInPlace(Omega_cExp, new Expression(Omega_c));
    Fbleached_bleachFastExp.substituteInPlace(WExp, new Expression(W));
    Parameter[] parameters = new Parameter[] { para_alpha, para_Kon_star, para_Koff };
    // Expression Fbleached_bleachFast = Fbleached_bleachFastExp.flatten();
    // choose optimization solver, currently we have Powell and CFSQP
    PowellOptimizationSolver optService = new PowellOptimizationSolver();
    OptimizationSpec optSpec = new OptimizationSpec();
    // create simple reference data
    double[][] realData = new double[2][t.length];
    for (int i = 0; i < t.length; i++) {
        realData[0][i] = t[i];
        realData[1][i] = data_bleached[i];
    }
    String[] colNames = new String[] { "t", "intensity" };
    double[] weights = new double[] { 1.0, 1.0 };
    SimpleReferenceData refData = new SimpleReferenceData(colNames, weights, realData);
    // send to optimization service
    ExplicitFitObjectiveFunction.ExpressionDataPair oneExpDataPair = new ExplicitFitObjectiveFunction.ExpressionDataPair(Fbleached_bleachFastExp.flatten(), 1);
    ExplicitFitObjectiveFunction.ExpressionDataPair[] expDataPairs = new ExplicitFitObjectiveFunction.ExpressionDataPair[] { oneExpDataPair };
    optSpec.setObjectiveFunction(new ExplicitFitObjectiveFunction(expDataPairs, refData));
    optSpec.setComputeProfileDistributions(true);
    // get the initial guess to send it to the f() function. ....
    for (int i = 0; i < parameters.length; i++) {
        optSpec.addParameter(parameters[i]);
    }
    // Parameters in OptimizationSolverSpec are solver type and objective function change tolerance.
    OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, 0.000001);
    OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
    OptimizationResultSet optResultSet = null;
    optResultSet = optService.solve(optSpec, optSolverSpec, optSolverCallbacks);
    String[] paramNames = optResultSet.getOptSolverResultSet().getParameterNames();
    ArrayList<ProfileDistribution> profileDistributionList = optResultSet.getOptSolverResultSet().getProfileDistributionList();
    for (int i = 0; i < profileDistributionList.size(); i++) {
        outputProfileLikelihood(profileDistributionList.get(i), i, paramNames[i], new File(fileDir));
    }
    return optResultSet;
}
Also used : PowellOptimizationSolver(cbit.vcell.opt.solvers.PowellOptimizationSolver) ProfileDistribution(cbit.vcell.opt.OptSolverResultSet.ProfileDistribution) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) OptSolverCallbacks(org.vcell.optimization.OptSolverCallbacks) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) ExplicitFitObjectiveFunction(cbit.vcell.opt.ExplicitFitObjectiveFunction) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) Expression(cbit.vcell.parser.Expression) DefaultOptSolverCallbacks(org.vcell.optimization.DefaultOptSolverCallbacks) Parameter(cbit.vcell.opt.Parameter) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) OptimizationSpec(cbit.vcell.opt.OptimizationSpec) File(java.io.File)

Example 7 with SimpleReferenceData

use of cbit.vcell.opt.SimpleReferenceData in project vcell by virtualcell.

the class ParameterEstimationTaskXMLPersistence method getParameterEstimationTask.

/**
 * Insert the method's description here.
 * Creation date: (5/5/2006 4:50:36 PM)
 * @return cbit.vcell.modelopt.ParameterEstimationTask
 * @param element org.jdom.Element
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
public static ParameterEstimationTask getParameterEstimationTask(Element parameterEstimationTaskElement, SimulationContext simContext) throws ExpressionException, MappingException, MathException, java.beans.PropertyVetoException {
    Namespace ns = parameterEstimationTaskElement.getNamespace();
    ParameterEstimationTask parameterEstimationTask = new ParameterEstimationTask(simContext);
    String name = parameterEstimationTaskElement.getAttributeValue(NameAttribute);
    parameterEstimationTask.setName(name);
    Element annotationElement = parameterEstimationTaskElement.getChild(AnnotationTag, ns);
    if (annotationElement != null) {
        String annotationText = annotationElement.getText();
        parameterEstimationTask.setAnnotation(annotationText);
    }
    // 
    // read ParameterMappingSpecs
    // 
    Element parameterMappingSpecListElement = parameterEstimationTaskElement.getChild(ParameterMappingSpecListTag, ns);
    if (parameterMappingSpecListElement != null) {
        List<Element> parameterMappingSpecElementList = parameterMappingSpecListElement.getChildren(ParameterMappingSpecTag, ns);
        for (Element parameterMappingSpecElement : parameterMappingSpecElementList) {
            String parameterName = parameterMappingSpecElement.getAttributeValue(ParameterReferenceAttribute);
            SymbolTableEntry ste = getSymbolTableEntry(simContext, parameterName);
            if (ste instanceof Parameter) {
                Parameter parameter = (Parameter) ste;
                ParameterMappingSpec parameterMappingSpec = parameterEstimationTask.getModelOptimizationSpec().getParameterMappingSpec(parameter);
                if (parameterMappingSpec != null) {
                    String lowLimitString = parameterMappingSpecElement.getAttributeValue(LowLimitAttribute);
                    if (lowLimitString != null) {
                        parameterMappingSpec.setLow(parseDouble(lowLimitString));
                    }
                    String highLimitString = parameterMappingSpecElement.getAttributeValue(HighLimitAttribute);
                    if (highLimitString != null) {
                        parameterMappingSpec.setHigh(parseDouble(highLimitString));
                    }
                    String currentValueString = parameterMappingSpecElement.getAttributeValue(CurrentValueAttribute);
                    if (currentValueString != null) {
                        parameterMappingSpec.setCurrent(Double.parseDouble(currentValueString));
                    }
                    String selectedString = parameterMappingSpecElement.getAttributeValue(SelectedAttribute);
                    if (selectedString != null) {
                        parameterMappingSpec.setSelected(Boolean.valueOf(selectedString).booleanValue());
                    }
                }
            } else {
                System.out.println("couldn't read parameterMappingSpec '" + parameterName + "', ste=" + ste);
            }
        }
    }
    // 
    // read ReferenceData
    // 
    Element referenceDataElement = parameterEstimationTaskElement.getChild(ReferenceDataTag, ns);
    if (referenceDataElement != null) {
        String numRowsText = referenceDataElement.getAttributeValue(NumRowsAttribute);
        String numColsText = referenceDataElement.getAttributeValue(NumColumnsAttribute);
        // int numRows = Integer.parseInt(numRowsText);
        int numCols = Integer.parseInt(numColsText);
        // 
        // read columns
        // 
        String[] columnNames = new String[numCols];
        double[] columnWeights = new double[numCols];
        int columnCounter = 0;
        Element dataColumnListElement = referenceDataElement.getChild(DataColumnListTag, ns);
        List<Element> dataColumnList = dataColumnListElement.getChildren(DataColumnTag, ns);
        for (Element dataColumnElement : dataColumnList) {
            columnNames[columnCounter] = dataColumnElement.getAttributeValue(NameAttribute);
            columnWeights[columnCounter] = Double.parseDouble(dataColumnElement.getAttributeValue(WeightAttribute));
            columnCounter++;
        }
        // 
        // read rows
        // 
        Vector<double[]> rowDataVector = new Vector<double[]>();
        Element dataRowListElement = referenceDataElement.getChild(DataRowListTag, ns);
        List<Element> dataRowList = dataRowListElement.getChildren(DataRowTag, ns);
        for (Element dataRowElement : dataRowList) {
            String rowText = dataRowElement.getText();
            CommentStringTokenizer tokens = new CommentStringTokenizer(rowText);
            double[] rowData = new double[numCols];
            for (int j = 0; j < numCols; j++) {
                if (tokens.hasMoreTokens()) {
                    String token = tokens.nextToken();
                    rowData[j] = Double.parseDouble(token);
                } else {
                    throw new RuntimeException("failed to read row data for ReferenceData");
                }
            }
            rowDataVector.add(rowData);
        }
        ReferenceData referenceData = new SimpleReferenceData(columnNames, columnWeights, rowDataVector);
        parameterEstimationTask.getModelOptimizationSpec().setReferenceData(referenceData);
    }
    // 
    // read ReferenceDataMappingSpecs
    // 
    Element referenceDataMappingSpecListElement = parameterEstimationTaskElement.getChild(ReferenceDataMappingSpecListTag, ns);
    if (referenceDataMappingSpecListElement != null) {
        List<Element> referenceDataMappingSpecList = referenceDataMappingSpecListElement.getChildren(ReferenceDataMappingSpecTag, ns);
        for (Element referenceDataMappingSpecElement : referenceDataMappingSpecList) {
            String referenceDataColumnName = referenceDataMappingSpecElement.getAttributeValue(ReferenceDataColumnNameAttribute);
            String referenceDataModelSymbolName = referenceDataMappingSpecElement.getAttributeValue(ReferenceDataModelSymbolAttribute);
            ReferenceDataMappingSpec referenceDataMappingSpec = parameterEstimationTask.getModelOptimizationSpec().getReferenceDataMappingSpec(referenceDataColumnName);
            SymbolTableEntry modelSymbolTableEntry = null;
            if (referenceDataModelSymbolName != null) {
                modelSymbolTableEntry = getSymbolTableEntry(simContext, referenceDataModelSymbolName);
                if (referenceDataMappingSpec != null && modelSymbolTableEntry != null) {
                    referenceDataMappingSpec.setModelObject(modelSymbolTableEntry);
                }
            }
        }
    }
    // 
    // read OptimizationSolverSpec
    // 
    Element optimizationSolverSpecElement = parameterEstimationTaskElement.getChild(OptimizationSolverSpecTag, ns);
    if (optimizationSolverSpecElement != null) {
        OptimizationSolverSpec optSolverSpec = null;
        String optimizationSolverTypeName = optimizationSolverSpecElement.getAttributeValue(OptimizationSolverTypeAttribute);
        // getting parameters
        Element optimizationSolverParameterList = optimizationSolverSpecElement.getChild(OptimizationListOfParametersTag, ns);
        if (optimizationSolverParameterList != null) {
            List<Element> listOfSolverParams = optimizationSolverParameterList.getChildren(OptimizationParameterTag, ns);
            CopasiOptimizationMethod copasiOptMethod = null;
            if (listOfSolverParams != null && listOfSolverParams.size() > 0) {
                List<CopasiOptimizationParameter> copasiSolverParams = new ArrayList<CopasiOptimizationParameter>();
                for (Element solverParam : listOfSolverParams) {
                    String paramName = solverParam.getAttributeValue(OptimizationParameterNameAttribute);
                    double paramValue = Double.parseDouble(solverParam.getAttributeValue(OptimizationParameterValueAttribute));
                    CopasiOptimizationParameter copasiParam = new CopasiOptimizationParameter(getCopasiOptimizationParameterTypeByName(paramName), paramValue);
                    copasiSolverParams.add(copasiParam);
                }
                copasiOptMethod = new CopasiOptimizationMethod(getCopasiOptimizationMethodTypeByName(optimizationSolverTypeName), copasiSolverParams.toArray(new CopasiOptimizationParameter[copasiSolverParams.size()]));
            } else // no parameters
            {
                copasiOptMethod = new CopasiOptimizationMethod(getCopasiOptimizationMethodTypeByName(optimizationSolverTypeName), new CopasiOptimizationParameter[0]);
            }
            optSolverSpec = new OptimizationSolverSpec(copasiOptMethod);
            // add number of runs attribute
            String numOfRunsStr = optimizationSolverSpecElement.getAttributeValue(OptimizationSolverNumOfRunsAttribute);
            if (numOfRunsStr != null) {
                int numOfRuns = Integer.parseInt(numOfRunsStr);
                optSolverSpec.setNumOfRuns(numOfRuns);
            }
        }
        parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
    }
    if (// optimization solver spec is null create a default copasi evolutionary programming
    optimizationSolverSpecElement == null || parameterEstimationTask.getOptimizationSolverSpec() == null) {
        OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(new CopasiOptimizationMethod(CopasiOptimizationMethodType.EvolutionaryProgram));
        parameterEstimationTask.setOptimizationSolverSpec(optSolverSpec);
    }
    // read optimization solver result set
    Element optimizationResultSetElement = parameterEstimationTaskElement.getChild(OptXmlTags.OptimizationResultSet_Tag, ns);
    if (optimizationResultSetElement != null) {
        OptimizationResultSet optResultSet = null;
        // read optsolverResultSet
        if (optimizationResultSetElement.getChild(OptXmlTags.bestOptRunResultSet_Tag, ns) != null) {
            Element optSolverResultSetElement = optimizationResultSetElement.getChild(OptXmlTags.bestOptRunResultSet_Tag, ns);
            OptSolverResultSet optSolverResultSet = null;
            // get best parameters, best func value, number of evaluations and construct an optRunResultSet
            Element paramListElement = optSolverResultSetElement.getChild(OptimizationListOfParametersTag, ns);
            OptRunResultSet optRunResultSet = null;
            List<String> paramNames = new ArrayList<String>();
            List<Double> paramValues = new ArrayList<Double>();
            if (paramListElement != null && !paramListElement.getChildren().isEmpty()) {
                List<Element> paramElements = paramListElement.getChildren(OptimizationParameterTag, ns);
                if (paramElements != null) {
                    for (Element paramElement : paramElements) {
                        String paramName = paramElement.getAttributeValue(OptimizationParameterNameAttribute);
                        double paramValue = Double.parseDouble(paramElement.getAttributeValue(OptimizationParameterValueAttribute));
                        paramNames.add(paramName);
                        paramValues.add(paramValue);
                    }
                }
            }
            Element bestFuncValueElement = optSolverResultSetElement.getChild(OptXmlTags.ObjectiveFunction_Tag, ns);
            double bestFuncValue = Double.parseDouble(bestFuncValueElement.getAttributeValue(OptimizationParameterValueAttribute));
            Element numEvaluationsElement = optSolverResultSetElement.getChild(OptXmlTags.OptSolverResultSetFunctionEvaluations_Tag, ns);
            long numEvaluations = Long.parseLong(numEvaluationsElement.getAttributeValue(OptimizationParameterValueAttribute));
            // change List<Double> to double[]
            double[] values = new double[paramValues.size()];
            int index = 0;
            for (Double value : paramValues) {
                values[index++] = value;
            }
            optRunResultSet = new OptRunResultSet(values, bestFuncValue, numEvaluations, null);
            // create optSolverResultSet
            optSolverResultSet = new OptSolverResultSet(paramNames.toArray(new String[paramNames.size()]), optRunResultSet);
            // create optimization result set
            optResultSet = new OptimizationResultSet(optSolverResultSet, null);
        }
        parameterEstimationTask.setOptimizationResultSet(optResultSet);
    }
    return parameterEstimationTask;
}
Also used : OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) Element(org.jdom.Element) ArrayList(java.util.ArrayList) OptSolverResultSet(cbit.vcell.opt.OptSolverResultSet) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) CopasiOptimizationMethod(cbit.vcell.opt.CopasiOptimizationMethod) CopasiOptimizationParameter(cbit.vcell.opt.CopasiOptimizationParameter) OptimizationSolverSpec(cbit.vcell.opt.OptimizationSolverSpec) Vector(java.util.Vector) Namespace(org.jdom.Namespace) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Parameter(cbit.vcell.model.Parameter) CopasiOptimizationParameter(cbit.vcell.opt.CopasiOptimizationParameter) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) OptRunResultSet(cbit.vcell.opt.OptSolverResultSet.OptRunResultSet)

Example 8 with SimpleReferenceData

use of cbit.vcell.opt.SimpleReferenceData in project vcell by virtualcell.

the class ModelOptimizationMapping method getRemappedReferenceData.

/**
 * Gets the constraintData property (cbit.vcell.opt.ConstraintData) value.
 * @return The constraintData property value.
 * @see #setConstraintData
 */
private ReferenceData getRemappedReferenceData(MathMapping mathMapping) throws MappingException {
    if (modelOptimizationSpec.getReferenceData() == null) {
        return null;
    }
    // 
    // make sure time is mapped
    // 
    ReferenceData refData = modelOptimizationSpec.getReferenceData();
    ReferenceDataMappingSpec[] refDataMappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
    RowColumnResultSet rowColResultSet = new RowColumnResultSet();
    Vector<SymbolTableEntry> modelObjectList = new Vector<SymbolTableEntry>();
    Vector<double[]> dataList = new Vector<double[]>();
    // 
    // find bound columns, (time is always mapped to the first column)
    // 
    int mappedColumnCount = 0;
    for (int i = 0; i < refDataMappingSpecs.length; i++) {
        SymbolTableEntry modelObject = refDataMappingSpecs[i].getModelObject();
        if (modelObject != null) {
            int mappedColumnIndex = mappedColumnCount;
            if (modelObject instanceof Model.ReservedSymbol && ((ReservedSymbol) modelObject).isTime()) {
                mappedColumnIndex = 0;
            }
            String origRefDataColumnName = refDataMappingSpecs[i].getReferenceDataColumnName();
            int origRefDataColumnIndex = refData.findColumn(origRefDataColumnName);
            if (origRefDataColumnIndex < 0) {
                throw new RuntimeException("reference data column named '" + origRefDataColumnName + "' not found");
            }
            double[] columnData = refData.getDataByColumn(origRefDataColumnIndex);
            if (modelObjectList.contains(modelObject)) {
                throw new RuntimeException("multiple reference data columns mapped to same model object '" + modelObject.getName() + "'");
            }
            modelObjectList.insertElementAt(modelObject, mappedColumnIndex);
            dataList.insertElementAt(columnData, mappedColumnIndex);
            mappedColumnCount++;
        }
    }
    // 
    if (modelObjectList.size() == 0) {
        throw new RuntimeException("reference data was not associated with model");
    }
    if (modelObjectList.size() == 1) {
        throw new RuntimeException("reference data was not associated with model, must map time and at least one other column");
    }
    boolean bFoundTimeVar = false;
    for (SymbolTableEntry ste : modelObjectList) {
        if (ste instanceof Model.ReservedSymbol && ((ReservedSymbol) ste).isTime()) {
            bFoundTimeVar = true;
            break;
        }
    }
    if (!bFoundTimeVar) {
        throw new RuntimeException("must map time column of reference data to model");
    }
    // 
    for (int i = 0; i < modelObjectList.size(); i++) {
        SymbolTableEntry modelObject = (SymbolTableEntry) modelObjectList.elementAt(i);
        try {
            // Find by name because MathSybolMapping has different 'objects' than refDataMapping 'objects'
            Variable variable = mathMapping.getMathSymbolMapping().findVariableByName(modelObject.getName());
            if (variable != null) {
                String symbol = variable.getName();
                rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
            } else if (modelObject instanceof Model.ReservedSymbol && ((Model.ReservedSymbol) modelObject).isTime()) {
                Model.ReservedSymbol time = (Model.ReservedSymbol) modelObject;
                String symbol = time.getName();
                rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
            }
        } catch (MathException | MatrixException | ExpressionException | ModelException e) {
            e.printStackTrace();
            throw new MappingException(e.getMessage(), e);
        }
    }
    // 
    // populate data columns (time and rest)
    // 
    double[] weights = new double[rowColResultSet.getColumnDescriptionsCount()];
    weights[0] = 1.0;
    int numRows = ((double[]) dataList.elementAt(0)).length;
    int numColumns = modelObjectList.size();
    for (int j = 0; j < numRows; j++) {
        double[] row = new double[numColumns];
        for (int i = 0; i < numColumns; i++) {
            row[i] = ((double[]) dataList.elementAt(i))[j];
            if (i > 0) {
                weights[i] += row[i] * row[i];
            }
        }
        rowColResultSet.addRow(row);
    }
    for (int i = 0; i < numColumns; i++) {
        if (weights[i] == 0) {
            weights[i] = 1;
        } else {
            weights[i] = 1 / weights[i];
        }
    }
    SimpleReferenceData remappedRefData = new SimpleReferenceData(rowColResultSet, weights);
    return remappedRefData;
}
Also used : ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) Vector(java.util.Vector) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ModelException(cbit.vcell.model.ModelException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) MathException(cbit.vcell.math.MathException) Model(cbit.vcell.model.Model)

Example 9 with SimpleReferenceData

use of cbit.vcell.opt.SimpleReferenceData in project vcell by virtualcell.

the class FRAPEstimationPanel_NotUsed method displayFit.

private void displayFit(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults diffAnalysisResults, double[] frapDataTimeStamps, int startIndexForRecovery) {
    if (diffAnalysisResults == null) {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = null;
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = null;
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = null;
        FRAPParameterEstimateEnum.START_TIME_RECOVERY.value = null;
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = null;
        multisourcePlotPane.setDataSources(null);
    } else {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = (diffAnalysisResults.getRecoveryDiffusionRate() == null ? null : diffAnalysisResults.getRecoveryDiffusionRate());
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = (diffAnalysisResults.getMobilefraction() == null ? null : diffAnalysisResults.getMobilefraction());
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = (FRAPParameterEstimateEnum.MOBILE_FRACTION.value == null ? null : 1.0 - FRAPParameterEstimateEnum.MOBILE_FRACTION.value);
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = (diffAnalysisResults.getBleachWhileMonitoringTau() == null ? null : diffAnalysisResults.getBleachWhileMonitoringTau());
        // int startIndexForRecovery = FRAPDataAnalysis.getRecoveryIndex(initFRAPData);
        // 
        // Experiment - Cell ROI Average
        // 
        double[] temp_background = initFRAPData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(initFRAPData, startIndexForRecovery);
        double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()), preBleachAvgXYZ, temp_background);
        ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { "t", "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, cellRegionData });
        DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("expCellAvg", expCellAvgData);
        // 
        // Analytic - Cell ROI Average with Bleach while monitor
        // 
        ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
        bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getFitBleachWhileMonitorExpression(), "CellROI_BleachWhileMonitor", null, "bleachWhileMonitorFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        {
            double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
            double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
            while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
                bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { T });
                T += deltaT;
            }
        }
        DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceRowColumnResultSet("bleachwm", bleachWhileMonitorOdeSolverResultSet);
        // Recovery curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { "t", "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", expRefData);
        ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
        fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            fitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getDiffFitExpression(), // "('"+FrapDataAnalysisResults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()]+"')",
            "BleachROI_Recovery", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            fitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
        double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
        while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
            fitOdeSolverResultSet.addRow(new double[] { T });
            T += deltaT;
        }
        DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", fitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expDataSource, fitDataSource, expCellAvgDataSource, bleachWhileMonitorDataSource });
        multisourcePlotPane.selectAll();
    }
    table.repaint();
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource)

Example 10 with SimpleReferenceData

use of cbit.vcell.opt.SimpleReferenceData in project vcell by virtualcell.

the class EstParams_ReactionOffRatePanel method displayResults.

private void displayResults(FRAPData frapData, int startIndexRecovery) throws ExpressionException, DivideByZeroException {
    Parameter[] currentParams = offRateParamPanel.getCurrentParameters();
    if (frapData == null || currentParams == null) {
        multisourcePlotPane.setDataSources(null);
    } else {
        double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
        // Experiment - Cell ROI Average
        double[] temp_background = frapData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(frapData, startIndexRecovery);
        /*double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()),preBleachAvgXYZ,temp_background);
			ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { ReservedSymbol.TIME.getName(), "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] {frapDataTimeStamps, cellRegionData });
			DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("exp", expCellAvgData);
			//Analytic - Cell ROI Average with Bleach while monitor
			ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
			bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedSymbol.TIME.getName()));
			Expression cellAvgExp = new Expression(FRAPOptFunctions.FUNC_CELL_INTENSITY);
			// substitute parameter values 
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_I_inicell), new Expression(cellRegionData[startIndexRecovery]));
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_BWM_RATE), new Expression(currentParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess()));
			// time shift
			cellAvgExp.substituteInPlace(new Expression(ReservedSymbol.TIME.getName()), new Expression(ReservedSymbol.TIME.getName()+"-"+frapDataTimeStamps[startIndexRecovery]));
			try {
				bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(
					new FunctionColumnDescription(
						cellAvgExp,
						"CellROIAvg",
						null,"bleachWhileMonitorFit",true));
			} catch (ExpressionException e) {
				e.printStackTrace();
			}
			for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) 
			{
				bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
			}
			DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceOdeSolverResultSet("fit", bleachWhileMonitorOdeSolverResultSet);*/
        // experimental bleach region average intensity curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { ReservedVariable.TIME.getName(), "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expBleachDataSource = new DataSource.DataSourceReferenceData("exp", expRefData);
        // Analytic - bleach region average intensity with bleach while monitoring rate
        ODESolverResultSet koffFitOdeSolverResultSet = new ODESolverResultSet();
        koffFitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedVariable.TIME.getName()));
        Expression bleachedAvgExp = frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().getRecoveryExpressionWithCurrentParameters(currentParams);
        try {
            koffFitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(bleachedAvgExp, "BleachROIAvg", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        double[] truncatedTimes = new double[frapDataTimeStamps.length - startIndexRecovery];
        for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) {
            koffFitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
            truncatedTimes[i - startIndexRecovery] = frapDataTimeStamps[i];
        }
        setCurrentEstimationResults(frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().createData(bleachedAvgExp.flatten(), truncatedTimes));
        DataSource koffFitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", koffFitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expBleachDataSource, koffFitDataSource /*, expCellAvgDataSource , bleachWhileMonitorDataSource*/
        });
        multisourcePlotPane.selectAll();
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Expression(cbit.vcell.parser.Expression) Parameter(cbit.vcell.opt.Parameter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Aggregations

SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)16 ReferenceData (cbit.vcell.opt.ReferenceData)8 Element (org.jdom.Element)6 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)4 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)4 ExplicitFitObjectiveFunction (cbit.vcell.opt.ExplicitFitObjectiveFunction)4 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)4 OptimizationSolverSpec (cbit.vcell.opt.OptimizationSolverSpec)4 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)4 ExpressionException (cbit.vcell.parser.ExpressionException)4 Constraint (cbit.vcell.opt.Constraint)3 Parameter (cbit.vcell.opt.Parameter)3 SpatialReferenceData (cbit.vcell.opt.SpatialReferenceData)3 PowellOptimizationSolver (cbit.vcell.opt.solvers.PowellOptimizationSolver)3 Expression (cbit.vcell.parser.Expression)3 File (java.io.File)3 ParseException (java.text.ParseException)3 Vector (java.util.Vector)3 CSV (cbit.vcell.math.CSV)2 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2