Ejemplo n.º 1
0
 internal HypercubeSampleGenerator(
     Arr <ParameterState> parameterStates,
     LatinHypercubeDesign latinHypercubeDesign,
     RankCorrelationDesign rankCorrelationDesign,
     int nSamples,
     int?seed,
     IRVisServerPool serverPool
     ) : base(parameterStates, rankCorrelationDesign, nSamples, seed, serverPool)
 {
     _latinHypercubeDesign = latinHypercubeDesign;
 }
Ejemplo n.º 2
0
 internal static _LatinHypercubeDesignDTO ToDTO(this LatinHypercubeDesign latinHypercubeDesign)
 {
     return(new _LatinHypercubeDesignDTO
     {
         C = latinHypercubeDesign.C.ToNullable(),
         Imax = latinHypercubeDesign.Imax,
         Iterations = latinHypercubeDesign.Iterations,
         LatinHypercubeDesignType = latinHypercubeDesign.LatinHypercubeDesignType.ToString(),
         P = latinHypercubeDesign.P.ToNullable(),
         Profile = latinHypercubeDesign.Profile.ToString(),
         T0 = latinHypercubeDesign.T0.ToNullable()
     });
 }
Ejemplo n.º 3
0
 internal SamplingDesign(
     DateTime createdOn,
     Arr <DesignParameter> designParameters,
     LatinHypercubeDesign latinHypercubeDesign,
     RankCorrelationDesign rankCorrelationDesign,
     int?seed,
     DataTable samples,
     Arr <int> noDataIndices
     )
 {
     CreatedOn             = createdOn;
     DesignParameters      = designParameters;
     LatinHypercubeDesign  = latinHypercubeDesign;
     RankCorrelationDesign = rankCorrelationDesign;
     Seed          = seed;
     Samples       = samples;
     NoDataIndices = noDataIndices;
 }
Ejemplo n.º 4
0
        internal static IRunControlTask Create(TomlTable taskSpec, IAppState appState, IAppService appService)
        {
            RequireTrue(
                taskSpec.ContainsKey("n_samples"),
                "Distribution sampling task spec has missing n_samples setting"
                );
            RequireTrue(
                taskSpec.ContainsKey("distributions"),
                "Distribution sampling task spec has missing distributions"
                );
            RequireTrue(
                taskSpec.ContainsKey("outputs"),
                "Distribution sampling task spec has missing outputs"
                );

            var name = taskSpec["name"].Get <string>();

            RequireNotNullEmptyWhiteSpace(name, "Invalid task name");

            var nSamples = taskSpec["n_samples"].Get <int>();

            RequireTrue(nSamples > 0, "Invalid n_samples");

            var distributionSpecs = taskSpec["distributions"] as TomlArray;

            RequireNotNull(
                distributionSpecs,
                "Distribution sampling task spec has missing or misspecified distributions"
                );
            RequireTrue(
                distributionSpecs.Length > 0,
                "Distribution sampling task spec has empty distributions"
                );

            var distributions = distributionSpecs.Items
                                .Select(tv => Distribution.ParseRelation(tv.Get <string>()))
                                .ToArr();

            LatinHypercubeDesign latinHypercubeDesign = LatinHypercubeDesign.Default;

            if (taskSpec.ContainsKey("latin_hypercube"))
            {
                var latinHypercubeSpec = taskSpec["latin_hypercube"] as TomlTable;
                RequireNotNull(latinHypercubeSpec, "Expecting Latin hypercube specified as table array");
                RequireTrue(latinHypercubeSpec.ContainsKey("type"), "Latin hypercube missing type");

                var type       = latinHypercubeSpec["type"].Get <LatinHypercubeDesignType>();
                var t0         = latinHypercubeSpec.ContainsKey("t0") ? latinHypercubeSpec["t0"].Get <double>() : NaN;
                var c          = latinHypercubeSpec.ContainsKey("c") ? latinHypercubeSpec["c"].Get <double>() : NaN;
                var iterations = latinHypercubeSpec.ContainsKey("iter") ? latinHypercubeSpec["iter"].Get <int>() : default;
                var p          = latinHypercubeSpec.ContainsKey("p") ? latinHypercubeSpec["p"].Get <double>() : NaN;
                var profile    = latinHypercubeSpec.ContainsKey("profile") ? latinHypercubeSpec["profile"].Get <TemperatureDownProfile>() : default;
                var imax       = latinHypercubeSpec.ContainsKey("imax") ? latinHypercubeSpec["imax"].Get <int>() : default;

                var haveDesignType = type != LatinHypercubeDesignType.None;

                var hasValidSA = IsNaN(t0) || (!IsNaN(c) && iterations > 0 && !IsNaN(p));

                RequireTrue(
                    !haveDesignType || hasValidSA,
                    "Invalid Latin hypercube configuration"
                    );

                latinHypercubeDesign = new LatinHypercubeDesign(type, t0, c, iterations, p, profile, imax);
            }

            Arr <(string Parameter, Arr <double> Correlations)> correlation = default;

            if (taskSpec.ContainsKey("correlation"))
            {
                var correlationSpec = taskSpec["correlation"] as TomlTableArray;
                RequireNotNull(correlationSpec, "Expecting correlation specified as table array");
                correlation = correlationSpec.Items
                              .Cast <TomlTable>()
                              .Select(tt => (
                                          Parameter: tt["name"].Get <string>(),
                                          Correlations: tt["values"].Get <double[]>().ToArr()))
                              .ToArr();

                var correlationComplete = distributions.ForAll(
                    d => correlation.Exists(c => c.Parameter == d.Variable)
                    );
                RequireTrue(correlationComplete, "Incomplete correlation matrix");
                RequireTrue(correlation.Count == distributions.Count, "Unexpected data in correlation matrix");
            }

            var outputSpecs = taskSpec["outputs"] as TomlArray;

            RequireNotNull(
                outputSpecs,
                "Distribution sampling task spec has missing or misspecified outputs"
                );
            RequireTrue(
                outputSpecs.Length > 0,
                "Distribution sampling task spec has empty outputs"
                );

            var outputNames = outputSpecs.To <string>().ToArr();

            return(new DistributionSamplingTask(
                       name,
                       nSamples,
                       distributions,
                       latinHypercubeDesign,
                       correlation,
                       outputNames,
                       appState,
                       appService
                       ));
        }