growingspheres/growingspheres.py
def generate_inside_spheres(self, center, segment, n, feature_variance=None):
        """
        Args:
            "center" corresponds to the target instance to explain
            Segment corresponds to the size of the hypersphere
            n corresponds to the number of instances generated
            feature_variance: Array of variance for each continuous feature
        """
        def norm(v):
            v= np.linalg.norm(v, ord=2, axis=1)
            return v
            
        #def perturb_continuous_features(continuous_features, n, segment, center, matrix_perturb_instances):
        """
            Perturb each continuous features of the n instances around center in the area of a sphere of radius equals to segment
            Return a matrix of n instances of d dimension perturbed based on the distribution of the dataset
            """
        """
            d = len(continuous_features)
            z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            to_add = np.zeros((n, len(center)))
            for continuous in continuous_features:
                to_add[:,continuous] = center[continuous]
            z = z + to_add[:,continuous_features]
            for nb, continuous in enumerate(continuous_features):
                matrix_perturb_instances[:,continuous] = z[:,nb].ravel()
            return matrix_perturb_instances
        """

        # Just for clarity of display
        d = center.shape[0]
        """z = np.zeros((n,d))
        if feature_variance is not None:
            for feature in range(d):
                # Modify the generation of artificial instance depending on the variance of each feature
                z[:,feature] = np.random.normal(0, feature_variance[feature], n)
        else:
            z = np.random.normal(0, 1, (n, d))"""
        z = np.random.normal(0, 1, (n, d))
        # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
        u = np.random.uniform(segment[0]**d, segment[1]**d, n)
        r = u**(1/float(d))
        z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
        z = z + center
        return z
        """if self.categorical_features != []:
            matrix_perturb_instances = np.zeros((n, len(center)))
            for i in range(len(self.categorical_features)):
                # add for each categorical feature these values to be considered as a probability 
                matrix_perturb_instances[:, self.categorical_features[i]] = center[self.categorical_features[i]]
            matrix_perturb_instances = perturb_continuous_features(self.continuous_features, n, segment, center, matrix_perturb_instances)
            return matrix_perturb_instances       
        else:
            # Just for clarity of display
            d = center.shape[0]
            z = np.zeros((n,d))
            if feature_variance is not None:
                for feature in range(d):
                    # Modify the generation of artificial instance depending on the variance of each feature
                    z[:,feature] = np.random.normal(0, feature_variance[feature], n)
            else:
                z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            z = z + center
            return z"""

        Args:
            "center" corresponds to the target instance to explain
            Segment corresponds to the size of the hypersphere
            n corresponds to the number of instances generated
            feature_variance: Array of variance for each continuous feature
        
"center" corresponds to the target instance to explain
Segment corresponds to the size of the hypersphere
n corresponds to the number of instances generated
feature_variance: Array of variance for each continuous feature
" center " corresponds to the target instance to explain Segment corresponds to the size of the hypersphere n corresponds to the number of instances generated feature_variance : Array of variance for each continuous feature
def generate_inside_spheres(self, center, segment, n, feature_variance=None):
        def norm(v):
            v= np.linalg.norm(v, ord=2, axis=1)
            return v
        d = center.shape[0]
        z = np.random.normal(0, 1, (n, d))
        u = np.random.uniform(segment[0]**d, segment[1]**d, n)
        r = u**(1/float(d))
        z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
        z = z + center
        return z
        """if self.categorical_features != []:
            matrix_perturb_instances = np.zeros((n, len(center)))
            for i in range(len(self.categorical_features)):
                # add for each categorical feature these values to be considered as a probability 
                matrix_perturb_instances[:, self.categorical_features[i]] = center[self.categorical_features[i]]
            matrix_perturb_instances = perturb_continuous_features(self.continuous_features, n, segment, center, matrix_perturb_instances)
            return matrix_perturb_instances       
        else:
            d = center.shape[0]
            z = np.zeros((n,d))
            if feature_variance is not None:
                for feature in range(d):
                    # Modify the generation of artificial instance depending on the variance of each feature
                    z[:,feature] = np.random.normal(0, feature_variance[feature], n)
            else:
                z = np.random.normal(0, 1, (n, d))
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            z = z + center
            return z"""
