the following function works only with values in [0, 1] and basically do an OR operation…
- User
the following function works only with values in [0, 1] and basically do an OR operation among the columns of the matrix called "and_rules". How can i make it works without unbounded values ? def disjunction_rule(self, and_rules: torch.Tensor) -> torch.Tensor: # Compute the disjunction (OR) function # and_rules is a tensor of shape [batch_size, n_rules], i.e. and_rules.shape[0] == batch_size, and_rules.shape[1] == n_rules expr = 1 - and_rules + self.epsilon log_expr = torch.log(expr) sum_log_expr = torch.sum(log_expr, dim=1) res = 1 - (-1.0 / (-1.0 + sum_log_expr)) return res
- Assistant
To make your
disjunction_rulefunction work with unbounded input values, you need to map these unbounded values into the ([0, 1]) interval before applying the OR-like operation. This is because the original function relies on the inputs being within ([0, 1]), as it computes a product of terms like ((1 - \text{input}_j)), which only makes sense for inputs in that range.You can achieve this mapping by applying a sigmoid function to your unbounded inputs, which will squash them into the ([0, 1]) interval. Then, you can adjust your function to correctly compute the OR operation over the probabilities derived from these inputs. Here's how you can modify your function: