Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions cpp/daal/include/algorithms/kernel_function/kernel_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/*
//++
// Implementation of the kernel function interface.
// Public interface for kernel functions.
//--
*/

Expand All @@ -34,12 +34,24 @@ namespace algorithms
{
namespace kernel_function
{
namespace interface1
{
/**
* @addtogroup kernel_function
* @{
*/

/**
* <a name="DAAL-ENUM-ALGORITHMS__KERNEL_FUNCTION__KERNELFUNCTIONTYPE"></a>
* \brief Available kernel function types
*/
enum KernelFunctionType
{
linearKernel = 0, /*!< Linear kernel function: k(X,Y) + b */
rbfKernel = 1, /*!< Radial Basis Function (RBF) kernel */
polynomialKernel = 2 /*!< Polynomial kernel function */
};

namespace interface1
{
/**
* <a name="DAAL-CLASS-ALGORITHMS__KERNEL_FUNCTION__KERNELIFACE"></a>
* \brief Abstract class that specifies the interface of the algorithms
Expand Down Expand Up @@ -110,11 +122,21 @@ class KernelIface : public daal::algorithms::Analysis<batch>
KernelIface & operator=(const KernelIface &);
};
typedef services::SharedPtr<KernelIface> KernelIfacePtr;
/** @} */

/**
* Creates a kernel function of specified type
* \tparam algorithmFPType Data type for the kernel function (float or double)
* \param[in] type Type of the kernel function to create
* \return Pointer to the newly created kernel function
*/
template <typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE>
DAAL_EXPORT KernelIfacePtr createKernelFunction(KernelFunctionType type);

} // namespace interface1
using interface1::KernelIface;
using interface1::KernelIfacePtr;

using interface1::createKernelFunction;
/** @} */
} // namespace kernel_function
} // namespace algorithms
} // namespace daal
Expand Down
6 changes: 2 additions & 4 deletions cpp/daal/include/algorithms/svm/svm_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "data_management/data/csr_numeric_table.h"
#include "algorithms/model.h"
#include "algorithms/kernel_function/kernel_function.h"
#include "algorithms/kernel_function/kernel_function_linear.h"
#include "algorithms/kernel_function/kernel_function_types.h"
#include "algorithms/classifier/classifier_model.h"

