001    /*

002     * JNI_SVM-light - A Java Native Interface for SVM-light

003     * 

004     * Copyright (C) 2005 

005     * Tom Crecelius & Martin Theobald 

006     * Max-Planck Institute for Computer Science

007     * 

008     * This program is free software; you can redistribute it and/or modify it under

009     * the terms of the GNU General Public License as published by the Free Software

010     * Foundation.

011     * 

012     * This program is distributed in the hope that it will be useful, but WITHOUT

013     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS

014     * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more

015     * details.

016     * 

017     * You should have received a copy of the GNU General Public License along with

018     * this program; if not, write to the Free Software Foundation, Inc., 51

019     * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

020     */

021    

022    package jnisvmlight;

023    

024    /**

025     * A kernel with sigmoid smoothing.

026     * 

027     * @author Tom Crecelius & Martin Theobald

028     */

029    public class SigmoidKernel extends ExtendedKernel {

030    

031      protected SigmoidKernel() {

032        super(new LinearKernel(), 1.0, 0.0);

033      }

034    

035      public SigmoidKernel(Kernel nestedKernel, double a, double c) {

036        super(nestedKernel, a, c);

037      }

038    

039      public double evaluate(FeatureVector v1, FeatureVector v2) {

040        return tanh(m_a * m_kernel.evaluate(v1, v2) + m_c);

041      }

042    

043      private double tanh(double a) {

044        double x = Math.exp(a);

045        double y = Math.exp(-a);

046        return (x - y) / (x + y);

047      }

048    

049      public String toString() {

050        return "Sigmoid kernel K(x, k) = tanh(" + m_a + ".k(x) + " + m_c + ")"

051            + ". k = " + m_kernel.toString();

052      }

053    }