Changeset 25097


Ignore:
Timestamp:
06/22/20 11:19:30 (5 years ago)
Author:
jdquinn
Message:

CHG: Added histogram bin uncertain for Python; cleanup

Location:
issm/trunk-jpl/src/m
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/array/MatlabArray.py

    r24873 r25097  
    11from copy import deepcopy
     2from functools import reduce
     3
    24import numpy as np
     5
     6from helpers import *
    37from MatlabFuncs import *
    4 #move this later
    5 from helpers import *
    6 from functools import reduce
    78
    89
     
    167168    such that: given the array / matrix a,
    168169        idim is the linear index of an element in a,
    169         return the x / y / z / w / ... coordinates of idim in n dimensions
     170        return the x/y/z/w/... coordinates of idim in n dimensions
    170171
    171172    ex. a = [1 2 3
  • issm/trunk-jpl/src/m/classes/qmu/histogram_bin_uncertain.m

    r25090 r25097  
    5959            end
    6060        end % }}}
     61                %virtual functions needed by qmu processing algorithms:
     62                %implemented:
    6163        function [desc]=prop_desc(hbu,dstr) % {{{
    6264            desc=cell(1,numel(hbu));
     
    7476            desc=allempty(desc);
    7577        end  %}}}
    76         function [initpt]=prop_initpt(hbu) % {{{
    77             initpt=[];
     78        function [mean]=prop_mean(hbu) % {{{
     79            mean=[];
     80        end % }}}
     81        function [stddev]=prop_stddev(hbu) % {{{
     82            stddev=[];
    7883        end % }}}
    7984        function [lower]=prop_lower(hbu) % {{{
     
    8287        function [upper]=prop_upper(hbu) % {{{
    8388            upper=[];
    84         end % }}}
    85         function [mean]=prop_mean(hbu) % {{{
    86             mean=[];
    87         end % }}}
    88         function [stddev]=prop_stddev(hbu) % {{{
    89             stddev=[];
    90         end % }}}
    91         function [initst]=prop_initst(hbu) % {{{
    92             initst=[];
    93         end % }}}
    94         function [stype]=prop_stype(hbu) % {{{
    95             stype={};
    96         end % }}}
    97         function [scale]=prop_scale(hbu) % {{{
    98             scale=[];
    9989        end % }}}
    10090                function [abscissas]=prop_abscissas(hbu) % {{{
     
    119109                        counts=allequal(counts,-Inf);
    120110        end % }}}
     111        function [initpt]=prop_initpt(hbu) % {{{
     112            initpt=[];
     113        end % }}}
     114        function [initst]=prop_initst(hbu) % {{{
     115            initst=[];
     116        end % }}}
     117        function [stype]=prop_stype(hbu) % {{{
     118            stype={};
     119        end % }}}
     120        function [scale]=prop_scale(hbu) % {{{
     121            scale=[];
     122        end % }}}
    121123                function scaled=isscaled(self) % {{{
    122124                        if strncmp(self.descriptor,'scaled_',7),
  • issm/trunk-jpl/src/m/classes/qmu/histogram_bin_uncertain.py

    r25090 r25097  
    11import numpy as np
     2
     3from MatlabArray import string_dim
    24
    35
     
    6567        else:
    6668            raise Exception("Construction of histogram_bin_uncertain class object requires either (1) no arguments, (2) a histogram_bin_uncertain instance to copy from, or (3) a descriptor and pairs per variable, abscissas, and counts lists")
     69
     70    @staticmethod
     71    def __repr__(hbu): #{{{
     72        s = ""
     73        for i in range(len(hbu)):
     74            s += "class {} object {} = \n".format(hbu.__class__.__name__, string_dim(hbu, i))
     75        s = "{}\n{}".format(s, fielddisplay(self, 'descriptor', 'name tag'))
     76        s = "{}\n{}".format(s, fielddisplay(self, 'pairs_per_variable', 'pairs per variable'))
     77        s = "{}\n{}".format(s, fielddisplay(self, 'abscissas', 'abscissas'))
     78        s = "{}\n{}".format(s, fielddisplay(self, 'counts', 'counts'))
     79
     80        return s
     81    #}}}
     82
     83    def checkconsistency(self, md, solution, analyses): #{{{
     84        return
     85    #}}}
     86
     87    #virtual functions needed by qmu processing algorithms
     88    #implemented:
     89
     90    @staticmethod
     91    def prop_desc(hbu, dstr): #{{{
     92        desc = ['' for i in range(np.size(hbu))]
     93        for i in range(np.size(hbu)):
     94            if hbu[i].descriptor != '' or type(hbu[i].descriptor) != str:
     95                desc[i] = str(hbu[i].descriptor)
     96            elif dstr != '':
     97                desc[i] = str(dstr) + str(string_dim(hbu, i, 'vector'))
     98            else:
     99                desc[i] = 'hbu' + str(string_dim(hbu, i, 'vector'))
     100
     101        desc = allempty(desc)
     102
     103        return desc
     104    #}}}
     105
     106    @staticmethod
     107    def prop_mean(hbu): #{{{
     108        mean = np.zeros(np.size(hbu))
     109        for i in range(np.size(hbu)):
     110            mean[i] = hbu[i].mean
     111        return mean
     112    #}}}
     113
     114    @staticmethod
     115    def prop_stddev(hbu): #{{{
     116        stddev = np.zeros(np.size(hbu))
     117        for i in range(np.size(hbu)):
     118            stddev[i] = hbu[i].stddev
     119        return stddev
     120    #}}}
     121
     122    @staticmethod
     123    def prop_lower(hbu): #{{{
     124        lower = []
     125        return
     126    #}}}
     127
     128    @staticmethod
     129    def prop_upper(hbu): #{{{
     130        upper = []
     131        return upper
     132    #}}}
     133
     134    #default
     135    @staticmethod
     136    def prop_abscissas(hbu): #{{{
     137        abscissas = []
     138        for i in range(len(hbu)):
     139            abscissas.extend(hbu[i].abscissas)
     140        abscissas = allequal(abscissas, -np.inf)
     141        return abscissas
     142    #}}}
     143
     144    @staticmethod
     145    def prop_pairs_per_variable(hbu): #{{{
     146        pairs_per_variable = np.zeros((1, len(hbu)))
     147        for i in range(len(hbu)):
     148            pairs_per_variable[i] = hbu[i].pairs_per_variable
     149        abscissas = allequal(pairs_per_variable, -np.inf)
     150        return pairs_per_variable
     151    #}}}
     152
     153    @staticmethod
     154    def prop_counts(hbu): #{{{
     155        counts = []
     156        for i in range(len(hbu)):
     157            counts.extend(hbu[i].counts)
     158        counts = allequal(counts, -np.inf)
     159        return counts
     160    #}}}
     161
     162    @staticmethod
     163    def prop_initpt(hbu): #{{{
     164        initpt = []
     165        return initpt
     166    #}}}
     167
     168    @staticmethod
     169    def prop_initst(hbu): #{{{
     170        inist = []
     171        return inist
     172    #}}}
     173
     174    @staticmethod
     175    def prop_stype(hbu): #{{{
     176        stype = []
     177        return stype
     178    #}}}
     179
     180    @staticmethod
     181    def prop_scale(hbu): #{{{
     182        scale = []
     183        return scale
     184    #}}}
     185
     186    #new methods:
     187    def isscaled(self): #{{{
     188        if strncmp(self.descriptor, 'scaled_', 7):
     189            return True
     190        else:
     191            return False
     192    #}}}
     193
     194    @staticmethod
     195    def dakota_write(fidi, dvar):
     196        # possible namespace pollution, the above import seems not to work
     197        from vlist_write import vlist_write
     198        # collect only the variables of the appropriate class
     199        hbu = deepcopy(dvar)
     200        fields = fieldnames(hbu)
     201        for field in fields:
     202            if getattr(hbu, field)[0].__class__.__name__ != 'histogram_bin_uncertain':
     203                delattr(hbu, field)
     204        if len(hbu) > 0:
     205            vlist_write(fidi, 'histogram_bin_uncertain', 'hbu', hbu)
     206    #}}}
  • issm/trunk-jpl/src/m/classes/qmu/linear_inequality_constraint.py

    r24261 r25097  
    1313  where the required args are:
    1414    matrix        (double row, variable coefficients, float('NaN'))
    15     lower         (double vector, lower bounds, -np.Inf)
     15    lower         (double vector, lower bounds, -np.inf)
    1616    upper         (double vector, upper bounds, 0.)
    1717  and the optional args and defaults are:
     
    2525    def __init__(self):
    2626        self.matrix = np.array([[float('NaN')]])
    27         self.lower = -np.Inf
     27        self.lower = -np.inf
    2828        self.upper = 0.
    2929        self.scale_type = 'none'
     
    131131            lower[i] = lic[i].lower
    132132
    133         lower = allequal(lower, -np.Inf)
     133        lower = allequal(lower, -np.inf)
    134134
    135135        return lower
  • issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.m

    r25088 r25097  
    133133                        end
    134134                end % }}}
    135                 %default
     135                function [lower]=prop_lower(nuv) % {{{
     136                        lower=[];
     137                end % }}}
     138                function [upper]=prop_upper(nuv) % {{{
     139                        upper=[];
     140                end % }}}
    136141                function [abscissas]=prop_abscissas(hbu) % {{{
    137142                        abscissas=[];
     
    145150                function [initpt]=prop_initpt(nuv) % {{{
    146151                        initpt=[];
    147                 end % }}}
    148                 function [lower]=prop_lower(nuv) % {{{
    149                         lower=[];
    150                 end % }}}
    151                 function [upper]=prop_upper(nuv) % {{{
    152                         upper=[];
    153152                end % }}}
    154153                function [initst]=prop_initst(nuv) % {{{
  • issm/trunk-jpl/src/m/classes/qmu/normal_uncertain.py

    r25090 r25097  
    4141    def __init__(self): #{{{
    4242        self.descriptor = ''
    43         self.mean       = np.NaN
    44         self.stddev     = np.NaN
     43        self.mean       = np.nan
     44        self.stddev     = np.nan
    4545        self.partition  = []
    4646        self.nsteps     = 0
     
    176176    #}}}
    177177
     178    @staticmethod
     179    def prop_lower(nuv): #{{{
     180        lower = []
     181        return lower
     182    #}}}
     183
     184    @staticmethod
     185    def prop_upper(nuv): #{{{
     186        upper = []
     187        return upper
     188    #}}}
     189
    178190    #default
    179191    @staticmethod
     
    184196
    185197    @staticmethod
     198    def prop_pairs_per_variable(hbu): #{{{
     199        pairs_per_variable = []
     200        return pairs_per_variable
     201    #}}}
     202
     203    @staticmethod
    186204    def prop_counts(hbu): #{{{
    187205        counts = []
    188206        return counts
    189207    #}}}
    190 
    191     @staticmethod
    192     def prop_pairs_per_variable(hbu): #{{{
    193         pairs_per_variable = []
    194         return pairs_per_variable
    195     #}}}
    196 
    197208    @staticmethod
    198209    def prop_initpt(nuv): #{{{
    199210        initpt = []
    200211        return initpt
    201     #}}}
    202 
    203     @staticmethod
    204     def prop_lower(nuv): #{{{
    205         lower = []
    206         return lower
    207     #}}}
    208 
    209     @staticmethod
    210     def prop_upper(nuv): #{{{
    211         upper = []
    212         return upper
    213212    #}}}
    214213
     
    244243        from vlist_write import vlist_write
    245244        # collect only the variables of the appropriate class
    246         # nuv = [struc_class(i, 'normal_uncertain', 'nuv') for i in dvar]
    247245        nuv = deepcopy(dvar)
    248246        fields = fieldnames(nuv)
  • issm/trunk-jpl/src/m/classes/qmu/uniform_uncertain.py

    r25090 r25097  
    4141    def __init__(self): #{{{
    4242        self.descriptor = ''
    43         self.lower      = -np.Inf
    44         self.upper      = np.Inf
     43        self.lower      = -np.inf
     44        self.upper      = np.inf
    4545        self.partition  = []
    4646        self.nsteps     = 0
     
    162162
    163163    @staticmethod
     164    def prop_stddev(uuv): #{{{
     165        stddev = []
     166        return stddev
     167    #}}}
     168
     169    @staticmethod
     170    def prop_mean(uuv): #{{{
     171        mean = []
     172        return mean
     173    #}}}
     174
     175    @staticmethod
    164176    def prop_lower(uuv): #{{{
    165177        lower = np.zeros(np.size(uuv))
     
    167179            lower[i] = uuv[i].lower
    168180
    169         lower = allequal(lower, -np.Inf)
     181        lower = allequal(lower, -np.inf)
    170182
    171183        return lower
     
    178190            upper[i] = uuv[i].upper
    179191
    180         #upper = allequal(upper, np.Inf)
     192        upper = allequal(upper, np.inf)
    181193
    182194        return upper
     
    184196
    185197    @staticmethod
    186     def prop_stddev(uuv): #{{{
    187         stddev = []
    188         return stddev
    189     #}}}
    190 
    191     @staticmethod
    192     def prop_mean(uuv): #{{{
    193         mean = []
    194         return mean
     198    def prop_abscissas(hbu): #{{{
     199        abscissas = []
     200        return abscissas
     201    #}}}
     202
     203    @staticmethod
     204    def prop_pairs_per_variable(hbu): #{{{
     205        pairs_per_variable = []
     206        return pairs_per_variable
     207    #}}}
     208
     209    @staticmethod
     210    def prop_counts(hbu): #{{{
     211        counts = []
     212        return counts
    195213    #}}}
    196214
     
    217235        scale = []
    218236        return scale
    219     #}}}
    220 
    221     @staticmethod
    222     def prop_abscissas(hbu): #{{{
    223         abscissas = []
    224         return abscissas
    225     #}}}
    226 
    227     @staticmethod
    228     def prop_counts(hbu): #{{{
    229         counts = []
    230         return counts
    231     #}}}
    232 
    233     @staticmethod
    234     def prop_pairs_per_variable(hbu): #{{{
    235         pairs_per_variable = []
    236         return pairs_per_variable
    237237    #}}}
    238238
     
    249249        # possible namespace pollution, the above import seems not to work
    250250        from vlist_write import vlist_write
    251         # # collect only the variables of the appropriate class
    252         # uuv = [struc_class(i, 'uniform_uncertain', 'uuv') for i in dvar]
     251        # collect only the variables of the appropriate class
    253252        uuv = deepcopy(dvar)
    254253        fields = fieldnames(uuv)
Note: See TracChangeset for help on using the changeset viewer.