SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LikelihoodModel.cpp
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2013 Roman Votyakov
00008  * Written (W) 2013 Heiko Strathmann
00009  * Copyright (C) 2012 Jacob Walker
00010  * Copyright (C) 2013 Roman Votyakov
00011  */
00012 
00013 #include <shogun/machine/gp/LikelihoodModel.h>
00014 
00015 using namespace shogun;
00016 
00017 CLikelihoodModel::CLikelihoodModel()
00018 {
00019 }
00020 
00021 CLikelihoodModel::~CLikelihoodModel()
00022 {
00023 }
00024 
00025 SGVector<float64_t> CLikelihoodModel::get_predictive_log_probabilities(
00026         SGVector<float64_t> mu, SGVector<float64_t> s2, const CLabels *lab)
00027 {
00028     return get_log_zeroth_moments(mu, s2, lab);
00029 }
00030 
00031 SGVector<float64_t> CLikelihoodModel::get_log_probability_fmatrix(
00032         const CLabels* lab, SGMatrix<float64_t> F) const
00033 {
00034     REQUIRE(lab, "Given labels are NULL!\n");
00035     REQUIRE(lab->get_num_labels()==F.num_rows, "Number of labels (%d) does "
00036             "not match dimension of functions (%d)\n",
00037             lab->get_num_labels(),F.num_rows);
00038     REQUIRE(F.num_cols>0, "Number of passed functions (%d) must be positive\n",
00039             F.num_cols);
00040 
00041     SGVector<float64_t> result(F.num_cols);
00042     for (index_t i=0; i<F.num_cols; ++i)
00043     {
00044         /* extract current sample from matrix, assume col-major, dont copy */
00045         SGVector<float64_t> f(&F.matrix[i*F.num_rows], F.num_rows, false);
00046         result[i]=SGVector<float64_t>::sum(get_log_probability_f(lab, f));
00047     }
00048 
00049     return result;
00050 }
00051 
00052 SGVector<float64_t> CLikelihoodModel::get_first_moments(SGVector<float64_t> mu,
00053         SGVector<float64_t> s2, const CLabels* lab) const
00054 {
00055     REQUIRE(lab, "Labels are required (lab should not be NULL)\n")
00056     REQUIRE((mu.vlen==s2.vlen) && (mu.vlen==lab->get_num_labels()),
00057             "Length of the vector of means (%d), length of the vector of "
00058             "variances (%d) and number of labels (%d) should be the same\n",
00059             mu.vlen, s2.vlen, lab->get_num_labels())
00060 
00061     SGVector<float64_t> result(mu.vlen);
00062 
00063     for (index_t i=0; i<mu.vlen; i++)
00064         result[i]=get_first_moment(mu, s2, lab, i);
00065 
00066     return result;
00067 }
00068 
00069 SGVector<float64_t> CLikelihoodModel::get_second_moments(SGVector<float64_t> mu,
00070         SGVector<float64_t> s2, const CLabels* lab) const
00071 {
00072     REQUIRE(lab, "Labels are required (lab should not be NULL)\n")
00073     REQUIRE((mu.vlen==s2.vlen) && (mu.vlen==lab->get_num_labels()),
00074             "Length of the vector of means (%d), length of the vector of "
00075             "variances (%d) and number of labels (%d) should be the same\n",
00076             mu.vlen, s2.vlen, lab->get_num_labels())
00077 
00078     SGVector<float64_t> result(mu.vlen);
00079 
00080     for (index_t i=0; i<mu.vlen; i++)
00081         result[i]=get_second_moment(mu, s2, lab, i);
00082 
00083     return result;
00084 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation