* @brief This function learns the topics of words in a document and is the * main step of a Gibbs sampling iteration. The word topic counts and * corpus topic counts are passed to this function in the first call and * then transfered to the rest calls through args.mSysInfo->user_fctx for * efficiency. * @param args[0] The unique words in the documents * @param args[1] The counts of each
| 175 | * the document |
| 176 | **/ |
| 177 | AnyType lda_gibbs_sample::run(AnyType & args) |
| 178 | { |
| 179 | ArrayHandle<int32_t> words = args[0].getAs<ArrayHandle<int32_t> >(); |
| 180 | ArrayHandle<int32_t> counts = args[1].getAs<ArrayHandle<int32_t> >(); |
| 181 | MutableArrayHandle<int32_t> doc_topic = args[2].getAs<MutableArrayHandle<int32_t> >(); |
| 182 | double alpha = args[4].getAs<double>(); |
| 183 | double beta = args[5].getAs<double>(); |
| 184 | int32_t voc_size = args[6].getAs<int32_t>(); |
| 185 | int32_t topic_num = args[7].getAs<int32_t>(); |
| 186 | int32_t iter_num = args[8].getAs<int32_t>(); |
| 187 | size_t model64_size = static_cast<size_t>(voc_size * (topic_num + 1) + 1) * sizeof(int32_t) / sizeof(int64_t); |
| 188 | |
| 189 | if(alpha <= 0) |
| 190 | throw std::invalid_argument("invalid argument - alpha"); |
| 191 | if(beta <= 0) |
| 192 | throw std::invalid_argument("invalid argument - beta"); |
| 193 | if(voc_size <= 0) |
| 194 | throw std::invalid_argument( |
| 195 | "invalid argument - voc_size"); |
| 196 | if(topic_num <= 0) |
| 197 | throw std::invalid_argument( |
| 198 | "invalid argument - topic_num"); |
| 199 | if(iter_num <= 0) |
| 200 | throw std::invalid_argument( |
| 201 | "invalid argument - iter_num"); |
| 202 | |
| 203 | if(words.size() != counts.size()) |
| 204 | throw std::invalid_argument( |
| 205 | "dimensions mismatch: words.size() != counts.size()"); |
| 206 | if(__min(words) < 0 || __max(words) >= voc_size) |
| 207 | throw std::invalid_argument( |
| 208 | "invalid values in words"); |
| 209 | if(__min(counts) <= 0) |
| 210 | throw std::invalid_argument( |
| 211 | "invalid values in counts"); |
| 212 | |
| 213 | int32_t word_count = __sum(counts); |
| 214 | if(doc_topic.size() != (size_t)(word_count + topic_num)) |
| 215 | throw std::invalid_argument( |
| 216 | "invalid dimension - doc_topic.size() != word_count + topic_num"); |
| 217 | if(__min(doc_topic, 0, topic_num) < 0) |
| 218 | throw std::invalid_argument("invalid values in topic_count"); |
| 219 | if( |
| 220 | __min(doc_topic, topic_num, word_count) < 0 || |
| 221 | __max(doc_topic, topic_num, word_count) >= topic_num) |
| 222 | throw std::invalid_argument( "invalid values in topic_assignment"); |
| 223 | |
| 224 | if (!args.getUserFuncContext()) { |
| 225 | ArrayHandle<int64_t> model64 = args[3].getAs<ArrayHandle<int64_t> >(); |
| 226 | if (model64.size() != model64_size) { |
| 227 | std::stringstream ss; |
| 228 | ss << "invalid dimension: model64.size() = " << model64.size(); |
| 229 | throw std::invalid_argument(ss.str()); |
| 230 | } |
| 231 | if (__min(model64) < 0) { |
| 232 | throw std::invalid_argument("invalid topic counts in model"); |
| 233 | } |
| 234 |
nothing calls this directly
no test coverage detected