Skip to content

Commit

Permalink
added add_kernel method in MMD
Browse files Browse the repository at this point in the history
  • Loading branch information
lambday committed Jul 13, 2016
1 parent 9a7ccb6 commit 121dd63
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
43 changes: 31 additions & 12 deletions src/shogun/statistical_testing/MMD.cpp
@@ -1,19 +1,31 @@
/*
* Restructuring Shogun's statistical hypothesis testing framework.
* Copyright (C) 2016 Soumyajit De
* Copyright (c) The Shogun Machine Learning Toolbox
* Written (w) 2016 Soumyajit De
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the Shogun Development Team.
*/

#include <utility>
Expand Down Expand Up @@ -68,6 +80,8 @@ struct CMMD::Self
std::function<float32_t(SGMatrix<float32_t>)> statistic_job;
std::function<float32_t(SGMatrix<float32_t>)> permutation_job;
std::function<float32_t(SGMatrix<float32_t>)> variance_job;

KernelManager kernel_selection_mgr;
};

CMMD::Self::Self(CMMD& cmmd) : owner(cmmd),
Expand Down Expand Up @@ -309,6 +323,11 @@ CMMD::~CMMD()
{
}

void CMMD::add_kernel(CKernel* kernel)
{
self->kernel_selection_mgr.push_back(kernel);
}

float64_t CMMD::compute_statistic()
{
return self->compute_statistic_variance().first;
Expand Down
39 changes: 26 additions & 13 deletions src/shogun/statistical_testing/MMD.h
@@ -1,19 +1,31 @@
/*
* Restructuring Shogun's statistical hypothesis testing framework.
* Copyright (C) 2016 Soumyajit De
* Copyright (c) The Shogun Machine Learning Toolbox
* Written (w) 2016 Soumyajit De
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the Shogun Development Team.
*/

#ifndef MMD_H_
Expand Down Expand Up @@ -64,8 +76,9 @@ class CMMD : public CTwoSampleTest
public:
CMMD();
virtual ~CMMD();
/*

void add_kernel(CKernel *kernel);
/*
void select_kernel(EKernelSelectionMethod kmethod);
CKernel* get_kernel() const;
*/
Expand Down
13 changes: 13 additions & 0 deletions src/shogun/statistical_testing/internals/KernelManager.cpp
Expand Up @@ -38,6 +38,11 @@
using namespace shogun;
using namespace internal;

KernelManager::KernelManager()
{
SG_SDEBUG("Kernel manager instance initialized!\n");
}

KernelManager::KernelManager(index_t num_kernels)
{
SG_SDEBUG("Kernel manager instance initialized with %d kernels!\n", num_kernels);
Expand Down Expand Up @@ -77,6 +82,14 @@ CKernel* KernelManager::kernel_at(size_t i) const
return m_precomputed_kernels[i].get();
}

void KernelManager::push_back(CKernel* kernel)
{
SG_SDEBUG("Entering!\n");
SG_REF(kernel);
m_kernels.push_back(std::shared_ptr<CKernel>(kernel, [](CKernel* ptr) { SG_UNREF(ptr); }));
SG_SDEBUG("Leaving!\n");
}

void KernelManager::precompute_kernel_at(size_t i)
{
SG_SDEBUG("Entering!\n");
Expand Down
5 changes: 4 additions & 1 deletion src/shogun/statistical_testing/internals/KernelManager.h
Expand Up @@ -48,12 +48,15 @@ namespace internal
class KernelManager
{
public:
KernelManager(index_t num_kernels);
KernelManager();
explicit KernelManager(index_t num_kernels);
~KernelManager();

InitPerKernel kernel_at(size_t i);
CKernel* kernel_at(size_t i) const;

void push_back(CKernel* kernel);

void precompute_kernel_at(size_t i);
void restore_kernel_at(size_t i);
private:
Expand Down

0 comments on commit 121dd63

Please sign in to comment.