|
35 | 35 | "colab_type": "text" |
36 | 36 | }, |
37 | 37 | "source": [ |
38 | | - "### **Debug Process**" |
39 | | - ] |
40 | | - }, |
41 | | - { |
42 | | - "cell_type": "markdown", |
43 | | - "metadata": { |
44 | | - "id": "q4o89dgjjjXb", |
45 | | - "colab_type": "text" |
46 | | - }, |
47 | | - "source": [ |
| 38 | + "## **Table of Contents**\n", |
| 39 | + "\n", |
| 40 | + "---\n", |
| 41 | + "\n", |
| 42 | + "\n", |
| 43 | + "1. **Importing Libraries**\n", |
| 44 | + "2. **Access to Google Drive**\n", |
| 45 | + "3.**Function Definitions**\n", |
| 46 | + "4. **Running the Model**\n", |
48 | 47 | "\n", |
49 | | - "1. Check algorithm structure is available. Each phase\n", |
50 | | - "\t1. Create Population\n", |
51 | | - "\t2. Evaluate Fitness of Each Chromosome in the Population\n", |
52 | | - "\t3. Create New Population by :\n", |
53 | | - "\t\t1. Select 2 Parents\n", |
54 | | - "\t\t2. Crossover\n", |
55 | | - "\t\t3. Mutate\n", |
56 | | - "\t\t4. Replace to the Population\n", |
57 | | - "\t4. Test if End condition is satisified\n", |
58 | | - "\t5. If Yes,end otherwise iterate with the new Population\n", |
59 | | - "\t\n", |
60 | | - "2. Functionality of each section\n" |
| 48 | + "\n", |
| 49 | + "\n" |
61 | 50 | ] |
62 | 51 | }, |
63 | 52 | { |
|
89 | 78 | } |
90 | 79 | }, |
91 | 80 | "source": [ |
92 | | - "#access to google drive\n", |
| 81 | + "#Access to google drive. The Video Store dataset was uploaded to google drive.\n", |
93 | 82 | "from google.colab import drive\n", |
94 | 83 | "drive.mount('/content/gdrive')" |
95 | 84 | ], |
|
112 | 101 | "colab": {} |
113 | 102 | }, |
114 | 103 | "source": [ |
115 | | - "#load dataset to a dataframe\n", |
| 104 | + "#The dataset is load dataset to a dataframe\n", |
116 | 105 | "df = pd.read_csv('/content/gdrive/My Drive/Genetic Algorithms/Assignment 01/dataset.csv')" |
117 | 106 | ], |
118 | 107 | "execution_count": 0, |
|
265 | 254 | "colab_type": "text" |
266 | 255 | }, |
267 | 256 | "source": [ |
268 | | - "### **Population Creation Function**" |
| 257 | + "### **Population Creation Function**\n", |
| 258 | + "A dataframe which consists of the entire population is returned when this function is called. The structure would be of 1 column to label the chromosome number and the remaining 10 columns will represent the file number of the dataset. The returned dataframe (population) will consist of random 0 or 1 values in the chromosome." |
269 | 259 | ] |
270 | 260 | }, |
271 | 261 | { |
|
278 | 268 | "source": [ |
279 | 269 | "# function for init population\n", |
280 | 270 | "def createInitPop(popSize):\n", |
281 | | - " chrom = [i for i in range(1,popSize+1)]\n", |
282 | | - " #emp = [0 for i in range(0,popSize)]\n", |
| 271 | + " #array of data to represent the chromosomes and random file labellings\n", |
283 | 272 | " values ={\n", |
284 | | - " 'chromosome':chrom,\n", |
| 273 | + " 'chromosome':[i for i in range(1,popSize+1)],\n", |
285 | 274 | " 'file 1':[random.randint(0, 1) for _ in range(popSize)],\n", |
286 | 275 | " 'file 2':[random.randint(0, 1) for _ in range(popSize)],\n", |
287 | 276 | " 'file 3':[random.randint(0, 1) for _ in range(popSize)],\n", |
|
293 | 282 | " 'file 9':[random.randint(0, 1) for _ in range(popSize)],\n", |
294 | 283 | " 'file 10':[random.randint(0, 1) for _ in range(popSize)],\n", |
295 | 284 | " }\n", |
296 | | - " return pd.DataFrame(values) " |
| 285 | + " #convert the array of population to a dataframe\n", |
| 286 | + " values = pd.DataFrame(values)\n", |
| 287 | + " \n", |
| 288 | + " #return the dataframe\n", |
| 289 | + " return values" |
297 | 290 | ], |
298 | 291 | "execution_count": 0, |
299 | 292 | "outputs": [] |
|
0 commit comments