22 using namespace shogun;
23 using namespace Eigen;
30 void CStudentsTLikelihood::init()
68 Map<VectorXd>
function(m_function.
vector, m_function.
vlen);
73 VectorXd result(
function.rows());
75 for (
index_t i = 0; i <
function.rows(); i++)
76 result[i] = labels->
get_labels()[i] -
function[i];
78 result = result.cwiseProduct(result);
80 result /=
m_df*m_sigma*m_sigma;
82 for (
index_t i = 0; i <
function.rows(); i++)
95 Map<VectorXd>
function(m_function.
vector, m_function.
vlen);
96 VectorXd result(
function.rows());
98 for (
index_t i = 0; i <
function.rows(); i++)
99 result[i] = (labels->
get_labels()[i] -
function[i]);
101 VectorXd result_squared = result.cwiseProduct(result);
103 VectorXd a(
function.rows());
104 VectorXd b(
function.rows());
105 VectorXd c(
function.rows());
106 VectorXd d(
function.rows());
110 for (
index_t i = 0; i <
function.rows(); i++)
111 a[i] = result_squared[i] +
m_df*m_sigma*m_sigma;
115 result = (
m_df+1)*result.cwiseQuotient(a);
116 for (
index_t i = 0; i < result.rows(); i++)
117 sgresult[i] = result[i];
121 for (
index_t i = 0; i <
function.rows(); i++)
122 b[i] = result_squared[i] -
m_df*m_sigma*m_sigma;
126 result = (
m_df+1)*b.cwiseQuotient(a.cwiseProduct(a));
127 for (
index_t i = 0; i < result.rows(); i++)
128 sgresult[i] = result[i];
132 for (
index_t i = 0; i <
function.rows(); i++)
133 c[i] = result_squared[i] - 3*
m_df*m_sigma*m_sigma;
135 d = a.cwiseProduct(a);
139 result = (
m_df+1)*2*result.cwiseProduct(c).cwiseQuotient(d.cwiseProduct(a));
140 for (
index_t i = 0; i < result.rows(); i++)
141 sgresult[i] = result[i];
148 SG_ERROR(
"Invalid index for derivative\n");
158 Map<VectorXd>
function(m_function.
vector, m_function.
vlen);
162 VectorXd result(
function.rows());
164 for (
index_t i = 0; i <
function.rows(); i++)
165 result[i] = (labels->
get_labels()[i] -
function[i]);
168 VectorXd result_squared = result.cwiseProduct(result);
170 VectorXd a(
function.rows());
171 VectorXd b(
function.rows());
172 VectorXd c(
function.rows());
173 VectorXd d(
function.rows());
176 if (strcmp(param->
m_name,
"df") == 0 && obj ==
this)
178 for (
index_t i = 0; i <
function.rows(); i++)
179 a[i] = result_squared[i] +
m_df*m_sigma*m_sigma;
181 a = result_squared.cwiseQuotient(a);
185 for (
index_t i = 0; i <
function.rows(); i++)
188 -
m_df*log(1+result_squared[i]/(
m_df*m_sigma*m_sigma))/2.0;
194 for (
index_t i = 0; i < result.rows(); i++)
195 sgresult[i] = result[i];
200 if (strcmp(param->
m_name,
"sigma") == 0 && obj ==
this)
202 for (
index_t i = 0; i <
function.rows(); i++)
203 a[i] = result_squared[i] +
m_df*m_sigma*m_sigma;
205 a = (
m_df+1)*result_squared.cwiseQuotient(a);
207 for (
index_t i = 0; i <
function.rows(); i++)
210 result = a/(m_sigma);
212 for (
index_t i = 0; i < result.rows(); i++)
213 sgresult[i] = result[i];
229 Map<VectorXd>
function(m_function.
vector, m_function.
vlen);
232 VectorXd result(
function.rows());
234 for (
index_t i = 0; i <
function.rows(); i++)
235 result[i] = (labels->
get_labels()[i] -
function[i]);
237 VectorXd result_squared = result.cwiseProduct(result);
239 VectorXd a(
function.rows());
240 VectorXd b(
function.rows());
241 VectorXd c(
function.rows());
242 VectorXd d(
function.rows());
244 if (strcmp(param->
m_name,
"df") == 0 && obj ==
this)
246 for (
index_t i = 0; i <
function.rows(); i++)
247 a[i] = result_squared[i] +
m_df*m_sigma*m_sigma;
249 b = result_squared.cwiseProduct(result_squared);
251 b = b - 3*result_squared*m_sigma*m_sigma*(
m_df+1);
253 for (
index_t i = 0; i <
function.rows(); i++)
254 b[i] = result_squared[i] - 3*m_sigma*m_sigma*(1+
m_df);
256 b = b.cwiseProduct(result_squared);
258 for (
index_t i = 0; i <
function.rows(); i++)
259 b[i] = b[i] + pow(m_sigma, 4)*
m_df;
263 c = a.cwiseProduct(a);
265 c = c.cwiseProduct(a);
267 result = b.cwiseQuotient(c);
269 result = result/(
m_df-1);
271 for (
index_t i = 0; i < result.rows(); i++)
272 sgresult[i] = result[i];
276 if (strcmp(param->
m_name,
"sigma") == 0 && obj ==
this)
278 for (
index_t i = 0; i <
function.rows(); i++)
279 a[i] = result_squared[i] +
m_df*m_sigma*m_sigma;
281 c = a.cwiseProduct(a);
283 c = c.cwiseProduct(a);
285 for (
index_t i = 0; i <
function.rows(); i++)
286 b[i] =
m_df*m_sigma*m_sigma - 3*result_squared[i];
288 b *= m_sigma*m_sigma*
m_df*2.0*(
m_df+1);
290 result = b.cwiseQuotient(c)/m_sigma;
292 for (
index_t i = 0; i < result.rows(); i++)
293 sgresult[i] = result[i];