Giter Club home page Giter Club logo

Comments (1)

clberube avatar clberube commented on August 18, 2024

Just pushed an update to invResults.py with the following code:
Also updated GUI with new Option: "Save traces in CSV"

def save_csv_traces(sol):
    """
    Saves the traces contained in mcmcinv 
    object sol to a single csv file.
    call with sol.save_csv_traces()
    """

    # Get some basic information from the mcmc object
    MDL, filepath = sol.MDL, sol.filename
    model = get_model_type(sol)
    sample_name = filepath.replace("\\", "/").split("/")[-1].split(".")[0]
    if sol.model in ['ColeCole', 'Dias', 'Shin']:
        tagno = 1 # Tags for CC model starts with 1 (m1, m2, tau1, tau2, c1, c2)
    else:
        tagno = 0 # Tags for DD model starts with 0 (a0, a1, a2, a3, a4, ...)
    
    # Decide where to save the csv
    save_where = '/TraceResults/'
    working_path = getcwd().replace("\\", "/")+"/"
    save_path = working_path + save_where + "%s/"%sample_name # Add subfolder for the sample
    
    # Get names of parameters for save file
    pm_names = [x.__name__ for x in MDL.stochastics]
    pm_shapes = [x.shape for x in MDL.stochastics]
    pm_shapes = [1 if len(v) == 0 else v[0] for v in pm_shapes]
    
    # Reshaping names for proper format
    all_pm_names = [x*[y] for x,y in zip(pm_shapes, pm_names)]
    all_pm_names = [item for sublist in all_pm_names for item in sublist]
    all_pm_names = [v + str(all_pm_names[:i].count(v) + tagno) if all_pm_names.count(v) > 1 else v for i, v in enumerate(all_pm_names)]
    all_pm_names = [model+"_"+s for s in all_pm_names]
    headers = ','.join(list(all_pm_names)) # Headers for CSV file

    # Start getting the traces from mcmcinv object
    trace_matrix = []
    for n, s in zip(pm_names,pm_shapes):
        trace_matrix.append(MDL.trace(n)[:])
    trace_matrix = np.hstack([x[:,np.newaxis] if x.ndim==1 else x for x in trace_matrix])
    
    # Do the saving
    print("\nSaving CSV traces in:\n", save_path)
    if not path.exists(save_path):
        makedirs(save_path)
    np.savetxt(save_path+'TRACES_%s-%s_%s.csv' %(sol.model,model,sample_name), trace_matrix, delimiter=',', header=headers, comments="")

closing issue

from bisip.

Related Issues (4)

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.