DiCE icon indicating copy to clipboard operation
DiCE copied to clipboard

proximity loss when there are not continous features

Open DBrughmans opened this issue 3 years ago • 4 comments

the method compute_proximity_loss() from dice_genetic.py returns an error when the dataset does not contain continous features.

    def compute_proximity_loss(self, x_hat_unnormalized, query_instance_normalized):
        """Compute weighted distance between two vectors."""
        x_hat = self.data_interface.normalize_data(x_hat_unnormalized)
        feature_weights = np.array(
            [self.feature_weights_list[0][i] for i in self.data_interface.continuous_feature_indexes])
        product = np.multiply(
            (abs(x_hat - query_instance_normalized)[:, [self.data_interface.continuous_feature_indexes]]),
            feature_weights)
        product = product.reshape(-1, product.shape[-1])
        proximity_loss = np.sum(product, axis=1)


        # Dividing by the sum of feature weights to normalize proximity loss
        return proximity_loss / sum(feature_weights)

DBrughmans avatar Mar 25 '22 13:03 DBrughmans

@DBrughmans, can you paste the error or the stack trace here?

gaugup avatar Mar 25 '22 19:03 gaugup

@DBrughmans can you paste the error or the stack trace here so that we can make progress on this issue?

gaugup avatar Apr 07 '22 20:04 gaugup

@gaugup I have the error message when setting all the variables as str to make it categorical: " 367 (abs(x_hat - query_instance_normalized)[:, [self.data_interface.continuous_feature_indexes]]), 368 feature_weights) --> 369 product = product.reshape(-1, product.shape[-1]) 370 proximity_loss = np.sum(product, axis=1) 371

ValueError: cannot reshape array of size 0 into shape (0) "

Bora-ds avatar Jun 20 '22 07:06 Bora-ds

I have the same error

Leinadj avatar Nov 04 '22 15:11 Leinadj