Code Monkey home page Code Monkey logo

Comments (4)

oentaryorj avatar oentaryorj commented on May 23, 2024 2

A new function set_cpd has been implemented in this commit and will be made available in the next release.

from causalnex.

mehtabpathan avatar mehtabpathan commented on May 23, 2024 1

Hi @helderc

It is possible to update the CPT after some serious pandas gymnastics - have a look at such function below. Essentially you will have to recreate a multi-index dataframe of the same format as the BN.cpds[node_you_want_to_change]

@benhorsburgh - An implementation to update CPTs of same nature as pomegranate library would be welcome! - https://pomegranate.readthedocs.io/en/latest/Distributions.html

def _set_CPDS(bn):
    '''
    Updates and returns the bayesian network with updated CPDs
    :param bn:
    :return:
    '''
    # Overwrite BN CPDS with those saved
    for node, cpd in bn.cpds.items():
        df = pd.read_csv(f"./data/output/CPDS/{node}.csv")
        # For DataFrames only containing priors (node_name, value)
        if len(df.columns) == 2:
            df = df.set_index(node)
            df.columns = ['']
        else:
            df = df.pivot_table(index=node, columns=[i for i in df.columns if i not in [node, 'value']], values='value')
            if len(df.columns.names) == 1:
                df.columns = pd.MultiIndex(levels=[df.columns.values], codes=[range(3)], names=[df.columns.names])
        # Update the CPDS with those specified
        bn.cpds[node].update(df)
    return bn

from causalnex.

benhorsburgh avatar benhorsburgh commented on May 23, 2024

Hey @helderc. At present, there isn't a way to manually define them.

I agree it would be interesting to have this feature, and I think it would be relatively easy to add. We're currently looking into a possible implementation.

Out of curiosity, what sort of things would you use this to explore? This may help inform an implementation.

from causalnex.

helderc avatar helderc commented on May 23, 2024

Hi @benhorsburgh.
I would like to use this feature mostly as a didactic way to implement a Bayes net and do some inference.
So basically, would be to perform calculations based on made-up examples.

Thank you all.

from causalnex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.