func function(config *config.Config) error { config.Uncertainty.Variance = 1.0 if len(*sampleSeed) > 0 { if number, err := strconv.ParseInt(*sampleSeed, 0, 64); err != nil { return err } else { config.Assessment.Seed = number } } if len(*sampleCount) > 0 { if number, err := strconv.ParseUint(*sampleCount, 0, 64); err != nil { return err } else { config.Assessment.Samples = uint(number) } } if config.Assessment.Samples == 0 { return errors.New("the number of samples should be positive") } output, err := database.Create(*outputFile) if err != nil { return err } defer output.Close() system, err := system.New(&config.System) if err != nil { return err } auncertainty, err := uncertainty.NewAleatory(system, &config.Uncertainty) if err != nil { return err } aquantity, err := quantity.New(system, auncertainty, &config.Quantity) if err != nil { return err } ni, no := aquantity.Dimensions() ns := config.Assessment.Samples points := support.Generate(ni, ns, config.Assessment.Seed) log.Printf("Evaluating the original model at %d points...\n", ns) values := quantity.Invoke(aquantity, points) if err := output.Put("points", points, ni, ns); err != nil { return err } if err := output.Put("values", values, no, ns); err != nil { return err } return nil }
func function(config *config.Config) error { output, err := database.Create(*outputFile) if err != nil { return err } defer output.Close() system, err := system.New(&config.System) if err != nil { return err } var anuncertainty uncertainty.Uncertainty if config.Solution.Aleatory { anuncertainty, err = uncertainty.NewAleatory(system, &config.Uncertainty) } else { anuncertainty, err = uncertainty.NewEpistemic(system, &config.Uncertainty) } if err != nil { return err } aquantity, err := quantity.New(system, anuncertainty, &config.Quantity) if err != nil { return err } ni, no := aquantity.Dimensions() index, err := detect(ni, *parameterIndex) if err != nil { return err } points, err := generate(ni, *nodeCount, config.Solution.Rule, index) if err != nil { return err } np := uint(len(points)) / ni log.Println(system) log.Println(aquantity) var values []float64 if len(*approximateFile) > 0 { approximate, err := database.Open(*approximateFile) if err != nil { return err } defer approximate.Close() asolution, err := solution.New(ni, no, &config.Solution) if err != nil { return err } surrogate := new(solution.Surrogate) if err = approximate.Get("surrogate", surrogate); err != nil { return err } log.Printf("Evaluating the approximation at %d points...\n", np) values = asolution.Evaluate(surrogate, points) } else { log.Printf("Evaluating the original model at %d points...\n", np) values = quantity.Invoke(aquantity, points) } if err := output.Put("values", values, no, np); err != nil { return err } if err := output.Put("points", points, ni, np); err != nil { return err } return nil }