def get_weights(self, weights_options):
        effective_csm_estimator = {"function": "power2_inverse_decreasing", "options": {"max_csm": 8.0}}

        self_weight_estimator = {
            "function": "power2_decreasing_exp",
            "options": {"max_csm": 5.4230949041608305, "alpha": 1.0},
        }

        self_csm_weight = SelfCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator, weight_estimator=self_weight_estimator
        )

        surface_definition = {
            "type": "standard_elliptic",
            "distance_bounds": {"lower": 1.05, "upper": 2.0},
            "angle_bounds": {"lower": 0.05, "upper": 0.95},
        }

        da_area_weight = DistanceAngleAreaNbSetWeight(
            weight_type="has_intersection",
            surface_definition=surface_definition,
            nb_sets_from_hints="fallback_to_source",
            other_nb_sets="0_weight",
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB,
        )

        weight_estimator = {"function": "smootherstep", "options": {"delta_csm_min": 0.5, "delta_csm_max": 3.0}}

        symmetry_measure_type = "csm_wcs_ctwcc"
        delta_csm_weight = DeltaCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator,
            weight_estimator=weight_estimator,
            symmetry_measure_type=symmetry_measure_type,
        )

        bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0, weight_cn13=4.0)
        angle_weight = AngleNbSetWeight()

        nad_weight = NormalizedAngleDistanceNbSetWeight(average_type="geometric", aa=1, bb=1)

        weights = {
            "DistAngArea": da_area_weight,
            "SelfCSM": self_csm_weight,
            "DeltaCSM": delta_csm_weight,
            "CNBias": bias_weight,
            "Angle": angle_weight,
            "NormalizedAngDist": nad_weight,
        }

        return weights
Пример #2
0
    def test_normalized_angle_distance_weight(self):
        fake_nb_set = FakeNbSet()
        dummy_se = DummyStructureEnvironments()

        nadw1 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=1, bb=1)
        nadw2 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=1, bb=1)
        nadw3 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=0, bb=1)
        nadw4 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=1, bb=0)
        nadw5 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0.1, bb=0.1)
        nadw6 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=0.1)
        nadw7 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0.1, bb=0)
        nadw8 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=2, bb=0)
        nadw9 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=2)
        nadw10 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=2, bb=2)
        nadw11 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=1, bb=2)
        nadw12 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=2, bb=1)
        self.assertNotEqual(nadw11, nadw12)
        with self.assertRaisesRegex(ValueError, 'Both exponents are 0.'):
            NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=0)
        with self.assertRaisesRegex(ValueError, 'Average type is "arithmetix" '
                                                'while it should be "geometric" or "arithmetic"'):
            NormalizedAngleDistanceNbSetWeight(average_type='arithmetix', aa=1, bb=1)

        fake_nb_set.normalized_distances = [1.2632574171572457, 1.1231971151388764, 1.0,
                                            1.1887986376446249, 1.188805134890625]
        fake_nb_set.normalized_angles = [0.6026448601336767, 0.8498933334305273, 1.0,
                                         0.7355039801931018, 0.7354996568248028]
        w1 = nadw1.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w1, 0.67310887189488189, delta=1e-8)
        w2 = nadw2.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w2, 0.69422258996523023, delta=1e-8)
        w3 = nadw3.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w3, 0.8700949310182079, delta=1e-8)
        w4 = nadw4.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w4, 0.7847083661164217, delta=1e-8)
        w5 = nadw5.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w5, 0.96148050989126843, delta=1e-8)
        w6 = nadw6.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w6, 0.98621181678741754, delta=1e-8)
        w7 = nadw7.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w7, 0.97479580875402994, delta=1e-8)
        w8 = nadw8.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w8, 0.63348507114489783, delta=1e-8)
        w9 = nadw9.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w9, 0.7668954450583646, delta=1e-8)
        w10 = nadw10.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w10, 0.51313920014833292, delta=1e-8)
        w11 = nadw11.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w11, 0.585668617459, delta=1e-8)
        w12 = nadw12.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w12, 0.520719679281, delta=1e-8)
