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 generate(into, from quantity.Quantity, ns uint, seed int64) []float64 { ni, _ := into.Dimensions() nf, _ := from.Dimensions() zi := make([]float64, ni*ns) zf := support.Generate(nf, ns, seed) for i := uint(0); i < ns; i++ { copy(zi[i*ni:(i+1)*ni], into.Forward(from.Backward(zf[i*nf:(i+1)*nf]))) } return zi }