Skip to content

Commit

Permalink
refactor: adjust to capturing all estimation methods
Browse files Browse the repository at this point in the history
lst parsing will still only get the last method, as will default
to the ext file, and lst will be a general fallback.

references #8 #18 #19 #20 #22
  • Loading branch information
dpastoor committed Aug 26, 2019
1 parent ec8ee8c commit c76507c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
8 changes: 5 additions & 3 deletions parsers/nmparser/parse_lst_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ func ParseLstEstimationFile(lines []string) ModelOutput {
// TODO re-replace parameter data from lst
result := ModelOutput{
RunDetails: ParseRunDetails(lines),
FinalParametersData: ParametersData{
Estimates: finalParameterEst,
StdErr: finalParameterStdErr,
ParametersData: []ParametersData{
ParametersData{
Estimates: finalParameterEst,
StdErr: finalParameterStdErr,
},
},
ParameterStructures: parameterStructures,
ParameterNames: parameterNames,
Expand Down
7 changes: 0 additions & 7 deletions parsers/nmparser/parse_parameter_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
"strings"
)

// ParameterNames containst the names of model parameters
type ParameterNames struct {
Theta []string
Omega []string
Sigma []string
}

// ParseThetaComments will parse out the names from theta parameters
func ParseThetaComments(lines []string) []string {
parsedLines := FormatThetaBlock(CleanThetaBlock(lines))
Expand Down
37 changes: 25 additions & 12 deletions parsers/nmparser/structs.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package parser

// ParameterNames containst the names of model parameters
type ParameterNames struct {
Theta []string `json:"theta,omitempty"`
Omega []string `json:"omega,omitempty"`
Sigma []string `json:"sigma,omitempty"`
}

// ParametersResult contains data about the parameter values for a model
type ParametersResult struct {
Theta []float64
Omega []float64
Sigma []float64
Theta []float64 `json:"theta,omitempty"`
Omega []float64 `json:"omega,omitempty"`
Sigma []float64 `json:"sigma,omitempty"`
}
type RandomEffectResult struct {
Omega []float64
Sigma []float64
Omega []float64 `json:"omega,omitempty"`
Sigma []float64 `json:"sigma,omitempty"`
}

type ParametersData struct {
Estimates ParametersResult `json:"final_parameter_estimates,omitempty"`
StdErr ParametersResult `json:"final_parameter_std_err,omitempty"`
Estimates ParametersResult `json:"estimates,omitempty"`
StdErr ParametersResult `json:"std_err,omitempty"`
// indicates this line contains the OMEGA and SIGMA elements in
// standard deviation/correlation format
RandomEffectSD RandomEffectResult
RandomEffectSD RandomEffectResult `json:"random_effect_sd,omitempty"`
// indicates this line contains the standard errors to the OMEGA and
// SIGMA elements in standard deviation/correlation format
RandomEffectSDSE RandomEffectResult
Fixed bool
RandomEffectSDSE RandomEffectResult `json:"random_effect_sdse,omitempty"`
Fixed bool `json:"fixed,omitempty"`
}

type RunHeuristics struct {
HasZeroGradient bool `json:"has_zero_gradient,omitempty"`
MinimizationSuccessful bool `json:"minimization_successful,omitempty"`
}

// RunDetails contains key information about logistics of the model run
Expand Down Expand Up @@ -89,8 +101,9 @@ type OfvDetails struct {

// ModelOutput is the output struct from a lst file
type ModelOutput struct {
RunDetails RunDetails `json:"run_details,omitempty"`
FinalParametersData ParametersData
RunDetails RunDetails `json:"run_details,omitempty"`
RunHeuristics RunHeuristics `json:"run_heuristics,omitempty"`
ParametersData []ParametersData `json:"parameters_data,omitempty"`
ParameterStructures ParameterStructures `json:"parameter_structures,omitempty"`
ParameterNames ParameterNames `json:"parameter_names,omitempty"`
OFV OfvDetails `json:"ofv,omitempty"`
Expand Down
15 changes: 8 additions & 7 deletions parsers/nmparser/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ func (results ModelOutput) Summary() bool {
}
thetaTable := termtables.CreateTable()
thetaTable.AddHeaders("Theta", "Name", "Estimate", "StdErr (RSE)")
if len(results.FinalParametersData.Estimates.Theta) != len(results.FinalParametersData.StdErr.Theta) {
finalEstimationMethodIndex := len(results.ParametersData) - 1
if len(results.ParametersData[finalEstimationMethodIndex].Estimates.Theta) != len(results.ParametersData[finalEstimationMethodIndex].StdErr.Theta) {
// if the standard errors aren't there, we should
// instead make an equal length slice so that looping to build the table won't blow
// up with an index out of bounds error
results.FinalParametersData.StdErr.Theta = make([]float64, len(results.FinalParametersData.Estimates.Theta))
results.ParametersData[finalEstimationMethodIndex].StdErr.Theta = make([]float64, len(results.ParametersData[finalEstimationMethodIndex].Estimates.Theta))
}
for i := range results.FinalParametersData.Estimates.Theta {
numResult := results.FinalParametersData.Estimates.Theta[i]
seResult := results.FinalParametersData.StdErr.Theta[i]
for i := range results.ParametersData[finalEstimationMethodIndex].Estimates.Theta {
numResult := results.ParametersData[finalEstimationMethodIndex].Estimates.Theta[i]
seResult := results.ParametersData[finalEstimationMethodIndex].StdErr.Theta[i]
var rse float64
if seResult != 0 && numResult != 0 {
rse = math.Abs(seResult / numResult * 100)
Expand Down Expand Up @@ -66,10 +67,10 @@ func (results ModelOutput) Summary() bool {
omegaTable := termtables.CreateTable()
omegaTable.AddHeaders("Omega", "Eta", "Estimate", "ShrinkageSD (%)")
diagIndices := GetDiagonalElements(results.ParameterStructures.Omega)
for i := range results.FinalParametersData.Estimates.Omega {
for i := range results.ParametersData[finalEstimationMethodIndex].Estimates.Omega {
omegaIndex, _ := omegaIndices[i]
if results.ParameterStructures.Omega[i] != 0 {
val := results.FinalParametersData.Estimates.Omega[i]
val := results.ParametersData[finalEstimationMethodIndex].Estimates.Omega[i]
var shrinkage float64
var etaName string
userEtaIndex := funk.IndexOfInt(diagIndices, i)
Expand Down

0 comments on commit c76507c

Please sign in to comment.