Пример #3
0
    def test_strategies(self):
        simplest_strategy_1 = SimplestChemenvStrategy()
        simplest_strategy_2 = SimplestChemenvStrategy(distance_cutoff=1.5,
                                                      angle_cutoff=0.5)
        self.assertFalse(simplest_strategy_1 == simplest_strategy_2)
        simplest_strategy_1_from_dict = SimplestChemenvStrategy.from_dict(
            simplest_strategy_1.as_dict())
        self.assertTrue(simplest_strategy_1, simplest_strategy_1_from_dict)

        effective_csm_estimator = {
            "function": "power2_inverse_decreasing",
            "options": {
                "max_csm": 8.0
            },
        }
        self_csm_weight = SelfCSMNbSetWeight()
        surface_definition = {
            "type": "standard_elliptic",
            "distance_bounds": {
                "lower": 1.1,
                "upper": 1.9
            },
            "angle_bounds": {
                "lower": 0.1,
                "upper": 0.9
            },
        }
        surface_definition_2 = {
            "type": "standard_elliptic",
            "distance_bounds": {
                "lower": 1.1,
                "upper": 1.9
            },
            "angle_bounds": {
                "lower": 0.1,
                "upper": 0.95
            },
        }
        da_area_weight = DistanceAngleAreaNbSetWeight(
            weight_type="has_intersection",
            surface_definition=surface_definition,
            nb_sets_from_hints="fallback_to_source",
            other_nb_sets="0_weight",
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB,
        )
        da_area_weight_2 = DistanceAngleAreaNbSetWeight(
            weight_type="has_intersection",
            surface_definition=surface_definition_2,
            nb_sets_from_hints="fallback_to_source",
            other_nb_sets="0_weight",
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB,
        )
        weight_estimator = {
            "function": "smootherstep",
            "options": {
                "delta_csm_min": 0.5,
                "delta_csm_max": 3.0
            },
        }
        symmetry_measure_type = "csm_wcs_ctwcc"
        delta_weight = DeltaCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator,
            weight_estimator=weight_estimator,
            symmetry_measure_type=symmetry_measure_type,
        )
        bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0,
                                                             weight_cn13=4.0)
        bias_weight_2 = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0,
                                                               weight_cn13=5.0)
        angle_weight = AngleNbSetWeight()
        nad_weight = NormalizedAngleDistanceNbSetWeight(
            average_type="geometric", aa=1, bb=1)
        multi_weights_strategy_1 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type,
        )
        multi_weights_strategy_2 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight_2,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type,
        )
        multi_weights_strategy_3 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight_2,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type,
        )
        multi_weights_strategy_1_from_dict = MultiWeightsChemenvStrategy.from_dict(
            multi_weights_strategy_1.as_dict())

        self.assertTrue(
            multi_weights_strategy_1 == multi_weights_strategy_1_from_dict)
        self.assertFalse(simplest_strategy_1 == multi_weights_strategy_1)
        self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_2)
        self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_3)
        self.assertFalse(multi_weights_strategy_2 == multi_weights_strategy_3)
Пример #4
0
    def test_normalized_angle_distance_weight(self):
        fake_nb_set = FakeNbSet()
        dummy_se = DummyStructureEnvironments()

        nadw1 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=1, bb=1)
        nadw2 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=1, bb=1)
        nadw3 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=0, bb=1)
        nadw4 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=1, bb=0)
        nadw5 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0.1, bb=0.1)
        nadw6 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=0.1)
        nadw7 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0.1, bb=0)
        nadw8 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=2, bb=0)
        nadw9 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=2)
        nadw10 = NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=2, bb=2)
        nadw11 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=1, bb=2)
        nadw12 = NormalizedAngleDistanceNbSetWeight(average_type='geometric', aa=2, bb=1)
        self.assertNotEqual(nadw11, nadw12)
        with self.assertRaisesRegex(ValueError, 'Both exponents are 0.'):
            NormalizedAngleDistanceNbSetWeight(average_type='arithmetic', aa=0, bb=0)
        with self.assertRaisesRegex(ValueError, 'Average type is "arithmetix" '
                                                'while it should be "geometric" or "arithmetic"'):
            NormalizedAngleDistanceNbSetWeight(average_type='arithmetix', aa=1, bb=1)

        fake_nb_set.normalized_distances = [1.2632574171572457, 1.1231971151388764, 1.0,
                                            1.1887986376446249, 1.188805134890625]
        fake_nb_set.normalized_angles = [0.6026448601336767, 0.8498933334305273, 1.0,
                                         0.7355039801931018, 0.7354996568248028]
        w1 = nadw1.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w1, 0.67310887189488189, delta=1e-8)
        w2 = nadw2.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w2, 0.69422258996523023, delta=1e-8)
        w3 = nadw3.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w3, 0.8700949310182079, delta=1e-8)
        w4 = nadw4.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w4, 0.7847083661164217, delta=1e-8)
        w5 = nadw5.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w5, 0.96148050989126843, delta=1e-8)
        w6 = nadw6.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w6, 0.98621181678741754, delta=1e-8)
        w7 = nadw7.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w7, 0.97479580875402994, delta=1e-8)
        w8 = nadw8.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w8, 0.63348507114489783, delta=1e-8)
        w9 = nadw9.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w9, 0.7668954450583646, delta=1e-8)
        w10 = nadw10.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w10, 0.51313920014833292, delta=1e-8)
        w11 = nadw11.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w11, 0.585668617459, delta=1e-8)
        w12 = nadw12.weight(nb_set=fake_nb_set, structure_environments=dummy_se)
        self.assertAlmostEqual(w12, 0.520719679281, delta=1e-8)
    def get_weights(self, weights_options):
        effective_csm_estimator = {
            'function': 'power2_inverse_decreasing',
            'options': {
                'max_csm': 8.0
            }
        }

        self_weight_estimator = {
            'function': 'power2_decreasing_exp',
            'options': {
                'max_csm': 5.4230949041608305,
                'alpha': 1.0
            }
        }

        self_csm_weight = SelfCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator,
            weight_estimator=self_weight_estimator)

        surface_definition = {
            'type': 'standard_elliptic',
            'distance_bounds': {
                'lower': 1.05,
                'upper': 2.0
            },
            'angle_bounds': {
                'lower': 0.05,
                'upper': 0.95
            }
        }

        da_area_weight = DistanceAngleAreaNbSetWeight(
            weight_type='has_intersection',
            surface_definition=surface_definition,
            nb_sets_from_hints='fallback_to_source',
            other_nb_sets='0_weight',
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB)

        weight_estimator = {
            'function': 'smootherstep',
            'options': {
                'delta_csm_min': 0.5,
                'delta_csm_max': 3.0
            }
        }

        symmetry_measure_type = 'csm_wcs_ctwcc'
        delta_csm_weight = DeltaCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator,
            weight_estimator=weight_estimator,
            symmetry_measure_type=symmetry_measure_type)

        bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0,
                                                             weight_cn13=4.0)
        angle_weight = AngleNbSetWeight()

        nad_weight = NormalizedAngleDistanceNbSetWeight(
            average_type='geometric', aa=1, bb=1)

        weights = {
            'DistAngArea': da_area_weight,
            'SelfCSM': self_csm_weight,
            'DeltaCSM': delta_csm_weight,
            'CNBias': bias_weight,
            'Angle': angle_weight,
            'NormalizedAngDist': nad_weight
        }

        return weights
