# a loss for binary step function data

I have some data with ground truth that looks like a binary step function, where part of it is 0 and part is one. An example for the GT can be like 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0

or something like this

I have a hard time to come up with a loss function that can optimize this problem, the simplest option would be something like CrossEntropy or BinaryCrossEntropy, but I am wondering if there is any other loss that I try.

Something that can take into account the property that when the GT is one (1) it is continuous 1 and when it is zero it is continuous.

To give a little more information, for example, I will never have a GT that be like this 0 0 1 0 1 0 1  also I will never have a GT like this  0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0. In other words, I will have one time ones in a continuous way (it can be at the start or middle or end) but it wont be two discontinuous 1s. Is there any loss function that take into account this properties?