Search in sources :

Example 1 with ParameterSpecification

use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.

the class ParameterSpecGroupSet method validate.

// ////////
// MISC //
// ////////
public void validate() throws ParameterSpecGroupSetValidationException {
    Set<Object> paramKeys = new HashSet<Object>();
    Set<Integer> specHashCodes = new HashSet<Integer>();
    for (ParameterSpecGroup group : this) {
        for (Object paramKey : group.keySet()) {
            ParameterSpecification spec = group.get(paramKey);
            // Validate
            if (specHashCodes.contains(spec.objectHashCode())) {
                throw new ParameterSpecGroupSetValidationException("Multiple parameter groups contain the same specification object '" + spec.getClass().getSimpleName() + "@" + spec.hashCode() + "'.  A specification object should be added to only a single group because it is permitted to save state between calls.");
            }
            if (group != defaultValueGroup && paramKeys.contains(paramKey)) {
                throw new ParameterSpecGroupSetValidationException("Multiple parameter groups contain a specification for the parameter '" + paramKey + "'.");
            }
            // Save
            specHashCodes.add(spec.objectHashCode());
            if (group != defaultValueGroup) {
                // Default value parameters do not prevent
                paramKeys.add(paramKey);
            // other groups from having the same parameters.
            }
            // Max values
            int max = spec.getMaxValues();
            if (max != -1 && group.getRunCount() > max) {
                throw new ParameterSpecGroupSetValidationException("Specification for parameter '" + paramKey + "' has a maximum run count less than the run count of its group.");
            }
        }
    }
}
Also used : UniformParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.UniformParameterSpecification) EvenSpacingParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification) ListParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.ListParameterSpecification) ParameterSpecification(gov.sandia.n2a.parms.ParameterSpecification) ConstantParameterSpecGroup(gov.sandia.umf.platform.ensemble.params.groups.ConstantParameterSpecGroup) LatinHypercubeParameterSpecGroup(gov.sandia.umf.platform.ensemble.params.groups.LatinHypercubeParameterSpecGroup) MonteCarloParameterSpecGroup(gov.sandia.umf.platform.ensemble.params.groups.MonteCarloParameterSpecGroup) ParameterSpecGroup(gov.sandia.umf.platform.ensemble.params.groups.ParameterSpecGroup) HashSet(java.util.HashSet)

Example 2 with ParameterSpecification

use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.

the class CompositeParameterSpecification method getValue.

// /////////
// VALUE //
// /////////
@Override
public Object getValue(int groupRunCount, int idx) {
    int total = 0;
    for (SubSpecification sspec : subSpecs) {
        int howMany = sspec.howMany;
        ParameterSpecification spec = sspec.spec;
        if (idx < total + howMany) {
            return spec.getValue(howMany, idx - total);
        }
        total += howMany;
    }
    throw new RuntimeException("Composite parameter specification is misconfigured.");
}
Also used : ParameterSpecification(gov.sandia.n2a.parms.ParameterSpecification)

Example 3 with ParameterSpecification

use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.

the class ParameterSpecGroupPanel method initPanel.

private void initPanel(ParameterSpecGroup group) {
    for (Object key : group.keySet()) {
        ParameterSpecification spec = group.get(key);
        String keyStr = key.toString();
        String[] path = keyStr.split("\\.");
        List<ParameterDomain> d = new ArrayList<ParameterDomain>();
        for (int i = 0; i < path.length - 1; i++) {
            String seg = path[i];
            d.add(new ParameterDomain(seg));
        }
        // , dv, desc,icon);
        Parameter param = new Parameter(path[path.length - 1]);
        ParameterBundle bundle = new ParameterBundle(d, param);
        addParam(bundle, spec);
    }
}
Also used : ConstantParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.ConstantParameterSpecification) ParameterSpecification(gov.sandia.n2a.parms.ParameterSpecification) UniformParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.UniformParameterSpecification) EvenSpacingParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification) ParameterDomain(gov.sandia.n2a.parms.ParameterDomain) ArrayList(java.util.ArrayList) Parameter(gov.sandia.n2a.parms.Parameter) ParameterBundle(gov.sandia.n2a.parms.ParameterBundle)

Example 4 with ParameterSpecification

use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.

the class ParameterSpecGroupPanel method addParam.

