source: issm/trunk-jpl/src/m/classes/qmu/uniform_uncertain.py@ 23095

Last change on this file since 23095 was 23095, checked in by kruegern, 7 years ago

NEW: added initial qmu/dakota functionality in Python, made minor adjustments to other, related files

File size: 4.0 KB
Line 
1import numpy as np
2from vlist_write import *
3from MatlabArray import *
4
5class uniform_uncertain(object):
6 '''
7 definition for the uniform_uncertain class.
8
9 [uuv] = uniform_uncertain.uniform_uncertain(args)
10 uuv = uniform_uncertain()
11
12 where the required args are:
13 descriptor (str, description, '')
14 lower (float, lower bound, -np.Inf)
15 upper (float, upper bound, np.Inf)
16
17 note that zero arguments constructs a default instance, one
18 argument of the class copies the instance, and three or more
19 arguments constructs a new instance from the arguments.
20'''
21
22 def __init__(self):
23 self.descriptor = ''
24 self.lower = -np.Inf
25 self.upper = np.Inf
26
27 @staticmethod
28 def uniform_uncertain(*args):
29 nargin = len(args)
30
31 # create a default object
32 if nargin == 0:
33 return uniform_uncertain()
34
35 # copy the object
36 elif nargin == 1:
37 if isinstance(args[0],uniform_uncertain):
38 uuv = args[0]
39 else:
40 raise RuntimeError('Object '+str(args[0])+' is a '+str(type(args[0]))+' class object, not "uniform_uncertain".')
41
42 # not enough arguments
43
44 elif nargin == 2:
45 raise RuntimeError('Construction of "uniform_uncertain" class object requires at least 3 inputs.')
46
47 # create the object from the input
48 else:
49 # leaving this here in case it becomes important in the future
50 #asizec=array_size(*args[0:min(nargin,3)])
51 #uuv = [uniform_uncertain() for i in range(asizec[0]) for j in range(asizec[1])]
52
53 uuv = uniform_uncertain()
54
55 uuv.descriptor = str(args[0])
56 uuv.lower = args[1]
57 uuv.upper = args[2]
58 if (nargin > 3):
59 print 'WARNING: uniform_uncertain:extra_arg: Extra arguments for object of class '+type(uuv)+'.'
60
61 return [uuv]
62
63
64 def __repr__(self):
65 # display an individual object
66 string = '\n'
67 string += 'class "uniform_uncertain" object = \n'
68 string += ' descriptor: ' + str(self.descriptor) + '\n'
69 string += ' lower: ' + str(self.lower) + '\n'
70 string += ' upper: ' + str(self.upper) + '\n'
71
72 return string
73
74 # from here on, uuv is either a single, or a 1d vector of, uniform_uncertain
75
76 @staticmethod
77 def prop_desc(uuv,dstr):
78 if type(uuv) not in [list,np.ndarray]:
79 if uuv.descriptor != '' or type(uuv.descriptor) != str:
80 desc = str(uuv.descriptor)
81 elif dstr != '':
82 desc = str(dstr)
83 else:
84 desc = 'uuv'
85 return desc
86
87 desc = ['' for i in range(np.size(uuv))]
88 for i in range(np.size(uuv)):
89 if uuv[i].descriptor != '' or type(uuv[i].descriptor) != str:
90 desc[i] = str(uuv[i].descriptor)
91 elif dstr != '':
92 desc[i] = str(dstr)+str(string_dim(uuv,i,'vector'))
93 else:
94 desc[i] = 'uuv'+str(string_dim(uuv,i,'vector'))
95
96 desc = allempty(desc)
97
98 return desc
99
100 @staticmethod
101 def prop_initpt(uuv):
102 initpt=[]
103 return initpt
104
105 @staticmethod
106 def prop_lower(uuv):
107 if type(uuv) not in [list,np.ndarray]:
108 return uuv.lower
109
110 lower = np.zeros(np.size(uuv))
111 for i in range(np.size(uuv)):
112 lower[i] = uuv[i].lower
113
114 lower = allequal(lower,-np.Inf)
115
116 return lower
117
118 @staticmethod
119 def prop_upper(uuv):
120 if type(uuv) not in [list,np.ndarray]:
121 return uuv.upper
122
123 upper = np.zeros(np.size(uuv))
124 for i in range(np.size(uuv)):
125 upper[i] = uuv[i].upper
126
127 upper = allequal(upper, np.Inf)
128
129 return upper
130
131 @staticmethod
132 def prop_mean(uuv):
133 mean=[]
134 return mean
135
136 @staticmethod
137 def prop_stddev(uuv):
138 stddev=[]
139 return stddev
140
141 @staticmethod
142 def prop_initst(uuv):
143 initst=[]
144 return initst
145
146 @staticmethod
147 def prop_stype(uuv):
148 stype=[]
149 return stype
150
151 @staticmethod
152 def prop_scale(uuv):
153 scale=[]
154 return scale
155
156 @staticmethod
157 def dakota_write(fidi,dvar):
158 # collect only the variables of the appropriate class
159 uuv = [struc_class(i,'uniform_uncertain','uuv') for i in dvar]
160
161 # possible namespace pollution, the above import seems not to work
162 from vlist_write import *
163 # write variables
164 vlist_write(fidi,'uniform_uncertain','uuv',uuv)
Note: See TracBrowser for help on using the repository browser.