-
Notifications
You must be signed in to change notification settings - Fork 26
/
get_postpred.py
78 lines (68 loc) · 3.16 KB
/
get_postpred.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
#=====================================================================================
#
# The UQ Toolkit (UQTk) version 3.1.4
# Copyright (2023) NTESS
# https://www.sandia.gov/UQToolkit/
# https://github.com/sandialabs/UQTk
#
# Copyright 2023 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
# Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
# retains certain rights in this software.
#
# This file is part of The UQ Toolkit (UQTk)
#
# UQTk is open source software: you can redistribute it and/or modify
# it under the terms of BSD 3-Clause License
#
# UQTk is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# BSD 3 Clause License for more details.
#
# You should have received a copy of the BSD 3 Clause License
# along with UQTk. If not, see https://choosealicense.com/licenses/bsd-3-clause/.
#
# Questions? Contact the UQTk Developers at https://github.com/sandialabs/UQTk/discussions
# Sandia National Laboratories, Livermore, CA, USA
#=====================================================================================
#=====================================================================================
import argparse
import numpy as np
from PyUQTk.utils.func import func
##########################################################################
##########################################################################
# Parse input arguments
usage_str = 'Script to evaluate surrogates given samples of the input'
parser = argparse.ArgumentParser(description=usage_str)
parser.add_argument("-p", "--input", dest="input_file",
type=str, default='input.dat', help="Parameter input file of size Nxd")
parser.add_argument("-f", "--output", dest="output_file",
type=str, default='output.dat', help="Output file name, the size will be NxL")
parser.add_argument("-n", "--nout", dest="nout",
type=int, default=1, help="Number of outputs, L")
args = parser.parse_args()
input_file = args.input_file
output_file = args.output_file
nout = args.nout
# Parameter input file of size Nxd
pinput = np.loadtxt(input_file, ndmin=2)
ninput = pinput.shape[0]
dim = pinput.shape[1]
# Hardwired, but this is surrogate type which is always LU
# Do not confuse this with the embedded PC type
pctype = 'LU'
# Output container
outputs = np.zeros((ninput, nout))
# For each output, read corresponding multiindex and
# PC coefficients and evaluate the PC
for j in range(nout):
# mindex = np.loadtxt('mindexp.dat',
# dtype=int).reshape(-1, dim)
mindex = np.loadtxt('mindexp.' + str(j) + '_pred.dat',
dtype=int).reshape(-1, dim)
# pcf = np.loadtxt('pccf_all.dat')[:,j]
pcf = np.loadtxt('pccfp.' + str(j) + '_pred.dat').reshape(-1, 1)
outputs[:, j] = func(pinput, 'PCmi', [mindex, pcf, pctype])
# Save the output in the requested file
np.savetxt(output_file, outputs)