forked from angrysky56/Essan-AI-symbolic-language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEssan Symbol Chain Evolution GA Use
More file actions
84 lines (70 loc) · 4.66 KB
/
Copy pathEssan Symbol Chain Evolution GA Use
File metadata and controls
84 lines (70 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
To use the script effectively, here’s a step-by-step guide:
### Purpose of the Script
The script you've provided is an evolutionary algorithm that operates on symbol chains (represented by unique characters such as `⧈`, `⧬`, etc.) to optimize their fitness for specific tasks. Each symbol has a predefined set of associated keywords, and the script uses these to evaluate how well a particular symbol chain meets the requirements of a task description.
This script attempts to:
1. Generate an initial population of symbol chains.
2. Evolve them over generations using selection, crossover, and mutation.
3. Select the fittest symbol chain based on its fitness score, which is computed according to how well it aligns with specific task descriptions.
### Requirements for Using the Script
1. **Dependencies**: The script relies on several Python packages:
- **SpaCy** for Natural Language Processing.
- **NLTK** for working with word synonyms.
- **Matplotlib** and **NumPy** for visualizing the results.
- Make sure to have these installed, or run:
```sh
pip install spacy nltk matplotlib numpy
python -m spacy download en_core_web_lg
```
2. **Dataset**: You don't need a traditional dataset. Instead, you provide the "task descriptions" in the `tasks` dictionary in the script. Each task is associated with a "modified task" and a set of weights. These tasks serve as the objectives against which the symbol chains will be optimized.
3. **Task Descriptions**: The tasks dictionary at the end of the script specifies:
```python
tasks = {
"Analyze sales data.": (
"Analyze revised sales data.",
{"accuracy": 0.4, "efficiency": 0.3, "adaptability": 0.15, "recursion": 0.05, "user_satisfaction": 0.1}
),
...
}
```
Here, `"Analyze sales data."` is the original task description, `"Analyze revised sales data."` is the modified task, and the dictionary specifies how important different criteria are for evaluating the fitness of a symbol chain.
### Steps to Use the Script
1. **Define the Tasks**:
- You can modify the `tasks` dictionary to include new tasks or change the existing ones.
- The weights (`"accuracy"`, `"efficiency"`, etc.) are used to prioritize different fitness metrics for each task.
2. **Run the Script**:
- Run the script in Python as a standalone program. It will print out results for each task, including the parameters used for evolution and the corresponding best fitness value.
- At the end of the script, the `experiment` function runs the genetic algorithm for different combinations of parameters (e.g., population size, number of generations, mutation rates).
3. **Understand the Output**:
- The script will print the best fitness for each parameter combination and task.
- It will generate plots to visualize the relationships between different parameters and the average fitness scores.
4. **Modify the Population Settings** (Optional):
- You can adjust `population_sizes`, `num_generations`, and `mutation_rates` in the script to explore different parameter combinations.
- These settings influence how the genetic algorithm evolves the symbol chains and can significantly impact performance.
5. **Run Experiment**:
- You will see output similar to this:
```
Processing task: Analyze sales data.
Parameters: (50, 50, 0.05), Best Fitness: 0.7890
...
```
This indicates the parameter settings used (`population_size`, `generations`, `mutation_rate`) and the resulting fitness.
6. **Visualizations**:
- The script will plot graphs for different parameters (`Population Size`, `Number of Generations`, `Mutation Rate`) against the average fitness.
- It will also generate a heatmap showing average fitness values for combinations of population size and mutation rate.
### Examples for Running the Script
- If you want to add your own task:
```python
tasks["Optimize supply chain"] = (
"Optimize production and logistics",
{"accuracy": 0.3, "efficiency": 0.2, "adaptability": 0.3, "recursion": 0.1, "user_satisfaction": 0.1}
)
```
- After adding tasks, simply run the script again:
```sh
python essan_ga_v02.py
```
### Summary
- **Input**: You provide task descriptions.
- **Output**: The script will print and plot results showing how well different symbol chains evolve to meet task requirements.
- **Experiment**: Adjust the parameters (population, generations, mutation rate) to see how they affect the evolution and optimization process.
This script is well-suited for experimenting with evolutionary approaches to symbol chains. If you have additional ideas or need more specific guidance on setting up the task objectives, let me know!