Search in sources :

Example 11 with Node

use of cbit.util.graph.Node in project vcell by virtualcell.

the class ModelOptimizationSpec method removeUncoupledParameters.

public void removeUncoupledParameters() {
    try {
        localIssueList.clear();
        MathMapping mathMapping = getSimulationContext().createNewMathMapping();
        MathDescription mathDesc = mathMapping.getMathDescription();
        MathSystemHash mathSystemHash = fromMath(mathDesc);
        Graph graph = mathSystemHash.getDependencyGraph(mathSystemHash.getSymbols());
        Tree[] spanningTrees = graph.getSpanningForest();
        // 
        for (int i = 0; i < spanningTrees.length; i++) {
            Node[] treeNodes = spanningTrees[i].getNodes();
            boolean bHasStateVariables = false;
            for (int j = 0; j < treeNodes.length; j++) {
                Node node = treeNodes[j];
                Variable var = mathDesc.getVariable(node.getName());
                if (var instanceof VolVariable || var instanceof MemVariable || var instanceof FilamentVariable || var instanceof VolumeRegionVariable || var instanceof MembraneRegionVariable || var instanceof FilamentRegionVariable) {
                    bHasStateVariables = true;
                    break;
                }
            }
            if (!bHasStateVariables) {
                spanningTrees = (Tree[]) BeanUtils.removeElement(spanningTrees, spanningTrees[i]);
                i--;
            }
        }
        // 
        // remove parameters not mapped to a surviving tree (not coupled to any state variables
        // 
        ArrayList<ParameterMappingSpec> paramMappingSpecsList = new ArrayList<ParameterMappingSpec>();
        paramMappingSpecsList.addAll(Arrays.asList(fieldParameterMappingSpecs));
        for (int i = 0; i < paramMappingSpecsList.size(); i++) {
            Parameter parameter = paramMappingSpecsList.get(i).getModelParameter();
            String mathName = mathMapping.getMathSymbolMapping().getVariable(parameter).getName();
            boolean bFoundInTree = false;
            for (int j = 0; j < spanningTrees.length; j++) {
                Node node = spanningTrees[j].getNode(mathName);
                if (node != null) {
                    bFoundInTree = true;
                }
            }
            if (!bFoundInTree) {
                paramMappingSpecsList.remove(i);
                i--;
            }
        }
        ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[paramMappingSpecsList.size()];
        paramMappingSpecsList.toArray(parameterMappingSpecs);
        setParameterMappingSpecs(parameterMappingSpecs);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        localIssueList.add(new Issue(this, localIssueContext, IssueCategory.ParameterEstimationGeneralWarning, e.getMessage(), Issue.SEVERITY_WARNING));
    // throw new RuntimeException(e.getMessage());
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Issue(org.vcell.util.Issue) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) Node(cbit.util.graph.Node) ArrayList(java.util.ArrayList) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) Tree(cbit.util.graph.Tree) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) Graph(cbit.util.graph.Graph) FilamentVariable(cbit.vcell.math.FilamentVariable) MathMapping(cbit.vcell.mapping.MathMapping) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

Node (cbit.util.graph.Node)11 Graph (cbit.util.graph.Graph)10 Edge (cbit.util.graph.Edge)9 Tree (cbit.util.graph.Tree)3 Expression (cbit.vcell.parser.Expression)3 Path (cbit.util.graph.Path)2 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 KineticsProxyParameter (cbit.vcell.model.Kinetics.KineticsProxyParameter)2 Membrane (cbit.vcell.model.Membrane)2 Model (cbit.vcell.model.Model)2 ModelParameter (cbit.vcell.model.Model.ModelParameter)2 Parameter (cbit.vcell.model.Parameter)2 Structure (cbit.vcell.model.Structure)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 ArrayList (java.util.ArrayList)2 OrigSurface (cbit.vcell.geometry.surface.OrigSurface)1 Polygon (cbit.vcell.geometry.surface.Polygon)1 Surface (cbit.vcell.geometry.surface.Surface)1 CurrentDensityClampStimulus (cbit.vcell.mapping.CurrentDensityClampStimulus)1