this function will calculate the weights for hidden sequence