Beispiel #1
0
def test_determin_category_weighting():
    cat_wcounts = {
        "17_40": {
            "BHR": 8,
            "BHT": 4,
            "BHZ": 16
        },
        "40_100": {
            "BHR": 4,
            "BHT": 2,
            "BHZ": 4
        },
        "90_250": {
            "BHR": 1,
            "BHT": 1,
            "BHZ": 2
        }
    }

    category_ratio = {
        "17_40": {
            "BHR": 1,
            "BHT": 2,
            "BHZ": 1
        },
        "40_100": {
            "BHR": 2,
            "BHT": 4,
            "BHZ": 2
        },
        "90_250": {
            "BHR": 8,
            "BHT": 8,
            "BHZ": 4
        }
    }
    category_param = {"flag": True, "ratio": category_ratio}

    weights = ww.calculate_category_weights_interface(category_param,
                                                      cat_wcounts)

    _true = {
        '17_40': {
            'BHR': 0.525,
            'BHT': 1.05,
            'BHZ': 0.525
        },
        '40_100': {
            'BHR': 1.05,
            'BHT': 2.1,
            'BHZ': 1.05
        },
        '90_250': {
            'BHR': 4.2,
            'BHT': 4.2,
            'BHZ': 2.1
        }
    }

    assert weights == _true
Beispiel #2
0
def get_category_weights(cat_wcounts):
    """
    Just normalize the sum of category weights to 1
    """
    print("category window counts:")
    pprint(cat_wcounts)
    cat_ratio = get_category_ratio(cat_wcounts)
    print("category weight ratio")
    pprint(cat_ratio)

    param = {"flag": True, "ratio": cat_ratio}
    cat_weights = calculate_category_weights_interface(
        param, cat_wcounts)

    pprint(cat_weights)
    # hack: normalize to 1
    vsum = 0
    for p, pinfo in cat_weights.iteritems():
        for c, cinfo in pinfo.iteritems():
            vsum += cinfo
    factor = 1.0 / vsum
    print("vsum and factor for category: %f, %f" % (vsum, factor))
    for p, pinfo in cat_weights.iteritems():
        for c in pinfo:
            pinfo[c] *= factor

    print("category final weights")
    pprint(cat_weights)

    return cat_weights
Beispiel #3
0
def get_category_weights(cat_wcounts):
    print("category window counts:")
    pprint(cat_wcounts)
    cat_ratio = get_category_ratio(cat_wcounts)
    print("category weight ratio")
    pprint(cat_ratio)

    param = {"flag": True, "ratio": cat_ratio}
    cat_weights = calculate_category_weights_interface(
        param, cat_wcounts)
    print("category final weights")
    pprint(cat_weights)

    return cat_weights
def test_category_validator():

    cat_wcounts = {"17_40":  {"BHR": 8, "BHT": 4, "BHZ": 16},
                   "40_100": {"BHR": 4, "BHT": 2, "BHZ": 4},
                   "90_250": {"BHR": 1, "BHT": 1, "BHZ": 2}}

    category_ratio = {"17_40":  {"BHR": 1, "BHT": 2, "BHZ": 1},
                      "40_100": {"BHR": 2, "BHT": 4, "BHZ": 2},
                      "90_250": {"BHR": 8, "BHT": 8, "BHZ": 4}}
    category_param = {"flag": True, "ratio": category_ratio}

    weights = ww.calculate_category_weights_interface(
        category_param, cat_wcounts)

    weights["17_40"]["BHR"] *= 2
    with pytest.raises(ValueError):
        ww._category_validator(weights, cat_wcounts)
Beispiel #5
0
def test_category_validator():

    cat_wcounts = {"17_40":  {"BHR": 8, "BHT": 4, "BHZ": 16},
                   "40_100": {"BHR": 4, "BHT": 2, "BHZ": 4},
                   "90_250": {"BHR": 1, "BHT": 1, "BHZ": 2}}

    category_ratio = {"17_40":  {"BHR": 1, "BHT": 2, "BHZ": 1},
                      "40_100": {"BHR": 2, "BHT": 4, "BHZ": 2},
                      "90_250": {"BHR": 8, "BHT": 8, "BHZ": 4}}
    category_param = {"flag": True, "ratio": category_ratio}

    weights = ww.calculate_category_weights_interface(
        category_param, cat_wcounts)

    weights["17_40"]["BHR"] *= 2
    with pytest.raises(ValueError):
        ww._category_validator(weights, cat_wcounts)
Beispiel #6
0
def test_determin_category_weighting():
    cat_wcounts = {"17_40":  {"BHR": 8, "BHT": 4, "BHZ": 16},
                   "40_100": {"BHR": 4, "BHT": 2, "BHZ": 4},
                   "90_250": {"BHR": 1, "BHT": 1, "BHZ": 2}}

    category_ratio = {"17_40":  {"BHR": 1, "BHT": 2, "BHZ": 1},
                      "40_100": {"BHR": 2, "BHT": 4, "BHZ": 2},
                      "90_250": {"BHR": 8, "BHT": 8, "BHZ": 4}}
    category_param = {"flag": True, "ratio": category_ratio}

    weights = ww.calculate_category_weights_interface(
        category_param, cat_wcounts)

    _true = {'17_40': {'BHR': 0.525, 'BHT': 1.05, 'BHZ': 0.525},
             '40_100': {'BHR': 1.05, 'BHT': 2.1, 'BHZ': 1.05},
             '90_250': {'BHR': 4.2, 'BHT': 4.2, 'BHZ': 2.1}}

    assert weights == _true
Beispiel #7
0
    def smart_run(self):
        validate_path(self.path)
        validate_param(self.param)
        # extract source location information
        self.src_info = extract_source_location(self.path["input"])
        # calculate receiver weights
        self.calculate_receiver_weights_asdf()
        # calculate category weights
        logger_block("Category Weighting")
        self.cat_weights = calculate_category_weights_interface(
            self.param["category_weighting"], self.cat_wcounts)

        # combine the receiver weights with category weights
        logger_block("Combine Weights")
        self.weights = combine_receiver_and_category_weights(
            self.rec_weights, self.cat_weights)

        # statistical analysis
        self.analyze()
        # dump the results out
        self.dump_weights()