iam-git / WellMet (public) (License: MIT) (since 2021-08-31) (hash sha1)
WellMet is pure Python framework for spatial structural reliability analysis. Or, more specifically, for "failure probability estimation and detection of failure surfaces by adaptive sequential decomposition of the design domain".

/samplebox.py (a0e0b4e593204ff6254f23a67652804db07800a6) (4284 bytes) (mode 100644) (type blob)

#!/usr/bin/env python
# coding: utf-8

"""
SampleBox = sample_R(f_model) + g_values
"""


import numpy as np


class SampleBox:
    """
    SampleBox = sample_R(f_model) + g_values
    
    .sampled_plan object
    .g_values
    .failsi
    
    Souřadnice primárně z prostoru modelu, ty co jsme rovnou
    posilali do g_modelu!
    """
    
        # nechtěl bys nazvy proměnných?
    def __new__(cls, sample_object, g_values=(), gm_signature=''):
        """
        Jedname tvrdě - není-li vstup konzistentní, 
        tak sbox vůbec nevytvaříme
        """
        g_values = np.atleast_1d(g_values)
        if len(sample_object) == len(g_values):
            sb = super(SampleBox, cls).__new__(cls)
            # nepotrebujeme žádné rozdělení, nic
            sb.sampled_plan = sample_object
            sb.g_values = g_values
            sb.gm_signature = gm_signature
            return sb
        else:
            raise ValueError("Sample and g_value hasn't the same length. Zkrátka, do sebe nepatří")
    
        
    def __str__(sb):
        return  '%s: %s at %s' %(sb.gm_signature, sb.g_values, sb.sampled_plan)
        
    def __repr__(sb):
        return  'SampleBox(%s, %s, %s)' %(repr(sb.sampled_plan), repr(sb.g_values), repr(sb.gm_signature))
        
    def __len__(sb):
        return len(sb.g_values)
        
        
    def __call__(sb):
        # я ваще хз
        # offer next sample?
        # do calculation?
        # add to this sample?
        # return new instance?
        # мар, сакра, кароно?
        
        # finally, we will offer sample to sample
        # like BlackBox does
        return sb.sampled_plan(1)
    
        
    def __getitem__(sb, slice):
        return SampleBox(sb.sampled_plan[slice], sb.g_values[slice], sb.gm_signature)
        
        
    def __getattr__(sb, attr):
        if attr == 'samplebox':
            return sb
        elif attr == 'failsi':
            # ~(g_values>0) to handle nan
            return ~(sb.g_values>0)
        elif attr == 'success_points':
            return np.argwhere(sb.g_values>0).flatten()
        elif attr == 'failure_points':
            return np.argwhere(~(sb.g_values>0)).flatten()
        elif attr == 'failure_samples':
            return sb[~(sb.g_values>0)]
        elif attr == 'success_samples':
            return sb[sb.g_values>0]
            
        # to je jistě k samplovi
        else:
            return getattr(sb.sampled_plan, attr)
        
        
    def add_sample(sb, input_sb):
        input_sb.consistency_check()
        
        # ты чьих будешь?
        # where are you from?
        # are you one of us?
        if sb.gm_signature == input_sb.gm_signature:
            # dá se tuhle kontrolu jednoduše napálit, ale to neřeším
            sb.sampled_plan.add_sample(input_sb.sampled_plan)
            sb.g_values = np.append(sb.g_values, input_sb.g_values)
            
            return sb.consistency_check()
            
            # je to pro případ prázdného sample_boxu
        elif sb.gm_signature == '':
            # dá se tuhle kontrolu jednoduše napálit, ale to neřeším
            sb.sampled_plan.add_sample(input_sb.sampled_plan)
            sb.g_values = np.append(sb.g_values, input_sb.g_values)
            sb.gm_signature = input_sb.gm_signature
            return sb.consistency_check()
        else:
            #raise ValueError("Merge sa nám nějak nepovedol")
            raise ValueError("gm_signatures are unequal. You are probably trying to merge data from different sources")
                
    def new_sample(sb, input_sb):
        """
        We want to create new SampleBox object with our distribution (f_model)
        but with data of input_sb (just like f_model.new_sample() does)
        """
        return SampleBox(sb.sampled_plan.new_sample(input_sb), input_sb.g_values, input_sb.gm_signature)
        
    def consistency_check(sb):
        if len(sb.sampled_plan)==len(sb.g_values):
            return True
        else:
            # уг тодӥськы чик мар кароно
            # ConsistencyError
            raise ValueError('SampleBox is in an inconsistent state and nobody knows what to do with it')
            


Mode Type Size Ref File
100644 blob 18023 dbc921a5ff53594363973972d53c5d572d2826d1 IS_stat.py
100644 blob 6 0916b75b752887809bac2330f3de246c42c245cd __init__.py
100644 blob 73368 3d245b8568158ac63c80fa0847631776a140db0f blackbox.py
100644 blob 11243 10c424c2ce5e8cdd0da97a5aba74c54d1ca71e0d candybox.py
100644 blob 53090 36d72557a0b012a8b30888e26a425a507929bfff dicebox.py
100644 blob 47075 3ad01c91c9781b03caf9d0365932c12eb1ccec5c estimation.py
100644 blob 35518 a9110165335638c5404f0698f93e5e6ed868ca42 f_models.py
100644 blob 31025 70bab60405bfe783a2f7a9f2c41b7c1629d3d474 g_models.py
100644 blob 42845 e66a644b3f32e3a7b2556eebe581ef7ef6a638d7 gl_plot.py
100644 blob 2718 5d721d117448dbb96c554ea8f0e4651ffe9ac457 gp_plot.py
100644 blob 29393 96162a5d181b8307507ba2f44bafe984aa939163 lukiskon.py
100644 blob 10489 1f6dd06a036fdc4ba6a7e6d61ac0b84e8ad3a4c1 mplot.py
100644 blob 1366 993a88f239b6304e48eb519c20a640f28055d7c9 plot.py
100644 blob 2807 1feb1d43e90e027f35bbd0a6730ab18501cef63a plotly_plot.py
100644 blob 87260 c43aa15fdb170b631d984e5427d856d03c12e6df qt_plot.py
100644 blob 6304 7fc6ac75e415df43af5b7aa9d6d1848aa5d0963d reader.py
100644 blob 4284 a0e0b4e593204ff6254f23a67652804db07800a6 samplebox.py
100644 blob 5553 bac994ae58f1df80c7f8b3f33955af5402f5a4f3 sball.py
100644 blob 21623 281aef80556b8d22842b8659f6f0b7dab0ad71af shapeshare.py
100644 blob 19837 5517d072307bd4c5a462a20943e3a354f32a9589 simplex.py
100644 blob 3411 526104441da7029c83ff7c5037ae6b0dbc9a118d testcases_2D.py
100644 blob 22048 4a6014ca5255aa96059ff9ed5a7e29df98d26ffc whitebox.py
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/iam-git/WellMet

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/iam-git/WellMet

Clone this repository using git:
git clone git://git.rocketgit.com/user/iam-git/WellMet

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main