Skip to content

Commit f356875

Browse files
committed
Created using Colaboratory
1 parent cf16462 commit f356875

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

Genetic_Algorithm_Assignment.ipynb

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,18 @@
3535
"colab_type": "text"
3636
},
3737
"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",
4847
"\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"
6150
]
6251
},
6352
{
@@ -89,7 +78,7 @@
8978
}
9079
},
9180
"source": [
92-
"#access to google drive\n",
81+
"#Access to google drive. The Video Store dataset was uploaded to google drive.\n",
9382
"from google.colab import drive\n",
9483
"drive.mount('/content/gdrive')"
9584
],
@@ -112,7 +101,7 @@
112101
"colab": {}
113102
},
114103
"source": [
115-
"#load dataset to a dataframe\n",
104+
"#The dataset is load dataset to a dataframe\n",
116105
"df = pd.read_csv('/content/gdrive/My Drive/Genetic Algorithms/Assignment 01/dataset.csv')"
117106
],
118107
"execution_count": 0,
@@ -265,7 +254,8 @@
265254
"colab_type": "text"
266255
},
267256
"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."
269259
]
270260
},
271261
{
@@ -278,10 +268,9 @@
278268
"source": [
279269
"# function for init population\n",
280270
"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",
283272
" values ={\n",
284-
" 'chromosome':chrom,\n",
273+
" 'chromosome':[i for i in range(1,popSize+1)],\n",
285274
" 'file 1':[random.randint(0, 1) for _ in range(popSize)],\n",
286275
" 'file 2':[random.randint(0, 1) for _ in range(popSize)],\n",
287276
" 'file 3':[random.randint(0, 1) for _ in range(popSize)],\n",
@@ -293,7 +282,11 @@
293282
" 'file 9':[random.randint(0, 1) for _ in range(popSize)],\n",
294283
" 'file 10':[random.randint(0, 1) for _ in range(popSize)],\n",
295284
" }\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"
297290
],
298291
"execution_count": 0,
299292
"outputs": []

0 commit comments

Comments
 (0)