{"action":"created","issue":{"url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/15","repository_url":"https://api.github.com/repos/dthuerck/mapmap_cpu","labels_url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/15/comments","events_url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/15/events","html_url":"https://github.com/dthuerck/mapmap_cpu/pull/15","id":390717263,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM4NDE5OTI2","number":15,"title":"Fix division by zero in StopWhenReturnsDiminish criterion","user":{"login":"stepankonrad","id":3874560,"node_id":"MDQ6VXNlcjM4NzQ1NjA=","avatar_url":"https://avatars3.githubusercontent.com/u/3874560?v=4","gravatar_id":"","url":"https://api.github.com/users/stepankonrad","html_url":"https://github.com/stepankonrad","followers_url":"https://api.github.com/users/stepankonrad/followers","following_url":"https://api.github.com/users/stepankonrad/following{/other_user}","gists_url":"https://api.github.com/users/stepankonrad/gists{/gist_id}","starred_url":"https://api.github.com/users/stepankonrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stepankonrad/subscriptions","organizations_url":"https://api.github.com/users/stepankonrad/orgs","repos_url":"https://api.github.com/users/stepankonrad/repos","events_url":"https://api.github.com/users/stepankonrad/events{/privacy}","received_events_url":"https://api.github.com/users/stepankonrad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-13T14:59:47Z","updated_at":"2018-12-15T16:15:09Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/dthuerck/mapmap_cpu/pulls/15","html_url":"https://github.com/dthuerck/mapmap_cpu/pull/15","diff_url":"https://github.com/dthuerck/mapmap_cpu/pull/15.diff","patch_url":"https://github.com/dthuerck/mapmap_cpu/pull/15.patch"},"body":"Hi @dthuerck,\r\nthis happens for example if the graph doesn't have any edges.\r\nIs this the right way to terminate? Can the cost go below 0?\r\nBest,\r\nStepan\r\n"},"comment":{"url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/comments/447579425","html_url":"https://github.com/dthuerck/mapmap_cpu/pull/15#issuecomment-447579425","issue_url":"https://api.github.com/repos/dthuerck/mapmap_cpu/issues/15","id":447579425,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NzU3OTQyNQ==","user":{"login":"dthuerck","id":11340264,"node_id":"MDQ6VXNlcjExMzQwMjY0","avatar_url":"https://avatars0.githubusercontent.com/u/11340264?v=4","gravatar_id":"","url":"https://api.github.com/users/dthuerck","html_url":"https://github.com/dthuerck","followers_url":"https://api.github.com/users/dthuerck/followers","following_url":"https://api.github.com/users/dthuerck/following{/other_user}","gists_url":"https://api.github.com/users/dthuerck/gists{/gist_id}","starred_url":"https://api.github.com/users/dthuerck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dthuerck/subscriptions","organizations_url":"https://api.github.com/users/dthuerck/orgs","repos_url":"https://api.github.com/users/dthuerck/repos","events_url":"https://api.github.com/users/dthuerck/events{/privacy}","received_events_url":"https://api.github.com/users/dthuerck/received_events","type":"User","site_admin":false},"created_at":"2018-12-15T16:15:09Z","updated_at":"2018-12-15T16:15:09Z","author_association":"OWNER","body":"Hi @stepankonrad,\r\n\r\nthanks for contributing! You're absolutely right, a 0-objective would cause a 0-division - shame on me :/\r\nGood point about negative costs. Though I always assumed costs are nonnegative, in general I see no issues with actually using negative costs...\r\n\r\nOn the modelling side, the best possible solution is adding a bias pushing the global minimum to 0 or above. Otherwise, there's all sorts of stuff that could go wrong (think sequences 20 -> 10 -> 0 -> -10 -> -20 or 10 -> -10).\r\nAfter considering some cases, I would propose the following to stick as close as possible to the previous meaning of the termination criterion: let's use the following:\r\n\r\n```\r\n    /* avoid nondecreasing objective */\r\n    if(newest_val >= oldest_val)\r\n        return true;\r\n\r\n    /* in order to support negative costs, handle the magnitudes only */\r\n    const _s_t<COSTTYPE, SIMDWIDTH> max_val = std::max(\r\n        oldest_val, newest_val);\r\n    const _s_t<COSTTYPE, SIMDWIDTH> min_val = std::min(\r\n        oldest_val, newest_val);\r\n\r\n    /* avoid 0-division when objective stays constant */\r\n    const _s_t<COSTTYPE, SIMDWIDTH> improv = \r\n        (max_val - min_val) / (static_cast<_s_t<COSTTYPE, SIMDWIDTH>(0.5) * \r\n        (std::abs(max_val) + std::abs(min_val)));\r\n\r\n    return (improv < m_improv_threshold);\r\n```\r\n\r\nThis would gracefully handle negative costs by biasing the expected loss the average. Does it solve you problem?"}}
{"actor":{"display_login":"dthuerck"}}