2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 ctx::num_t ctx::MahalModel::__distance(const std::vector<num_t> &v1, const std::vector<num_t> &v2, const std::vector<num_t> &m)
24 if (m.size() != n * n) {
25 _E("m.size() != n * n");
26 return 0.0; // this value does not make any sense
29 std::vector<num_t> diff(n);
30 for (size_t i = 0; i < n; i++) {
31 diff[i] = v2[i] - v1[i];
34 num_t dist2 = 0; // squared distance
35 for (size_t j = 0; j < n; j++) {
36 for (size_t i = 0; i < n; i++) {
37 dist2 += m[i * n + j] * diff[i] * diff[j];
43 ctx::num_t ctx::MahalModel::distance(const std::vector<ctx::num_t> &v)
45 return __distance(v, __mean, __sigma);