Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash in SGObject #2838

Closed
yorkerlin opened this issue May 5, 2015 · 4 comments
Closed

hash in SGObject #2838

yorkerlin opened this issue May 5, 2015 · 4 comments

Comments

@yorkerlin
Copy link
Member

@vigsterkr , @lisitsyn , @karlnapf
there may be a bug.
If CSGObject::update_parameter_hash() is called more than once, CSGObject::parameter_hash_changed() always returns true even when variables remain the same.

for example

void CExactInferenceMethod::update()
{

    CInferenceMethod::update();
    update_chol();
    update_alpha();
    update_deriv();
    update_mean();
    update_cov();

    update_parameter_hash();
    SG_SPRINT("hash value1 %d \n", m_hash);  
    update_parameter_hash();
    SG_SPRINT("hash value2 %d \n", m_hash);  

}

hash value1 and hash value2 are different since

void CSGObject::update_parameter_hash()
{
    uint32_t carry=0;
    uint32_t length=0;

    get_parameter_incremental_hash(m_hash, carry, length); 
    m_hash=CHash::FinalizeIncrementalMurmurHash3(m_hash, carry, length);
}

where m_hash becomes non-zero after update_parameter_hash() is called

what is worse,

bool CSGObject::parameter_hash_changed()
{
    uint32_t hash=0;
    uint32_t carry=0;
    uint32_t length=0;

    get_parameter_incremental_hash(hash, carry, length); 
    hash=CHash::FinalizeIncrementalMurmurHash3(hash, carry, length);

    return (m_hash!=hash);
}

Note that hash is zero, which means if update_parameter_hash() is called more than once, CSGObject::parameter_hash_changed() always returns true even when variables remain the same.

@yorkerlin
Copy link
Member Author

I am not sure whether the hash value should be changed if parameter_hash_changed() is called even when values of variables in the object remain unchanged

@yorkerlin
Copy link
Member Author

if you think this is a bug, the fix is quite simple.

void CSGObject::update_parameter_hash()
{
    uint32_t carry=0;
    uint32_t length=0;

    //CHANGE m_hash to 0
    get_parameter_incremental_hash(0, carry, length);  
    m_hash=CHash::FinalizeIncrementalMurmurHash3(m_hash, carry, length);
}

@karlnapf
Copy link
Member

karlnapf commented May 7, 2015

I think this is a bug! This should not be. Do unit tests break if you fix it?
Make sure to add unit tests for the hashing if you do fix it
Thanks!

@yorkerlin
Copy link
Member Author

this issue is solved.
I close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants