Skip to content
Snippets Groups Projects
Commit 11f380b1 authored by Fabian Peter's avatar Fabian Peter
Browse files

Merge branch 'main' into 'branch-2'

# Conflicts:
#   data/raw/likelihood/subcategories_likelihood_example.json
parents 0d043f44 3eff326f
No related branches found
No related tags found
1 merge request!1Added likelihoods and sources for a good amount of subcategories
# Itmds
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.informatik.uni-bremen.de/benzinab/itmds.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.informatik.uni-bremen.de/benzinab/itmds/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
# Synthetic Citizen Data Generator
This python project generates and visualizes synthetic datasets of citizens based on actions obtained from the Chinese Credit System and their likelihood (based on German statistics).
## Project Structure
The project consists of the following structure:
- `data`
- `processed`
- `raw`
- `actions` (contains actions that could be taken by citizens in different formats)
- `actions.json`
- `converted_actions.json`
- `example_actions.json`
- `likelihood` (contains the likelihood of each action to be taken)
- `action_likelihoods.rtf`
- `subcategories_likelihood_example.json`
- `src` (contains the source code of the project)
- `data_processing` (contains classes to generate synthetic citizen data based on actions and their likelihood)
- `__init__.py`
- `citizen_data_generator.py`
- `data_statistics` (contains classes to visualize the data generated)
- `__init__.py`
- `categories_visualizer.py`
- `citizen_data_visualizer.py`
- `utils` (contains helper classes)
- `__init__.py`
- `actions_converter.py`
- `__init__.py`
- `main.py` (the main class of the program)
## Running the Program
The program can be run by executing the `main.py` file located in the `src` folder.
## Requirements
- Python 3.6 or higher
- Additional library requirements can be found in the `requirements.txt` file.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
If you have any questions or issues with the program, please open an issue on the GitHub repository or contact the developer directly.
......@@ -53,18 +53,18 @@
"Geld aufheben und nicht verstecken": 0.01,
"Sozialethik": 0.01,
"Dorfmanagement": 0.01,
"Persönliche Integrität": 0.01,
"Soziales Gut (im Laufe des Jahres aufgelaufen oder umgewandelt)": 0.01,
"Soziales Gut": 0.01,
"Management der wichtigsten Bevölkerungsgruppen": 0.01,
"Arbeit im Zentrum": 0.01,
"Persönliche Integrität": 0.09,
"Soziales Gut (im Laufe des Jahres aufgelaufen oder umgewandelt)": 0.09,
"Soziales Gut": 0.08,
"Management der wichtigsten Bevölkerungsgruppen": 0.09,
"Arbeit im Zentrum": 0.17,
"Anerkennungspreise": 0.08,
"Eintritt in die Armee (Auszeichnungen für Einzelpersonen und Eltern)": 0.01,
"Nationale Beamte Schätzung": 0.01,
"Investitionsförderung": 0.01,
"Eintritt in die Armee (Auszeichnungen für Einzelpersonen und Eltern)": 0.2,
"Nationale Beamte Schätzung": 0.05,
"Investitionsförderung": 0.09,
"Kulturelle und sportliche Aktivitäten": 0.01,
"Gemeinnützige Spenden, Soziales (im Laufe des Jahres abgegrenzt oder abgezinst)": 0.01,
"Mit Integrität arbeiten": 0.08,
"Mit Integrität arbeiten": 0.18,
"Verwaltung": 0.01,
"Verwaltungsrechtliche Sanktionen (öffentliche Sicherheit)": 0.01,
"Verwaltungssanktionen (Brandbekämpfung)": 0.000203522,
......
......@@ -17,6 +17,7 @@ classifications = {
class CitizenDataGenerator:
def __init__(self):
self.criteria = self.init_criteria()
self.classifications = classifications
def init_criteria(self):
# Load the actions from the JSON file
......@@ -36,7 +37,7 @@ class CitizenDataGenerator:
# Check if the regular expression matched any numeric characters
if rating:
try:
likelihood = (100 + abs(rating)) / 200 * subcategory_likelihoods[
likelihood = (abs(rating) - 1) / 100 * subcategory_likelihoods[
subcategory["name"]]
except KeyError:
likelihood = 0
......@@ -47,17 +48,12 @@ class CitizenDataGenerator:
return criteria
# Define a function that applies a random action to a given citizen
def apply_random_action(self, citizen):
def apply_action(self, citizen):
# Select an action based on the likelihood
likelihoods = [c["likelihood"] for c in self.criteria]
normalizing_factor = sum(likelihoods)
normalized_likelihoods = [likelihood / normalizing_factor for likelihood in likelihoods]
action_index = np.random.choice(len(self.criteria), p=normalized_likelihoods)
action = self.criteria[action_index]
action = self.select_action()
# Apply the action to the citizen
citizen['credit_score'] += int(action["rating"])
# Meke sure that the credit score is between 0 and 1030
# Make sure that the credit score is between 0 and 1030
citizen['credit_score'] = np.clip(citizen['credit_score'], 0, 1030)
# Add the action to the citizen's history
......@@ -69,6 +65,31 @@ class CitizenDataGenerator:
citizen["classification"] = classification
break
def select_action(self):
"""
Randomly select an action from a list of criteria based on their likelihoods.
The method first initializes a list, cumulative_likelihoods, with the first element being the likelihood of
the first criteria in the criteria list. It then iterates through the rest of the criteria, adding the
current action's likelihood to the previous cumulative likelihood and appending it to the
cumulative_likelihoods list. A random number between 0 and 1 is then generated using the random.random()
method. The method then iterates through the cumulative_likelihoods list and compares the random number with
each likelihood. If the random number is less than the current likelihood, the corresponding criteria is
chosen as the action and the loop breaks. The chosen action is then returned.
"""
cumulative_likelihoods = [self.criteria[0]["likelihood"]]
for i in range(1, len(self.criteria)):
cumulative_likelihoods.append(cumulative_likelihoods[i - 1] + self.criteria[i]["likelihood"])
random_number = random.random()
chosen_action = None
for i, likelihood in enumerate(cumulative_likelihoods):
if random_number < likelihood:
chosen_action = self.criteria[i]
break
return chosen_action
# Define the main function that generates synthetic data for a sample of citizens
def generate_synthetic_data(self, n_citizens, max_actions):
# Initialize a list of citizens with 100 credit score and classification "A"
......@@ -77,8 +98,7 @@ class CitizenDataGenerator:
for citizen in citizens:
n_actions = random.randint(1, max_actions)
for _ in range(n_actions):
self.apply_random_action(citizen)
self.apply_action(citizen)
# Return the list of citizens with updated credit scores, applied actions, and classifications
return citizens
......@@ -90,7 +110,7 @@ def convert_string(string):
if match:
# Extract the numbers from the match object and return the average
num1, num2 = int(match.group(1)), int(match.group(2))
return (num1+num2) / 2
return (num1 + num2) / 2
else:
# If the string is not in the "bis" format, return the single number
return int(string)
......@@ -2,7 +2,7 @@ from src.data_processing.citizen_data_generator import CitizenDataGenerator
from src.data_statistics.citizen_data_visualizer import CitizenDataVisualizer
data_generator = CitizenDataGenerator()
citizens = data_generator.generate_synthetic_data(100, 100)
citizens = data_generator.generate_synthetic_data(100, 50)
data_visualizer = CitizenDataVisualizer(citizens)
data_visualizer.print_data_frame()
data_visualizer.display_classification_bar()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment