| 110 | ) const { return force_assignment; } |
| 111 | |
| 112 | void predict_assignments ( |
| 113 | const std::vector<lhs_element>& lhs, |
| 114 | const std::vector<rhs_element>& rhs, |
| 115 | result_type& assignment |
| 116 | ) const |
| 117 | { |
| 118 | assignment.clear(); |
| 119 | |
| 120 | matrix<double> cost; |
| 121 | unsigned long size; |
| 122 | if (force_assignment) |
| 123 | { |
| 124 | size = std::max(lhs.size(), rhs.size()); |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | size = rhs.size() + lhs.size(); |
| 129 | } |
| 130 | cost.set_size(size, size); |
| 131 | |
| 132 | typedef typename feature_extractor::feature_vector_type feature_vector_type; |
| 133 | feature_vector_type feats; |
| 134 | |
| 135 | // now fill out the cost assignment matrix |
| 136 | for (long r = 0; r < cost.nr(); ++r) |
| 137 | { |
| 138 | for (long c = 0; c < cost.nc(); ++c) |
| 139 | { |
| 140 | if (r < (long)lhs.size() && c < (long)rhs.size()) |
| 141 | { |
| 142 | fe.get_features(lhs[r], rhs[c], feats); |
| 143 | cost(r,c) = dot(weights, feats) + bias; |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | cost(r,c) = 0; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | if (cost.size() != 0) |
| 154 | { |
| 155 | // max_cost_assignment() only works with integer matrices, so convert from |
| 156 | // double to integer. |
| 157 | const double scale = static_cast<double>(std::numeric_limits<dlib::int64>::max())/1000/max(abs(cost)); |
| 158 | matrix<dlib::int64> int_cost = matrix_cast<dlib::int64>(round(cost*scale)); |
| 159 | assignment = max_cost_assignment(int_cost); |
| 160 | assignment.resize(lhs.size()); |
| 161 | } |
| 162 | |
| 163 | // adjust assignment so that non-assignments have a value of -1 |
| 164 | for (unsigned long i = 0; i < assignment.size(); ++i) |
| 165 | { |
| 166 | if (assignment[i] >= (long)rhs.size()) |
| 167 | assignment[i] = -1; |
| 168 | } |
| 169 | } |
nothing calls this directly
no test coverage detected