#workspace()
#cd("C:/Users/aruoba/Dropbox/Active Research Projects/ACS - Efficient Estimation/Julia/ZLB/Versions/Simple")

#Declare using packages
using Clustering
using LsqFit
using Distributions
using Distances
using LinearAlgebra
using Random
using CSV
using DelimitedFiles
using JLD

#Declare all needed functions:
include("params.jl")
include("options.jl")
include("ghpoints.jl")
include("get_GH_nodes.jl")
include("get_Monomial_nodes.jl")
include("Monomials_2_N4.jl")
include("get_coefs_plc.jl")
include("simulate_plc_lin.jl")
#include("simulate_plc_nlin.jl")
include("cga_grid_h.jl")
include("cga_grid_km.jl")
include("cga_grid_kms.jl")
include("tsga_grid.jl")
include("system_piecewise_linear_jacob_33_lin.jl")
#include("system_piecewise_linear_jacob_33_nlin.jl")
include("eval_hh_33_revised.jl")
include("solve_sgu.jl")
include("gx_hx.jl")
include("get_order1_sgu.jl")
include("my_levenberg_marquardt2.jl")
include("PLC_main.jl")
include("PLC_solve.jl")

# Solution Options

options_int_use, options_float_use = options()

# Parameters

params_use = params()

options_int_use["M"] = 10000
options_int_use["int_d"] = 1
options_int_use["GH"] = 5
options_int_use["cluster_d"] = 3
options_int_use["k"] = 10
options_int_use["maxIt"] = 1000

#keep errors and thetas
theta_out, time_tot, flag_mat, GMM, theta_mat, out_res, out_x = PLC_main(params_use,options_int_use,options_float_use)

#save("theta_PO_v3.jld", "theta_PO", theta_out)
