Search in sources :

Example 1 with KernelType

use of org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType in project knime-core by knime.

the class SVMLearnerNodeModel method loadValidatedSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_paramC.loadSettingsFrom(settings);
    m_classcol.loadSettingsFrom(settings);
    if (settings.containsKey(CFG_KERNELTYPE)) {
        m_kernelType = KernelType.valueOf(settings.getString(CFG_KERNELTYPE));
    }
    for (Map.Entry<KernelType, Vector<SettingsModelDouble>> entry : m_kernelParameters.entrySet()) {
        Vector<SettingsModelDouble> kernelsettings = entry.getValue();
        for (SettingsModelDouble smd : kernelsettings) {
            try {
                smd.loadSettingsFrom(settings);
            } catch (InvalidSettingsException ise) {
                // it's not bad if a parameter is missing. This may be
                // an old version, but inform the user.
                LOGGER.warn("Did not find " + smd.toString() + " in the" + " NodeSettings. Using default value instead.");
            }
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelDouble(org.knime.core.node.defaultnodesettings.SettingsModelDouble) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) KernelType(org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType) Vector(java.util.Vector) DoubleVector(org.knime.base.node.mine.svm.util.DoubleVector)

Example 2 with KernelType

use of org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType in project knime-core by knime.

the class SVMLearnerNodeModel method createKernelParams.

/**
 * creates the kernel parameter SettingsModels.
 *
 * @return HashMap containing the kernel and its assigned SettingsModels.
 */
static LinkedHashMap<KernelType, Vector<SettingsModelDouble>> createKernelParams() {
    LinkedHashMap<KernelType, Vector<SettingsModelDouble>> kernelParameters = new LinkedHashMap<KernelType, Vector<SettingsModelDouble>>();
    for (KernelType kerneltype : KernelType.values()) {
        Kernel kernel = KernelFactory.getKernel(kerneltype);
        Vector<SettingsModelDouble> settings = new Vector<SettingsModelDouble>();
        for (int i = 0; i < kernel.getNumberParameters(); i++) {
            settings.add(new SettingsModelDouble(CFG_KERNELPARAM + "_" + kernel.getParameterName(i), kernel.getDefaultParameter(i)));
        }
        kernelParameters.put(kerneltype, settings);
    }
    return kernelParameters;
}
Also used : SettingsModelDouble(org.knime.core.node.defaultnodesettings.SettingsModelDouble) KernelType(org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType) Vector(java.util.Vector) DoubleVector(org.knime.base.node.mine.svm.util.DoubleVector) Kernel(org.knime.base.node.mine.svm.kernel.Kernel) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with KernelType

use of org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType in project knime-core by knime.

the class SVMLearnerNodeModel method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) {
    settings.addString(CFG_KERNELTYPE, m_kernelType.toString());
    m_paramC.saveSettingsTo(settings);
    m_classcol.saveSettingsTo(settings);
    for (Map.Entry<KernelType, Vector<SettingsModelDouble>> entry : m_kernelParameters.entrySet()) {
        Vector<SettingsModelDouble> kernelsettings = entry.getValue();
        for (SettingsModelDouble smd : kernelsettings) {
            smd.saveSettingsTo(settings);
        }
    }
}
Also used : SettingsModelDouble(org.knime.core.node.defaultnodesettings.SettingsModelDouble) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) KernelType(org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType) Vector(java.util.Vector) DoubleVector(org.knime.base.node.mine.svm.util.DoubleVector)

Example 4 with KernelType

use of org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType in project knime-core by knime.

the class SVMLearnerNodeModel method validateSettings.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    if (settings.containsKey(CFG_KERNELTYPE)) {
        String tmpKernel = settings.getString(CFG_KERNELTYPE);
        boolean found = false;
        for (String kernel : KernelFactory.getKernelNames()) {
            if (tmpKernel.equals(kernel)) {
                found = true;
            }
        }
        if (!found) {
            throw new InvalidSettingsException("Unknown kernel type: " + tmpKernel);
        }
    }
    for (Map.Entry<KernelType, Vector<SettingsModelDouble>> entry : m_kernelParameters.entrySet()) {
        Vector<SettingsModelDouble> kernelsettings = entry.getValue();
        for (SettingsModelDouble smd : kernelsettings) {
            try {
                smd.validateSettings(settings);
            } catch (InvalidSettingsException ise) {
                // it's not bad if a parameter is missing. This may be
                // an old version, but inform the user.
                LOGGER.warn("Did not find " + smd.toString() + " in the" + " NodeSettings. Using default value instead.");
            }
        }
    }
    m_paramC.validateSettings(settings);
    m_classcol.validateSettings(settings);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelDouble(org.knime.core.node.defaultnodesettings.SettingsModelDouble) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) KernelType(org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType) Vector(java.util.Vector) DoubleVector(org.knime.base.node.mine.svm.util.DoubleVector)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)4 Vector (java.util.Vector)4 KernelType (org.knime.base.node.mine.svm.kernel.KernelFactory.KernelType)4 DoubleVector (org.knime.base.node.mine.svm.util.DoubleVector)4 SettingsModelDouble (org.knime.core.node.defaultnodesettings.SettingsModelDouble)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Kernel (org.knime.base.node.mine.svm.kernel.Kernel)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1