namespace daal
Expand Down Expand Up @@ -65,8 +63,8 @@ namespace interface2
/* [Parameter source code] */
struct DAAL_EXPORT Parameter : public classifier::Parameter
{
Parameter(const services::SharedPtr<kernel_function::KernelIface> & kernelForParameter =
services::SharedPtr<kernel_function::KernelIface>(new kernel_function::linear::Batch<>()),
Parameter(const kernel_function::KernelIfacePtr & kernelForParameter =
kernel_function::createKernelFunction(kernel_function::linearKernel),
double C = 1.0, double accuracyThreshold = 0.001, double tau = 1.0e-6, size_t maxIterations = 1000000, size_t cacheSize = 8000000,
bool doShrinking = true, size_t shrinkingStep = 1000)
: C(C),
Expand Down
4 changes: 0 additions & 4 deletions cpp/daal/include/daal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@
#include "algorithms/pca/transform/pca_transform_types.h"
#include "algorithms/pca/transform/pca_transform_batch.h"
#include "algorithms/kernel_function/kernel_function_types.h"
#include "algorithms/kernel_function/kernel_function_types_linear.h"
#include "algorithms/kernel_function/kernel_function_types_rbf.h"
#include "algorithms/kernel_function/kernel_function.h"
#include "algorithms/kernel_function/kernel_function_linear.h"
#include "algorithms/kernel_function/kernel_function_rbf.h"
#include "algorithms/svm/svm_model.h"
#include "algorithms/svm/svm_model_builder.h"
#include "algorithms/svm/svm_train_types.h"
Expand Down
4 changes: 0 additions & 4 deletions cpp/daal/include/daal_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@
#include "algorithms/pca/transform/pca_transform_types.h"
#include "algorithms/pca/transform/pca_transform_batch.h"
#include "algorithms/kernel_function/kernel_function_types.h"
#include "algorithms/kernel_function/kernel_function_types_linear.h"
#include "algorithms/kernel_function/kernel_function_types_rbf.h"
#include "algorithms/kernel_function/kernel_function.h"
#include "algorithms/kernel_function/kernel_function_linear.h"
#include "algorithms/kernel_function/kernel_function_rbf.h"
#include "algorithms/svm/svm_model.h"
#include "algorithms/svm/svm_model_builder.h"
#include "algorithms/svm/svm_train_types.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#define __KERNEL_FUNCTION_CSR_BASE_H__

#include "data_management/data/numeric_table.h"
#include "algorithms/kernel_function/kernel_function_types_linear.h"
#include "algorithms/kernel_function/kernel_function_types_rbf.h"
#include "algorithms/kernel_function/kernel_function_linear.h"
#include "algorithms/kernel_function/kernel_function_rbf.h"
#include "src/algorithms/kernel_function/kernel_function_types_linear.h"
#include "src/algorithms/kernel_function/kernel_function_types_rbf.h"
#include "src/algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_rbf.h"
#include "src/data_management/service_numeric_table.h"
#include "src/algorithms/kernel.h"
#include "src/algorithms/kernel_function/kernel_function_dense_base.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#define __KERNEL_FUNCTION_DENSE_BASE_H__

#include "data_management/data/numeric_table.h"
#include "algorithms/kernel_function/kernel_function_types_linear.h"
#include "algorithms/kernel_function/kernel_function_types_rbf.h"
#include "algorithms/kernel_function/kernel_function_linear.h"
#include "algorithms/kernel_function/kernel_function_rbf.h"
#include "src/algorithms/kernel_function/kernel_function_types_linear.h"
#include "src/algorithms/kernel_function/kernel_function_types_rbf.h"
#include "src/algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_rbf.h"
#include "src/data_management/service_micro_table.h"
#include "src/algorithms/kernel.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* file: kernel_function_factory.cpp */
/*******************************************************************************
* Copyright 2014 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

/*
//++
// Implementation of kernel function factory.
//--
*/

#include "algorithms/kernel_function/kernel_function.h"
#include "src/algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_rbf.h"

namespace daal
{
namespace algorithms
{
namespace kernel_function
{
namespace interface1
{
template <typename algorithmFPType>
DAAL_EXPORT KernelIfacePtr createKernelFunction(KernelFunctionType type)
{
switch (type)
{
case linearKernel: return KernelIfacePtr(new linear::internal::Batch<algorithmFPType>());
case rbfKernel: return KernelIfacePtr(new rbf::internal::Batch<algorithmFPType>());
default: return KernelIfacePtr();
}
}

// Explicit instantiations
template DAAL_EXPORT KernelIfacePtr createKernelFunction<float>(KernelFunctionType type);
template DAAL_EXPORT KernelIfacePtr createKernelFunction<double>(KernelFunctionType type);

} // namespace interface1
} // namespace kernel_function
} // namespace algorithms
} // namespace daal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//--
*/

#include "algorithms/kernel_function/kernel_function_types_linear.h"
#include "src/algorithms/kernel_function/kernel_function_types_linear.h"
#include "src/services/service_defines.h"

using namespace daal::data_management;
Expand All @@ -35,7 +35,7 @@ namespace kernel_function
{
namespace linear
{
namespace interface1
namespace internal
{
Parameter::Parameter(double k, double b) : ParameterBase(), k(k), b(b) {}

Expand All @@ -60,7 +60,7 @@ Status Input::check(const daal::algorithms::Parameter * par, int method) const
return services::Status();
}

} // namespace interface1
} // namespace internal
} // namespace linear
} // namespace kernel_function
} // namespace algorithms
Expand Down
137 changes: 137 additions & 0 deletions cpp/daal/src/algorithms/kernel_function/kernel_function_linear.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* file: kernel_function_linear.h */
/*******************************************************************************
* Copyright 2014 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

/*
//++
// Implementation of the interface for the linear kernel function algorithm
//--
*/

#ifndef __KERNEL_FUNCTION_LINEAR_H__
#define __KERNEL_FUNCTION_LINEAR_H__

