zackxconti / bnmetamodel_gh

Repo for bnmetamodel lib version for Lab Mouse Grasshopper plug-in.
1 stars 2 forks source link

Update laplacesmooth to align with condprobve/lmeestimateparams #46

Open kallewesterling opened 11 months ago

kallewesterling commented 11 months ago

See Helper_functions.laplacesmooth: update laplacesmooth as per code written in condprobve or lmeestimateparams.

def laplacesmooth(bn):
    for vertex in bn.V:
        numBins = bn.Vdata[vertex]['numoutcomes']

        if not (bn.Vdata[vertex]["parents"]):  # has no parents
            for i in range(len(bn.Vdata[vertex]['cprob'])):
                bn.Vdata[vertex]['cprob'][i][0] += 1  # numerator (count)
                bn.Vdata[vertex]['cprob'][i][1] += numBins  # denominator (total count)
        else:
            for i in range(numBins):
                binindex = [str(float(i))]
                bincounts = bn.Vdata[vertex]['cprob'][str(binindex)]
                for j in range(len(bincounts)):
                    bincounts[j][0] += 1  # numerator (count)
                    bincounts[j][1] += numBins  # denominator (total count)

    return bn