Пример #6
0
    def test_strategies(self):
        simplest_strategy_1 = SimplestChemenvStrategy()
        simplest_strategy_2 = SimplestChemenvStrategy(distance_cutoff=1.5,
                                                      angle_cutoff=0.5)
        self.assertFalse(simplest_strategy_1 == simplest_strategy_2)
        simplest_strategy_1_from_dict = SimplestChemenvStrategy.from_dict(
            simplest_strategy_1.as_dict())
        self.assertTrue(simplest_strategy_1, simplest_strategy_1_from_dict)

        effective_csm_estimator = {
            'function': 'power2_inverse_decreasing',
            'options': {
                'max_csm': 8.0
            }
        }
        self_csm_weight = SelfCSMNbSetWeight()
        surface_definition = {
            'type': 'standard_elliptic',
            'distance_bounds': {
                'lower': 1.1,
                'upper': 1.9
            },
            'angle_bounds': {
                'lower': 0.1,
                'upper': 0.9
            }
        }
        surface_definition_2 = {
            'type': 'standard_elliptic',
            'distance_bounds': {
                'lower': 1.1,
                'upper': 1.9
            },
            'angle_bounds': {
                'lower': 0.1,
                'upper': 0.95
            }
        }
        da_area_weight = DistanceAngleAreaNbSetWeight(
            weight_type='has_intersection',
            surface_definition=surface_definition,
            nb_sets_from_hints='fallback_to_source',
            other_nb_sets='0_weight',
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB)
        da_area_weight_2 = DistanceAngleAreaNbSetWeight(
            weight_type='has_intersection',
            surface_definition=surface_definition_2,
            nb_sets_from_hints='fallback_to_source',
            other_nb_sets='0_weight',
            additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB)
        weight_estimator = {
            'function': 'smootherstep',
            'options': {
                'delta_csm_min': 0.5,
                'delta_csm_max': 3.0
            }
        }
        symmetry_measure_type = 'csm_wcs_ctwcc'
        delta_weight = DeltaCSMNbSetWeight(
            effective_csm_estimator=effective_csm_estimator,
            weight_estimator=weight_estimator,
            symmetry_measure_type=symmetry_measure_type)
        bias_weight = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0,
                                                             weight_cn13=4.0)
        bias_weight_2 = CNBiasNbSetWeight.linearly_equidistant(weight_cn1=1.0,
                                                               weight_cn13=5.0)
        angle_weight = AngleNbSetWeight()
        nad_weight = NormalizedAngleDistanceNbSetWeight(
            average_type='geometric', aa=1, bb=1)
        multi_weights_strategy_1 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type)
        multi_weights_strategy_2 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight_2,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type)
        multi_weights_strategy_3 = MultiWeightsChemenvStrategy(
            dist_ang_area_weight=da_area_weight_2,
            self_csm_weight=self_csm_weight,
            delta_csm_weight=delta_weight,
            cn_bias_weight=bias_weight,
            angle_weight=angle_weight,
            normalized_angle_distance_weight=nad_weight,
            symmetry_measure_type=symmetry_measure_type)
        multi_weights_strategy_1_from_dict = MultiWeightsChemenvStrategy.from_dict(
            multi_weights_strategy_1.as_dict())

        self.assertTrue(
            multi_weights_strategy_1 == multi_weights_strategy_1_from_dict)
        self.assertFalse(simplest_strategy_1 == multi_weights_strategy_1)
        self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_2)
        self.assertFalse(multi_weights_strategy_1 == multi_weights_strategy_3)
        self.assertFalse(multi_weights_strategy_2 == multi_weights_strategy_3)