Merge implems - #5
Conversation
Summary of ChangesHello @VincentAuriau, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a foundational framework for simulating complex decision-making processes and subsequently inferring the underlying utility functions. It introduces new capabilities for generating diverse synthetic datasets, significantly enhances the core logic for modeling decision-makers with a more flexible utility function representation, and integrates powerful optimization tools to estimate these utility functions from the generated data. These changes collectively improve the system's ability to model and analyze decision-making behaviors. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces significant changes, including a new implementation for data generation, a refactoring of the DecisionMaker class to use piecewise linear utility functions, and new Gurobi-based models for fitting UTA parameters. While the changes add important functionality, I've found several critical issues that need to be addressed. There are potential ZeroDivisionError exceptions in python/decision_maker.py and python/distances.py, and a NameError in python/distances.py that will cause a crash. Additionally, there's a likely logic bug in python/data_generation.py. I've also noted opportunities to improve maintainability by addressing significant code duplication and use of mutable default arguments. Please review the detailed comments for suggestions on how to fix these issues.
| dv = du - u_j + self.break_point_y[criterion_j][i+1] | ||
| return i+1 - (dv / self.slopes[criterion_j][i]) | ||
| dv = marginal_utility_difference_i - marginal_utility_value_j + max_bp_value | ||
| return self.breakpoints_x[break_point] + (dv / (max_bp_value - min_bp_value)) * (self.breakpoints_x[break_point+1] - self.breakpoints_x[break_point]) |
There was a problem hiding this comment.
|
|
||
| if sample_weight is not None: | ||
| self.solver.setObjective( | ||
| gp.quicksum(sigma_err[i] * sample_weight[i] for i in range(n_samples)), |
There was a problem hiding this comment.
| for i in range(self.n_pieces): | ||
| if inflexions_x[i] <= val <= inflexions_x[i + 1]: | ||
| return coeffs[i] + ( | ||
| (val - inflexions_x[i]) / (inflexions_x[i + 1] - inflexions_x[i]) |
There was a problem hiding this comment.
The term (inflexions_x[i + 1] - inflexions_x[i]) could be zero, which would cause a ZeroDivisionError. Although _determine_inflexions attempts to handle cases where the min and max values are equal, it's still possible for a segment to have zero length with certain data distributions or due to floating-point inaccuracies. Please add a check to prevent division by zero. This issue is present in multiple places where this calculation is performed (e.g., lines 189, 365, 517, 655).
| return i + dv / self.slopes[criterion_j][i] | ||
| dv = - marginal_utility_difference_i + marginal_utility_value_j - min_bp_value | ||
|
|
||
| return self.breakpoints_x[break_point] + dv / (max_bp_value - min_bp_value) * (self.breakpoints_x[break_point+1] - self.breakpoints_x[break_point]) |
| x = np.around( | ||
| np.random.uniform(0, 1, self.n_criteria), decimals=self.decimals | ||
| ) | ||
| ux = np.around(self.utility(x), decimals=self.decimals)[0] |
There was a problem hiding this comment.
The utility ux is always calculated for the first decision maker ([0]) instead of the current one in the loop (i). This is likely a bug. It should use [i] to be consistent with the logic for uy on line 155.
| ux = np.around(self.utility(x), decimals=self.decimals)[0] | |
| ux = np.around(self.utility(x), decimals=self.decimals)[i] |
| # Useless now that we have clusters | ||
| populations = [0] * self.n_dms | ||
| if not isinstance(num_pairs, list): | ||
| num_pairs = [np.ceil(num_pairs / self.n_dms)] * self.n_dms |
There was a problem hiding this comment.
There are a couple of issues here:
- The comment on line 53, "Useless now that we have clusters", is misleading as
populationsis used later in the method. It should be updated or removed. - On line 56,
num_pairsis calculated usingnp.ceil, which results in a list of floats. It's safer to convert these to integers using.astype(int)as done ingenerate_indifference_dataon line 129 to avoid potential issues.
| # Useless now that we have clusters | |
| populations = [0] * self.n_dms | |
| if not isinstance(num_pairs, list): | |
| num_pairs = [np.ceil(num_pairs / self.n_dms)] * self.n_dms | |
| # The `populations` list tracks the number of pairs generated for each DM cluster. | |
| populations = [0] * self.n_dms | |
| if not isinstance(num_pairs, list): | |
| num_pairs = np.array([np.ceil(num_pairs / self.n_dms)] * self.n_dms).astype(int) |
| self.min, self.max, self.inflexions = self._determine_inflexions(X, Y) | ||
|
|
||
| if verbose == 0: | ||
| self.solver.params.outputflag = 0 # mode muet |
There was a problem hiding this comment.
This comment is in French, while the rest of the codebase is in English. For consistency, it's better to use a single language for all comments. For example, 'silent mode'. This applies to other French comments in this file as well (e.g., line 179).
| self.solver.params.outputflag = 0 # mode muet | |
| self.solver.params.outputflag = 0 # silent mode |
| print("Optimize") | ||
| self.solver.optimize() | ||
| self.status = self.solver.Status | ||
| print(self.status) |
| """for k, v in estimate_x.items(): | ||
| estimate_x[k] = v.x | ||
| for k, v in estimate_y.items(): | ||
| estimate_y[k] = v.x | ||
|
|
||
| return estimate_x, estimate_y""" |
| ### ### | ||
| # Add Renormalization here # | ||
| ### ### No newline at end of file |
There was a problem hiding this comment.
This comment block appears to be a placeholder for future implementation. It would be more effective to replace it with a TODO comment explaining what needs to be done, or to create a ticket in your issue tracker.
| ### ### | |
| # Add Renormalization here # | |
| ### ### | |
| # TODO: Add Renormalization here |
No description provided.