Beispiel #1
0
    def run(self):
        """
        Compute the Sobol indices with the chosen algorithm. 
        """

        # create the NumericalMathFunction which computes the POD for a given
        # realization and for all defect sizes.
        if self._podType == "kriging":
            self._PODaggr = ot.NumericalMathFunction(
                PODaggrKriging(self._POD, self._dim, self._defectSizes,
                               self._detectionBoxCox))
        elif self._podType == "chaos":
            self._PODaggr = ot.NumericalMathFunction(
                PODaggrChaos(self._POD, self._dim, self._defectSizes,
                             self._detectionBoxCox, self._simulationSize))

        if self._method == "Saltelli":
            self._sa = ot.SaltelliSensitivityAlgorithm(self._distribution,
                                                       self._N, self._PODaggr,
                                                       False)
        elif self._method == "Martinez":
            self._sa = ot.MartinezSensitivityAlgorithm(self._distribution,
                                                       self._N, self._PODaggr,
                                                       False)
        elif self._method == "Jansen":
            self._sa = ot.JansenSensitivityAlgorithm(self._distribution,
                                                     self._N, self._PODaggr,
                                                     False)
        elif self._method == "MauntzKucherenko":
            self._sa = ot.MauntzKucherenkoSensitivityAlgorithm(
                self._distribution, self._N, self._PODaggr, False)
def myMauntzKucherenkoSobolEstimator(distribution, size, model):
    inputDesign = ot.SobolIndicesExperiment(distribution, size,
                                            True).generate()
    outputDesign = model(inputDesign)
    sensitivityAnalysis = ot.MauntzKucherenkoSensitivityAlgorithm(
        inputDesign, outputDesign, size)
    return sensitivityAnalysis
Beispiel #3
0
    def run(self):
        """
        Compute the Sobol indices with the chosen algorithm. 
        """

        # create the Function which computes the POD for a given
        # realization and for all defect sizes.
        if self._podType == "kriging":
            self._PODaggr = ot.Function(
                PODaggrKriging(self._POD, self._dim, self._defectSizes,
                               self._detectionBoxCox))
        elif self._podType == "chaos":
            self._PODaggr = ot.Function(
                PODaggrChaos(self._POD, self._dim, self._defectSizes,
                             self._detectionBoxCox, self._simulationSize))

        input_design = ot.SobolIndicesExperiment(self._distribution, self._N,
                                                 False).generate()
        output_design = self._PODaggr(input_design)

        # remove the output marginal when the variance is null because it causes
        # a failure. Must remove also the associated defect sizes.
        selected_marginal_index = []
        for index_output in range(output_design.getDimension()):
            if output_design.getMarginal(
                    index_output)[:self._N].computeCovariance()[0, 0] != 0:
                selected_marginal_index.append(index_output)

        if len(selected_marginal_index) != output_design.getDimension():
            self.setDefectSizes(self._defectSizes[selected_marginal_index])
            selected_output_design = np.array(
                output_design)[:, selected_marginal_index]

            logging.warning("Warning : some output variances are null. " + \
                         "Only the following defect sizes are taken into " + \
                         "account : {}".format(self._defectSizes))
        else:
            selected_output_design = output_design

        if self._method == "Saltelli":
            self._sa = ot.SaltelliSensitivityAlgorithm(input_design,
                                                       selected_output_design,
                                                       self._N)
        elif self._method == "Martinez":
            self._sa = ot.MartinezSensitivityAlgorithm(input_design,
                                                       selected_output_design,
                                                       self._N)
        elif self._method == "Jansen":
            self._sa = ot.JansenSensitivityAlgorithm(input_design,
                                                     selected_output_design,
                                                     self._N)
        elif self._method == "MauntzKucherenko":
            self._sa = ot.MauntzKucherenkoSensitivityAlgorithm(
                input_design, selected_output_design, self._N)

        self._sa.setUseAsymptoticDistribution(True)
    Zc = H + Zv
    S = Zc - Zd
    return [S]


myFunction = ot.PythonFunction(4, 1, flooding)
myParam = ot.GumbelAB(1013.0, 558.0)
Q = ot.ParametrizedDistribution(myParam)
Q = ot.TruncatedDistribution(Q, 0.0, ot.SpecFunc.MaxScalar)
Ks = ot.Normal(30.0, 7.5)
Ks = ot.TruncatedDistribution(Ks, 0.0, ot.SpecFunc.MaxScalar)
Zv = ot.Uniform(49.0, 51.0)
Zm = ot.Uniform(54.0, 56.0)
inputX = ot.ComposedDistribution([Q, Ks, Zv, Zm])
inputX.setDescription(["Q", "Ks", "Zv", "Zm"])

size = 5000
computeSO = True
inputDesign = ot.SobolIndicesExperiment(inputX, size, computeSO).generate()
outputDesign = myFunction(inputDesign)
sensitivityAnalysis = ot.MauntzKucherenkoSensitivityAlgorithm(
    inputDesign, outputDesign, size)

graph = sensitivityAnalysis.draw()

fig = plt.figure(figsize=(8, 4))
plt.suptitle(graph.getTitle())
axis = fig.add_subplot(111)
axis.set_xlim(auto=True)
View(graph, figure=fig, axes=[axis], add_legend=True)