public ParameterSpecPanel addParam(ParameterBundle bundle, ParameterSpecification useThisSpec) {
    ParameterSpecification spec;
    GroupType type = (GroupType) cboGroupType.getSelectedItem();
    Object defaultValue = bundle.getParameter().getDefaultValue();
    if (useThisSpec == null) {
        spec = chooseDefaultSpecification(type, defaultValue);
    } else {
        spec = useThisSpec;
    }
    final ParameterSpecPanel pnlSpec = new ParameterSpecPanel(bundle, spec, readOnly);
    pnlSpec.addRemoveListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            pnlParams.remove(specPanels.get(pnlSpec));
            specPanels.remove(pnlSpec);
            pnlParams.updateUI();
            fireChangeNotifier();
        }
    });
    pnlSpec.addEditListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            ParameterSpecification spec = pnlSpec.getSpecification();
            GroupType type = (GroupType) cboGroupType.getSelectedItem();
            switch(type) {
                case LATIN_HYPERCUBE:
                    if (!(spec instanceof EvenSpacingParameterSpecification)) {
                        cboGroupType.setSelectedItem(GroupType.MIXED);
                    }
                    break;
                case MONTE_CARLO:
                    if (!(spec instanceof EvenSpacingParameterSpecification)) {
                        cboGroupType.setSelectedItem(GroupType.MIXED);
                    }
                    break;
            }
            fireChangeNotifier();
        }
    });
    JPanel cont = Lay.p(pnlSpec, "eb=10t,opaque=false");
    specPanels.put(pnlSpec, cont);
    pnlParams.add(cont);
    updateUI();
    fireChangeNotifier();
    return pnlSpec;
}
Also used : JPanel(javax.swing.JPanel) ConstantParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.ConstantParameterSpecification) ParameterSpecification(gov.sandia.n2a.parms.ParameterSpecification) UniformParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.UniformParameterSpecification) EvenSpacingParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification) EvenSpacingParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 5 with ParameterSpecification

use of gov.sandia.n2a.parms.ParameterSpecification in project n2a by frothga.

the class ParameterSpecGroupSet method addGroupParamsToParamSet.

private void addGroupParamsToParamSet(ParameterSet set, ParameterSpecGroup group, int idx, Set<Object> skipDVGroupParams) {
    for (Object paramKey : group.keySet()) {
        // are contained in other non-default value groups.
        if (group == defaultValueGroup && skipDVGroupParams.contains(paramKey)) {
            continue;
        }
        ParameterSpecification paramSpec = group.get(paramKey);
        Object value;
        if (!paramSpec.isStable() && group.isEnforceStability(paramKey)) {
            // Save and reload values from cache.
            if (group.isInStabilityCache(paramKey, idx)) {
                value = group.getFromStabilityCache(paramKey, idx);
            } else {
                value = paramSpec.getValue(group.getRunCount(), idx);
                group.putInStabilityCache(paramKey, idx, value);
            }
        } else {
            value = paramSpec.getValue(group.getRunCount(), idx);
        }
        set.put(paramKey, value);
    }
}
Also used : UniformParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.UniformParameterSpecification) EvenSpacingParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification) ListParameterSpecification(gov.sandia.umf.platform.ensemble.params.specs.ListParameterSpecification) ParameterSpecification(gov.sandia.n2a.parms.ParameterSpecification)

Aggregations

ParameterSpecification (gov.sandia.n2a.parms.ParameterSpecification)7 EvenSpacingParameterSpecification (gov.sandia.umf.platform.ensemble.params.specs.EvenSpacingParameterSpecification)5 UniformParameterSpecification (gov.sandia.umf.platform.ensemble.params.specs.UniformParameterSpecification)5 ParameterSpecGroup (gov.sandia.umf.platform.ensemble.params.groups.ParameterSpecGroup)3 ConstantParameterSpecification (gov.sandia.umf.platform.ensemble.params.specs.ConstantParameterSpecification)3 ParameterDomain (gov.sandia.n2a.parms.ParameterDomain)2 ListParameterSpecification (gov.sandia.umf.platform.ensemble.params.specs.ListParameterSpecification)2 Parameter (gov.sandia.n2a.parms.Parameter)1 ParameterBundle (gov.sandia.n2a.parms.ParameterBundle)1 ParameterKeyPath (gov.sandia.n2a.parms.ParameterKeyPath)1 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)1 ConstantParameterSpecGroup (gov.sandia.umf.platform.ensemble.params.groups.ConstantParameterSpecGroup)1 LatinHypercubeParameterSpecGroup (gov.sandia.umf.platform.ensemble.params.groups.LatinHypercubeParameterSpecGroup)1 MonteCarloParameterSpecGroup (gov.sandia.umf.platform.ensemble.params.groups.MonteCarloParameterSpecGroup)1 ParameterSpecGroupSet (gov.sandia.umf.platform.ensemble.params.groupset.ParameterSpecGroupSet)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1