lanl-ansi / GraphicalModelLearning.jl

Algorithms for Learning Graphical Models
https://lanl-ansi.github.io/GraphicalModelLearning.jl/stable/
Other
23 stars 10 forks source link

Multi-interactions #15

Closed ccoffrin closed 6 years ago

ccoffrin commented 6 years ago

Preliminary tests on current data look resonable. I suggest we merge this into master.

Here is a little script I am currently using for testing.

#!/usr/bin/env julia

using ArgParse
using JSON
using GraphicalModelLearning
using Ipopt

function main(args)
    samples = readcsv(args["samples"])

    gm = learn(samples, multiRISE(0.0, false, args["order"]), NLP(IpoptSolver(tol=1e-12)))

    data = []
    for (k,v) in sort(collect(gm), by=(x) -> abs(x[2]), rev=true)
        println(k, " => ", v)
        push!(data, Dict("term" => k, "weight" => v))
    end
    println()

    open(args["model"], "w") do f
        write(f, JSON.json(data))
    end
end

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "--samples", "-s"
            help = "the samples input data file (.csv)"
            required = true
        "--model", "-m"
            help = "the model output data file (.json)"
            required = true
        "--order", "-o"
            help = "the model order"
            default = 4
            arg_type = Int64
    end

    return parse_args(s)
end

if isinteractive() == false
    main(parse_commandline())
end