def generate_inside_spheres ( self , center , segment , n , feature_variance = None ) : def norm ( v ) : v = np . linalg . norm ( v , ord = 2 , axis = 1 ) return v """
            Perturb each continuous features of the n instances around center in the area of a sphere of radius equals to segment
            Return a matrix of n instances of d dimension perturbed based on the distribution of the dataset
            """ """
            d = len(continuous_features)
            z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            to_add = np.zeros((n, len(center)))
            for continuous in continuous_features:
                to_add[:,continuous] = center[continuous]
            z = z + to_add[:,continuous_features]
            for nb, continuous in enumerate(continuous_features):
                matrix_perturb_instances[:,continuous] = z[:,nb].ravel()
            return matrix_perturb_instances
        """ d = center . shape [ 0 ] """z = np.zeros((n,d))
        if feature_variance is not None:
            for feature in range(d):
                # Modify the generation of artificial instance depending on the variance of each feature
                z[:,feature] = np.random.normal(0, feature_variance[feature], n)
        else:
            z = np.random.normal(0, 1, (n, d))""" z = np . random . normal ( 0 , 1 , ( n , d ) ) u = np . random . uniform ( segment [ 0 ] ** d , segment [ 1 ] ** d , n ) r = u ** ( 1 / float ( d ) ) z = np . array ( [ a * b / c for a , b , c in zip ( z , r , norm ( z ) ) ] ) z = z + center return z """if self.categorical_features != []:
            matrix_perturb_instances = np.zeros((n, len(center)))
            for i in range(len(self.categorical_features)):
                # add for each categorical feature these values to be considered as a probability 
                matrix_perturb_instances[:, self.categorical_features[i]] = center[self.categorical_features[i]]
            matrix_perturb_instances = perturb_continuous_features(self.continuous_features, n, segment, center, matrix_perturb_instances)
            return matrix_perturb_instances       
        else:
            # Just for clarity of display
            d = center.shape[0]
            z = np.zeros((n,d))
            if feature_variance is not None:
                for feature in range(d):
                    # Modify the generation of artificial instance depending on the variance of each feature
                    z[:,feature] = np.random.normal(0, feature_variance[feature], n)
            else:
                z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            z = z + center
            return z"""
Args:
"center" corresponds to the target instance to explain
Segment corresponds to the size of the hypersphere
n corresponds to the number of instances generated
feature_variance: Array of variance for each continuous feature
Args : " center " corresponds to the target instance to explain Segment corresponds to the size of the hypersphere n corresponds to the number of instances generated feature_variance : Array of variance for each continuous feature
"""
        Args:
            "center" corresponds to the target instance to explain
            Segment corresponds to the size of the hypersphere
            n corresponds to the number of instances generated
            feature_variance: Array of variance for each continuous feature
        """ #def perturb_continuous_features(continuous_features, n, segment, center, matrix_perturb_instances): """
            Perturb each continuous features of the n instances around center in the area of a sphere of radius equals to segment
            Return a matrix of n instances of d dimension perturbed based on the distribution of the dataset
            """ """
            d = len(continuous_features)
            z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            to_add = np.zeros((n, len(center)))
            for continuous in continuous_features:
                to_add[:,continuous] = center[continuous]
            z = z + to_add[:,continuous_features]
            for nb, continuous in enumerate(continuous_features):
                matrix_perturb_instances[:,continuous] = z[:,nb].ravel()
            return matrix_perturb_instances
        """ # Just for clarity of display """z = np.zeros((n,d))
        if feature_variance is not None:
            for feature in range(d):
                # Modify the generation of artificial instance depending on the variance of each feature
                z[:,feature] = np.random.normal(0, feature_variance[feature], n)
        else:
            z = np.random.normal(0, 1, (n, d))""" # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain """if self.categorical_features != []:
            matrix_perturb_instances = np.zeros((n, len(center)))
            for i in range(len(self.categorical_features)):
                # add for each categorical feature these values to be considered as a probability 
                matrix_perturb_instances[:, self.categorical_features[i]] = center[self.categorical_features[i]]
            matrix_perturb_instances = perturb_continuous_features(self.continuous_features, n, segment, center, matrix_perturb_instances)
            return matrix_perturb_instances       
        else:
            # Just for clarity of display
            d = center.shape[0]
            z = np.zeros((n,d))
            if feature_variance is not None:
                for feature in range(d):
                    # Modify the generation of artificial instance depending on the variance of each feature
                    z[:,feature] = np.random.normal(0, feature_variance[feature], n)
            else:
                z = np.random.normal(0, 1, (n, d))
            # Draw uniformaly instances between the value of segment[0]**d and segment[1]**d with d the number of dimension of the instance to explain
            u = np.random.uniform(segment[0]**d, segment[1]**d, n)
            r = u**(1/float(d))
            z = np.array([a * b / c for a, b, c in zip(z, r,  norm(z))])
            z = z + center
            return z"""
self
center
segment
n
feature_variance