#include "algorithms/algorithm.h"
#include "data_management/data/numeric_table.h"
#include "src/algorithms/kernel_function/kernel_function_types_linear.h"
#include "algorithms/kernel_function/kernel_function.h"

namespace daal
{
namespace algorithms
{
namespace kernel_function
{
namespace linear
{
namespace internal
{
/**
* @defgroup kernel_function_linear_batch Batch
* @ingroup kernel_function_linear
* @{
*/
/**
* <a name="DAAL-CLASS-ALGORITHMS__KERNEL_FUNCTION__LINEAR__BATCH"></a>
* \brief Computes a linear kernel function in the batch processing mode.
* <!-- \n<a href="DAAL-REF-KERNEL_FUNCTION_LINEAR-ALGORITHM">Kernel function algorithm description and usage models</a> -->
*
* \tparam algorithmFPType Data type to use in intermediate computations of kernel functions, double or float
* \tparam method Computation method of the algorithm, \ref Method
*
* \par Enumerations
* - \ref Method Methods for computing kernel functions
* - \ref InputId Identifiers of input objects for the kernel function algorithm
* - \ref ResultId Identifiers of results of the kernel function algorithm
*
* \par References
* - \ref interface1::Result "Result" class
*
* \DAAL_DEPRECATED
*/
template <typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
class Batch : public KernelIface
{
public:
typedef KernelIface super;

typedef algorithms::kernel_function::linear::Input InputType;
typedef algorithms::kernel_function::linear::Parameter ParameterType;
typedef typename super::ResultType ResultType;

ParameterType parameter; /*!< Parameter of the kernel function*/
InputType input; /*!< %Input data structure */

/** Default constructor */
DAAL_DEPRECATED Batch();

/**
* Constructs linear kernel function algorithm by copying input objects and parameters
* of another linear kernel function algorithm
* \param[in] other An algorithm to be used as the source to initialize the input objects
* and parameters of the algorithm
*/
Batch(const Batch<algorithmFPType, method> & other);

/**
* Returns the method of the algorithm
* \return Method of the algorithm
*/
int getMethod() const override { return (int)method; }

/**
* Get input objects for the kernel function algorithm
* \return %Input objects for the kernel function algorithm
*/
InputType * getInput() override { return &input; }

/**
* Get parameters of the kernel function algorithm
* \return Parameters of the kernel function algorithm
*/
ParameterBase * getParameter() override { return &parameter; }

/**
* Returns a pointer to the newly allocated linear kernel function algorithm with a copy of input objects
* and parameters of this linear kernel function algorithm
* \return Pointer to the newly allocated algorithm
*/
services::SharedPtr<Batch<algorithmFPType, method> > clone() const { return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl()); }

protected:
void initialize();

Batch<algorithmFPType, method> * cloneImpl() const override { return new Batch<algorithmFPType, method>(*this); }

services::Status allocateResult() override
{
services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int)method);
_res = _result.get();
return s;
}

private:
Batch & operator=(const Batch &);
};
/** @} */
} // namespace internal
using internal::Batch;

} // namespace linear
} // namespace kernel_function
} // namespace algorithms
} // namespace daal
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//--
*/

#include "algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/algorithm_dispatch_container_batch.h"
#include "src/algorithms/kernel_function/polynomial/kernel_function_polynomial.h"
#include "src/algorithms/kernel_function/polynomial/kernel_function_polynomial_dense_default_kernel.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//--
*/

#include "algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_linear.h"
#include "src/algorithms/kernel_function/kernel_function_linear_batch_container.h"

namespace daal
Expand All @@ -33,7 +33,7 @@ namespace kernel_function
{
namespace linear
{
namespace interface1
namespace internal
{
template <>
void Batch<DAAL_FPTYPE, kernel_function::linear::fastCSR>::initialize()
Expand All @@ -55,7 +55,7 @@ DAAL_EXPORT BatchType::Batch(const BatchType & other) : KernelIface(other), para
{
initialize();
}
} // namespace interface1
} // namespace internal
} // namespace linear
} // namespace kernel_function
} // namespace algorithms
Expand Down
Loading
Loading